Double Extension and Null Byte Injection
What you'll learn: How attackers manipulate filenames with double extensions and null bytes to bypass file upload filters and execute malicious code.
When applications check uploaded files, they often look at the file extension to decide if it's safe. Attackers exploit weaknesses in how servers parse these filenames to slip dangerous files past the guards.
Double Extension Attack
Imagine a filter that only checks the last extension in a filename. An attacker uploads malicious.php.jpg. The filter sees .jpg at the end and thinks "image file, safe!" But the web server might process it differently—some servers read extensions from left to right or use the first recognized extension. When Apache (with certain configurations) sees malicious.php.jpg, it might execute it as PHP because it found .php first.
The trick: The attacker's web shell looks like an innocent image to the filter, but executes as code on the server.
Null Byte Injection
Think of a null byte (%00 or \x00) as a string terminator—it tells many programming languages "the string ends here, ignore everything after." If a vulnerable application appends .jpg to all uploads, an attacker can submit shell.php%00.jpg.
The application thinks it's storing shell.php%00.jpg (safe!), but when the underlying file system or older language interpreter processes it, the null byte acts like scissors—it cuts off .jpg and saves the file as just shell.php.
The result: The filter is bypassed, and executable code lands on the server.
How This Works Together
Both techniques exploit the gap between what the security filter thinks it's checking and what the server actually does with the filename. It's like telling a security guard "I'm delivering flowers.jpg" while hiding flowers.php underneath.
Key Takeaway: Double extensions and null byte injection exploit filename parsing inconsistencies between validation layers and execution environments—always validate file content, not just names, and use allowlists with strict parsing rules.