Just read
this article about defeating comment spam and thought write about how we defeat
trackback spam on
modprobe.de pretty good for some time now.
fail2ban is usually used to prevent
1337 h4xX0rZ from
brute forcing ssh logins on a server. But it can be very useful for other stuff too since it's not really more than a log analyzer.
nion.modprobe.de 207.67.117.173 - - [09/Sep/2007:22:59:03 +0200] "POST /blog/comment.php?type=trackback&entry_id=295 HTTP/1.1" 200 87 "-" "-"
This is how a typical trackback spam attempt looks in an apach2 log file.
If someone tries to place a trackback spam usually alot of log lines like this appear for every try of the spammer which is then causing a high load on your webserver (we had a load of 40) which is a real problem.
The first thing you have to do is to install fail2ban.
Then to prevent the trackback spam we create a filter file called blog.conf and place it under
/etc/fail2ban/filter.d:
[Definition]
failregex = (nion.modprobe.de|deifl.modprobe.de) <HOST> - -.*"POST /blog/comment\.php\?type=trackback
ignoreregex =
This regex scans for log lines for nion.modprobe.de or deifl.modprobe.de (most problematic vhosts).
For this you need an apache log file which adds the virtual host at the beginning of the line
(
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined)
Then you have to adapt your /etc/fail2ban/jail.conf and add a section like this:
[apache-blog]
enabled = true
port = http
filter = blog
logpath = /var/log/apache2/all_access.log
bantime = 43200
maxretry = 3
ignoreip = SERVER
Fail2ban should now see if more than 3 log lines like the one in the regular expression appear from one host and DROP this host via iptables.
If you don't have a log file for all virtual hosts you can use * to scan multiple files too.
I think the variables are pretty much self explanatory, setting the ignoreip to your server is a good idea if you set the maxretry to 0 and won't lose the chance to trackback yourself.
If you have really alot of traffic and don't rotate logs very often it is a good idea to have a second log file you delete every n hours because fail2ban costs a lot of CPU power on big log files.
To test your regular expressions you may want to use fail2ban-regex 'REGEX' 'LOGLINE'. This shows if fail2ban will match for this log line and how the will provide some small benchmark information.