4 069
contributi
(17 versioni intermedie di 5 utenti non mostrate) | |||
Riga 1: | Riga 1: | ||
{{Versioni compatibili|}} | {{Versioni compatibili|Squeeze|Wheezy|Jessie|Stretch}} | ||
== Introduzione == | == Introduzione == | ||
'''Fail2ban''' ([http://www.fail2ban.org Sito ufficiale]) è un software che è nato per permettere di bloccare gli host che stanno tentando di effettuare un attacco di [[brute force]] via [[SSH]]. | '''Fail2ban''' ([http://www.fail2ban.org Sito ufficiale]) è un software che è nato per permettere di bloccare gli host che stanno tentando di effettuare un attacco di [[brute force]] via [[SSH]]. | ||
Riga 46: | Riga 46: | ||
</pre> | </pre> | ||
== Attivazione di nuovi filtri == | == Attivazione di nuovi filtri (Da Debian Stretch) == | ||
Fail2ban utilizza una directory apposita per l'attivazione e la gestione di filtri personalizzati. Tutti i file inseriti in questa directory e aventi estensione <tt>.conf</tt> vengono letti e processati all'avvio del demone. | |||
<br/> | |||
Per attivare dei filtri su demoni diversi da SSH è sufficiente quindi creare un nuovo file di configurazione, inserendolo nella directory <tt>/etc/fail2ban/jail.d</tt>: | |||
<pre> | |||
# nano /etc/fail2ban/jail.d/custom.conf | |||
</pre> | |||
Un contenuto per il file, che ci garantisca un buon numero di filtri attivi può essere il seguente: | |||
<pre> | |||
[DEFAULT] | |||
bantime = 14400 | |||
ignoreip = 127.0.0.1/8 | |||
maxretry = 5 | |||
[sshd] | |||
enabled = true | |||
port = 2293 | |||
logpath = %(sshd_log)s | |||
backend = %(sshd_backend)s | |||
[sshd-ddos] | |||
enabled = true | |||
port = 2293 | |||
logpath = %(sshd_log)s | |||
backend = %(sshd_backend)s | |||
[dropbear] | |||
enabled = true | |||
port = 2293 | |||
logpath = %(dropbear_log)s | |||
backend = %(dropbear_backend)s | |||
[apache-auth] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
[apache-badbots] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_access_log)s | |||
bantime = 172800 | |||
maxretry = 1 | |||
[apache-noscript] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
[apache-overflows] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
maxretry = 2 | |||
[apache-nohome] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
maxretry = 2 | |||
[apache-botsearch] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
maxretry = 2 | |||
[apache-fakegooglebot] | |||
port = http,https | |||
logpath = %(apache_access_log)s | |||
maxretry = 1 | |||
ignorecommand = %(ignorecommands_dir)s/apache-fakegooglebot <ip> | |||
[apache-modsecurity] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
maxretry = 2 | |||
[apache-shellshock] | |||
enabled = true | |||
port = http,https | |||
logpath = %(apache_error_log)s | |||
maxretry = 1 | |||
[php-url-fopen] | |||
enabled = true | |||
port = http,https | |||
logpath = %(nginx_access_log)s | |||
%(apache_access_log)s | |||
[suhosin] | |||
enabled = true | |||
port = http,https | |||
logpath = %(suhosin_log)s | |||
[roundcube-auth] | |||
[roundcube-auth] | |||
#enabled = true | |||
port = http,https | |||
logpath = %(roundcube_errors_log)s | |||
[drupal-auth] | |||
enabled = true | |||
port = http,https | |||
logpath = %(syslog_daemon)s | |||
backend = %(syslog_backend)s | |||
[monit] | |||
#enabled = true | |||
port = 2812 | |||
logpath = /var/log/monit | |||
[webmin-auth] | |||
enabled = true | |||
port = 10000 | |||
logpath = %(syslog_authpriv)s | |||
backend = %(syslog_backend)s | |||
[froxlor-auth] | |||
enabled = true | |||
port = http,https | |||
logpath = %(syslog_authpriv)s | |||
backend = %(syslog_backend)s | |||
[vsftpd] | |||
enabled = true | |||
port = ftp,ftp-data,ftps,ftps-data | |||
logpath = %(vsftpd_log)s | |||
[postfix] | |||
#enabled = true | |||
port = smtp,465,submission | |||
logpath = %(postfix_log)s | |||
backend = %(postfix_backend)s | |||
[postfix-rbl] | |||
#enabled = true | |||
port = smtp,465,submission | |||
logpath = %(postfix_log)s | |||
backend = %(postfix_backend)s | |||
maxretry = 1 | |||
[postfix-sasl] | |||
#enabled = true | |||
port = smtp,465,submission,imap3,imaps,pop3,pop3s | |||
logpath = %(postfix_log)s | |||
backend = %(postfix_backend)s | |||
[squirrelmail] | |||
#enabled = true | |||
port = smtp,465,submission,imap2,imap3,imaps,pop3,pop3s,http,https,socks | |||
logpath = /var/lib/squirrelmail/prefs/squirrelmail_access_log | |||
[recidive] | |||
enabled = true | |||
logpath = /var/log/fail2ban.log | |||
banaction = %(banaction_allports)s | |||
bantime = 604800 ; 1 week | |||
findtime = 86400 ; 1 day | |||
[pam-generic] | |||
enabled = true | |||
banaction = %(banaction_allports)s | |||
logpath = %(syslog_authpriv)s | |||
backend = %(syslog_backend)s | |||
[xinetd-fail] | |||
enabled = true | |||
banaction = iptables-multiport-log | |||
logpath = %(syslog_daemon)s | |||
backend = %(syslog_backend)s | |||
maxretry = 2 | |||
</pre> | |||
== Attivazione di nuovi filtri (Fino a Debian Jessie) == | |||
=== Server di posta Dovecot === | === Server di posta Dovecot === | ||
Creare il file di filtro <code>/etc/fail2ban/filter.d/dovecot-pop3imap.conf</code>: | Creare il file di filtro <code>/etc/fail2ban/filter.d/dovecot-pop3imap.conf</code>: | ||
Riga 99: | Riga 274: | ||
</pre> | </pre> | ||
=== Apache | === Apache === | ||
Aggiungere in <code>/etc/fail2ban/jail.d/jail.local i seguenti filtri: | |||
<pre> | |||
##To block failed login attempts use the below jail. | |||
[apache] | |||
enabled = true | |||
port = http,https | |||
filter = apache-auth | |||
logpath = /var/log/apache2/*error.log | |||
maxretry = 3 | |||
bantime = 600 | |||
##To block the remote host that is trying to request suspicious URLs, use the below jail. | |||
[apache-overflows] | |||
enabled = true | |||
port = http,https | |||
filter = apache-overflows | |||
logpath = /var/log/apache2/*error.log | |||
maxretry = 3 | |||
bantime = 600 | |||
##To block the remote host that is trying to search for scripts on the website to execute, use the below jail. | |||
[apache-noscript] | |||
enabled = true | |||
port = http,https | |||
filter = apache-noscript | |||
logpath = /var/log/apache2/*error.log | |||
maxretry = 3 | |||
bantime = 600 | |||
##To block the remote host that is trying to request malicious bot, use below jail. | |||
[apache-badbots] | |||
enabled = true | |||
port = http,https | |||
filter = apache-badbots | |||
logpath = /var/log/apache2/*error.log | |||
maxretry = 3 | |||
bantime = 600 | |||
##To stop DOS attack from remote host. | |||
[http-get-dos] | |||
enabled = true | |||
port = http,https | |||
filter = http-get-dos | |||
logpath = /var/log/apache*/access.log | |||
maxretry = 400 | |||
findtime = 400 | |||
bantime = 600 | |||
action = iptables[name=HTTP, port=http, protocol=tcp] | |||
</pre> | |||
Dovremo quindi creare la regola dell'unico filtro mancante nel pacchetto installato dai repository: | |||
<pre> | |||
# nano /etc/fail2ban/filter.d/http-get-dos.conf | |||
</pre> | |||
con questo contenuto: | |||
<pre> | <pre> | ||
# Fail2Ban configuration file | # Fail2Ban configuration file | ||
[Definition] | [Definition] | ||
failregex = | # Option: failregex | ||
# Note: This regex will match any GET entry in your logs, so basically all valid and not valid entries are a match. | |||
# You should set up in the jail.conf file, the maxretry and findtime carefully in order to avoid false positives. | |||
failregex = ^<HOST> -.*"(GET|POST).* | |||
# Option: ignoreregex | |||
ignoreregex = | ignoreregex = | ||
</pre> | </pre> | ||
Salviamo e riavviamo: | |||
<pre> | <pre> | ||
# systemctl restart fail2ban | |||
</pre> | </pre> | ||
=== Server FTP=== | === Server FTP=== | ||
All'interno del file | All'interno del file /etc/fail2ban/jail.conf è presente una sezione FTP in cui basta abilitare quello che si desidera. | ||
<pre> | <pre> | ||
# FTP servers | # FTP servers | ||
Riga 162: | Riga 384: | ||
=== SSH === | === SSH === | ||
All'interno del file <code>/etc/fail2ban/jail.conf</code> è presente una sezione | |||
All'interno del file <code>/etc/fail2ban/jail.conf</code> è presente una sezione SSH in cui basta abilitare quello che si desidera. | |||
<pre> | <pre> | ||
[ssh] | [ssh] | ||
Riga 170: | Riga 394: | ||
filter = sshd | filter = sshd | ||
logpath = /var/log/auth.log | logpath = /var/log/auth.log | ||
maxretry = | maxretry = 3 | ||
[ssh-ddos] | [ssh-ddos] | ||
Riga 178: | Riga 402: | ||
filter = sshd-ddos | filter = sshd-ddos | ||
logpath = /var/log/auth.log | logpath = /var/log/auth.log | ||
maxretry = | maxretry = 3 | ||
</pre> | |||
Per ciò che riguarda la riga: | |||
<pre> | |||
port = ssh | |||
</pre> | </pre> | ||
"ssh" va sostituito con la porta effettivamente usata dall'utente. Nel caso si lasci "ssh", il ban avverrà sulla porta di default di SSH (porta 22). | |||
port | === Altri filtri consigliati === | ||
Alcuni filtri utili da inserire in <code>jail.local</code>: | |||
<pre> | |||
[pam-generic] | |||
enabled = true | |||
banaction = iptables-allports | |||
[apache-nohome] | |||
enabled = true | |||
port = http,https | |||
filter = apache-nohome | |||
banaction = iptables-multiport | |||
action = %(action_mwl)s | |||
logpath = /var/log/apache*/*access.log | |||
maxretry = 1 | |||
[php-url-fopen] | |||
enabled = true | |||
port = http,https | |||
filter = php-url-fopen | |||
logpath = /var/log/apache*/*access.log | |||
maxretry = 1 | |||
</pre> | |||
=== Attivazione dei nuovi filtri === | === Attivazione dei nuovi filtri === | ||
Riga 490: | Riga 741: | ||
|Verificata_da= | |Verificata_da= | ||
:[[Utente:porkyhttp|porkyhttp]] 17:04, 06 mag 2012 (CEST) | :[[Utente:porkyhttp|porkyhttp]] 17:04, 06 mag 2012 (CEST) | ||
|Numero_revisori= | : lula 12 gen 2017 (CET) | ||
|Numero_revisori=2 | |||
|Estesa_da = | |Estesa_da = | ||
: [[Utente : mm-barabba|mm-barabba]] 06-04-2013 | : [[Utente : mm-barabba|mm-barabba]] 06-04-2013 |