Coraza WAF via SPOE: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 1: | Zeile 1: | ||
===Was ist das?=== | ===Was ist das?=== | ||
Coraza ist eine moderne WAF-Engine (Go), die das OWASP Core Rule Set (CRS) ausführt. Die Integration in HAProxy erfolgt über SPOE – denselben Mechanismus wie bei CrowdSec. | Coraza ist eine moderne WAF-Engine (Go), die das OWASP Core Rule Set (CRS) ausführt. Die Integration in HAProxy erfolgt über SPOE – denselben Mechanismus wie bei CrowdSec. | ||
| + | |||
===Schaubild=== | ===Schaubild=== | ||
{{#drawio:Coraza WAF}} | {{#drawio:Coraza WAF}} | ||
===Installation des SPOE-Agents=== | ===Installation des SPOE-Agents=== | ||
| − | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| − | apt install golang git | + | apt install -y golang-go git |
| − | |||
git clone https://github.com/corazawaf/coraza-spoa.git /opt/coraza-spoa | git clone https://github.com/corazawaf/coraza-spoa.git /opt/coraza-spoa | ||
cd /opt/coraza-spoa | cd /opt/coraza-spoa | ||
| − | go build -o | + | go build -o /usr/local/bin/coraza-spoa . |
| − | + | cd / | |
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | ;Hinweis: <code>go build -o /usr/local/bin/coraza-spoa .</code> – nur das Hauptpackage, Binary direkt ans Ziel. <code>./...</code> funktioniert hier nicht da das Repo mehrere Packages enthält. | |
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | </ | ||
===Coraza-Konfiguration=== | ===Coraza-Konfiguration=== | ||
| + | Das Verzeichnis und die YAML-Konfigurationsdatei anlegen: | ||
| − | *nano /etc/coraza/coraza. | + | *mkdir -p /etc/coraza-spoa |
| + | *mkdir -p /var/log/coraza | ||
| + | *chown haproxy:haproxy /var/log/coraza | ||
| + | *nano /etc/coraza-spoa/coraza-spoa.yaml | ||
| − | <syntaxhighlight lang=" | + | <syntaxhighlight lang="yaml"> |
| − | + | bind: 127.0.0.1:9000 | |
| − | + | log_level: info | |
| + | log_file: /var/log/coraza/coraza-spoa.log | ||
| + | log_format: json | ||
| + | default_application: sample_app | ||
| − | SecRuleEngine On | + | applications: |
| − | SecRequestBodyAccess On | + | - name: sample_app |
| − | SecResponseBodyAccess On | + | directives: | |
| − | SecAuditLog /var/log/coraza/audit.log | + | Include @coraza.conf-recommended |
| − | SecAuditLogType Serial | + | Include @crs-setup.conf.example |
| − | SecAuditEngine RelevantOnly | + | Include @owasp_crs/*.conf |
| + | SecRuleEngine On | ||
| + | SecRequestBodyAccess On | ||
| + | SecResponseBodyAccess On | ||
| + | SecAuditLog /var/log/coraza/audit.log | ||
| + | SecAuditLogType Serial | ||
| + | SecAuditEngine RelevantOnly | ||
| + | response_check: false | ||
| + | transaction_ttl_ms: 60000 | ||
| + | log_level: info | ||
| + | log_file: /var/log/coraza/coraza-spoa.log | ||
| + | log_format: json | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | ;Hinweis: Die OWASP-Regeln (<code>@owasp_crs/</code>, <code>@coraza.conf-recommended</code>) sind im Binary eingebaut – kein separater CRS-Clone nötig. | |
===SPOE-Agent als Systemd-Service=== | ===SPOE-Agent als Systemd-Service=== | ||
| − | |||
*nano /etc/systemd/system/coraza-spoa.service | *nano /etc/systemd/system/coraza-spoa.service | ||
| − | <syntaxhighlight lang=" | + | <syntaxhighlight lang="ini"> |
[Unit] | [Unit] | ||
Description=Coraza SPOA for HAProxy | Description=Coraza SPOA for HAProxy | ||
| Zeile 51: | Zeile 61: | ||
[Service] | [Service] | ||
| − | ExecStart=/usr/local/bin/coraza-spoa -config /etc/coraza/coraza. | + | ExecStart=/usr/local/bin/coraza-spoa -config /etc/coraza-spoa/coraza-spoa.yaml |
Restart=on-failure | Restart=on-failure | ||
User=haproxy | User=haproxy | ||
| Zeile 65: | Zeile 75: | ||
===SPOE-Konfiguration für HAProxy=== | ===SPOE-Konfiguration für HAProxy=== | ||
| + | *nano /etc/haproxy/coraza.cfg | ||
| − | + | <syntaxhighlight lang="text"> | |
| + | [coraza] | ||
| + | spoe-agent coraza-agent | ||
| + | messages coraza-req | ||
| + | option var-prefix coraza | ||
| + | option set-on-error error | ||
| + | timeout hello 2s | ||
| + | timeout idle 2m | ||
| + | timeout processing 500ms | ||
| + | use-backend coraza-spoa | ||
| − | + | spoe-message coraza-req | |
| − | + | args app=str(sample_app) id=unique-id src-ip=src src-port=src_port dst-ip=dst dst-port=dst_port method=method path=path query=query version=req.ver headers=req.hdrs body=req.body | |
| − | + | event on-frontend-http-request | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | ;Wichtig: Der Section-Header <code>[coraza]</code> muss exakt mit dem engine-Namen in <code>haproxy.cfg</code> übereinstimmen. Leerzeile am Dateiende ist zwingend, sonst meldet HAProxy ''Missing LF on last line''. | ||
===HAProxy Konfiguration erweitern=== | ===HAProxy Konfiguration erweitern=== | ||
| − | |||
Im <code>frontend ft_https</code> ergänzen: | Im <code>frontend ft_https</code> ergänzen: | ||
| Zeile 90: | Zeile 102: | ||
frontend ft_https | frontend ft_https | ||
# ... bestehende Einträge ... | # ... bestehende Einträge ... | ||
| − | filter spoe engine coraza config /etc/haproxy/ | + | filter spoe engine coraza config /etc/haproxy/coraza.cfg |
| − | http-request deny deny_status 403 if { var(txn.coraza.action) -m str | + | http-request deny deny_status 403 hdr waf-block "request" if { var(txn.coraza.action) -m str deny } |
</syntaxhighlight> | </syntaxhighlight> | ||
| − | Backend für den Coraza- | + | Backend für den Coraza-SPOA hinzufügen: |
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
| − | backend | + | backend coraza-spoa |
| + | mode tcp | ||
server coraza 127.0.0.1:9000 | server coraza 127.0.0.1:9000 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | ;Wichtig: <code>mode tcp</code> ist zwingend – ohne das schlägt der Config-Check fehl. | ||
===Konfiguration testen und neu laden=== | ===Konfiguration testen und neu laden=== | ||
| − | |||
*haproxy -c -f /etc/haproxy/haproxy.cfg | *haproxy -c -f /etc/haproxy/haproxy.cfg | ||
*systemctl reload haproxy | *systemctl reload haproxy | ||
===Test=== | ===Test=== | ||
| − | |||
Klassischer WAF-Test mit einem OWASP-typischen Angriff (SQL Injection): | Klassischer WAF-Test mit einem OWASP-typischen Angriff (SQL Injection): | ||
| Zeile 120: | Zeile 133: | ||
Erwartet: HTTP 403 | Erwartet: HTTP 403 | ||
| − | + | Logs beobachten: | |
| + | *journalctl -fu coraza-spoa | ||
*tail -f /var/log/coraza/audit.log | *tail -f /var/log/coraza/audit.log | ||
Version vom 23. Mai 2026, 15:28 Uhr
Was ist das?
Coraza ist eine moderne WAF-Engine (Go), die das OWASP Core Rule Set (CRS) ausführt. Die Integration in HAProxy erfolgt über SPOE – denselben Mechanismus wie bei CrowdSec.
Schaubild
Installation des SPOE-Agents
apt install -y golang-go git
git clone https://github.com/corazawaf/coraza-spoa.git /opt/coraza-spoa
cd /opt/coraza-spoa
go build -o /usr/local/bin/coraza-spoa .
cd /
- Hinweis
go build -o /usr/local/bin/coraza-spoa .– nur das Hauptpackage, Binary direkt ans Ziel../...funktioniert hier nicht da das Repo mehrere Packages enthält.
Coraza-Konfiguration
Das Verzeichnis und die YAML-Konfigurationsdatei anlegen:
- mkdir -p /etc/coraza-spoa
- mkdir -p /var/log/coraza
- chown haproxy:haproxy /var/log/coraza
- nano /etc/coraza-spoa/coraza-spoa.yaml
bind: 127.0.0.1:9000
log_level: info
log_file: /var/log/coraza/coraza-spoa.log
log_format: json
default_application: sample_app
applications:
- name: sample_app
directives: |
Include @coraza.conf-recommended
Include @crs-setup.conf.example
Include @owasp_crs/*.conf
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On
SecAuditLog /var/log/coraza/audit.log
SecAuditLogType Serial
SecAuditEngine RelevantOnly
response_check: false
transaction_ttl_ms: 60000
log_level: info
log_file: /var/log/coraza/coraza-spoa.log
log_format: json
- Hinweis
- Die OWASP-Regeln (
@owasp_crs/,@coraza.conf-recommended) sind im Binary eingebaut – kein separater CRS-Clone nötig.
SPOE-Agent als Systemd-Service
- nano /etc/systemd/system/coraza-spoa.service
[Unit]
Description=Coraza SPOA for HAProxy
After=network.target
[Service]
ExecStart=/usr/local/bin/coraza-spoa -config /etc/coraza-spoa/coraza-spoa.yaml
Restart=on-failure
User=haproxy
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now coraza-spoa
SPOE-Konfiguration für HAProxy
- nano /etc/haproxy/coraza.cfg
[coraza]
spoe-agent coraza-agent
messages coraza-req
option var-prefix coraza
option set-on-error error
timeout hello 2s
timeout idle 2m
timeout processing 500ms
use-backend coraza-spoa
spoe-message coraza-req
args app=str(sample_app) id=unique-id src-ip=src src-port=src_port dst-ip=dst dst-port=dst_port method=method path=path query=query version=req.ver headers=req.hdrs body=req.body
event on-frontend-http-request
- Wichtig
- Der Section-Header
[coraza]muss exakt mit dem engine-Namen inhaproxy.cfgübereinstimmen. Leerzeile am Dateiende ist zwingend, sonst meldet HAProxy Missing LF on last line.
HAProxy Konfiguration erweitern
Im frontend ft_https ergänzen:
frontend ft_https
# ... bestehende Einträge ...
filter spoe engine coraza config /etc/haproxy/coraza.cfg
http-request deny deny_status 403 hdr waf-block "request" if { var(txn.coraza.action) -m str deny }
Backend für den Coraza-SPOA hinzufügen:
backend coraza-spoa
mode tcp
server coraza 127.0.0.1:9000
- Wichtig
mode tcpist zwingend – ohne das schlägt der Config-Check fehl.
Konfiguration testen und neu laden
- haproxy -c -f /etc/haproxy/haproxy.cfg
- systemctl reload haproxy
Test
Klassischer WAF-Test mit einem OWASP-typischen Angriff (SQL Injection):
- curl -vk "https://revproxy.it2XX.int/?id=1'+OR+'1'='1"
Erwartet: HTTP 403
XSS-Test:
- curl -vk "https://revproxy.it2XX.int/?q=<script>alert(1)</script>"
Erwartet: HTTP 403
Logs beobachten:
- journalctl -fu coraza-spoa
- tail -f /var/log/coraza/audit.log
