Adding “File Does Not Exist” Filter To Fail2Ban: Ubuntu 12.04 LTS

Ok so here is a quick post to a common question… adding a filter to fail2ban for bot/scanners searching for files, folders or simply doing recon which can result in exploit discovery, this filter will automatically block a visitor/bot after 4 attempts to scan for a file that does not exist on your domain/server.

like always… BASH IN! (lol…)

sudo bash

First Lets create a new entry in our jail.local file…

vim /etc/fail2ban/jail.local

 

copy the following text after the last apache entry…

[apache-nofile]
enabled = true
port = http,https
filter = apache-nofile
logpath = /var/log/apache*/*error.log
maxretry = 4

 

Now that we have added the entry into our jail.local we proceed, change to the filter.d directory, in this folder you will see lots of other pre-configured filters

cd /etc/fail2ban/filter.d

 

instead of creating a new filter file simply copy another, this will make the next step easier…

cp /etc/fail2ban/filter.d/apache-auth.conf /etc/fail2ban/filter.d/apache-nofile.conf

 

find the line identical to the one below (Line 23)

failregex = ^%(_apache_error_client)s user .* (authentication failure|not found|password mismatch)\s*$

 

replace it with the following one.

failregex = [[]client <HOST>[]] File does not exist:

 

At this point your pretty much done, close the file and restart fail2ban

service fail2ban restart

 

Comment if you have questions, like my post if you find it helpful :)

 

 

 

 

Published by

Miguel

I am a bilingual Network Engineer with over 20 years of professional experience in computer science and information technology. I am the founder and operator of Web Semantics, based in Vancouver, Washington, where I design, secure, and manage enterprise-grade infrastructure for small and mid-sized businesses across the West Coast. I provide bilingual IT support in English and Spanish, specializing in network architecture, systems engineering, security, and operational resilience. Soy un ingeniero de redes bilingüe con más de 20 años de experiencia profesional en ciencias de la computación y tecnología de la información. Soy fundador y operador de Web Semantics, con sede en Vancouver, Washington, donde diseño, protejo y administro infraestructura empresarial para pequeñas y medianas empresas en la costa oeste. Ofrezco soporte de IT bilingüe en inglés y español, con especialización en arquitectura de redes, ingeniería de sistemas, seguridad y resiliencia operativa.