Skip to content

Instantly share code, notes, and snippets.

@i-sync
Created February 22, 2017 06:12
Show Gist options
  • Save i-sync/d01b35cf67effb8db9384fa7bb9fd79c to your computer and use it in GitHub Desktop.
Save i-sync/d01b35cf67effb8db9384fa7bb9fd79c to your computer and use it in GitHub Desktop.
SSH-Failed
#!/bin/sh
SCANIP=`grep "Failed" /var/log/secure | awk '{print $(NF-3)}' | sort | uniq -c | awk '{print $1"="$2;}'`
for i in $SCANIP
do
NUMBER=`echo $i | awk -F= '{print $1}'`
SCANIP=`echo $i | awk -F= '{print $2}'`
echo "$SCANIP:$NUMBER"
if [ $NUMBER -gt 10 ]
then
grep $SCANIP /etc/hosts.deny >/dev/null 2>&1 || echo "sshd:$SCANIP" >> /etc/hosts.deny
echo "`date` $SCANIP $NUMBER" >> /var/log/scanip.log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment