The Accidental RCE: How a Simple File Upload Led to Remote Code
A file upload feature accepted a file with a double extension and then executed the PHP code inside it when the file was accessed via its URL. An attacker could run system commands and read sensitive files on the server.
Published on cybersecuritywriteups.com
Imagine uploading what seems like a harmless image, only to gain full control over a web server. Sounds like a hacker’s dream, right?
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 server validated only the file extension and stored uploaded files in a web-accessible directory where they could be executed.
What the attacker needed
Ability to upload a file; server executes uploaded files
The fix
The vulnerability was fixed by the company after responsible disclosure.
How it was found
- Check that the site only allows .jpg, .png, and .gif extensions.
- Try renaming a .php file to .jpg and observe that the backend rejects it.
- Notice that uploaded files are stored in an uploads directory and accessible via direct URL.
- Rename the payload file to have a double extension (.php.jpg) and upload it.
- Access the uploaded file via its URL and observe that the server executes the PHP code.
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.
A file upload feature let people send pictures, but the server did not properly check what kind of file it was. By naming a malicious file with two extensions, the attacker tricked the server into running it as a program, giving them control over 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.