Overview
This guide provides real-world test cases to verify that Coraza Proxy correctly detects and blocks common web attacks. All examples usecurl commands from the project’s test suite.
Prerequisites
Before testing, ensure:- Coraza Proxy is running on
localhost:8081 - Add test hostnames to
/etc/hosts:
- Configure backend:
- Start the proxy:
SQL Injection Tests
Test 1: Classic Boolean-Based SQLi
Attack Type: SQL Injection using OR condition Test Command:- Status Code:
403 Forbidden - Response Body:
Request blocked by WAF (body)orRequest blocked by WAF (headers) - Log Entry: Rule 942xxx triggered (SQL injection)
1' OR '1'='1 attempts to manipulate SQL query logic to bypass authentication or extract unauthorized data.
Test 2: UNION-Based SQLi
Attack Type: SQL Injection using UNION to extract data from other tables Test Command:- Status Code:
403 Forbidden - Response Body:
Request blocked by WAF - Triggered Rules: SQL keyword
UNION,SELECT, and comment--
Test 3: Boolean-Based Blind SQLi
Attack Type: Time-based or boolean-based blind SQL injection Test Command:- Status Code:
403 Forbidden - Detection: SQL operator
ANDwith boolean logic
Cross-Site Scripting (XSS) Tests
Test 4: Classic XSS
Attack Type: Basic script tag injection Test Command:- Status Code:
403 Forbidden - Response Body:
Request blocked by WAF - Triggered Rules: Rule 941xxx (XSS detection)
<script> tag can execute arbitrary JavaScript in the victim’s browser, leading to session hijacking, data theft, or defacement.
Test 5: Advanced XSS with Event Handler
Attack Type: XSS using HTML event handlers Test Command:<img src=x onerror=alert(1)>
Expected Result:
- Status Code:
403 Forbidden - Detection: XSS event handler
onerror, HTML tag<img>
onerror, onload, onclick can execute JavaScript without <script> tags, bypassing basic XSS filters.
Path Traversal / Local File Inclusion Tests
Test 6: Directory Traversal (LFI)
Attack Type: Local File Inclusion attempting to read/etc/passwd
Test Command:
- Status Code:
403 Forbidden - Triggered Rules: Rule 930xxx (Path Traversal)
- Detection:
../sequences
Remote Command Execution Tests
Test 7: Command Injection
Attack Type: Shell command injection using semicolon separator Test Command:- Status Code:
403 Forbidden - Triggered Rules: Rule 932xxx (RCE detection)
- Detection: Shell metacharacter
;and commandls
Test 8: Command Substitution
Attack Type: Remote command execution using command substitution Test Command:- Status Code:
403 Forbidden - Detection: Command substitution
$(...),catcommand
$() executes commands and injects their output, allowing file reading and command execution.
Test 9: Piped Command Injection
Attack Type: Command chaining using pipe operator Test Command:- Status Code:
403 Forbidden - Detection: Pipe operator
|,sleepcommand
Protocol Attack Tests
Test 10: Missing Host Header
Attack Type: HTTP protocol violation Test Command:- Status Code:
403 Forbiddenor400 Bad Request - Triggered Rules: Rule 920xxx (Protocol enforcement)
Test 11: HTTP Request Smuggling
Attack Type: HTTP request smuggling using chunked encoding Test Command:- Connection: Terminated or blocked
- Detection: Invalid chunked encoding structure
This test requires
netcat (nc) installed. HTTP smuggling is complex and may not always trigger immediate blocking but should be logged.Encoding Attack Tests
Test 12: Invalid UTF-8 Encoding
Attack Type: Malformed UTF-8 to bypass detection Test Command:- Status Code:
403 Forbidden - Detection: Invalid UTF-8 byte sequence
- Configuration:
tx.crs_validate_utf8_encoding=1
API-Specific Tests
Test 13: XSS in JSON Payload
Attack Type: XSS injection in API JSON data Test Command:- Status Code:
403 Forbidden - Response Body:
Request blocked by WAF (body) - Detection: XSS in JSON value
Test 14: Header Injection
Attack Type: XSS in custom HTTP header Test Command:- Status Code:
403 Forbidden - Detection: XSS pattern in request header
Known Vulnerability Tests
Test 15: Log4Shell (CVE-2021-44228)
Attack Type: JNDI injection via Log4j vulnerability Test Command:- Status Code:
403 Forbidden - Triggered Rules: Rule 944240 (Log4Shell specific)
- Detection: JNDI injection pattern
${jndi:
Rate Limiting Tests
Test 16: Rate Limit Bypass Detection
Attack Type: Brute force / DoS attempt Test Command:- First 10 requests:
200 OK(or backend response) - After burst exhausted:
429 Too Many Requests - Rate limit: 5 req/s with burst of 10 (default)
Test 17: Rate Limit with Delay
Attack Type: Legitimate traffic pattern Test Command:- All requests:
200 OK(or backend response) - No rate limiting: Requests stay within allowed rate
Interpreting Test Results
Successful Block
- Status code:
403 Forbidden - Response body contains “Request blocked by WAF”
- Request did NOT reach backend application
Failed Block (Security Issue)
- Status code:
200 OKor other success code - Response from backend application
- Attack payload was NOT blocked
Rate Limiting
- Status code:
429 Too Many Requests - Response body: “Too Many Requests”
- IP has exceeded rate limit
Checking Audit Logs
After running tests, inspect the audit logs for detailed information:- Rule ID: 942270
- Phase: Phase 2 (request body)
- Pattern: Union + Select keywords
- Location: ARGS:q (query parameter named ‘q’)
- Action: Denied with 403
Customizing Tests for Your Application
1. Update Hostnames
Replacewaf.test.local with your actual test domain:
2. Test Specific Endpoints
Test endpoints that accept user input:3. Adjust for PL1 vs PL2
For PL2 APIs, ensure proper content-type:4. Test Authenticated Endpoints
Include authentication headers:Troubleshooting
Test Shows 200 OK (Attack Not Blocked)
-
Check WAF is active:
-
Verify host configuration:
-
Check CRS rules loaded:
-
Review anomaly thresholds:
- Threshold too high for attack severity
- Check
tx.inbound_anomaly_score_thresholdin profile config
Test Shows 502 Bad Gateway
- Backend not running: Start your backend application on configured port
- Backend configuration: Check
BACKENDSenvironment variable - Network issues: Verify backend is accessible from proxy
Test Shows 429 Too Many Requests
- Rate limit hit: Wait 60 seconds for rate limiter cleanup
- Adjust limits:
No Logs Generated
-
Check log directory permissions:
-
Verify audit logging enabled:
- Check
coraza.confforSecAuditLogdirective
- Check
Best Practices
- Run all tests before deploying to production
- Test both PL1 and PL2 profiles if using both
- Monitor audit logs during testing to understand rule triggers
- Create custom tests for your application’s specific input fields
- Test after CRS updates to ensure rules still work correctly
- Document false positives and create exclusion rules as needed
- Automate testing using CI/CD pipelines for regression testing
Regular security testing should be part of your development workflow. Run these tests whenever you update WAF rules, CRS versions, or make significant application changes.
Next Steps
- Review Protection Levels to understand PL1 vs PL2
- Read Attack Detection for detailed detection mechanisms
- Configure custom rule exclusions for false positives
- Set up monitoring and alerting for blocked requests
