How To Block Spammers/Hackers With Apache2's mod_spamhaus (Debian Etch)
mod_spamhaus is an Apache module that uses DNSBL in order to block spam relay via web forms, preventing URL injection, block http DDoS attacks from bots and generally protecting your web service denying access to a known bad IP address.
In order to compile mod_spamhaus, you must have apxs2 (APache eXtenSion tool) tool installed.
The follow command will install it:
apt-get install apache2-prefork-dev
Now we need to download the source package present at http://sourceforge.net/projects/mod-spamhaus/ or download it using wget application and this direct link to the repository:
Next open archive, compile and install module with those commands:
tar zxvf mod_spamhaus05.tar.gz
You must add LoadModule directive to the main config file of you're web server to load mod_spamhaus module.
[...] LoadModule spamhaus_module /usr/lib/apache2/modules/mod_spamhaus.so
Before we are able to write our configuration, we should known what directives are supported by mod_spamhaus:MS_Methods - If the httpd's method used by the visitor match, module verify user's ip address
MS_WhiteList - A simple whitelist file where you can put ip address to bypass
MS_DNS - DNSBL to use. Usefull if you want make a local rbldnsd instance
MS_CacheSize - Number of cached addresses
Now we open config file of our web server in order to write a basic configuration:
[...] <IfModule mod_spamhaus.c> MS_METHODS POST,PUT,OPTIONS,CONNECT MS_WhiteList /etc/spamhaus.wl MS_CacheSize 256 </IfModule> [...]
Next we create an empty whitelist file:
Finally we restart Apache2: