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 [2020/10/18 14:59] – [PHP] angelegt Sebastian Hetzelubuntu:apache_webserver [2022/11/06 15:28] (aktuell) – [Certbot installieren] Sebastian Hetzel
Zeile 1: Zeile 1:
-====== Ubuntu 18.04 und 20.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 107: Zeile 115:
 apt-get install python-certbot-apache</code> apt-get install python-certbot-apache</code>
  
-Bei Ubuntu 20.04 ist dies nicht mehr notwendig:+Ab Ubuntu 20.04 ist dies nicht mehr notwendig:
  
-<code> +Folgende Anleitung verwenden (snapd): 
-aptitude install certbot +https://certbot.eff.org/instructions?ws=apache&os=ubuntufocal
-aptitude install python3-certbot-apache +
-</code>+
 ==== Cerbot: Zertifikate anfordern und Webserver anpassen ==== ==== Cerbot: Zertifikate anfordern und Webserver anpassen ====
  
Zeile 211: Zeile 217:
 # 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 # 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> </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.1603025967.txt.gz · Zuletzt geändert: von Sebastian Hetzel

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki