Last active
December 17, 2015 12:39
-
-
Save koy1619/5611116 to your computer and use it in GitHub Desktop.
shell脚本防止暴力破解SSH服务
crontab
*/30 * * * * root sh /home/hosts_deny.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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