First, I should mention that my system's tolerance for spam is nil. I have several hundred rulesets configured in the MTA, to block based on common subjects/heuristics, a very tweaked SpamAssassin setup, 6 different RBLs, including blackholes.us for 7 countries, clamav, and some very detailed procmail recipes to handle the AV and other things that slip through.
That being said, spam still gets in.
The piece of the puzzle that I'm trying to solve now, is being able to firewall off people/machines that are brute-forcing accounts on servers with domains we host (quite a few). An example of this from one of the live servers looks like this.
I cooked up a quick hackish bash script to deal with these, and half-shimmed in some perl to regex out the IP. I'd like to entertain some ideas and approaches to handling this entire thing in Perl exclusively.
Currently, it looks like this, and works perfectly, though is hackish:
# Wrapped for Perl Monks, unwrap before using LOG="/path/to/mail.log" IPT="/sbin/iptables" BAN="$IPT -A INPUT -s {} -p tcp -m tcp --dport 25 -j REJECT" DUP="$IPT -D INPUT -s {} -p tcp -m tcp --dport 25 -j \ REJECT --reject-with icmp-port-unreachable" # Find the offenders and ban them from reaching port 25 grep -A1 "User unknown" $LOG | grep nr \ | perl -lne 'print /\[((?:\d+\.){3}\d+)\]/' \ | sort | uniq -d | xargs -i $BAN # Check the existing rulesets for dupes, and remove $IPT-save | sort | uniq -d | perl -lne 'print /((?:\d+\.){3}\d+)/' \ | xargs -i $DUP
The process is:
Anyone want to take a stab at converting this little shell'ism to "Pure Perl™"?
In reply to Firewalling brute-force spam attacks by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |