Benutzer-Werkzeuge

Webseiten-Werkzeuge


ubuntu:apache_webserver

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
ubuntu:apache_webserver [2019/06/21 10:28] – [Virtuellen Host konfigurieren] Erklärungen ergänzt und geändert Sebastian Hetzelubuntu:apache_webserver [2022/11/06 15:28] (aktuell) – [Certbot installieren] Sebastian Hetzel
Zeile 1: Zeile 1:
-====== Ubuntu 18.04: Apache Webserver ======+====== Ubuntu 18.04 und 20.04 und 22.04: Apache Webserver ====== 
 + 
 +{{:ubuntu:apache2_it_works.png|}}
  
 Ich verwende in dieser Anleitung das MPM ITK - http://mpm-itk.sesse.net/ . Ich verwende in dieser Anleitung das MPM ITK - http://mpm-itk.sesse.net/ .
Zeile 27: Zeile 29:
 </file> </file>
  
 +Sicherheistskritische Module ausschalten:
 +
 +<code>
 +# a2dismod info
 +# a2dismod status
 +</code>
 ===== Webserver-User für virtuellen Host ===== ===== Webserver-User für virtuellen Host =====
  
Zeile 96: Zeile 104:
 ==== Certbot installieren ==== ==== Certbot installieren ====
  
-Als root ausführen:+Für Ubuntu 18.04 musste noch ein PPA eingebunden werden. 
 +Bitte nachfolgende Befhele als root ausführen:
  
 <code> <code>
Zeile 106: Zeile 115:
 apt-get install python-certbot-apache</code> apt-get install python-certbot-apache</code>
  
 +Ab Ubuntu 20.04 ist dies nicht mehr notwendig:
 +
 +Folgende Anleitung verwenden (snapd):
 +> https://certbot.eff.org/instructions?ws=apache&os=ubuntufocal
 ==== Cerbot: Zertifikate anfordern und Webserver anpassen ==== ==== Cerbot: Zertifikate anfordern und Webserver anpassen ====
  
Zeile 113: Zeile 126:
 # certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email certadmin@meine-domain.de --domain www.meine-domain.de --domain meine-domain.de # certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email certadmin@meine-domain.de --domain www.meine-domain.de --domain meine-domain.de
 </code> </code>
 +
 +==== Cerbot: Zertifikatserneuerung testen ====
 +
 +<code>
 +# certbot renew --dry-run
 +</code>
 +==== Cerbot Zertifikatserneuerung automatisieren ====
 +
 +Als User root:
 +<code>
 +# crontab -e
 +</code>
 +
 +Beispiel für die Crontab:
 +
 +<code>
 +[...]
 +# m h  dom mon dow   command
 +35 7 * * * /usr/bin/certbot renew  >> /var/log/le-renew.log
 +</code>
 +
 +==== Verschlüsselung: Protokolle und Ciphers ====
 +
 +<file | /etc/letsencrypt/options-ssl-apache.conf>
 +# This file contains important security parameters. If you modify this file
 +# manually, Certbot will be unable to automatically provide future security
 +# updates. Instead, Certbot will print and log an error message with a path to
 +# the up-to-date file that you will need to refer to when manually updating
 +# this file.
 +
 +SSLEngine on
 +
 +# Intermediate configuration, tweak to your needs
 +SSLProtocol             all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
 +SSLCipherSuite          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS
 +SSLHonorCipherOrder     on
 +SSLCompression          off
 +
 +SSLOptions +StrictRequire
 +
 +# Add vhost name to log entries:
 +LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
 +LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
 +
 +#CustomLog /var/log/apache2/access.log vhost_combined
 +#LogLevel warn
 +#ErrorLog /var/log/apache2/error.log
 +
 +# Always ensure Cookies have "Secure" set (JAH 2012/1)
 +#Header edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4"
 +</file>
 +
 +In der Konfiguration des virtuellen Hosts:
 +
 +<code>
 +[...]
 +<IfModule mod_headers.c>
 +                 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
 +</IfModule>
 +[...]
 +</code>
 +===== Logfiles rotieren lassen =====
 +
 +<file | /etc/logrotate.d/apache2 >
 +/var/log/apache2/*.log /srv/www/*/log/*.log {
 +        daily
 +        missingok
 +        rotate 14
 +        compress
 +        delaycompress
 +        notifempty
 +        create 640 root adm
 +        sharedscripts
 +        postrotate
 +                if invoke-rc.d apache2 status > /dev/null 2>&1; then \
 +                    invoke-rc.d apache2 reload > /dev/null 2>&1; \
 +                fi;
 +        endscript
 +        prerotate
 +                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
 +                        run-parts /etc/logrotate.d/httpd-prerotate; \
 +                fi; \
 +        endscript
 +}
 +</file>
 +
 +===== PHP =====
 +
 +<code>
 +# aptitude install php php-cli php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath libapache2-mod-php php-imagick php-common
 +</code>
 +
 +===== ModSecurity =====
 +
 +Dieses Apache-Modul erkennt Angriffmuster (z. B. Session Hijacking, Cross-Site-Scripting) und verweigert bei Angriff die Anfrage.
 +
 +==== Installation ====
 +
 +<code>aptitude install libapache2-mod-security2</code>
 +
 +==== Konfiguration ====
 +
 +<code>
 +cd /etc/modsecurity/
 +cp modsecurity.conf-recommended modsecurity.conf
 +</code>
 +
 +ModSecurity sollte nun im DetectOnly-Modus laufen und erkannte Angriffsmuster unter ''/var/log/apache2/modsec_audit.log'' aufzeichnen.
 +
 +Dies kann folgendermaßen geändert werden:
 +
 +<file |h /etc/modsecurity/modsecurity.conf>
 +[...]
 +# Enable ModSecurity, attaching it to every transaction. Use detection
 +# only to start with, because that minimises the chances of post-installation
 +# disruption.
 +#
 +#SecRuleEngine DetectionOnly
 +SecRuleEngine On
 +[...]
 +</file>
 +
 +<file |h /etc/modsecurity/modsecurity.conf>
 +[...]
 +# Log everything we know about a transaction.
 +#SecAuditLogParts ABDEFHIJZ
 +SecAuditLogParts ABCEFHJKZ
 +[...]
 +</file>
 +
 +==== Aktuelles OWASP Core Rule Set ====
 +
 +<code>
 +cd /etc/modsecurity
 +git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
 +cd owasp-modsecurity-crs
 +cp crs-setup.conf.example crs-setup.conf
 +</code>
 +
 +Das Regelwerk hinterlegen:
 +
 +<file |h /etc/apache2/mods-enabled/security2.conf>
 +<IfModule security2_module>
 +        # Default Debian dir for modsecurity's persistent data
 +        SecDataDir /var/cache/modsecurity
 +
 +        # Include all the *.conf files in /etc/modsecurity.
 +        # Keeping your local configuration in that directory
 +        # will allow for an easy upgrade of THIS file and
 +        # make your life easier
 +        # IncludeOptional /etc/modsecurity/*.conf
 +        IncludeOptional /etc/modsecurity/modsecurity.conf
 +        IncludeOptional /etc/modsecurity/owasp-modsecurity-crs/crs-setup.conf
 +        IncludeOptional /etc/modsecurity/owasp-modsecurity-crs/rules/*.conf
 +
 +        # Include OWASP ModSecurity CRS rules if installed
 +        # IncludeOptional /usr/share/modsecurity-crs/*.load
 +</IfModule>
 +</file>
 +
 +Aktualisieren kann man das Ruleset, indem man einfach eine aktuelle Kopie von github zieht und diese in sein Conf-Verzeichnis kopiert. Bitte vorher die Konfig-Dateien an Seite legen.
 +
 +==== Logfiles ====
 +
 +Da sehr viele Daten geloggt werden, sollte man das Logfile täglich rotieren lassen:
 +
 +<file |h /etc/logrotate.d/modsecurity>
 +/var/log/apache2/modsec_audit.log
 +{
 +        rotate 14
 +        daily
 +        missingok
 +        compress
 +        delaycompress
 +        notifempty
 +}
 +</file>
 +
 +==== Regelausnahmen: Nextcloud ====
 +
 +=== Virtuellen Host anpassen für WebDAV ===
 +
 +<code>
 +[...]
 +<IfModule mod_headers.c>
 +                 Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
 +                 Redirect 301 /.well-known/carddav /remote.php/dav
 +                 Redirect 301 /.well-known/caldav /remote.php/dav
 +</IfModule>
 +[...]
 +</code>
 +
 +=== Ausnahmeregelungen für Nextcloud ===
 +
 +<file | REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf>
 +[...]
 +# Own ip address not monitored
 +SecRule REMOTE_ADDR "^20\.21\.22\.23" "id:1002,phase:1,nolog,allow,ctl:ruleEngine=Off"
 +
 +SecRule REQUEST_URI "@beginsWith /remote.php/dav" "id:1003,phase:1,nolog,allow,ctl:ruleRemoveById=932110"
 +</file>
 +
 +=== Globale Ausnahme-Presets für Nextcloud ===
 +
 +Achtung: Gilt für alle virtuellen Hosts!
 +
 +<file | >
 +[...]
 +SecAction \
 + "id:900130,\
 +  phase:1,\
 +  nolog,\
 +  pass,\
 +  t:none,\
 +  setvar:tx.crs_exclusions_nextcloud=1"
 +[...]
 +</file>
 +
 +> https://www.linuxbabe.com/security/modsecurity-apache-debian-ubuntu
ubuntu/apache_webserver.1561105726.txt.gz · Zuletzt geändert: von Sebastian Hetzel

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki