Random Bits

Random Bits

  • Home
  • Contact

Integrate fail2ban with WordPress: Spam Log Plugin

Recently, I’ve encountered some very aggressive WordPress spam bots. These bots post a new spam comment almost every minute for hours on end. Needless to say my spam queue is a mess. I wrote the following plugin to solve this problem.

What is Spam Log?

Spam Log is a simple WordPress plugin that logs a message every time a comment is marked as spam. Each log message includes the IP address of the poster and the comment’s ID. The log can easily be processed by fail2ban. fail2ban is a daemon that scans log files for misbehaving clients and bans them by IP address. Here is sample output generated by Spam Log:

2009-04-20 04:15:03 comment id=527 from host=83.233.30.32 marked as spam
2009-04-20 04:18:15 comment id=528 from host=83.233.30.32 marked as spam
2009-04-20 04:20:36 comment id=529 from host=83.233.30.32 marked as spam
2009-04-20 04:21:46 comment id=530 from host=83.233.30.32 marked as spam
2009-04-20 04:22:49 comment id=531 from host=83.233.30.32 marked as spam

Why use Spam Log and fail2ban if Akismet/wp-recaptcha/etc. is already catching all the spam?

  • Many spammers post 50+ comments a day from a single IP address. Even if every comment is correctly marked as spam, the volume alone means that you can’t easily monitor the spam queue for false positives. Spam Log and fail2ban should considerably reduce the total amount of spam.
  • Even if spam comments never appear on your blog, they still waste valuable resources on your server. Low-memory virtual servers need all available resources for serving legitimate users. Banning spammers at the firewall before they ever connect to your web server is very efficient.

Installation

Spam Log

  1. Upload the spam-log folder to the wp-content/plugins directory.
  2. Active the plugin through the WordPress Admin menu.
  3. Set the location of the spam log through Spam Log’s Options page in the WordPress Admin menu. By default, the location is set to wp-content/spam.log. The file or containing directory needs to be writeable by the user that the web server runs as. On Debian or Ubuntu systems, you can do the following:

$ sudo touch /path/to/spam.log
$ sudo chown www-data.www-data /path/to/spam.log

fail2ban Configuration

Create /etc/fail2ban/filter.d/spam-log.conf with the following contents:

[Definition]
failregex = ^\s*comment id=\d+ from host=<HOST> marked as spam$
ignoreregex =

Add the following lines to /etc/fail2ban/jail.local:

[spam-log]
enabled  = true
port     = http,https
filter   = spam-log
logpath  = /path/to/spam.log
maxretry = 5
findtime = 3600
bantime  = 86400

Change logpath to the path you set on Spam Log’s Options page. This configuration will ban an IP address for a day if it’s used to post 5 comments within an hour that are marked as spam. Warning: Some captcha plugins mark comments as spam when a user fails a captcha. Be careful decreasing maxretry if you’re using such a plugin as there’s a risk that you will ban legitimate users.

Download

spam-log-0.1.tar.gz
spam-log-0.1.zip

Related Posts:

  • Using YSlow to Optimize Web Site Performance

    An article/tutorial on using the YSlow firebug extension to optimize...

  • Log iptables Messages to a Separate File with rsyslog

    Learn how to filter iptables log messages to a separate...

  • Firefox 3 Native Form Widgets Look Terrible

    Firefox 3 added native form widgets on Linux. Most of...

  • Using YSlow to Optimize Web Site Performance Continued

    The second part of an article/tutorial on using the YSlow...

Sponsored Links:

This entry was posted on Monday, April 20th, 2009 at 7:26 AM and is filed under Linux, Web. You can leave a response, or trackback from your own site.

17 Comments on “Integrate fail2ban with WordPress: Spam Log Plugin”

  1. » Integrate fail2ban with bWordPress/b: bSpam/b Log Plugin | Random Bits Wordpress UK: Wordpress UK, taking it further… says:
    June 1, 2009 at 12:30 PM

    [...] Read more from the original source: Integrate fail2ban with bWordPress/b: bSpam/b Log Plugin | Random Bits [...]

    Reply
  2. » Integrate fail2ban with WordPress: Spam Log Plugin Wordpress UK: Wordpress UK, taking it further… says:
    June 5, 2009 at 1:15 AM

    [...] Source:Integrate fail2ban with WordPress: Spam Log Plugin [...]

    Reply
  3. Week in Geek: The painful WordPress Upgrade Edition | How to says:
    June 15, 2009 at 5:58 AM

    [...] Integrate fail2ban with WordPress: Spam Log Plugin [Random Bits]This is ubergeeky, but being able to block spammers is loads of fun. [...]

    Reply
  4. Week in Geek: The Painful WordPress Upgrade Edition | SemiBeta says:
    June 18, 2009 at 9:43 PM

    [...] Integrate fail2ban with WordPress: Spam Log Plugin [Random Bits]This is ubergeeky, but being able to block spammers is loads of fun. [...]

    Reply
  5. Joern says:
    March 21, 2010 at 10:00 AM

    Thanks for that great plugin!
    Using it with a lot of success so far!! :)

    Even tho I have one question about the usage:

    I am running more than one website on my server.
    How is it possible to add more than one spam-log to it?
    Right now the jail.conf points to one of the websites spam.log file.

    Can I just add another one of those into the jail.conf or won’t it work:

    [spam-log]
    enabled = true
    port = http,https
    filter = spam-log
    logpath = /path/to/spam.log
    maxretry = 5
    findtime = 3600
    bantime = 86400

    Thanks in advance,

    Joern

    Reply
    • btmorex says:
      March 21, 2010 at 7:08 PM

      I think that will work although I personally haven’t tried.

      You will probably have the change the name (“[spam-log]“) and the path to the log (“logpath = /path/to/spam.log”) for each separate entry in jail.conf.

      If you have any problems, post again and I can probably figure it out.

      Edit: Also, it looks fail2ban > 0.7 supports wildcards in the logpath directive. So, another options would be something like “logpath = /path/to/sites/*/spam.log” where * gets expanded to site1, site2, site3, etc.

      That might be easier depending on your directory structure and the number of sites.

      Reply
      • Joern says:
        March 28, 2010 at 1:21 PM

        It works great!
        I chose the first option you wrote down and it works like a charm.
        Gonna try the wildcard-version too.

        Thanks a lot for your help!!

        I really appreciate it!

        Reply
  6. mensajes claro says:
    October 3, 2010 at 11:30 PM

    It works so good a small update about that plugin will help us to be save.

    Reply
  7. mensajes claro says:
    October 7, 2010 at 6:44 PM

    It really works.
    This spam log plugin will save a lot of time on my big blog .

    Reply
  8. Ssesbwrf says:
    July 4, 2011 at 1:21 PM

    mister cartoon flash,

    Reply
  9. AutoAnna says:
    August 8, 2011 at 3:42 AM

    Business – a motor mechanism, appliance, intended for the carriage of goods, towing trailers, trailers (not a farm tractor) or to schlep people (and not a bus) with a pardonable slews of across 3500 kg.

    Transporter may outdo a person with a area C (in search appear trucks GVW from 3.5 to 7.5 tons is satisfactorily category C1). In the state of combinations of vehicles (lorry with trailer or semi-trailer) is also required to have a license group E.

    There is also a pressure acutance, which defines the principle of the car for the sundries for companies seeking to remove VAT on the acquisition price. It defines the “Law on contribution on goods and services”.
    Chłodnia
    In North America (U.S. and Canada), the sundries is a channel with a allowable all-out authority exceeding 26,000 pounds, or regarding 11700 kg. It can be carried minus after obtaining a commission called the English: Commercial Driver License.

    Reply
  10. tracey m says:
    September 27, 2011 at 10:05 AM

    my site…

    [...]Integrate fail2ban with WordPress: Spam Log Plugin | Random Bits[...]…

    Reply
  11. Eragmaearnell says:
    November 18, 2011 at 8:52 AM

    hosting
    Wypatrujesz prostego i opłacalnego wyjścia, iżby zwiększyć dochody osobistej firmy? Mam zatem dla Ciebie inteligentne wyjście. Reklama. Wiem, miało być bez zbytnich kosztów, jednak przynoszę Ci pewność, iż tak będzie. Najprostszą i w najwyższym stopniu całościową, acz w tym samym czasie w największym stopniu wydajną jakością reklamy jest witryna. W tym momencie, jeśliby Twojej firmy nie ma w Necie to możesz zapomnieć o sporych zyskach. Każdy wypatruje najpierw w sieci, dopiero potem możliwie sięga po ogłoszenia w gazecie, lub pyta znajomych. Popatrzmyż prawdzie w oczy, strona jest de facto konieczne. Jeżeli nie jesteś znający się w sprawach domen i Internetu nie obawiaj się. Nasza firma wstała z tej przyczyny szczególnie dla Ciebie. Przekazujemy usługi z obrębu hosting od początku do finału. Nasi koneserzy odpowiedzą na Twoje wszystkie zapytania i pomogą dobrać najlepszą ofertę dla Ciebie. Dzięki nam możesz wzmóc dochody swojej firmy przy w rzeczy samej mizernym nakładzie płatniczym. Jakim sposobem? Przez wzgląd usługi hosting. Zaznajomisz się tutaj z kompletną ofertą na hosting i przyuważysz dane do kontaktu z nami. Sprawdź w jaki sposób Internet może Cię wesprzeć.

    Reply
  12. doogeoxenry says:
    November 21, 2011 at 2:42 AM

    mielno Jeśli pragniesz wybrać się w tym roku nad nasze morze, to warto zdecydować się na odwiedzenie niedużego Mielna. Na Wybrzeżu Słowińskim leży jedno bardzo atrakcyjne miasteczko niegdyś rybackie czyli Mielno. Polacy bardzo często w trakcie urlopu wyruszają do Mielna wspólnie ze swoimi znajomymi. Do Mielna przyjeżdżają turyści nie wyłącznie z naszego kraju, natomiast z całego świata, albowiem to jeden z najpopularniejszych Polskich kurortów. Do Mielna wyruszają turyści wespół z rodziną czy też ze znajomymi, a także urządzane są obozy dla młodzieży. Noclegi Mielno znajdują się na rzeczywiście wysokim poziomie, przy swojej niskiej ceny. Każda osoba, którą znam twierdzi, iż wakacje to niepowtarzalny okres podczas całego roku. Wobec wakacyjnego wyjazdu mamy wiele postulowań. Powinniśmy się nie tylko idealnie bawić wraz z najbliższymi oraz także powrócić wypoczęci. Mielno umożliwia nam znakomitą zabawę. Funkcjonuje w tej miejscowości dużo fascynujących dyskotek, do których można wybrać się ze znajomymi i pobawić. Atrakcyjne noclegi Mielno to pola namiotowe oraz domki kempingowe w najlepszych punktach tego kurortu. Jest to niezwykle dobra oferta dla osób z mniejszą ilością gotówki czyli dla młodych ludzi. Każdego roku w ciągu wakacji nad Polskie morze wybiera się aż 8 milionów podróżników z naszego kraju i z zagranicy.

    Reply
  13. wordpress blog hosting says:
    December 11, 2011 at 5:53 PM

    wordpress blog hosting…

    [...]Integrate fail2ban with WordPress: Spam Log Plugin | Random Bits[...]…

    Reply
  14. Darmowe ogłoszenia bezrejestracji says:
    December 12, 2011 at 9:32 AM

    whoah this blog is wonderful i really like studying your articles. Keep up the good paintings! You understand, many people are hunting around for this information, you could help them greatly.

    Reply
  15. how to improve spoken english online free says:
    January 30, 2012 at 2:31 PM

    how to improve spoken english online free…

    [...]Integrate fail2ban with WordPress: Spam Log Plugin | Random Bits[...]…

    Reply

Leave a Reply

Click here to cancel reply.

  • Topics

    • Personal (2)
    • Technology (13)
      • Linux (11)
      • Web (4)
  • Meta

    • Register
    • Log in
    • Valid XHTML

Feed | Privacy Policy
Copyright © 2008-2009 Random Bits
Powered by Wordpress