Apache als Reverse Proxy mit WAF: Unterschied zwischen den Versionen
(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…“) |
|||
| Zeile 2: | Zeile 2: | ||
== Ziel == | == 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 == | == Pakete installieren == | ||
| Zeile 22: | Zeile 22: | ||
== Regel gegen Command Injection erstellen == | == Regel gegen Command Injection erstellen == | ||
| + | Erstelle die Datei mit folgendem Inhalt: | ||
| + | |||
* nano /etc/modsecurity/custom-rules/10-command-injection.conf | * nano /etc/modsecurity/custom-rules/10-command-injection.conf | ||
| − | + | ||
| + | Inhalt: | ||
| + | |||
SecRule ARGS "(;|\||&|`)" \ | SecRule ARGS "(;|\||&|`)" \ | ||
"id:10001,phase:2,deny,log,status:403,msg:'Command Injection erkannt'" | "id:10001,phase:2,deny,log,status:403,msg:'Command Injection erkannt'" | ||
== Regel gegen SQL Injection erstellen == | == Regel gegen SQL Injection erstellen == | ||
| + | Erstelle die Datei mit folgendem Inhalt: | ||
| + | |||
* nano /etc/modsecurity/custom-rules/11-sql-injection.conf | * nano /etc/modsecurity/custom-rules/11-sql-injection.conf | ||
| − | + | ||
| + | Inhalt: | ||
| + | |||
SecRule ARGS "(?i)(union select|select.+from|insert into|drop table|--|#|;)" \ | SecRule ARGS "(?i)(union select|select.+from|insert into|drop table|--|#|;)" \ | ||
"id:10002,phase:2,deny,log,status:403,msg:'SQL Injection erkannt'" | "id:10002,phase:2,deny,log,status:403,msg:'SQL Injection erkannt'" | ||
== Regeln einbinden == | == Regeln einbinden == | ||
| + | Bearbeite die Datei security2.conf: | ||
| + | |||
* nano /etc/apache2/mods-enabled/security2.conf | * nano /etc/apache2/mods-enabled/security2.conf | ||
| − | + | ||
| + | Füge am Ende ein: | ||
| + | |||
IncludeOptional /etc/modsecurity/custom-rules/*.conf | IncludeOptional /etc/modsecurity/custom-rules/*.conf | ||
== Apache als Reverse Proxy mit HTTPS konfigurieren == | == Apache als Reverse Proxy mit HTTPS konfigurieren == | ||
| + | Benötigte Module aktivieren: | ||
| + | |||
* a2enmod proxy | * a2enmod proxy | ||
* a2enmod proxy_http | * a2enmod proxy_http | ||
* a2enmod proxy_https | * a2enmod proxy_https | ||
* a2enmod ssl | * a2enmod ssl | ||
| + | |||
| + | Verzeichnis für Zertifikate erstellen: | ||
| + | |||
* mkdir -p /etc/apache2/ssl | * 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 | * nano /etc/apache2/sites-available/blau.it113.int.conf | ||
| − | + | ||
| + | Inhalt: | ||
| + | |||
<VirtualHost *:443> | <VirtualHost *:443> | ||
ServerName blau.it113.int | ServerName blau.it113.int | ||
| Zeile 65: | Zeile 90: | ||
CustomLog /var/log/apache2/waf-access.log combined | CustomLog /var/log/apache2/waf-access.log combined | ||
</VirtualHost> | </VirtualHost> | ||
| + | |||
| + | Site aktivieren und Apache neu laden: | ||
| + | |||
* a2ensite blau.it113.int | * a2ensite blau.it113.int | ||
* systemctl reload apache2 | * systemctl reload apache2 | ||
== Test Command Injection == | == Test Command Injection == | ||
| + | Ziel: Test eines typischen Kommandoinjektionsversuchs per GET-Parameter | ||
| + | |||
* curl -k "https://blau.it113.int/?cmd=ls|cat /etc/passwd" | * curl -k "https://blau.it113.int/?cmd=ls|cat /etc/passwd" | ||
| − | + | ||
| − | + | Erwartung: 403 Forbidden | |
| + | Log prüfen: /var/log/apache2/waf-error.log | ||
== Test SQL Injection == | == Test SQL Injection == | ||
| + | Ziel: SQL-Injection-Test mit einfachem manipuliertem Parameter | ||
| + | |||
* curl -k "https://blau.it113.int/?id=1' OR '1'='1" | * curl -k "https://blau.it113.int/?id=1' OR '1'='1" | ||
| − | + | ||
| − | + | Erwartung: 403 Forbidden | |
| + | Log prüfen: /var/log/apache2/waf-error.log | ||
Version vom 25. März 2025, 06:08 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
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