Skip to content

Instantly share code, notes, and snippets.

@dennyhalim
Created October 30, 2009 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennyhalim/222184 to your computer and use it in GitHub Desktop.
Save dennyhalim/222184 to your computer and use it in GitHub Desktop.
#!/bin/bash
#http://tuxopia.net/security_ssh_probe_block_script
AWK=/bin/awk
SORT=/bin/sort
GREP=/bin/grep
UNIQ=/bin/uniq
SED=/bin/sed
LOGFILE=/var/log/messages
BADCOUNT="5"
$GREP 'Failed password' $LOGFILE | $AWK '{ a=NF-3; print $a}' | $UNIQ -c| $SED 's/^ *//'| $SORT -n | while read i
do
COUNT=`echo $i | cut -d " " -f1`
IP=`echo $i | cut -d " " -f2`
INLIST=`$GREP $IP /etc/hosts.deny | $GREP sshd`
if [ -z "$INLIST" ]
then
if [ "$COUNT" -ge "$BADCOUNT" ]
then
echo "sshd: $IP" >> /etc/hosts.deny
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment