How I Got Full RCE (And Accidentally Skipped Two Flags Doing It)�
An upload form used a user-supplied filename as a disk path, allowing path traversal to write files into the webroot. Because the extension blacklist only blocked .php, an attacker could upload a .phtml file containing PHP code and execute commands as the web server user.
Published on medium.com
Bare bones app. Upload form with two fields: a text input called filename, and an actual file input called upload.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the filename field was used directly as a filesystem path without sanitising traversal sequences, and the upload filter used a blacklist of one extension instead of an allowlist.
Impact
An attacker could execute arbitrary commands on the server as the web server user, and in this case read all challenge flag files directly.
What the attacker needed
Access to the upload form; no authentication required
How it was found
- Upload a normal image and observe two filename fields in the multipart request.
- Put a path traversal string in the filename text field and see a permission error for deep traversal.
- Use a single-level traversal filename and confirm the file lands in the webroot.
- Try a .php filename and get blocked by an extension check.
- Upload a .phtml file with PHP code and see it execute.
- Replace the payload with a command runner and run commands as the web server user.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The upload form let the user choose the name of the saved file, and it did not stop names like '../file' that move the file into a different folder. The site also tried to block dangerous PHP files by checking only for the exact ending '.php', so a file ending in '.phtml' slipped through and the server ran it as code. That let the attacker run commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.