File Upload Vulnerabilities Explained: How a Profile Picture Becomes a Shell


Almost every website lets users upload files — profile pictures, documents, attachments. And almost every major web breach involving a file upload started the same way: the server trusted the file, and the file was a lie. Here is how the bug works and how to defend against it.

How a File Upload Becomes a Shell

When you upload a profile picture, the server saves the file and later serves it back. If the server does not properly check what was uploaded, an attacker can upload a script instead of an image — for example, a PHP file disguised as a photo. When the server executes that file, the attacker gets a web shell: a backdoor that runs commands on the server.

The Classic Bypasses Hunters Test

Developers usually add checks, and attackers test whether each check can be fooled. On your own applications and in authorized testing, these are the patterns to understand:

  • Extension checks. If the app only blocks .php, try .php5, .phtml, .phar, or .php.jpg. Some servers execute files based on the last extension, others on the first — that mismatch is the bug.
  • MIME type checks. The browser sends a Content-Type header with the upload. Changing it from image/jpeg to image/png is trivial — if the server trusts the header instead of inspecting the file, the check is useless.
  • Magic byte checks. Real image files start with specific bytes (JPEG starts with FF D8 FF). Attackers prepend those bytes to a script, so the file looks like an image to a naive checker but still executes as code.
  • Double extensions and null bytes. Old-school tricks like shell.php%00.jpg relied on the server stopping at the null byte while the filesystem saw .php. Modern frameworks fixed most of these — but legacy code still falls for them.
  • Filename tricks. Path traversal inside a filename (../../shell.php) can place the file somewhere the attacker controls, or overwrite an existing file.

How to Test It (Legally)

In a bug bounty program, file upload features are prime targets — but only inside the program’s scope. A typical test flow on your own lab or an in-scope target:

  1. Upload a harmless text file with a .php extension and see if it is accepted.
  2. Upload a real image, then rename it to .php and re-upload.
  3. Check where the file lands and whether the URL is predictable.
  4. If the file is stored but not executed, test whether its content is served with a dangerous content type.

Never upload a real shell to a target you do not own — even “just to prove it” crosses the line from testing into unauthorized access.

How Developers Stop It

  • Allowlist, never blocklist. Accept only specific extensions (.jpg, .png) instead of blocking known-bad ones. New dangerous extensions appear constantly.
  • Verify content, not headers. Inspect the actual file bytes server-side, and re-encode images through a library so any hidden script is destroyed.
  • Store uploads outside the web root. If the file can never be reached by a URL, it can never be executed by a request.
  • Randomize filenames. A random name with no extension the server executes removes the attacker’s ability to call the file.
  • Serve uploads from a separate domain. A different origin means even a successful upload cannot run scripts in your site’s context.
  • Set the right headers. Content-Disposition: attachment and X-Content-Type-Options: nosniff stop browsers from guessing a file is executable.

Why This Bug Keeps Paying

File upload vulnerabilities are a bug bounty classic because the impact is enormous — a working upload bypass often means full server compromise — and the fix is easy to get wrong. A single missed extension or a content check that trusts the client is all it takes.

Learn to spot it in your own code, and you will find it in other people’s too — legally, and for a payout.

Only test systems you own or have written permission to test.

Comments

Popular Posts