XXD Server

Description

I wrote a little app that allows you to hex dump files over the internet.

Author: hashkitten

Application: https://web-xxd-server-2680de9c070f.2023.ductf.devarrow-up-right Downloads: xxd_server.ziparrow-up-right

Analysis

The application allows you to upload files and view them as hexdump.

There's interesting rule in .htaccess

# Everything not a PHP file, should be served as text/plain
<FilesMatch "\.(?!(php)$)([^.]*)$">
    ForceType text/plain
</FilesMatch>

So we are allowed to upload PHP scripts and get RCE. But there's limitation:

if (isset($_FILES['file-upload'])) {
	$upload_dir = 'uploads/' . bin2hex(random_bytes(8));
	$upload_path = $upload_dir . '/' . basename($_FILES['file-upload']['name']);
	mkdir($upload_dir);
	$upload_contents = xxd(file_get_contents($_FILES['file-upload']['tmp_name']));
	if (file_put_contents($upload_path, $upload_contents)) {
		$message = 'Your file has been uploaded. Click <a href="' . htmlspecialchars($upload_path) . '">here</a> to view';
	} else {
	    $message = 'File upload failed.';
	}
}

When we upload file it's placed into random folder, contents is converted to hexdump and served. If we upload php script it's not going to work due to hexdump. We still can get RCE, but we are limited to 16 characters due to hexdump.

If you try to uplaod file with contents <?= phpinfo() ?> (16 characters), you'll get phpinfo page, this means we need to build payload using only 16 character per line.

xxd-server-1arrow-up-right

Solution

Remove newlines:

Output:

circle-check

Last updated