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/homedirectory 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