Skip to content
File upload Write-up Intermediate

File Upload Vulnerabilities Part-6 : Remote code execution via p

The image upload feature validated the file header but not metadata, allowing a PHP payload hidden in the Comment field of a JPEG to be executed. An attacker could upload such a polyglot file and run server-side code to read the secret file.

Ahmad Sopyan Follow

Published on medium.com

In my journey to learn web application security, I realized that loopholes in the file upload feature are often the entry point for serious attacks.

Ahmad Sopyan, on medium.com

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 validator only checked the file header and extension, not the metadata, and the server executed PHP in files with a .php extension even if they were valid images.

Impact

An attacker could execute arbitrary server-side code and read sensitive files, leading to remote code execution.

What the attacker needed

A free account; victim clicks a link

The fix

Validate file content on the server side, use a whitelist of allowed formats, store uploads outside executable directories, and disable script execution in the upload folder.

How it was found

  1. Log in and go to the image upload feature.
  2. Try uploading a .php file and observe the rejection.
  3. Use ExifTool to embed a PHP payload in the Comment field of a valid JPEG and save it as polyglot.php.
  4. Upload the polyglot.php file successfully.
  5. Open the uploaded file via its URL to execute the PHP and retrieve the secret.

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 web server can be tricked into running a file as a program if the file looks like an image but contains hidden code. Here, the upload check only looked at the start of the file, so code placed in the image's comment section was still executed when the file was opened.

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.

More by Ahmad Sopyan

View all

3 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.