Normalmente, esto es ocasionado por intentos de hackeos (scriptkiddies, hackers, crackers) o simplemente, usuarios pelotudos.
Fail2ban soporta muchos logs, uno de ellos es postfix, el MTA predilecto.
Que buscamos eliminar en los logs?
* Usuarios desconocidos (logueos)
* Registros PTR o A no configurados correctamente.
* Usuarios desconocidos (mail no existente al recibir)
En /etc/fail2ban/filter.d/postfix.conf , agregamos las siguientes lineas (o adaptamos)
dijo:
failregex = reject: RCPT from (.*)[<HOST>]: 550 5.1.1
reject: RCPT from (.*)[<HOST>]: 450 4.7.1
reject: RCPT from (.*)[<HOST>]: 550 5.7.1
Comprobamos que este todo bien con
dijo:fenix:~# fail2ban-regex /var/log/zimbra.log /etc/fail2ban/filter.d/postfix.conf|less
Running tests
=============
Use regex file : /etc/fail2ban/filter.d/postfix.conf
Use log file : /var/log/zimbra.log
Results
=======
Failregex
|- Regular expressions:
| [1] reject: RCPT from (.*)[<HOST>]: 550 5.1.1
| [2] reject: RCPT from (.*)[<HOST>]: 450 4.7.1
| [3] reject: RCPT from (.*)[<HOST>]: 554 5.7.1
|
`- Number of matches:
[1] 7242 match(es)
[2] 0 match(es)
[3] 380 match(es)
Ignoreregex
|- Regular expressions:
|
`- Number of matches:
Summary
=======
Addresses found:
[1]
24.244.172.17 (Sun Aug 22 06:25:20 2010)
94.217.138.77 (Sun Aug 22 06:25:20 2010)
[....] Muchas IPs [...]
84.229.123.248 (Sun Aug 22 08:05:51 2010)
84.229.123.248 (Sun Aug 22 08:05:51 2010)
Date template hits:
113840 hit(s): Month Day Hour:Minute:Second
0 hit(s): Weekday Month Day Hour:Minute:Second Year
0 hit(s): Weekday Month Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/Month/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601
Success, the total number of match is 7565
However, look at the above section ‘Running tests’ which could contain important
information.
Si todo marcha supercaligfragilisticoultraespialidoso, la habilitamos en jail.conf , estableciendo enabled = true
dijo:[postfix]
enabled = true
port = smtp,ssmtp
filter = postfix
maxretry = 6
bantime = 86400
findtime = 600
action = %(action_)s
logpath = /var/log/zimbra.log
Como soy un sysadmin muy, pero que muy sorete, bloqueo por 24 horas (86.400 segundos, bantime) a aquellos que me molestaron 6 veces (maxretry) en los ultimos 10 minutos (findtime).
Si fuera sorete total, setearia bantime a -1, lo cual lo haria permanente (o hasta que se reinice el server, las reglas de iptables o recarguemos el filtro de fail2ban)
Recargamos fail2ban
dijo:fenix:~# fail2ban-client reload
Y si queremos ver como va la cosa, utilizamos el comando watch, que cada 2 segundos nos muestra el estado del comando pasado. (Salimos presionando Ctrl+C)
dijo:fenix:~# watch fail2ban-client status postfix
Every 2,0s: fail2ban-client status postfix Sun Aug 22 09:42:56 2010
Status for the jail: postfix
|- filter
| |- File list: /var/log/zimbra.log
| |- Currently failed: 598
| `- Total failed: 7657
`- action
|- Currently banned: 342
| `- IP list: 62.194.198.x ... .... .... ... ... ... ... ... ... ... ... 166.227
`- Total banned: 341
Y asi, mi joven Padawan, es como yo he filtrado casi 350 IPs en 30 minutos, ahorrandome recursos y dandome mas tiempo para ir a decorar mis pulmones con un hermoso color alquitran.
Atencion: en mi caso, utilizo Zimbra OS, si solo usan postfix cambiar /var/log/zimbra.log por el path al log correspondiente.
Atencion: Cuidadin con los tiempos que utilizan, vayan probando de a 5 minutos. Sino, es probable que bloqueen a un usuario valido, y se arme la rosca

... Hablo por experiencia 