Apache – How to use fail2ban to ban all php and cgi-bin requests

apache-httpdfail2ban

On daily basis I see Apache log full of requests initiated by different vulnerability scanner apps. Those hundreds of requests from usually same IP addresses not only makes the log dirty but also uses some server resources.

As I do not have any PHP nor CGI-BIN scripts on my Apache, I would like to use fail2ban to ban all those IP addresses on a first request, for a certain amount of time.

Does any one have such ready-to-go fail2ban configuration?

Best Answer

Thank to Joel comment here is the solution I currently use.

To /etc/fail2ban/jail.conf this is added to the end:

[urlscanners]
enabled  = true
port     = http,https
filter   = urlscanners
logpath  = /var/log/apache*/*error.log
maxretry = 1
bantime  = 86400

File /etc/fail2ban/filter.d/urlscanners.conf is like this:

#block port scanners
[Definition]
failregex = [[]client (?P<host>\S*)[]] (File does not exist): .*(w00tw00t|CFIDE|php|cgi-bin|htdocs\.7z|htdocs\.rar|htdocs\.zip|root\.7z|root\.rar|root\.zip|www\.7z|www\.rar|wwwroot\.7z)
ignoreregex =

Paths may vary on different OSes.

Related Question