First off, I assume you are “running as root” if not you will need to add “sudo” in front of the commands offered below. I am using Ubuntu; you can use this as a model if you are running a different flavor of *nix.
Prerequisites – all the crap you forgot
You will need to have build essential installed, this is to compile stuff.
apt-get install build-essential
You will also need to have a proper hostname!
nano /etc/hostname
It should look like this:
yourdomain.com
one more place:
nano /etc/hosts
It should look like this:
your.ip.goes.here yourdomain.com
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Get some development files:
apt-get install apache2-prefork-dev libxml++2.6-dev liblua5.1-0 liblua5.1-0-dev
Download and Install Mod Security:
Download from http://www.modsecurity.org/download/index.html
Get over it, just register it’s free.
I suggest downloading to your home directory.
Uncompress the file:
tar -xvvzf modsecurity-apache_2.5.7.tar.gz
Get into the right position:
cd /modsecurity-apache_2.5.7/apache2
Configure some things:
./configure --with-apxs=/usr/bin/apxs2
make your install:
make install
Load mod security 2 module up by creating a load file in Apache 2:
nano /etc/apache2/mods-available/mod-security2.load
Make it look like this:
LoadFile /usr/lib/libxml2.so
LoadFile /usr/lib/liblua5.1.so
LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so
Enable the Apache Module:
ln -s /etc/apache2/mods-available/mod-security2.load /etc/apache2/mods-enabled
enable unique id module which is already packed with apache2:
ln -s /etc/apache2/mods-available/unique_id.load /etc/apache2/mods-enabled
Tell Apache where we moved crap:
nano /etc/apache2/conf.d/modsecurity2.conf
It should look like this:
Include /etc/modsecurity/*.conf
Create a mod security directory where we can place our rule files and logs:
mkdir /etc/modsecurity
mkdir /etc/modsecurity/logs
touch /etc/modsecurity/logs/modsec_audit.log
touch /etc/modsecurity/logs/modsec_debug.log
Now we are going to gather the mod security 2 rules files, which came with the package mod security 2 you downloaded early on. There should be a directory called rules.
Go into that directory then we going to copy the rule config files over to /etc/modsecurity/:
sudo cp *.conf /etc/modsecurity/
Edit the rule config file called “modsecurity_crs_10_config.conf”:
nano /etc/modsecurity/modsecurity_crs_10_config.conf
Two changes need to be made:
SecDebugLog logs/modsec_debug.log
to
SecDebugLog /etc/modsecurity/logs/modsec_debug.log
SecAuditLog logs/modsec_audit.log
to
SecAuditLog /etc/modsecurity/logs/modsec_audit.log
Time to restart apache:
/etc/init.d/apache2 restart
check to make sure you listened correctly:
cat /var/log/apache2/error.log | grep ModSecurity
If it look like the following you=win!
[Sun Nov 26 21:64:51 2008] [notice] ModSecurity for Apache/2.5.7 (http://www.modsecurity.org/) configured
DONE!
Any questions leave a comment.