How a Verbose Error Message Led Me to RCE Through a File Upload
A file upload feature passed the user-supplied filename into a shell command, so a crafted filename could run arbitrary commands on the server. The tester confirmed command execution and read system files, though a webshell could not be served because of the web server configuration.
medium.com
Published on medium.com
File uploads are a common feature in web applications — and also a common target during penetration testing. In this case, the real issue wasn’t the upload functionality itself, but how the server handled errors and used the uploaded file name.
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 application concatenated the user-controlled upload filename into a shell command without escaping or sanitising it, and returned verbose errors that disclosed the command.
Impact
An attacker could run arbitrary commands on the server and read files such as the system password file, but serving a PHP webshell was blocked by the web server configuration.
What the attacker needed
Ability to upload a file; no authentication stated
The fix
The report recommends avoiding user input in shell commands, using native libraries, strictly sanitising filenames, limiting error verbosity and running services with low privileges; it does not say the issue was fixed.
How it was found
- Upload a malformed file with valid magic bytes to trigger a verbose error.
- Read the error to learn the server-side command and that the filename is randomised but keeps its extension.
- Upload a file whose name appends a command after the extension to confirm execution.
- Try commands containing a forward slash and observe errors related to sed.
- Base64-encode the command and pipe output through base64 to work around the slash and single-line limits.
- Attempt to write a PHP webshell and find it is not served because of the web server configuration.
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.
When a program builds a command for the operating system by gluing text together, any text the user controls can become part of that command. Here the uploaded file's name was placed inside a shell command, so adding special characters let the tester run their own commands. The server also showed detailed error messages that revealed the command, which helped the tester understand the setup.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.