Apache als Reverse Proxy mit WAF
Apache als Reverse Proxy mit WAF für blau.it113.int
Ziel
Apache2 fungiert als Reverse Proxy für die öffentliche Seite blau.it113.int ModSecurity wird als Web Application Firewall aktiviert Zwei eigene Regeln werden erstellt: – Gegen Command Injection – Gegen SQL Injection Die Weiterleitung zum internen Webserver erfolgt über HTTPS ohne Zertifikatsprüfung Die SSL-Zertifikate liegen unter /etc/apache2/ssl
Pakete installieren
- apt update
- apt install apache2 libapache2-mod-security2
ModSecurity aktivieren
- cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
- sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' /etc/modsecurity/modsecurity.conf
Verzeichnis für eigene Regeln erstellen
- mkdir /etc/modsecurity/custom-rules
Regel gegen Command Injection erstellen
Erstelle die Datei mit folgendem Inhalt:
- nano /etc/modsecurity/custom-rules/10-command-injection.conf
Inhalt:
SecRule ARGS "(;|\||&|`)" \
"id:10001,phase:2,deny,log,status:403,msg:'Command Injection erkannt'"
Regel gegen SQL Injection erstellen
Erstelle die Datei mit folgendem Inhalt:
- nano /etc/modsecurity/custom-rules/11-sql-injection.conf
Inhalt:
SecRule ARGS "(?i)(union select|select.+from|insert into|drop table|--|#|;)" \
"id:10002,phase:2,deny,log,status:403,msg:'SQL Injection erkannt'"
Regeln einbinden
Bearbeite die Datei security2.conf:
- nano /etc/apache2/mods-enabled/security2.conf
Füge am Ende ein:
IncludeOptional /etc/modsecurity/custom-rules/*.conf
Apache als Reverse Proxy mit HTTPS konfigurieren
Benötigte Module aktivieren:
- a2enmod proxy
- a2enmod proxy_http
- a2enmod proxy_https
- a2enmod ssl
Verzeichnis für Zertifikate erstellen:
- mkdir -p /etc/apache2/ssl
Zertifikate dort ablegen: – blau.it113.int.crt – blau.it113.int.key
Virtuelle Host-Konfiguration erstellen:
- nano /etc/apache2/sites-available/blau.it113.int.conf
Inhalt:
<VirtualHost *:443>
ServerName blau.it113.int
SSLEngine on SSLCertificateFile /etc/apache2/ssl/blau.it113.int.crt SSLCertificateKeyFile /etc/apache2/ssl/blau.it113.int.key
ProxyPreserveHost On SSLProxyEngine On SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off ProxyPass / https://10.113.0.200/ ProxyPassReverse / https://10.113.0.200/
ErrorLog /var/log/apache2/waf-error.log CustomLog /var/log/apache2/waf-access.log combined
</VirtualHost>
Site aktivieren und Apache neu laden:
- a2ensite blau.it113.int
- systemctl reload apache2
Test Command Injection
Ziel: Test eines typischen Kommandoinjektionsversuchs per GET-Parameter
- curl -k "https://blau.it113.int/?cmd=ls%7Ccat /etc/passwd"
Erwartung: 403 Forbidden Log prüfen: /var/log/apache2/waf-error.log
Test SQL Injection
Ziel: SQL-Injection-Test mit einfachem manipuliertem Parameter
- curl -k "https://blau.it113.int/?id=1' OR '1'='1"
Erwartung: 403 Forbidden Log prüfen: /var/log/apache2/waf-error.log