$13,500 for a File That Was Two Things At Once: Polyglot Upload B
The upload validation checked file extension, content type, and image signature, but a polyglot GIF/PHP file passed all three because the PHP code was appended after the GIF terminator. A separate image reprocessing endpoint allowed the attacker to specify an output filename ending in .php, causing the server to write the same bytes with a PHP extension and execute them, leading to remote code execution.
The upload validation on this target wasn’t lazy. It checked the file extension, checked the declared content type, and inspected the actual file content for a valid image signature before accepting anything.
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 upload validation only checked for a valid image signature at the start of the file and did not reject trailing data, while the reprocessing endpoint allowed a client-specified output filename with a .php extension.
Impact
Full remote code execution on the application server, achievable by any user able to upload an image and invoke the image reprocessing feature.
What the attacker needed
A free account; ability to upload images; access to image reprocessing feature
The fix
The team deployed re-encoding-based upload sanitization and restricted the reprocessing endpoint's output extensions.
How it was found
- Send malformed uploads to map which validation layers exist (extension, content type, magic bytes).
- Build a polyglot file with a valid GIF header and appended PHP code, name it with a .gif extension.
- Upload the polyglot file; it passes all three validation checks.
- Use the image reprocessing endpoint, specifying an output filename ending in .php.
- Request the resulting .php file with a command parameter to confirm code 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 polyglot file is a single file that is valid in two different formats at once. Here, a file started with a valid GIF image header so image checks passed, but it also contained PHP code after the image data. A separate feature that reprocessed images let the attacker choose a .php output name, so the server saved the file as executable PHP and ran it.
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.