• Apache: Bot? No, thank you Margaret

    Running a development server under OpenBSD, I am regularly confronted with a flood of errors in my Apache logs.
    Most of the time these are “page not found” errors generated by robots that roam the net looking for badly configured or simply out-of-date web applications.

    It is not very bothersome, but if it can be avoided, why not do it?

    So I wrote a small, unpretentious script whose mission is to ban the vermin.

    It is very simple, only requires the Ruby interpreter installed on the machine, and uses Packet Filter (OpenBSD’s firewall) by default to ban the IPs.

    It can nevertheless be adapted very easily, by changing the few constants at the beginning of the script:

    LOGFILE = "/var/www/logs/error_log"
    BANLOG = "/var/log/banlog"
    FCMD = "pfctl -t bruteforce -T add"
    EXIP = ["10.0.0.0/8","127.0.0.0/8","172.16.0.0/12","192.168.0.0/16"]
    MRATE = "3/10" # n/m : a max of n tries in m seconds

    It is certainly not a miracle solution, let alone a revolutionary one, but it has the merit of working and meeting my expectations.

    Download

    by Cédric TESSIER on