Skip to content
File upload Write-up Intermediate

From File Upload to Remote Code Execution (RCE)

An image upload feature checked content type and file content but allowed arbitrary file extensions, and the server's image transformation left some bytes unmodified. An attacker could upload a GIF containing PHP code with a .php extension, and the server would execute it, achieving remote code execution.

medium.com

Published on medium.com

This vulnerability was discovered during testing on the Synack platform and later shared on Synack’s blog. This is the remastered article.

Lukasz Wierzbicki, 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 validation checked content type and image content but did not restrict the file extension, and the image transformation preserved some bytes, allowing executable code to remain.

Impact

An attacker could execute arbitrary code on the server, leading to full compromise.

What the attacker needed

Ability to upload an image file; server uses PHP and ImageMagick; server allows arbitrary file extensions

The fix

The upload feature should validate file extensions in addition to content type and content, and store uploaded files in non-executable directories.

How it was found

  1. Upload a simple one-colour GIF and download the transformed version to compare.
  2. Replicate the server's transformations locally using ImageMagick and PHP.
  3. Identify an unmodified section of the GIF file filled with zero bytes.
  4. Insert PHP code into that unmodified section using a hex editor.
  5. Upload the modified GIF with a .php extension and trigger 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.

The website let people upload pictures, and it checked that the file looked like an image. But it did not stop the file from being saved with a .php extension, which tells the server to run it as a program. The author hid some PHP code inside the image data that the server's resizing step did not change, so when the file was run, the hidden code executed.

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.