Skip to content
File upload Write-up Intermediate

Unrestricted File Upload

A discussion forum's image upload feature checked file extensions on both the client and server side, but only at the initial upload stage. An attacker could upload a PHP file by first submitting it as an image, then changing the extension to .PHP before publishing, potentially leading to server-side code execution.

Binamra Pandey Follow

Published on binamrapandey.medium.com

I was testing on a website let’s call it “buggyweb.xyz”. After some time I found that there was a discussion forum which URL was something like this “discussion.buggyweb.xyz”.

Binamra Pandey, on binamrapandey.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 application validated the file extension only during the initial upload request and not again when the file was published, allowing the extension to be changed after validation.

Impact

An attacker could upload a PHP file to the server, which could lead to remote code execution if the file is executed.

What the attacker needed

Access to the discussion forum; ability to intercept HTTP requests

How it was found

  1. Find the file upload feature on the discussion forum.
  2. Try uploading a .php file and observe it is rejected due to whitelisting.
  3. Upload a valid image file and capture the request in Burp Suite.
  4. Change the file content to PHP code and forward the request.
  5. Before publishing, intercept the request again and change the file extension to .PHP.
  6. Forward the request and the file is uploaded successfully.

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 lets users send files to a website. The site tried to block dangerous file types like PHP scripts by checking the file's ending (extension) in two places. However, the check only happened when the file was first uploaded, not when it was later published, so the attacker could sneak a PHP file through by changing its name at the last moment.

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.

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.