Apache als Reverse Proxy mit WAF: Unterschied zwischen den Versionen
(→Ziel) |
|||
| Zeile 8: | Zeile 8: | ||
– Gegen SQL Injection | – Gegen SQL Injection | ||
Die Weiterleitung zum internen Webserver erfolgt über HTTPS ohne Zertifikatsprüfung | Die Weiterleitung zum internen Webserver erfolgt über HTTPS ohne Zertifikatsprüfung | ||
| + | Die SSL-Zertifikat= 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 | Die SSL-Zertifikate liegen unter /etc/apache2/ssl | ||
| + | |||
| + | == Pakete installieren == | ||
| + | ;Installiere Apache und ModSecurity | ||
| + | * apt update | ||
| + | * apt install apache2 libapache2-mod-security2 | ||
| + | |||
| + | == ModSecurity aktivieren == | ||
| + | |||
| + | Kopiere die empfohlene Konfigurationsdatei und aktiviere den WAF-Modus. | ||
| + | |||
| + | * 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 == | ||
| + | ;Erstelle ein Verzeichnis für benutzerdefinierte Regeln | ||
| + | * mkdir /etc/modsecurity/custom-rules | ||
| + | |||
| + | == Regel gegen Command Injection == | ||
| + | |||
| + | Erstelle eine Datei mit einer einfachen Command-Injection-Erkennung. | ||
| + | |||
| + | * nano /etc/modsecurity/custom-rules/10-command-injection.conf | ||
| + | |||
| + | SecRule ARGS "(;|\||&|`)" \ | ||
| + | "id:10001,phase:2,deny,log,status:403,msg:'Command Injection erkannt'" | ||
| + | |||
| + | == Regel gegen SQL Injection == | ||
| + | |||
| + | Erstelle eine Datei mit einer einfachen SQL-Injection-Erkennung. | ||
| + | |||
| + | * nano /etc/modsecurity/custom-rules/11-sql-injection.conf | ||
| + | |||
| + | 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 == | ||
| + | |||
| + | Binde die benutzerdefinierten Regeln in die aktive Konfiguration ein. | ||
| + | |||
| + | * nano /etc/apache2/mods-enabled/security2.conf | ||
| + | |||
| + | IncludeOptional /etc/modsecurity/custom-rules/*.conf | ||
| + | |||
| + | == Apache als Reverse Proxy mit HTTPS konfigurieren == | ||
| + | |||
| + | Aktiviere die benötigten Apache-Module. | ||
| + | |||
| + | * a2enmod proxy | ||
| + | * a2enmod proxy_http | ||
| + | * a2enmod proxy_https | ||
| + | * a2enmod ssl | ||
| + | |||
| + | Erstelle ein Verzeichnis für die SSL-Zertifikate. | ||
| + | |||
| + | * mkdir -p /etc/apache2/ssl | ||
| + | |||
| + | Lege die Zertifikatsdateien dort ab: | ||
| + | – blau.it113.int.crt | ||
| + | – blau.it113.int.key | ||
| + | |||
| + | Erstelle die Virtual-Host-Konfiguration. | ||
| + | |||
| + | * nano /etc/apache2/sites-available/blau.it113.int.conf | ||
| + | |||
| + | <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> | ||
| + | |||
| + | Aktiviere die neue Site und lade Apache neu. | ||
| + | |||
| + | * a2ensite blau.it113.int | ||
| + | * systemctl reload apache2 | ||
| + | |||
| + | == Test Command Injection == | ||
| + | ;Test eines typischen Kommandoinjektionsversuchs | ||
| + | * 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 einer einfachen 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 | ||
| + | e liegen unter /etc/apache2/ssl | ||
== Pakete installieren == | == Pakete installieren == | ||
Version vom 25. März 2025, 06:15 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-Zertifikat= 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
- Installiere Apache und ModSecurity
- apt update
- apt install apache2 libapache2-mod-security2
ModSecurity aktivieren
Kopiere die empfohlene Konfigurationsdatei und aktiviere den WAF-Modus.
- 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
- Erstelle ein Verzeichnis für benutzerdefinierte Regeln
- mkdir /etc/modsecurity/custom-rules
Regel gegen Command Injection
Erstelle eine Datei mit einer einfachen Command-Injection-Erkennung.
- nano /etc/modsecurity/custom-rules/10-command-injection.conf
SecRule ARGS "(;|\||&|`)" \ "id:10001,phase:2,deny,log,status:403,msg:'Command Injection erkannt'"
Regel gegen SQL Injection
Erstelle eine Datei mit einer einfachen SQL-Injection-Erkennung.
- nano /etc/modsecurity/custom-rules/11-sql-injection.conf
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
Binde die benutzerdefinierten Regeln in die aktive Konfiguration ein.
- nano /etc/apache2/mods-enabled/security2.conf
IncludeOptional /etc/modsecurity/custom-rules/*.conf
Apache als Reverse Proxy mit HTTPS konfigurieren
Aktiviere die benötigten Apache-Module.
- a2enmod proxy
- a2enmod proxy_http
- a2enmod proxy_https
- a2enmod ssl
Erstelle ein Verzeichnis für die SSL-Zertifikate.
- mkdir -p /etc/apache2/ssl
Lege die Zertifikatsdateien dort ab: – blau.it113.int.crt – blau.it113.int.key
Erstelle die Virtual-Host-Konfiguration.
- nano /etc/apache2/sites-available/blau.it113.int.conf
<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>
Aktiviere die neue Site und lade Apache neu.
- a2ensite blau.it113.int
- systemctl reload apache2
Test Command Injection
- Test eines typischen Kommandoinjektionsversuchs
- 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
- Test einer einfachen 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 e 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