Skip to content
File upload Write-up Beginner

Bypassing Content-Type Restrictions to Upload Web Shells

The upload feature trusted the client-supplied Content-Type header to decide whether a file was an image, so a PHP script labelled as an image was accepted. An attacker could upload a web shell and read a secret file from the server.

medium.com

Published on medium.com

I started the lab by clicking on Access the Lab button & itredirected me to the Blogs page like showed below;

Sumit Tiwari, 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 server validated the upload only by the client-controlled Content-Type header rather than by inspecting the file's actual content or extension.

Impact

An attacker with an account could upload and execute server-side code, reading files the web server can access.

What the attacker needed

A free account; upload feature available

How it was found

  1. Log in to the lab with the provided account.
  2. Find the file upload feature on the account page.
  3. Try to upload a PHP script and observe the Content-Type rejection.
  4. Change the request's Content-Type to image/jpeg and upload the same script.
  5. Open the uploaded file in a new tab to trigger it and read 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 website let people upload pictures, and it decided what kind of file something was by reading a label the browser sends along with the file. The author changed that label from 'this is a PHP script' to 'this is a JPEG image', and the site believed it and stored the script. When the script was opened, the server ran it and printed out a private file.

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.