HackerOne CTF TempImage (Spoilers)
The landing page is sparse. It indicates the product is unregistered, and has a single link to an upload page:
The upload page is just one basic form element allowing the user to select and local file and submit it with the "Upload" button:
Upload
The HTML source of the upload page shows they're using PHP on the server, and a little bit of jquery on the client side to set the value of a hidden div. That's interesting:
<!doctype html>
<html>
<head>
<title>TempImage — Trial</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<h1>Upload</h1>
<form action="doUpload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="hidden" name="filename" id="filename">
<input type="submit" value="Upload">
</form>
<script>
$(document).ready(function() {
$('#file').change(function(e) {
$('#filename').val(e.target.files[0].name)
})
})
</script>
</body>
</html>
After uploading a PNG image, the file is available at the URL https://*.ctf.hacker101.com/files/364be8860e8d72b4358b5e88099a935a_test.png
, with the string "364be8860e8d72b4358b5e88099a935a_" prepended to the filename. The hidden field for the filename is interesting. I wonder if there's a way to exploit this? What about a path traversal against the hidden #filename
form field attribute name? With Caido it's super easy to replay the requests with changes to the POST data:
POST /doUpload.php HTTP/1.1
Host: *.ctf.hacker101.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
Content-Type: multipart/form-data; boundary=---------------------------10206805192242284186201372139
Content-Length: 408
Origin: https://*.ctf.hacker101.com
Connection: keep-alive
Referer: https://*.ctf.hacker101.com/upload.php
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=0, i
-----------------------------10206805192242284186201372139
Content-Disposition: form-data; name="file"; filename="test.png"
Content-Type: image/png
PNG