Locking Down Apache - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: LAMP (https://www.linux-noob.com/forums/forum-83.html) +--- Thread: Locking Down Apache (/thread-2569.html) |
Locking Down Apache - xDamox - 2005-07-04 Well I though I would write another tutorial :) this time on apache on making it more secure and defending against DOS attacks this tutorial is for Apache version 2. The two packages I am going to use are the following: mod_security which is available from [/url]http://www.modsecurity.org/ mod_dosevasive which is available from http://www.nuclearelephant.com/projects/dosevasive/ I would like to give credit to fedoranew.org (Jorge A Gallegos) as I stumbled into mod_security there. Once you have downloaded the two packages unpack the as shown below. Code: tar zvxf modsecurity-1.8.7.tar.gz This will create two directory's which will contain the source code. Before we install these modules you should get the apxs which will build the module into apache for you, this tool can be downloaded via yum as shown below. Code: yum install httpd-devel Once that is installed go into mod_security decompressed directory and type the following as root: Code: apxs -cia mod_security.c This should produce the following out put: Code: /bin/sh /usr/lib/apr/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -march=i386 -mcpu=i686 -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apr-0 -I/usr/include/httpd -c -o mod_security.lo mod_security.c && touch mod_security.slo Once that has been done go to the /etc/httpd/conf.d/ directory and create a file called: "mod_security.conf". Once this file is created paste the following into the config file: Code: <IfModule mod_security.c> That is the config file I use, you can also visit mod_security web site to view all the rules that can be applied into this config file. Once the config file has been setup restart apache as shown below. Code: services httpd restart Once thats restarted open your web browser and type 127.0.0.1/etc this should say in you web browser: Code: Not Acceptable Now goto /var/log/httpd and you should see a file called audit_log the content will display something similar to: Code: ======================================== As you may have noticed it has filtered out /etc and displayed the attackers details. Now that we have mod_security setup its now time to setup mod_dosevasive, first step is to change into mod_dosevasive decompressed directory and issue the following command. Code: apxs -i -a -c mod_dosevasive20.c This will produce the output similar to mod_security once that has installed you can delete both decompressed directorys and their comrpess version. Open the httpd.conf file and add the following entry: Code: <IfModule mod_dosevasive20.c> The following values are as stated from the mod_dosevasive. DOSHashTableSize ---------------- The hash table size defines the number of top-level nodes for each child's hash table. Increasing this number will provide faster performance by decreasing the number of iterations required to get to the record, but consume more memory for table space. You should increase this if you have a busy web server. The value you specify will automatically be tiered up to the next prime number in the primes list (see mod_dosevasive.c for a list of primes used). DOSPageCount ------------ This is the threshhold for the number of requests for the same page (or URI) per page interval. Once the threshhold for that interval has been exceeded, the IP address of the client will be added to the blocking list. DOSSiteCount ------------ This is the threshhold for the total number of requests for any object by the same client on the same listener per site interval. Once the threshhold for that interval has been exceeded, the IP address of the client will be added to the blocking list. DOSPageInterval --------------- The interval for the page count threshhold; defaults to 1 second intervals. DOSSiteInterval --------------- The interval for the site count threshhold; defaults to 1 second intervals. DOSBlockingPeriod ----------------- The blocking period is the amount of time (in seconds) that a client will be blocked for if they are added to the blocking list. During this time, all subsequent requests from the client will result in a 403 (Forbidden) and the timer being reset (e.g. another 10 seconds). Since the timer is reset for every subsequent request, it is not necessary to have a long blocking period; in the event of a DoS attack, this timer will keep getting reset. DOSEmailNotify -------------- If this value is set, an email will be sent to the address specified whenever an IP address becomes blacklisted. A locking mechanism using /tmp prevents continuous emails from being sent. NOTE: Be sure MAILER is set correctly in mod_dosevasive.c (or mod_dosevasive20.c). The default is "/bin/mail -t %s" where %s is used to denote the destination email address set in the configuration. If you are running on linux or some other operating system with a different type of mailer, you'll need to change this. DOSSystemCommand ---------------- If this value is set, the system command specified will be executed whenever an IP address becomes blacklisted. This is designed to enable system calls to ip filter or other tools. A locking mechanism using /tmp prevents continuous system calls. Use %s to denote the IP address of the blacklisted IP. DOSLogDir --------- Choose an alternative temp directory By default "/tmp" will be used for locking mechanism, which opens some security issues if your system is open to shell users. [url=http://security.lss.hr/index.php?page=deta...=LSS-2005-01-01]http://security.lss.hr/index.php?page=deta...=LSS-2005-01-01 In the event you have nonprivileged shell users, you'll want to create a directory writable only to the user Apache is running as (usually root), then set this in your httpd.conf. Once all that is setup restart your apache server and enjoy the know fact that you have locked it down :)note that mod_dosevasive provide a test.pl file to check the mod_dosevasive is functioning correctly. Code: service httpd restart Locking Down Apache - anyweb - 2005-07-04 fantastic post, and moved to apache with a link here to it thanks cheers anyweb Locking Down Apache - znx - 2005-07-10 \o\ sweet knew about mod_security.. but mod_doevasive!! woot cheers xDamox |