Skip to content

Instantly share code, notes, and snippets.

@koy1619
Last active December 17, 2015 12:39
Show Gist options
  • Save koy1619/5611116 to your computer and use it in GitHub Desktop.
Save koy1619/5611116 to your computer and use it in GitHub Desktop.
shell脚本防止暴力破解SSH服务 crontab */30 * * * * root sh /home/hosts_deny.sh
#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /home/black.txt
DEFINE="5"
for i in `cat /home/black.txt`
do
IP=`echo $i |awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]; then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ]; 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