Skip to content
File upload Write-up Beginner

Bypassing File Upload Whitelists to Achieve RCE

The article describes a file upload whitelist that only checks the filename extension as a string, so an attacker can append a null byte and a permitted extension to a PHP filename. The server then truncates the name at the null byte and executes the uploaded file as PHP, achieving remote code execution.

medium.com

Published on medium.com

You used a Whitelist to prevent Remote Code Execution? Sorry… RCE is still possible 🙂

Yehya Hamdy Shehata, 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 validation and the file handling disagree about where the filename ends, because the check reads the whole string while the server stops at a null byte.

Impact

The uploaded file is executed as PHP, which the article presents as remote code execution; it does not discuss any defence that limited the attack.

What the attacker needed

An upload feature that checks extensions only; a server that truncates filenames at a null byte; the upload directory allows script execution

The fix

The article says uploads should be secured by renaming files on the server, validating MIME types correctly, disabling execution permissions in upload directories and not relying on extensions alone.

How it was found

  1. Upload a file whose name contains a PHP extension, a null byte and an allowed image extension.
  2. The validation sees the allowed image extension and permits the upload.
  3. The server stops reading the filename at the null byte and saves the file with the PHP extension.
  4. Request the uploaded file so the server executes it as PHP.

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 whitelist is a list of allowed file extensions, such as .jpg and .png. The article says the check looks at the filename as text, but the server later treats a null byte as the end of the name. So a name that looks like an image to the check can become a PHP script when the server saves it, and the attacker can run code on the server.

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.