Bypassing Blacklisted Commands

🎭 Command Obfuscation: Techniques to disguise commands and bypass word-based filters

Overview

We have discussed various methods for bypassing single-character filters. However, there are different methods when it comes to bypassing blacklisted commands. A command blacklist usually consists of a set of words, and if we can obfuscate our commands and make them look different, we may be able to bypass the filters.

There are various methods of command obfuscation that vary in complexity. We will cover basic techniques that may enable us to change the look of our command to bypass filters manually.


Understanding Command Blacklists

Basic Command Blacklist Filter

A basic command blacklist filter in PHP would look like the following:

$blacklist = ['whoami', 'cat', 'ls', 'id', 'pwd', ...];
foreach ($blacklist as $word) {
    if (strpos($_POST['ip'], $word) !== false) {
        echo "Invalid input";
    }
}

Key Points:

  • Checks for exact matches of blacklisted words

  • Case-sensitive in most implementations

  • Can be bypassed through obfuscation techniques

  • May also block common file paths like /etc/passwd

Testing for Command Blacklists

After successfully bypassing character filters, test if commands are blacklisted:

This indicates a command-based filter is active.


Cross-Platform Obfuscation Techniques

Quote Injection (Linux & Windows)

πŸ”— Universal Method: Works on both Bash and PowerShell

Single Quotes:

Double Quotes:

Important Rules:

  • βœ… Even number of quotes required

  • βœ… Cannot mix quote types in same command

  • βœ… Works with any command (cat, ls, id, etc.)

HTB Academy Lab Example

Testing Quote Obfuscation:

Expected Result:


Linux-Only Obfuscation Techniques

Backslash Escaping

Method:

Advantages:

  • βœ… Odd or even number of characters

  • βœ… Flexible placement

  • βœ… Works with any position in command

Positional Parameter ($@)

Method:

Technical Note: $@ represents positional parameters in Bash, but when empty, it's ignored during command execution.

Combined Linux Techniques

Advanced Obfuscation:


Windows-Only Obfuscation Techniques

Caret Character (^)

Method:

PowerShell Alternative:


HTB Academy Lab Solution

Challenge: Command Blacklist Bypass

Target: Find the content of flag.txt in the home folder of the previously discovered user.

Previous Context:

  • User found: 1nj3c70r (from /home directory listing)

  • Need to read: /home/1nj3c70r/flag.txt

Step-by-Step Solution

Method 1: Quote Obfuscation

Method 2: Backslash Obfuscation (Linux)

Method 3: Mixed Techniques

Lab Answer Format

Expected Flag Content:


Advanced Obfuscation Examples

File Reading Techniques

Obfuscating cat /etc/passwd:

Directory Listing Techniques

Obfuscating ls -la /home:


Detection & Testing Methodology

1. Identify Blacklisted Commands

Test Common Commands:

2. Test Obfuscation Methods

Systematic Testing:

3. Character Combination

Advanced Payload Construction:


Practical Applications

1. Web Application Testing

Burp Suite Intruder Setup:

2. Automated Obfuscation

Python Script Example:


Key Takeaways

βœ… Universal Techniques

  • Quote injection works on all platforms

  • Environment variables provide character flexibility

  • Multiple bypasses can be combined

🎯 Platform-Specific

  • Linux: Backslash (\) and positional parameters ($@)

  • Windows: Caret (^) and backtick (`)

πŸ”§ Best Practices

  • Test systematically - one technique at a time

  • Combine methods for complex filters

  • Use automation for efficiency in assessments

This comprehensive approach to command obfuscation enables penetration testers to bypass sophisticated word-based filtering mechanisms while maintaining reliable command execution.

Last updated