ModSecurity (NGINX) – Erkennung von Command Injection in Formularfeldern

Aus Xinux Wiki
Version vom 19. Februar 2026, 06:00 Uhr von Thomas.will (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „= ModSecurity (NGINX) – Erkennung von Command Injection in Formularfeldern = == Ziel der Übung == * Demonstration der Layer-7-Inspektion durch eine Web App…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

ModSecurity (NGINX) – Erkennung von Command Injection in Formularfeldern

Ziel der Übung

  • Demonstration der Layer-7-Inspektion durch eine Web Application Firewall
  • Erkennung von Command Injection in einem HTML-Formular
  • Blockierung von Angriffen vor Weiterleitung an das Backend
  • Analyse von POST-Parametern (ARGS_POST) nach TLS-Terminierung

Voraussetzung

  • NGINX mit ModSecurity v3 aktiv
  • OWASP Core Rule Set (CRS) eingebunden
  • TLS-Terminierung erfolgt auf der WAF
  • Webanwendung mit HTML-Formular (POST)

Architektur

  • Client sendet HTTPS-Anfrage an WAF
  • TLS-Verbindung endet an der WAF
  • HTTP-POST-Body liegt entschlüsselt vor
  • ModSecurity analysiert Formularinhalte
  • Nur geprüfte Anfragen werden an Backend weitergeleitet

CRS-Einbindung prüfen

  • cat /etc/nginx/modsec/modsecurity.conf

Folgende Includes müssen vorhanden sein:

Include /etc/nginx/modsec/coreruleset/crs-setup.conf
Include /etc/nginx/modsec/coreruleset/rules/*.conf
Include /etc/nginx/modsec/custom-rules/security-policy.conf

Lokale Detection-Regel erstellen

  • vi /etc/nginx/modsec/custom-rules/local-detection.conf

Inhalt:

SecRule ARGS_POST "@rx (?i)\b(pwd|ls|id|whoami|cat|uname)\b" \
"id:1001,\
phase:2,\
t:urlDecodeUni,\
t:compressWhitespace,\
deny,\
log,\
msg:'POST Command Injection Detected'"

Regel einbinden

  • vi /etc/nginx/modsec/custom-rules/security-policy.conf

Am Ende ergänzen:

Include /etc/nginx/modsec/custom-rules/local-detection.conf

Konfiguration neu laden

  • nginx -t
  • systemctl reload nginx

Testangriff über Webformular

Formularfeld
xinux.de ; pwd

Erwartetes Verhalten

  • HTTP-Statuscode 403
  • Anfrage wird von WAF blockiert
  • Backend erhält keine Anfrage

Audit-Log prüfen

  • grep pwd /var/log/nginx/modsec_audit.log

Ergebnis

  • Command Injection im POST-Body erkannt
  • Anfrage auf Layer 7 analysiert
  • Angriff vor Applikationsverarbeitung blockiert