Basic Bypass Techniques

��️ Filter Evasion: Essential methods to bypass upload restrictions and execute malicious files

Overview

Upload filters come in two main types: blacklists (deny specific extensions) and whitelists (allow only specific extensions). Whitelists are generally more secure than blacklists, but both can be bypassed with proper techniques.

Use Cases:

  • Blacklist - File managers allowing wide variety of file types

  • Whitelist - Upload functionality with limited allowed file types

  • Combined - Both used in tandem for enhanced security


Whitelist Filters

🎯 More Secure: Only specified extensions are allowed, but still vulnerable to bypass techniques

Understanding Whitelist Validation

Example PHP Whitelist Test:

$fileName = basename($_FILES["uploadFile"]["name"]);

if (!preg_match('^.*\.(jpg|jpeg|png|gif)', $fileName)) {
    echo "Only images are allowed";
    die();
}

⚠️ Vulnerability: The regex only checks if the filename contains the extension, not if it ends with it.

Fuzzing Whitelisted Extensions

Test with extension wordlist:

Expected Response:


Double Extensions

πŸ”„ Classic Bypass: Add allowed extension while keeping malicious extension

Double Extension Technique

Concept: If .jpg is allowed, use shell.jpg.php to:

  1. Pass whitelist test - contains .jpg extension

  2. Execute as PHP - ends with .php extension

Implementation:

Burp Suite Request:

Testing Execution:

Strict Regex Patterns

More Secure Implementation:

This pattern blocks: shell.jpg.php (doesn't end with image extension)


Reverse Double Extension

πŸ”„ Server Misconfiguration: Exploit web server configuration weaknesses

Web Server Configuration Vulnerability

Apache PHP Configuration (`/etc/apache2/mods-enabled/php7.4.conf`):

⚠️ Vulnerability: Missing `$` at the end allows any file containing PHP extensions to execute.

Reverse Double Extension Attack

Technique: Use `shell.php.jpg` to:

  1. Pass strict whitelist - ends with `.jpg`

  2. Execute as PHP - contains `.php` in filename

Implementation:

Burp Suite Request:

Testing Execution:


Character Injection

πŸ’‰ Advanced Bypass: Inject special characters to manipulate filename interpretation

Character Injection Techniques

Injectable Characters:

  • `%20` - Space character

  • `%0a` - Line Feed (LF)

  • `%00` - Null byte (PHP ≀ 5.X)

  • `%0d0a` - Carriage Return + Line Feed (CRLF)

  • `/` - Forward slash

  • `.\` - Backslash with dot

  • `.` - Dot

  • `…` - Horizontal ellipsis

  • `:` - Colon (Windows)

Null Byte Injection

Classic PHP ≀ 5.X Bypass:

Windows Colon Injection

Windows-specific bypass:

Character Injection Wordlist Generator

Automated Permutation Script:

Enhanced Script with More Extensions:

Burp Suite Fuzzing Setup

Intruder Configuration:

  1. Intercept upload request

  2. Set payload position in filename

  3. Load character injection wordlist

  4. Disable URL encoding in payload processing

  5. Run attack and analyze responses

Payload Position:


HTB Academy Lab Solution

Lab Information

  • Objective: Bypass blacklist and whitelist to upload PHP script

  • Target: Read `/flag.txt` using uploaded shell

  • Techniques: Double extensions, character injection

Step-by-Step Walkthrough

Step 1: Reconnaissance

Step 2: Double Extension Bypass

Step 3: Upload Web Shell

Step 4: Execute Commands

Step 5: Alternative Methods (if needed)

Expected Flag Format


Bypass Methodology

Systematic Testing Approach

1. Baseline Testing:

2. Double Extension Testing:

3. Reverse Double Extension:

4. Character Injection:

5. Web Server Specific:

Response Analysis

Success Indicators:

  • HTTP 200 status code

  • Upload confirmation message

  • File accessible via direct URL

  • Command execution works

Failure Indicators:

  • HTTP 403/406 status codes

  • "Only images allowed" messages

  • File not accessible

  • No command execution

Tools for Testing

Burp Suite Intruder:

  • Load bypass wordlists

  • Disable URL encoding

  • Analyze response patterns

  • Filter successful uploads

Custom Fuzzing Scripts:

This comprehensive guide covers all essential bypass techniques for defeating upload filters, providing both theoretical understanding and practical implementation methods for successful exploitation.

Last updated