## Script Name - blacklistscript ##DEFINING VARIABLES IPT=/sbin/iptables SEARCHDIR=/var/log/messages BLACKLIST=/admin/conf/badips EXCLUDE="<your internal IP address range" ## THIS IS THE BIT THAT FINDS THE IP'S ## ADAPT AS NEEDED. ## Note: the grep -v invalid is excluded because we are not concerned with logins to invalid usernames BADIP=`cat $SEARCHDIR | grep -e "Failed" | grep -v invalid | grep -v $EXCLUDE | gawk '{ print $11 }' | sort | uniq` ## CLEAR OUT OLD RULEBASE $IPT -F $IPT -X $IPT -N BLACKLIST $IPT -A INPUT -i <incoming interface> -j BLACKLIST ## CREATE SPECIFIC RULES AND ADD TO HISTORY for x in `echo $BADIP` do echo $x >> $BLACKLIST $IPT -A BLACKLIST -s $x -i <incoming interface> -p tcp --dport 22 -j DROP done $IPT -A BLACKLIST -j RETURN >> $BLACKLIST |
*/5 * * * * /admin/bin/blacklistscript |