Como usar o fail2ban para banir todos os pedidos php e cgi-bin

1

Diariamente, vejo o log do Apache cheio de solicitações iniciadas por diferentes aplicativos de varredura de vulnerabilidades. Essas centenas de solicitações, geralmente com os mesmos endereços IP, não apenas deixam o log sujo, mas também usam alguns recursos do servidor.

Como não tenho scripts PHP nem CGI-BIN no meu Apache, gostaria de usar o fail2ban para banir todos os endereços IP em uma primeira solicitação, por um determinado período de tempo.

Alguém tem essa configuração fail2ban pronta para uso?

    
por ssasa 13.03.2014 / 13:33

2 respostas

3

Obrigado ao Joel comentar aqui é a solução que eu uso atualmente.

Para /etc/fail2ban/jail.conf , isso é adicionado ao final:

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

O arquivo /etc/fail2ban/filter.d/urlscanners.conf é assim:

#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 =

Os caminhos podem variar em diferentes sistemas operacionais.

    
por 17.03.2014 / 14:42
0

Obtendo isso no Fedora 28 (atualizado para mostrar mais linhas):

2018-08-29 16:19:58,135 fail2ban.jail           [31014]: INFO    Creating new jail 'urlscanners'
2018-08-29 16:19:58,135 fail2ban.jail           [31014]: INFO    Jail 'urlscanners' uses pyinotify {}
2018-08-29 16:19:58,150 fail2ban.jail           [31014]: INFO    Initiated 'pyinotify' backend
2018-08-29 16:19:58,153 fail2ban.filter         [31014]: ERROR   No failure-id group in '[[]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)'
2018-08-29 16:19:58,154 fail2ban.transmitter    [31014]: WARNING Command ['set', 'urlscanners', 'addfailregex', '[[]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)'] has failed. Received RegexException("No failure-id group in '[[]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)'",)
2018-08-29 16:19:58,154 fail2ban                [31014]: ERROR   NOK: ("No failure-id group in '[[]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)'",)
2018-08-29 16:19:58,155 fail2ban.filter         [31014]: INFO    Added logfile: '/usr/local/etc/httpd/logs/error_log' (pos = 819643, hash = 01289652cb6817b4a991911956c7aa9a160eb60b)
    
por 21.08.2018 / 21:20