"Not a Pentest" Hinweis: Dieser Guide dient der Absicherung eigener Web-Applikationen. Kein Angriffs-Tool.
Was ist WAF Konfiguration?
WAF Konfiguration umfasst OWASP-Regeln, Custom Policies und Best Practices für ModSecurity, nginx WAF und Cloudflare WAF. Sie blockiert bösartige Anfragen wie SQL-Injection und XSS vor der Anwendung.
Eine WAF blockiert bis zu 90% aller OWASP Top 10 Angriffe bei korrekter Konfiguration.
WAF Konfiguration: Web Application Firewall Setup
Vollständige WAF-Konfiguration mit OWASP-Regeln und Custom Security Policies für ModSecurity, nginx WAF und Cloudflare.
WAF Grundlagen
Kernkomponenten
- OWASP Core Rule Set (CRS) Integration
- Custom-Regel-Konfiguration
- Rate-Limiting und DDoS-Schutz
- Request/Response-Inspektion
- Virtual Patching
ModSecurity Konfiguration
# Enable ModSecurity with OWASP CRS
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On
SecRequestBodyLimit 13107200
SecRequestBodyNoFilesLimit 131072
# Include OWASP Core Rule Set
Include owasp-modsecurity-crs/rules/*.conf
# Custom rules for application-specific protection
SecRule ARGS "@detectSQLi" "id:1001, phase:2, block, msg:'SQL Injection Attack Detected', logdata:'Matched Data: %{MATCHED_VAR} found within %{MATCHED_VAR_NAME}', tag:'application-multi', tag:'language-multi', tag:'platform-multi', tag:'attack-sqli'"Cloudflare WAF Setup
# Cloudflare WAF Rules via API
curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone_id}/firewall/rules" -H "Authorization: Bearer {api_token}" -H "Content-Type: application/json" --data '{
"action": "block",
"filter": {
"expression": "(http.request.uri.path contains "admin" and ip.src ne 192.168.1.0/24)"
},
"description": "Block admin access except from internal network"
}'
# Rate limiting rule
curl -X POST "https://api.cloudflare.com/client/v4/zones/{zone_id}/rate_limits" -H "Authorization: Bearer {api_token}" -H "Content-Type: application/json" --data '{
"action": {
"mode": "simulate",
"response": {
"content_type": "application/json",
"body": "{"error":"Rate limit exceeded"}"
}
},
"match": {
"request": {
"methods": ["POST"],
"url": "https://example.com/api/*"
}
},
"period": 60,
"threshold": 100,
"description": "API rate limiting"
}'Nginx WAF Configuration
# Nginx with ModSecurity module
server {
listen 443 ssl http2;
server_name example.com;
# Enable ModSecurity
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/main.conf;
# Custom WAF rules
location /api/ {
# Rate limiting
limit_req zone=api burst=20 nodelay;
# Request size limits
client_max_body_size 1M;
# Security headers
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header X-XSS-Protection "1; mode=block";
}
# Rate limiting zone
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
}WAF Best Practices
Rule Management
Regularly update OWASP CRS and review custom rules for false positives.
Monitoring
Implement comprehensive logging and alerting for WAF events.
Testing
Test WAF rules in monitoring mode before enabling blocking.
Performance
Optimize rule sets to balance security with application performance.