Apache2: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
(typo)
K (cat)
Zeile 1: Zeile 1:
als Webserver verwenden wir Apache2 mit PHP4, mod_security, mod_auth_pam, mod_deflate. Desweiteren lassen wir die Logfiles nach einem Tag rotieren. Rotiert wird nach UTC, d.h. wir müssen eine Stunde wieder abziehen (-60).
als Webserver verwenden wir Apache2 mit PHP4, mod_security, mod_auth_pam, mod_deflate. Desweiteren lassen wir die Logfiles nach einem Tag rotieren. Rotiert wird nach UTC, d.h. wir müssen eine Stunde wieder abziehen (-60).  


==Multihome-Umgebung==
== Multihome-Umgebung ==
In einer Multihome-Umgebung laufen z.b. mehrere verschiedene Domains/Apache-Prozesse auf einem Server. Diese Domains haben aber überhaupt nichts miteinander zu tun. D. h.  wiederrum, daß die Domains bzw. der User, die dahinter stehen, natürlich auch kein Zugriff auf die jeweiligen Dateien der andere Domains haben. Gleiches gilt natürlich für den Apache-Prozess! Desweiteren sollten die Apache-Prozesse aus Sicherheitsgründen in einem [http://de.wikipedia.org/wiki/Chroot Chroot] laufen. Diese Funktionalität bringt mod-security mit. Alternativen zu Chroot wären noch z.b. BSD-Jails, Xen, uml (user mode linux), virtuozzo(openvz), bochs, Sun-Zones, qemu bzw. vmware, da chroot auch nicht immer das beste ist, siehe [http://www.bpfh.net/simes/computing/chroot-break.html hier]. Der Vorteil beim chroot von mod-security ist, das man selbst '''kein''' eigenes Chroot bauen muß, da mod-security den chroot-call erst am Ende der Konfiguration macht. Der Apache-Prozess ist also in seinem Document-Root ''gefangen''.


Für die technische Umsetzung bedeutet das folgendes:
In einer Multihome-Umgebung laufen z.b. mehrere verschiedene Domains/Apache-Prozesse auf einem Server. Diese Domains haben aber überhaupt nichts miteinander zu tun. D. h. wiederrum, daß die Domains bzw. der User, die dahinter stehen, natürlich auch kein Zugriff auf die jeweiligen Dateien der andere Domains haben. Gleiches gilt natürlich für den Apache-Prozess! Desweiteren sollten die Apache-Prozesse aus Sicherheitsgründen in einem [http://de.wikipedia.org/wiki/Chroot Chroot] laufen. Diese Funktionalität bringt mod-security mit. Alternativen zu Chroot wären noch z.b. BSD-Jails, Xen, uml (user mode linux), virtuozzo(openvz), bochs, Sun-Zones, qemu bzw. vmware, da chroot auch nicht immer das beste ist, siehe [http://www.bpfh.net/simes/computing/chroot-break.html hier]. Der Vorteil beim chroot von mod-security ist, das man selbst '''kein''' eigenes Chroot bauen muß, da mod-security den chroot-call erst am Ende der Konfiguration macht. Der Apache-Prozess ist also in seinem Document-Root ''gefangen''.  
*Jede Domain hat eine eigenen User/Gruppe (der User ist nicht in seiner eigene Gruppe!, der User bekommt nur r-Rechte, die Gruppe rw-Rechte. In dieser Gruppe muß auch der User sein, der die Seiten der Website pflegt.)
* Chroot ins Document-Root
* Jede Domain hat eigene apache2_xxx.conf
* init-script "multidomain"-fähig machen
* Der Sitename darf keine Zahlen am anfang haben, sonst gehen die Scripts nicht.


===apache2.conf===
Für die technische Umsetzung bedeutet das folgendes:
Bisher war die globale Config in der Datei apache2.conf. Das wollen wir jetzt ändern, aber so, daß die orginal-apache-scripts noch funktionieren. Deshalb kopieren wir apache2.conf nach apache2_common.conf und entfernen die letzte Zeile. Nun eine neue apache2.conf:
 
<pre>
*Jede Domain hat eine eigenen User/Gruppe (der User ist nicht in seiner eigene Gruppe!, der User bekommt nur r-Rechte, die Gruppe rw-Rechte. In dieser Gruppe muß auch der User sein, der die Seiten der Website pflegt.)
# include global-apache2.conf
*Chroot ins Document-Root
*Jede Domain hat eigene apache2_xxx.conf
*init-script "multidomain"-fähig machen
*Der Sitename darf keine Zahlen am anfang haben, sonst gehen die Scripts nicht.
 
=== apache2.conf ===
 
Bisher war die globale Config in der Datei apache2.conf. Das wollen wir jetzt ändern, aber so, daß die orginal-apache-scripts noch funktionieren. Deshalb kopieren wir apache2.conf nach apache2_common.conf und entfernen die letzte Zeile. Nun eine neue apache2.conf:  
<pre># include global-apache2.conf
include /etc/apache2/apache2_common.conf
include /etc/apache2/apache2_common.conf
# Include the virtual host configurations:
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/[^.#]
Include /etc/apache2/sites-enabled/[^.#]
</pre>
</pre>  
=== apache2_website.conf ===


===apache2_website.conf===
Nun kommt die eigentliche Website-Config /etc/apache2/chroot/xxx.conf  
Nun kommt die eigentliche Website-Config /etc/apache2/chroot/xxx.conf
<pre># include global-apache2.conf
<pre>
# include global-apache2.conf
include /etc/apache2/apache2_common.conf
include /etc/apache2/apache2_common.conf
LockFile /data/www/meine.de/www/var/lock/apache2/accept.lock
LockFile /data/www/meine.de/www/var/lock/apache2/accept.lock
Zeile 38: Zeile 39:


Listen 10.0.0.2:82
Listen 10.0.0.2:82
<VirtualHost 10.0.0.2:82>
&lt;VirtualHost 10.0.0.2:82&gt;
  ServerName www.meine.de
  ServerName www.meine.de
  ServerAdmin webmaster@website.tld
  ServerAdmin webmaster@website.tld
  DocumentRoot htdocs/
  DocumentRoot htdocs/
  <Directory />
  &lt;Directory /&gt;
   Options FollowSymLinks
   Options FollowSymLinks
   AllowOverride all
   AllowOverride all
  </Directory>
  &lt;/Directory&gt;
  ErrorLog log/error.log
  ErrorLog log/error.log


Zeile 54: Zeile 55:


  CustomLog "|/usr/sbin/rotatelogs log/access.log.%Y-%m-%d 86400 -60" combined
  CustomLog "|/usr/sbin/rotatelogs log/access.log.%Y-%m-%d 86400 -60" combined
</VirtualHost>
&lt;/VirtualHost&gt;
</pre>
</pre>  
== virt. Host ==


==virt. Host==
bsp site-conf /etc/apache2/sites-available/xxxtemplate:  
bsp site-conf /etc/apache2/sites-available/xxxtemplate:


  Listen 62.146.xxx.xxx:80
  Listen 62.146.xxx.xxx:80
  <VirtualHost 62.146.xxx.xxx:80>
  &lt;VirtualHost 62.146.xxx.xxx:80&gt;
         ServerAdmin webmaster@xxx
         ServerAdmin webmaster@xxx
         ServerName www.xxxx
         ServerName www.xxxx
         ServerAlias xxxx2
         ServerAlias xxxx2
         DocumentRoot /home/www/xxxx/htdocs
         DocumentRoot /home/www/xxxx/htdocs
         <Directory />
         &lt;Directory /&gt;
                 Options FollowSymLinks
                 Options FollowSymLinks
                 AllowOverride None
                 AllowOverride None
         </Directory>
         &lt;/Directory&gt;
         ErrorLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/error.log.%Y.%m.%d 86400 -60"
         ErrorLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/error.log.%Y.%m.%d 86400 -60"
         # Possible values include: debug, info, notice, warn, error, crit,
         # Possible values include: debug, info, notice, warn, error, crit,
Zeile 75: Zeile 76:
         LogLevel warn
         LogLevel warn
         CustomLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/access.log.%Y.%m.%d 86400 -60" combined
         CustomLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/access.log.%Y.%m.%d 86400 -60" combined
  </VirtualHost>
  &lt;/VirtualHost&gt;
 
== Module ==
 
=== Verzeichnisschutz ===
 
==== mod_auth_pam ====
 
Für den Verzeichnisschutz verwenden wir mod_auth_pam, d.h. wir können die gleichen Logindaten wie am System nutzen. '''Damit man eine Gruppe nutzen kann, wird libapache2-mod-auth-sys-group benötigt!'''


==Module==
eine bsp. .htaccess:
===Verzeichnisschutz===
====mod_auth_pam====
Für den Verzeichnisschutz verwenden wir mod_auth_pam, d.h. wir können die gleichen Logindaten wie am System nutzen. '''Damit man eine Gruppe nutzen kann, wird libapache2-mod-auth-sys-group benötigt!'''


eine bsp. .htaccess:
  AuthPAM_Enabled on
  AuthPAM_Enabled on
  AuthType Basic
  AuthType Basic
Zeile 88: Zeile 93:
  require group staff
  require group staff


Falls es nicht geht, vom error.log:
Falls es nicht geht, vom error.log:  
 
  [error] [client 217.229.133.31] PAM: user 'xyz' - not authenticated: Authentication failure
  [error] [client 217.229.133.31] PAM: user 'xyz' - not authenticated: Authentication failure


'''Der User www-data muß Mitglied der Gruppe shadow sein!'''
'''Der User www-data muß Mitglied der Gruppe shadow sein!'''  
 
==== mod_auth_mysql ====


====mod_auth_mysql====
alternativ kann man die User für den Schutz auch in eine MySQL-DB ablegen, anstatt z.b. aus passwd (PAM)  
alternativ kann man die User für den Schutz auch in eine MySQL-DB ablegen, anstatt z.b. aus passwd (PAM)


*MySQL-DB und Tabelle anlegen
*MySQL-DB und Tabelle anlegen
<pre>
<pre>CREATE TABLE `clients` (
CREATE TABLE `clients` (
`username` varchar(25) NOT NULL default '',
`username` varchar(25) NOT NULL default '',
`passwd` varchar(25) NOT NULL default '',
`passwd` varchar(25) NOT NULL default '',
Zeile 106: Zeile 112:
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


INSERT INTO `clients` VALUES ('<username>', password('<password>'), '<group>');
INSERT INTO `clients` VALUES ('&lt;username&gt;', password('&lt;password&gt;'), '&lt;group&gt;');
</pre>
</pre>  
 
*Modul in der Site (VirtualHost) aktivieren
*Modul in der Site (VirtualHost) aktivieren
<pre>
<pre>#/etc/apache2/sites-available/domain.com
#/etc/apache2/sites-available/domain.com
Auth_MySQL_Info localhost mysqluser mysqlpasswd
Auth_MySQL_Info localhost mysqluser mysqlpasswd
</pre>
</pre>  
 
und Schutz aktivieren (.htaccess)  
und Schutz aktivieren (.htaccess)
<pre>AuthMYSQL on
<pre>
AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_Authoritative on
AuthMySQL_DB mysqldb
AuthMySQL_DB mysqldb
Zeile 128: Zeile 130:
AuthType Basic
AuthType Basic


<Limit GET POST>
&lt;Limit GET POST&gt;
require group www
require group www
</Limit>
&lt;/Limit&gt;


</pre>
</pre>  
==== mod-auth-imap ====


====mod-auth-imap====
Source: http://ben.brillat.net/projects/mod_auth_imap/<br> kleines Howto: https://hw.cs.southern.edu/prot/mod_auth_imap.htm  
Source: http://ben.brillat.net/projects/mod_auth_imap/<br>
kleines Howto: https://hw.cs.southern.edu/prot/mod_auth_imap.htm


Debian-Package (http://debian.gallet.info/locale.do?language=en):
Debian-Package (http://debian.gallet.info/locale.do?language=en): http://www.gallet.info.free.fr/debian/pool/main/sarge/libapache2-mod-auth-imap/libapache2-mod-auth-imap_2.0.2-1_i386.deb oder per source.list  
http://www.gallet.info.free.fr/debian/pool/main/sarge/libapache2-mod-auth-imap/libapache2-mod-auth-imap_2.0.2-1_i386.deb oder per source.list
<pre>deb http://www.gallet.info.free.fr/debian/ sarge contrib main non-free
<pre>
deb http://www.gallet.info.free.fr/debian/ sarge contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge contrib main non-free


deb http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free
deb http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free
</pre>
</pre>  
 
<br> .htaccess  
<pre>#Turn on IMAP Authentication
.htaccess
<pre>
#Turn on IMAP Authentication
Auth_IMAP_Enabled on
Auth_IMAP_Enabled on


Zeile 173: Zeile 169:
#Turn on some extra logging (login attempts, etc.) in Apache's Error Log
#Turn on some extra logging (login attempts, etc.) in Apache's Error Log
Auth_IMAP_Log on
Auth_IMAP_Log on
</pre>
</pre>  
=== mod_security ===


===mod_security===
ModSecurity is an open source, free web application firewall (WAF) Apache module. With over 70% of all attacks now carried out over the web application level, organizations need all the help they can get in making their systems secure. WAFs are deployed to establish an external security layer that increases security, detects and prevents attacks before they reach web applications. It provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and real-time analysis with little or no changes to existing infrastructure.<br>  
ModSecurity is an open source, free web application firewall (WAF) Apache module. With over 70% of all attacks now carried out over the web application level, organizations need all the help they can get in making their systems secure. WAFs are deployed to establish an external security layer that increases security, detects and prevents attacks before they reach web applications. It provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and real-time analysis with little or no changes to existing infrastructure.<br/>


Installation http://www.vinno.net/linux/server/how-to-install-mod-security-2<br/>
Installation http://www.vinno.net/linux/server/how-to-install-mod-security-2<br>  


<source lang="apache">
<source lang="apache">
Zeile 212: Zeile 208:
     #SecFilter "<(.|\n)+>"
     #SecFilter "<(.|\n)+>"
  </IfModule>
  </IfModule>
</source>
</source>  


Für bestimmte Verzeichnisse kann man den Filter auch ausstellen:
Für bestimmte Verzeichnisse kann man den Filter auch ausstellen: <source lang="apache">
<source lang="apache">
  <Location /upload.php>
  <Location /upload.php>
     # Do not inherit filters from the parent folder
     # Do not inherit filters from the parent folder
     SecFilterInheritance Off
     SecFilterInheritance Off
  </Location>
  </Location>
</source>
</source>  
 
[http://www.infosecwriters.com/texts.php?op=display&id=255Defending Web Services using Mod Security (Apache) Methodology and Filtering Techniques by Shreeraj Shah on 19/01/05]
 
http://www.gotroot.com/mod_security+rules


[http://www.infosecwriters.com/texts.php?op=display&id=255Defending Web Services using Mod Security (Apache) Methodology and Filtering Techniques  by  Shreeraj Shah on  19/01/05]
[http://www.heise.de/security/artikel/69070/0 Die Apache-Firewall: Web-Server mit mod_security absichern]  


http://www.gotroot.com/mod_security+rules
=== mod_php ===


[http://www.heise.de/security/artikel/69070/0 Die Apache-Firewall: Web-Server mit mod_security absichern]
Aus Sicherheitsgründen vestecken wir die PHP-Version im HTTP-Header /etc/php4/apache2/php.ini


===mod_php===
Aus Sicherheitsgründen vestecken wir die PHP-Version im HTTP-Header /etc/php4/apache2/php.ini
  expose_php = off
  expose_php = off
  memory_limit = 50M     ; Maximum amount of memory a script may consume (8MB)
  memory_limit = 50M     &nbsp;; Maximum amount of memory a script may consume (8MB)
  allow_url_fopen = Off
  allow_url_fopen = Off
  [Zend]
  [Zend]
Zeile 242: Zeile 239:
  #zend_extension_ts=/usr/lib/php4/Zend/lib/ZendExtensionManager_TS.so
  #zend_extension_ts=/usr/lib/php4/Zend/lib/ZendExtensionManager_TS.so


PHP kann man auch mit Hilfe von fastcgi als cgi installieren. Desweiteren ist es dann möglich, die einzelnen PHP-prozesse unter verschiedenen Usern laufen zu lassen. Die Anleitung gibts hier: http://www.debianhowto.de/doku.php/de:howtos:sarge:apache2_php-fcgi
PHP kann man auch mit Hilfe von fastcgi als cgi installieren. Desweiteren ist es dann möglich, die einzelnen PHP-prozesse unter verschiedenen Usern laufen zu lassen. Die Anleitung gibts hier: http://www.debianhowto.de/doku.php/de:howtos:sarge:apache2_php-fcgi  
 
Security-Tips: http://aymanh.com/checklist-for-securing-php-configuration


Security-Tips: http://aymanh.com/checklist-for-securing-php-configuration
=== mod_dav ===


===mod_dav===
[http://httpd.apache.org/docs/2.0/mod/mod_dav.html WEBDAV-Modul] für Apache. Damit ist es möglich Dateien über https zu manipulieren (ändern, löschen, erstellen usw.). installieren: a2enmod dav  
[http://httpd.apache.org/docs/2.0/mod/mod_dav.html WEBDAV-Modul] für Apache. Damit ist es möglich Dateien über https zu manipulieren (ändern, löschen, erstellen usw.).
installieren: a2enmod dav


<br> gretchen:/etc/mail# more /etc/apache2/mods-enabled/dav_fs.conf


gretchen:/etc/mail# more /etc/apache2/mods-enabled/dav_fs.conf
  DAVLockDB /var/lock/apache2/DAVLock
  DAVLockDB /var/lock/apache2/DAVLock


httpd.conf
httpd.conf  
 
  Alias /phparea /home/gstein/php_files
  Alias /phparea /home/gstein/php_files
  Alias /php-source /home/gstein/php_files
  Alias /php-source /home/gstein/php_files
  DavLockDB /tmp/DavLock.myvhost
  DavLockDB /tmp/DavLock.myvhost
  <Location /php-source>
  &lt;Location /php-source&gt;
   Dav On
   Dav On
   AuthType Basic
   AuthType Basic
Zeile 265: Zeile 263:
   require group staff
   require group staff
   php_flag engine off # oder  ForceType text/plain
   php_flag engine off # oder  ForceType text/plain
  </Location>
  &lt;/Location&gt;
 
=== mod_evasive ===


===mod_evasive===
mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities.  
mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities.


Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:
Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:  


* Requesting the same page more than a few times per second
*Requesting the same page more than a few times per second  
* Making more than 50 concurrent requests on the same child per second
*Making more than 50 concurrent requests on the same child per second  
* Making any requests while temporarily blacklisted (on a blocking list)
*Making any requests while temporarily blacklisted (on a blocking list)


http://www.debianhowto.de/doku.php/de:howtos:sarge:mod_evasive
http://www.debianhowto.de/doku.php/de:howtos:sarge:mod_evasive  


ungetestet:
ungetestet: <source lang="apache">
<source lang="apache">
<IfModule mod_evasive.c>
<IfModule mod_evasive.c>
   #DOSHashTableSize gibt die Größe der Hashtabelle in Bytes an
   #DOSHashTableSize gibt die Größe der Hashtabelle in Bytes an
Zeile 309: Zeile 307:
   #DOSWhitelist 127.0.0.1
   #DOSWhitelist 127.0.0.1
</IfModule>
</IfModule>
</source>
</source>  


=== mod_cband  ===
=== mod_cband  ===
Zeile 322: Zeile 320:
SSLProtocol -all +SSLv3
SSLProtocol -all +SSLv3
SSLCipherSuite SSLv3:+HIGH:+MEDIUM
SSLCipherSuite SSLv3:+HIGH:+MEDIUM
</source>
</source>  
 
== Links ==
 
http://httpd.apache.org/docs/2.0/programs/rotatelogs.html<br> http://www.php-accelerator.co.uk/<br> [http://mambo.edes.at/index.php?option=com_docman&Itemid=30&task=view_category&catid=81&order=dmdate_published&ascdesc=DESC, ''PHPACA Web Front End'']<br> http://www.modsecurity.org/<br> http://www.nuclearelephant.com/projects/mod_evasive/<br> [http://www.askapache.com/2006/htaccess/speed-up-sites-with-htaccess-caching.html/ Speed Up Sites with htaccess Caching]
 
[[Category:WWW]]


==Links==
[[Kategorie:WWW]]
http://httpd.apache.org/docs/2.0/programs/rotatelogs.html<br>
[[Kategorie:Apache]]
http://www.php-accelerator.co.uk/<br>
[http://mambo.edes.at/index.php?option=com_docman&Itemid=30&task=view_category&catid=81&order=dmdate_published&ascdesc=DESC,''PHPACA Web Front End'']<br>
http://www.modsecurity.org/<br>
http://www.nuclearelephant.com/projects/mod_evasive/<br>
[http://www.askapache.com/2006/htaccess/speed-up-sites-with-htaccess-caching.html/ Speed Up Sites with htaccess Caching]
[[Category: WWW]]

Version vom 4. Februar 2011, 03:27 Uhr

als Webserver verwenden wir Apache2 mit PHP4, mod_security, mod_auth_pam, mod_deflate. Desweiteren lassen wir die Logfiles nach einem Tag rotieren. Rotiert wird nach UTC, d.h. wir müssen eine Stunde wieder abziehen (-60).

Multihome-Umgebung

In einer Multihome-Umgebung laufen z.b. mehrere verschiedene Domains/Apache-Prozesse auf einem Server. Diese Domains haben aber überhaupt nichts miteinander zu tun. D. h. wiederrum, daß die Domains bzw. der User, die dahinter stehen, natürlich auch kein Zugriff auf die jeweiligen Dateien der andere Domains haben. Gleiches gilt natürlich für den Apache-Prozess! Desweiteren sollten die Apache-Prozesse aus Sicherheitsgründen in einem Chroot laufen. Diese Funktionalität bringt mod-security mit. Alternativen zu Chroot wären noch z.b. BSD-Jails, Xen, uml (user mode linux), virtuozzo(openvz), bochs, Sun-Zones, qemu bzw. vmware, da chroot auch nicht immer das beste ist, siehe hier. Der Vorteil beim chroot von mod-security ist, das man selbst kein eigenes Chroot bauen muß, da mod-security den chroot-call erst am Ende der Konfiguration macht. Der Apache-Prozess ist also in seinem Document-Root gefangen.

Für die technische Umsetzung bedeutet das folgendes:

  • Jede Domain hat eine eigenen User/Gruppe (der User ist nicht in seiner eigene Gruppe!, der User bekommt nur r-Rechte, die Gruppe rw-Rechte. In dieser Gruppe muß auch der User sein, der die Seiten der Website pflegt.)
  • Chroot ins Document-Root
  • Jede Domain hat eigene apache2_xxx.conf
  • init-script "multidomain"-fähig machen
  • Der Sitename darf keine Zahlen am anfang haben, sonst gehen die Scripts nicht.

apache2.conf

Bisher war die globale Config in der Datei apache2.conf. Das wollen wir jetzt ändern, aber so, daß die orginal-apache-scripts noch funktionieren. Deshalb kopieren wir apache2.conf nach apache2_common.conf und entfernen die letzte Zeile. Nun eine neue apache2.conf:

# include global-apache2.conf
include /etc/apache2/apache2_common.conf
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/[^.#]

apache2_website.conf

Nun kommt die eigentliche Website-Config /etc/apache2/chroot/xxx.conf

# include global-apache2.conf
include /etc/apache2/apache2_common.conf
LockFile /data/www/meine.de/www/var/lock/apache2/accept.lock

User wwwxxx
Group wwwxxx
ServerRoot "/data/www/meine.de/www"
SecChrootLock /data/www/meine.de/www/log/modsec_chroot.lock
SecChrootDir /data/www/meine.de/www

# PidFile: The file in which the server should record its process
# identification number when it starts.
PidFile /data/www/meine.de/www/var/run/apache2.pid

Listen 10.0.0.2:82
<VirtualHost 10.0.0.2:82>
 ServerName www.meine.de
 ServerAdmin webmaster@website.tld
 DocumentRoot htdocs/
 <Directory />
  Options FollowSymLinks
  AllowOverride all
 </Directory>
 ErrorLog log/error.log

 php_admin_value open_basedir /var/www/user1/user1-1.tld/
 php_admin_value upload_tmp_dir /var/www/user1/user1-1.tld/temp
 php_admin_value session.save_path /var/www/user1/user1-1.tld/temp/
 php_admin_value safe_mode 1

 CustomLog "|/usr/sbin/rotatelogs log/access.log.%Y-%m-%d 86400 -60" combined
</VirtualHost>

virt. Host

bsp site-conf /etc/apache2/sites-available/xxxtemplate:

Listen 62.146.xxx.xxx:80
<VirtualHost 62.146.xxx.xxx:80>
       ServerAdmin webmaster@xxx
       ServerName www.xxxx
       ServerAlias xxxx2
       DocumentRoot /home/www/xxxx/htdocs
       <Directory />
               Options FollowSymLinks
               AllowOverride None
       </Directory>
       ErrorLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/error.log.%Y.%m.%d 86400 -60"
       # Possible values include: debug, info, notice, warn, error, crit,
       # alert, emerg.
       LogLevel warn
       CustomLog "|/usr/sbin/rotatelogs /home/www/xxxx/logs/access.log.%Y.%m.%d 86400 -60" combined
</VirtualHost>

Module

Verzeichnisschutz

mod_auth_pam

Für den Verzeichnisschutz verwenden wir mod_auth_pam, d.h. wir können die gleichen Logindaten wie am System nutzen. Damit man eine Gruppe nutzen kann, wird libapache2-mod-auth-sys-group benötigt!

eine bsp. .htaccess:

AuthPAM_Enabled on
AuthType Basic
AuthName "secure area"
require group staff

Falls es nicht geht, vom error.log:

[error] [client 217.229.133.31] PAM: user 'xyz' - not authenticated: Authentication failure

Der User www-data muß Mitglied der Gruppe shadow sein!

mod_auth_mysql

alternativ kann man die User für den Schutz auch in eine MySQL-DB ablegen, anstatt z.b. aus passwd (PAM)

  • MySQL-DB und Tabelle anlegen
CREATE TABLE `clients` (
`username` varchar(25) NOT NULL default '',
`passwd` varchar(25) NOT NULL default '',
`groups` varchar(25) NOT NULL default '',
PRIMARY KEY (`username`),
KEY `groups` (`groups`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `clients` VALUES ('<username>', password('<password>'), '<group>');
  • Modul in der Site (VirtualHost) aktivieren
#/etc/apache2/sites-available/domain.com
Auth_MySQL_Info localhost mysqluser mysqlpasswd

und Schutz aktivieren (.htaccess)

AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_DB mysqldb
AuthMySQL_Password_Table clients
AuthMySQL_Group_Table clients
AuthMySQL_Empty_Passwords off
AuthMySQL_Encryption_Types MySQL

AuthName Adminarea
AuthType Basic

<Limit GET POST>
require group www
</Limit>

mod-auth-imap

Source: http://ben.brillat.net/projects/mod_auth_imap/
kleines Howto: https://hw.cs.southern.edu/prot/mod_auth_imap.htm

Debian-Package (http://debian.gallet.info/locale.do?language=en): http://www.gallet.info.free.fr/debian/pool/main/sarge/libapache2-mod-auth-imap/libapache2-mod-auth-imap_2.0.2-1_i386.deb oder per source.list

deb http://www.gallet.info.free.fr/debian/ sarge contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge contrib main non-free

deb http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free
deb-src http://www.gallet.info.free.fr/debian/ sarge-update contrib main non-free


.htaccess

#Turn on IMAP Authentication
Auth_IMAP_Enabled on

#Give a name to the authentication domain, whatever you want:
AuthName "SAU Email username and password"

#Only basic authentication is supported for now:
AuthType Basic

#If you feel like it, restrict the users or allow all valid users:
Require valid-user
#Make IMAP Authentication authoritative for this .htaccess file:
Auth_IMAP_Authoritative on

#Set the IMAP Server to which you want to connect (default=localhost):
Auth_IMAP_Server imap.southern.edu

#Set the port on which the imap server is running (default=143):
Auth_IMAP_Port 143

#Turn on some extra logging (login attempts, etc.) in Apache's Error Log
Auth_IMAP_Log on

mod_security

ModSecurity is an open source, free web application firewall (WAF) Apache module. With over 70% of all attacks now carried out over the web application level, organizations need all the help they can get in making their systems secure. WAFs are deployed to establish an external security layer that increases security, detects and prevents attacks before they reach web applications. It provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring and real-time analysis with little or no changes to existing infrastructure.

Installation http://www.vinno.net/linux/server/how-to-install-mod-security-2

#v1.9x
#/etc/apache2/mods-avaible/mod-security.conf
 <IfModule mod_security.c>
    # Turn the filtering engine On or Off
    SecFilterEngine On
    # Make sure that URL encoding is valid
    SecFilterCheckURLEncoding On
    # Only allow bytes from this range
    SecFilterForceByteRange 1 255
    # The audit engine works independently and
    # can be turned On of Off on the per-server or
    # on the per-directory basis
    SecAuditEngine RelevantOnly
    # The name of the audit log file
    SecAuditLog /var/log/apache2/audit_log
    SecFilterDebugLog /var/log/apache2/modsec_debug_log
    SecFilterDebugLevel 0
    # Should mod_security inspect POST payloads
    SecFilterScanPOST On
    # Action to take by default
    SecFilterDefaultAction "deny,log,status:406"
    # Prevent OS specific keywords
    SecFilter /etc/ password
    SecFilter /bin/ ls
    # Prevent path traversal (..) attacks
    SecFilter "\.\./"
    # Weaker XSS protection but allows common HTML tags
    SecFilter "<( |\n)*script"
    # Prevent XSS atacks (HTML/Javascript injection)
    #SecFilter "<(.|\n)+>"
 </IfModule>

Für bestimmte Verzeichnisse kann man den Filter auch ausstellen:

 <Location /upload.php>
    # Do not inherit filters from the parent folder
    SecFilterInheritance Off
 </Location>

Web Services using Mod Security (Apache) Methodology and Filtering Techniques by Shreeraj Shah on 19/01/05

http://www.gotroot.com/mod_security+rules

Die Apache-Firewall: Web-Server mit mod_security absichern

mod_php

Aus Sicherheitsgründen vestecken wir die PHP-Version im HTTP-Header /etc/php4/apache2/php.ini

expose_php = off
memory_limit = 50M      ; Maximum amount of memory a script may consume (8MB)
allow_url_fopen = Off
[Zend]
zend_optimizer.optimization_level=15
zend_extension_manager.optimizer=/usr/lib/php4/Zend/lib/Optimizer-2.5.10
zend_extension_manager.optimizer_ts=/usr/lib/php4/Zend/lib/Optimizer_TS-2.5.10
zend_optimizer.version=2.5.10a
#zend_extension=/usr/lib/php4/Zend/lib/ZendExtensionManager.so
zend_extension=/usr/lib/php4/20020429/php_accelerator_1.3.3r2.so
#zend_extension_ts=/usr/lib/php4/Zend/lib/ZendExtensionManager_TS.so

PHP kann man auch mit Hilfe von fastcgi als cgi installieren. Desweiteren ist es dann möglich, die einzelnen PHP-prozesse unter verschiedenen Usern laufen zu lassen. Die Anleitung gibts hier: http://www.debianhowto.de/doku.php/de:howtos:sarge:apache2_php-fcgi

Security-Tips: http://aymanh.com/checklist-for-securing-php-configuration

mod_dav

WEBDAV-Modul für Apache. Damit ist es möglich Dateien über https zu manipulieren (ändern, löschen, erstellen usw.). installieren: a2enmod dav


gretchen:/etc/mail# more /etc/apache2/mods-enabled/dav_fs.conf

DAVLockDB /var/lock/apache2/DAVLock

httpd.conf

Alias /phparea /home/gstein/php_files
Alias /php-source /home/gstein/php_files
DavLockDB /tmp/DavLock.myvhost
<Location /php-source>
 Dav On
 AuthType Basic
 AuthName DAV
 AuthPAM_Enabled on
 require group staff
 php_flag engine off # oder  ForceType text/plain
</Location>

mod_evasive

mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities.

Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:

  • Requesting the same page more than a few times per second
  • Making more than 50 concurrent requests on the same child per second
  • Making any requests while temporarily blacklisted (on a blocking list)

http://www.debianhowto.de/doku.php/de:howtos:sarge:mod_evasive

ungetestet:

<IfModule mod_evasive.c>
  #DOSHashTableSize gibt die Größe der Hashtabelle in Bytes an
  DOSHashTableSize 3097

  #DOSPageCount gibt die Anzahl der Seitenaufrufe eines Clients pro DOSPageInterval-Zeitintervall
  DOSPageCount 5

  #DOSSiteCount gibt die Anzahl der Seitenaufrufe auf einen Child-Prozess pro DOSSiteInterval-Zeitintervall
  DOSSiteCount 50

  #DOSPageInterval und DOSSiteInterval werden in Sekunden angegeben
  DOSPageInterval 1
  DOSSiteInterval 1

  #DOSBlockingPeriod gibt die Sperrzeit in Seknunden an
  DOSBlockingPeriod 60

  #DOSEmailNotify gibts die eMail Adresse an, an welche eine Warnmail geschickt wird
  DOSEmailNotify admin@mydomain.net

  #DOSSystemCommand führt bei einem Angriff weitere Programme/Scripte aus wenn gewünscht
  #DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"

  #DOSLogDir gibt das Verzeichnis an in dem das Modul seine Logfiles schreibt
  DOSLogDir "/var/log/apache2/"

  #DOSWhitelist beinhaltet eine Aufzählung aller IP-Adressen für die mod_evasive NICHT gilt
  #DOSWhitelist 127.0.0.1
</IfModule>

mod_cband

Bandbreiten-Beschränkung http://nodomain.cc/archives/2007/01/05/684-Apache2-Zugriffskontrolle-mit-mod_cband.html

mod_ssl

Disable SSLv2, from http://aruljohn.com/info/sslversion/

SSLProtocol -all +SSLv3
SSLCipherSuite SSLv3:+HIGH:+MEDIUM

Links

http://httpd.apache.org/docs/2.0/programs/rotatelogs.html
http://www.php-accelerator.co.uk/
PHPACA Web Front End
http://www.modsecurity.org/
http://www.nuclearelephant.com/projects/mod_evasive/
Speed Up Sites with htaccess Caching