1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # cat hosts_deny.sh ----------------------------------------------------------------------- #!/bin/bash #Host.deny Shell Script #2013-08-24 cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c | awk '{print $2 "=" $1;}' > /tmp/black_ip .txt DEFINE=10 for i in ` cat /tmp/black_ip .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 ----------------------------------------------------------------------- # crontab -l * /1 * * * * sh /shell_script/hosts_deny .sh ----------------------------------------------------------------------- # grep sshd /etc/hosts.deny sshd:116.10.202.163 sshd:116.10.202.169 sshd:118.26.203.66 sshd:119.80.39.55 sshd:202.203.194.45 sshd:219.148.36.20 sshd:60.190.219.98 sshd:61.155.177.58 sshd:67.205.111.20 sshd:70.34.202.31 sshd:77.65.0.86 |
防止服務器被外網的IP地址ssh連接或掃描試探等
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.