1
0
Fork 0
scripts-admin-quickndirty-p.../fail2ban-mail-nocommand-dirty.sh

12 lines
523 B
Bash
Executable file

#!/bin/sh
# Création de la chaîne si elle n'existe pas
iptables-save | grep auth2ban >/dev/null 2>&1 || ( iptables -N auth2ban ; iptables -I INPUT 2 -j auth2ban )
# Vidange
iptables -F auth2ban
# Remplissage
tail -n 3000 /var/log/syslog | grep "did not issue MAIL/EXPN/VRFY/ETRN during connection" | sed -n 's/.*\[\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\] .*/\1/p' | sort | uniq -c | grep -v "^[[:space:]]*1 " | awk '{ print $2 }' | while read LINE; do
iptables -A auth2ban -s "$LINE" -j DROP
done