File Extension Filtering and Bypass Techniques
What you'll learn: How web applications filter file uploads by extension and the clever tricks attackers use to bypass those filters.
The Core Idea
File extension filtering is one of the most common defenses against malicious file uploads. Servers check the filename's extension (like .jpg, .pdf, or .php) and reject anything suspicious. For example, a server might block .php files to prevent web shell uploads.
However, extension filtering is notoriously weak because attackers have developed numerous bypass techniques to slip dangerous files past these checks.
How Extension Filtering Works
A basic implementation might look at the filename after the last dot:
photo.jpg→ Allowedshell.php→ Blocked
The server maintains either a blacklist (block dangerous extensions) or whitelist (allow only safe extensions). Blacklists are particularly vulnerable because attackers constantly find new ways around them.
Common Bypass Techniques
Double Extensions: Using names like shell.php.jpg tricks poorly-written filters that only check the final extension. The server might save it as executable .php depending on configuration.
Case Manipulation: Uploading shell.PhP or shell.pHp can bypass case-sensitive blacklists on certain systems.
Null Byte Injection: Inserting a null character (%00) like shell.php%00.jpg can truncate the filename at the null byte, causing the server to process only shell.php.
Appending Dots or Spaces: Some systems strip trailing characters, so shell.php. or shell.php becomes shell.php after processing.
Alternative Extensions: Using lesser-known executable extensions like .phtml, .php3, .php5, or .phar when only .php is blacklisted.
Defense Requires Depth
Extension filtering alone is insufficient. As you've learned, combining it with magic byte verification, Content-Type validation, and proper server configuration creates stronger protection.
Key Takeaway: File extension filtering is easily bypassed through double extensions, null bytes, case manipulation, and alternative extensions—never rely on it as your sole defense mechanism.