File Upload
Insecure file upload occurs when an application accepts file uploads without proper validation of type, content, or destination. Attackers can upload webshells, abuse allowed extensions or content types, or combine upload with XXE to read or execute code.
Process
- Identify the web technologies used (e.g. PHP).
- Brute-force a command page like
index.<EXT>using/usr/share/wordlists/seclists/Discovery/Web-Content/web-extensions.txt. - Browser addon: https://www.wappalyzer.com/
- Brute-force a command page like
- Check for client- and server-side validation and filtering.
- Intercept file submission with a web proxy and test modifications of:
- Filename extensions in the request body
Content-Typeheaders
- Disable client-side validation (e.g. via proxy or DevTools: delete or modify the validation functions).
- Bypass server-side validation:
- Fuzz file extensions (e.g.
.php7,.phtml, or mixed case.pHP) via Intruder. Untick “URL Encoding” so the dot is not encoded. - Try double extensions such as
.jpgFUZZorFUZZ.jpg. - Use
ffuf -od reqswith a minimal “Hello World” payload for the target tech to see which extension actually executes.
- Fuzz file extensions (e.g.
Content-Type for Uploads
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
multipart/form-datafor filesapplication/x-www-form-urlencodedfor simple POST data
Fuzz the request body’s Content-Type (not the HTTP header).
NOTE: Uncheck the URL-encode option in the proxy (e.g. Intruder) so the payload is sent literally.
Magic Bytes
| File Type | Magic Bytes (Hex) | ASCII Representation |
|---|---|---|
| GIF | 47 49 46 38 39 61 or 47 49 46 38 37 61 | GIF8, GIF89a or GIF87a |
| JPG | FF D8 FF E0 (standard) | ÿØÿà |
| PNG | 89 50 4E 47 0D 0A 1A 0A | .PNG.... |
Magic bytes are the first bytes inside the file (not metadata or extension) that identify the file type. Prepending valid magic bytes can help bypass content checks while keeping executable content (e.g. PHP) after them.
Character Injection
This approach uses character workarounds that can bypass validation on some (especially older) PHP versions.
Files with XXE (via local file reads)
SVG, PDF, Word, PowerPoint, and other formats that parse XML can execute or expose data via embedded XXE. If the upload is processed as XML, check Page Source for reflected data that may not be shown in the rendered page.
Read File
Read PHP
NOTE: The response may need to be base64-decoded. This assumes the PHP filter wrapper is available.
To read server configs or PHP without executing them:
Simple Webshell
Append PHP code to the SVG payload so the uploaded file both triggers the XXE and contains the webshell.