Software/ModSecurity, Webserver- und Webapplikationsmanagement von PSL Firmen-Wikis Content Management Systeme Projektmanagement Tools Sicherheit
Aus Sysdoc
2.2.6 ModSecurity (WAF)
Das Bundesamt für Sicherheit in der Informationstechnik (BSI) empfiehlt die Verwendung einer sogenannten Web Application Firewall (WAF).
Auf dem Server ? der X ist dieses durch die frei erhältliche Apache-Erweiterung ModSecurity realisiert. Die Installation und Inbetriebnahme jener Software gestaltet sich relativ aufwendig, weshalb hier ein Installationsprotokoll angeboten wird, welches zusätzlich zu den öffentlichen Anleitungen Hilfestellungen im Kontext der spezifischen Server-Konfiguration von ? geben soll.
1. Auf richtige Apache Version überprüfen:
/etc/init.d/apache2 restart -v (ModSecurity 2.x works with Apache 2.0.x or better)
2. Die Datei/Library "mod_unique_id.so" in /usr/lib/apache2-prefork lokalisieren und falls ggf. vorhanden in /etc/apache2/sysconfig.d/loadmodule.conf eintragen:
LoadModule rewrite_module /usr/lib/apache2-prefork/mod_unique_id.so
3. Ueberpruefen ob libxml2 auf dem System installiert ist:
rpm -qa >> pakete.txt
4. Lua nachinstallieren:
4.1 Das Tool Checkinstall runterladen (macht leichter zu installierende RPMS aus make-files etc.):
http://www.asic-linux.com.mx/~izto/checkinstall/download.php
4.2 Das Hilfsprogramm Checkinstall installieren:
rpm -ivh checkinstall-1.6.1-1.i386.rpm
4.3 Lua runter laden:
http://www.asic-linux.com.mx/~izto/checkinstall/download.php
4.4 Lua entpacken:
tar -zxvf lua-5.1.3.tar.gz
4.5 In das Verzeichnis wechseln
cd lua-5.1.3
4.6 Make ausfuehren
make linux
4.7 Lua - RPM erstellen
checkinstall
4.8 In das RPM-Verzeicnnis wechseln und Lua-RPM installieren:
cd /usr/src/packages/RPMS/i386/lua-5.1.3-1.i386.rpm
rpm -ivh lua-5.1.3-1.i386.rpm
5. Lua Share Library installieren:
cd /usr/local/lib
gcc -shared -o liblua.5.1.3.so /usr/local/lib/liblua.a
ln -s liblua.5.1.3.so liblua.so
6. Apache stoppen
/etc/init.d/apache2 stop
7. ModSecurity kompilieren und installieren
7.1 Paket entpacken und in Verzeichnis wechseln:
tar -xzvf modsecurity-apache_2.5.6.tar.tar cd modsecurity-apache_2.5.6 cd apache2
7.2 Versuchen "configure" auszuführen:
./configure
7.3 Vorgehen im "Configure-Fehlerfall" Fehler: "pcre needed" neue pcre-lib installieren:
rpm runterladen,
tar -xzvf pcre-7.7.tar.tar,
cd pcre-7.7
./configure
make
checkinstall
cd /usr/src/packages/RPMS/i386/
rpm -i pcre-7.7-1.i386.rpm
7.4 ModSecurity kompilieren:
cd /modsecurity-apache_2.5.6/apache2 ./configure make install (die rpm-geschichten funktionieren an dieser stellen nicht...also nur normal installieren)
7.5 Die Datei /etc/apache2/conf.d/mod_security.conf nach Template anlegen (diese wird dann automatisch eingebunden).
Das angepasste Template befindet sich in:
/etc/apache2/conf.d/
7.6 Extrarieren und konfigurieren der Core Rules:
Get the core rules from http://www.modsecurity.org/download/modsecurity-core-rules_2.5-1.6.0.tar.gz.
7.7 Rules anlengen in /etc/apache2/modsecurity
cd /etc/apache2
mkdir modsecurity
cd modsecurity
tar -zxvf ../modsecurity-core-rules_2.5-1.6.0.tar.gz
Modify modsecurity_crs_10_config.conf to meet the location of your config files:
IRM-Settings:
SecDebugLog /var/log/apache2/modsec_debug.log
SecAuditLog /var/log/apache2/modsec_audit.log
8. Optionaler Test (auf dem Server der X erfolgreich durchgefuehrt)
To test the installation, write a simple (insecure) PHP script like this:
file $text=$_GET['file'];
echo "Content of File $text";
echo `cat $text`;
Then access it to try opening insecure files:
http://ip.of.your.server.de/index.php?file=/etc/passwd
You should get ERROR 501 in your browser and the SecAuditLog file should show:
[...]
GET /index.php?file=/etc/passwd HTTP/1.1 ...
[...]
Message: Access denied with code 501 (phase 2). Pattern match "(?:\b(?:\.(?:ht(?:access|passwd|group
)|www_?acl)|global\.asa|httpd\.conf|boot\.ini)\b|\/etc\/)" at ARGS:file. [file "/etc/apache2/modsecu
rity/modsecurity_crs_40_generic_attacks.conf"] [line "114"] [id "950005"] [msg "Remote File Access A
ttempt"] [data "/etc/"] [severity "CRITICAL"] [tag "WEB_ATTACK/FILE_INJECTION"]
9 Konfiguration pro Virtual Host (siehe auch offizielle Dokumentation im Web)
[...] SecRuleEnine On SecDefaultAction log,pass,phase:2 [...]
10. mlogc Log-Collector downloaden und installieren:
- mit build - Kommando erzeugen - die daraus resultierende mlogc-binary entsprechend install-readme kopieren - mlogc.conf konfigurieren ...................Web-Info falsch: Please note that mlogc is now distributed with ModSecurity 2.5 and you are advised against using the standalone version unless you are using a version of ModSecurity prior to 2.5. ...................Web-Info richtig: The ModSecurity Log Collector (mlogc) is used to send ModSecurity audit log data to a console or Breach Security appliance. The final packaged release of ModSecurity 2.5.6 did not contain the mlogc source as it should have. This means that a "make mlogc" will fail. However, the mlogc source is also packaged separately and can be downloaded from Breach Labs (https://bsn.breach.com/downloads/mlogc/). Please use the source from Breach Labs to build mlogc until the next release of ModSecurity.
11. In etc/apache2/conf.d/mod_security.conf auf mlogc zeigen
# Use the same /CollectorRoot/LogStorageDir as in mlogc.conf SecAuditLogStorageDir /var/log/mlogc/data # Pipe audit log to mlogc with your configuration SecAuditLog "|/opt/mlogc/mlogc /opt/mlogc/mlogc.conf"
12. ModSecurity Console (Web-GUI) kompilieren, installieren und in Betrieb nehmen (wird in das Verzeichnis "/opt" installiet):
rpm -i modsecurity-console_1_0_5_linux.rpm
13. Den Port 8888 für die Web-Console in Server-Firewall freischalten (Plesk)
14. Interne error page fuer redirects anlegen um ggf. berechtigte Kunden zu informieren, dass ein request ggf. in der WAF "hängen blieb":
# Status 501/redirect (not implimented invoked durch custom error-page in /usr/share/apache2/error/blocked.html.var angemeldet in /etc/apache2/errors.conf)
15. Literatur:
Install Apache Mode Security, mod_sec: http://www.modsecurity.org/documentation/modsecurity-apache/2.5.6/modsecurity2-apache-reference.html#installation Downloads Lua: http://luabinaries.luaforge.net/download.html Install Lua: http://luabinaries.luaforge.net/installation.html How To Install mod_security/mod_security2 On SuSE Linux Enterprise Server http://www.howtoforge.com/installing-mod-security-on-sles10
16. Bemerkungen:
Im Internet kusieren diverse Anleitungen die alle von der falschen ModSecurity Version ausgehen! Es muss so gemacht, besonders konfiguriert werden wie es hier dokumentiert ist (modsecurity-apache_2.5.6). Die im Web erhältliche mod_security_syntax_changes_migration.pdf gibt im Zweifel Auskunft ueber neuere Schreibweisen. ModSec.- Einstellungen werden in: etc/apache2/conf.d/mod_security.conf, und im Verzeichnis /etc/apache2/modsecurity in den core rules (modsecurity_crs_10_config.conf etc.) gemacht. Beim Auswechseln der uebervollen /var/log/apache2/modsec_audit.log (Betrieb ohne mlogc) muss der apache neu gestartet werden da die datei zuvor umbenannt wurde (modsec_audit.log_backup)
