DON'T USE THIS, KEEP READING THE RESET OF THE THREAD!
--
I would be my lazy self and write this script and run it out of cron every 3-5 min.
-----start script-----
#!/bin/sh
grep sshd /var/log/authlog | grep "Invalid" | awk '{print $10}' | sort | uniq -c | \
(while read num ips; do
if [ $num -gt 5 ]; then
if ! pfctl -s rules | grep -q $ips ; then
pfctl -t attackers -T add $ips
fi
fi
done
)
grep sshd /var/log/authlog | grep "Failed" | rev | cut -d\ -f 4 | rev | sort | uniq -c | \
( while read num ips; do
if [ $num -gt 5 ]; then
if ! pfctl -s rules | grep -q $ips ; then
pfctl -t attackers -T add $ips
fi
fi
done
)
----end script-------------
Then I would add the following to my pf.conf
table <attackers> persist file "/etc/fuckers" #add any ip you want to block to this file
block log quick on $ext_if from { <attackers> } to any
If you're using iptables I dunno, it sucks.
You will still get connects and they are mildly annoying, but after a few min they are blocked for good.
This of course assumes you need general access to ssh from anywhere... if you only come from set addresses you should block all ssh connections from non-trusted sources.
-id
Edited 1 time(s). Last edit at 07/13/2008 02:18PM by id.