File Upload Vulnerabilities: From Webshell to RCE
Unrestricted file upload is one of the most reliable paths from anonymous access to remote code execution. The vulnerability requires three things to align: (1) the server accepts a file with an executable extension, (2) the file is stored inside the webroot or a path the application later executes, and (3) the server can be coerced into executing it. Defenses fail at any of these three points.
Web applications · By Thimmagurudu Bathini · Published · 7 min read · Last reviewed
Extension check failures
The most common failure is client-side or blacklist-based extension validation. Bypasses testers use:
- Case variations —
.PhP,.PHP3,.phtml,.phar - Double extensions —
shell.jpg.php,shell.php.jpgwith ApacheAddHandlermisconfig - Null bytes —
shell.php%00.jpgon older PHP/CGI stacks - Trailing dots and spaces —
shell.php.,shell.phpon Windows - Polyglot files — valid GIF/JPG header plus PHP/JSP code in metadata or after the image data
Content-type and magic-byte checks
Both are bypassable. Content-Type comes from the client. Magic bytes can be prepended to almost any payload. The only reliable signal is the actual file contents, parsed by a hardened library that rejects anything unexpected.
Path traversal in stored filenames
If the uploaded filename is used unsanitized, ../../../var/www/html/shell.php can land anywhere. Combine with an SVG that contains JavaScript and you have stored XSS at minimum.
Defenses that actually work
- Allowlist extensions (not blacklist) — explicitly list the four or five you accept
- Store uploads outside the webroot, serve them through an application proxy that sets Content-Disposition
- Rename every upload to a server-generated UUID — never trust the client filename
- For images, re-encode through a hardened library (Pillow, Sharp); for documents, render to PDF and discard the original
- Set
X-Content-Type-Options: nosniffon serving responses
Written by Thimmagurudu Bathini, BERRY9 IT SERVICES PRIVATE LIMITED, Hyderabad. Questions about your own systems? Request a scoping call or call +91 86868 92922.
Plan your next security test
Tell us what needs testing and when you need it done, and we will propose a scope and timeline. We respond within 24 hours. If you would rather talk first, call or write to us.
- +91 86868 92922
- contact@berry9.com
- H.No: 8-3-945/A/12 & 13, Sri Venkata Sai Nest Apartments, Nagarjuna Nagar Colony, Yellareddyguda, Hyderabad 500073, Telangana