Skip to content
File upload Write-up Intermediate

From Testing File Uploads to Discovering Remote Code Execution (R

An invoice upload endpoint accepted a PHP file while every other upload feature rejected it, and the file was stored in a web-accessible directory that executed PHP. An attacker could upload a script and run arbitrary code on the server.

Hussein Kteish Follow

Published on medium.com

During my first professional web and mobile application penetration test, one of the areas I focused on was file upload functionality. Upload features are often overlooked during development, yet they remain one of the most common sources of critical vulnerabilities.

Hussein Kteish, 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

The invoice upload endpoint was implemented separately and lacked the extension validation, non-executable storage and non-predictable path used by the other upload features.

Impact

An attacker could execute arbitrary PHP code on the server, potentially reading sensitive files and credentials, compromising the database and establishing persistent access.

What the attacker needed

Access to the invoice upload feature; a completed payment flow

The fix

The same upload validation should be applied to every endpoint, with approved extensions only, content and MIME checks, randomised file names, storage outside the web root and script execution disabled in upload directories.

How it was found

  1. Review every upload feature in the web and mobile applications and try server-side script files against each one.
  2. Find an additional invoice upload feature in the mobile app that had not been tested.
  3. Upload a PHP file to the invoice endpoint and observe that it is accepted without a validation error.
  4. Intercept the upload and note the returned file URL, which does not execute when opened.
  5. Enumerate directories and common upload paths to find the real storage location.
  6. Open the file at the discovered storage path and observe that the PHP code executes.

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 should only accept safe files like images. Here one upload form let a person send a program file, and the server later ran that program instead of just storing it. That let the tester run their own code on the server, which is called remote code execution.

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.