Courses

Bypassing File Upload Restrictions and File Extension Filters
OSWE · Chapter 11

Bypassing File Upload Restrictions and File Extension Filters

File upload functionality is a frequent path to remote code execution when an attacker can upload a server-side executable script (e.g. a `.php` webshell) and then have the server execute it — bypassing weak or purely client-side extension checks.

Key concepts

  • Never trust a client-supplied `Content-Type` header — it is trivially spoofed and must not be the only validation performed.
  • Extension allow-lists (not deny-lists) plus validating actual file content/signature (magic bytes) are the strongest combination of checks.
  • Classic bypasses: double extensions (`shell.php.jpg`), null-byte truncation (`shell.php%00.jpg`), and case variation on filesystems that treat extensions case-insensitively.
  • Even with strict validation, store uploads outside the webroot (or in a location with no script execution permission) so that even a successfully uploaded malicious file cannot be directly executed.

Example

# Classic double-extension bypass attempt against a weak filter (lab only)
curl -F "file=@shell.php.jpg" https://target/upload

Try it yourself

On a lab file-upload challenge, try bypassing an extension filter using a double extension or a null-byte trick, then confirm whether the server actually executes the uploaded file when you request it directly.

@ Daniel Burlacu