Guest Blog: From File Upload to RCE
An image upload feature validated the file's content type and header but not its extension, and the server set the response Content-Type from the extension. An attacker could upload a GIF containing PHP code with a .php extension, and the server would execute it, achieving remote code execution.
Published on synack.com
(Author’s Note: This vulnerability was found during testing on Synack. I have anonymized, altered, or removed all detail about the customer to keep this information confidential in line with Synack policies.)
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
The application validated the uploaded file's content type and header but did not restrict the file extension, and it derived the response Content-Type from the extension, allowing a PHP file to be served and executed.
Impact
An attacker could execute arbitrary code on the server, leading to full compromise.
What the attacker needed
Image upload functionality; server runs PHP; attacker can upload files
How it was found
- Upload a simple GIF image and download the result to compare transformations.
- Identify that the server clears EXIF data and resizes the image to 300x300.
- Recreate the transformations locally using ImageMagick and PHP to test.
- Find an unmodified space in the GIF file (a field of '00' values).
- Inject PHP code into that space by modifying hex values in Burp.
- Upload the modified GIF with a .php extension and trigger execution.
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 website let people upload pictures. It checked that the file looked like an image, but it did not check the file's name ending. The server then decided how to treat the file based on that ending. So a file that was a real image but also contained hidden computer code could be saved with a .php ending, and the server would run that code as a program.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.