Veröffentlichung 6. Juli 2018 @ 18:19
Letzte Änderung 6. Juli 2018 @ 18:19
Voraussetzungen
Netzwerk
- htpasswd-Benutzer ADGVVNVjJnF6sBnhOV1f
- Ports HTTP 80, HTTPS 443, HTTPS 42443
Software
- Apache 2.4.18 #apache2 -v
- OpenSSL 1.0.2g #openssl version
- Ubuntu Server 16.04.04 LTS #lsb_release -a
Ordner und Dateien
- Konfiguration /etc/apache2, /etc/apache2/conf-available, /etc/apache2/mods-available, /etc/init.d/apache2, /etc/logrotate.d/apache2, /etc/sysctl.conf, /proc/sys/kernel/core_pattern
- Log /tmp, /var/log/apache2/access.log, /var/log/apache2/error.log, /var/log/apache2/other_vhosts_access.log
- systemd /lib/systemd/system/apache2.service.d/apache2-systemd.conf
Apache und Module FastCGI und mod_php installieren und Module expires, headers, rewrite und ssl aktivieren
apt install apache2 libapache2-mod-fastcgi libapache2-mod-php7.0 a2enmod expires a2enmod headers a2enmod rewrite a2enmod ssl
[Optional] Zusätzlichen Port 42443 für HTTPS definieren
Security through Obscurity
... <IfModule ssl_module> Listen 443 Listen 42443 </IfModule> <IfModule mod_gnutls.c> Listen 443 Listen 42443 </IfModule> ...
Konfiguration absichern
... <Directory /> #Options FollowSymLinks Options None AllowOverride None Require all denied </Directory> #<Directory /usr/share> # AllowOverride None # Require all granted #</Directory> #<Directory /var/www/> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory> ...
... #ServerTokens OS ServerTokens Prod ... #ServerSignature On ServerSignature Off ...
Zusätzliche Sicherheitsheader definieren
... Header always set Content-Security-Policy "default-src 'self'" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set X-Content-Type-Options "nosniff" Header always set X-Frame-Options "SAMEORIGIN" Header always set X-XSS-Protection "1; mode=block"
Standard-Host deaktivieren
a2dissite 000-default.conf
TLS-Konfiguration absichern
Mit Mozilla SSL Configuration Generator Apache-Einstellungen für Konfiguration Modern ermitteln
https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=apache-2.4.28&openssl=1.0.2g&hsts=yes&profile=modern ...
Konfigurationsdatei ssl.conf anpassen
... #SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 ... #SSLProtocol all ... Header always set Strict-Transport-Security "max-age=15768000" SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256 SSLHonorCipherOrder on SSLCompression off SSLSessionTickets off SSLUseStapling on SSLStaplingResponderTimeout 5 SSLStaplingReturnResponderErrors off SSLStaplingCache shmcb:/var/run/ocsp(128000) ...
Konfiguration testen, Apache neustarten und Status abfragen
apache2ctl configtest systemctl reload apache2 systemctl status apache2.service
[Optional] Benutzerdatei für Basis-Authentifizierung geschützter Website-Bereiche anlegen
Benutzernamen mit Passwortgenerator z. B. KeePass generieren
ADGVVNVjJnF6sBnhOV1f
Benutzerdatei mit bcrypt-Passwort-Hash neu erstellen
htpasswd -B -c /etc/apache2/.htpasswd ADGVVNVjJnF6sBnhOV1f
[Optional] mit Parameter -C Anzahl der Iterationen für bcrypt (Parameter -B) erhöhen (Defaultwert 5) => Sicherheit höher, Seitenaufrufe langsamer
[Optional] Logdateien nur 7 Tage lang aufbewahren
... #rotate 14 rotate 7 ...
[Optional] Core Dumps einrichten
Verzeichnis für Core Dumps in Apache-Konfiguration hinterlegen
... CoreDumpDirectory /tmp
Größenbegrenzung für Core Dumps vor Apache-Start aufheben
Apache-SysVinit-Skript ergänzen
... do_start() { ulimit -c unlimited #Größenbegrenzung für Core Dumps aufheben ...
systemd-Konfigurationsdateien neu laden und Units neu starten
systemctl daemon-reload
Aufbau der Core-Dump-Dateinamen festlegen
Format core-Programm-Hostname-PID-UID-GID-Zeitstempel
Temporär bis zum nächsten Neustart
echo "/tmp/core-%e-%h-%p-%u-%g-%t" > /proc/sys/kernel/core_pattern
Dauerhaft bei jedem Systemstart
... kernel.core_pattern=/tmp/core-%e-%h-%p-%u-%g-%t
sysctl --load=/etc/sysctl.conf
Konfiguration testen, Apache neustarten und Status abfragen
apache2ctl configtest systemctl restart apache2 systemctl status apache2.service
Quellen
https://httpd.apache.org/
https://httpd.apache.org/docs/2.4/misc/security_tips.html
https://httpd.apache.org/docs/2.4/mod/mod_ssl.html
https://httpd.apache.org/docs/2.4/programs/htpasswd.html
https://infosec.mozilla.org/guidelines/web_security.html
https://keepass.info/
http://manpages.ubuntu.com/manpages/xenial/man5/core.5.html
http://manpages.ubuntu.com/manpages/xenial/man5/sysctl.conf.5.html
http://manpages.ubuntu.com/manpages/xenial/man8/logrotate.8.html
http://manpages.ubuntu.com/manpages/xenial/man8/sysctl.8.html
https://mozilla.github.io/server-side-tls/ssl-config-generator/
https://wiki.mozilla.org/Security/Server_Side_TLS