Apache als Reverse Proxy mit WAF: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „= 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 * ModSecur…“) |
(kein Unterschied)
|
Version vom 25. März 2025, 06:01 Uhr
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
- 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
- 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
- nano /etc/apache2/mods-enabled/security2.conf
- Folgende Zeile am Ende einfügen:
IncludeOptional /etc/modsecurity/custom-rules/*.conf
Apache als Reverse Proxy mit HTTPS konfigurieren
- a2enmod proxy
- a2enmod proxy_http
- a2enmod proxy_https
- a2enmod ssl
- mkdir -p /etc/apache2/ssl
- Zertifikate nach /etc/apache2/ssl legen
- 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>
- a2ensite blau.it113.int
- systemctl reload apache2
Test Command Injection
- 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
- curl -k "https://blau.it113.int/?id=1' OR '1'='1"
- Erwartung: 403 Forbidden
- Log prüfen: /var/log/apache2/waf-error.log