< 返回

Linux_ssh防爆破教程(Shell脚本)

2020-10-01 03:51 作者:小鹿-it6666 阅读量:1254

命名we:[root@localhost]# vim kill.sh 

###################################################

#!/bin/bash

cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c |awk '{print $2"="$1}' > /tmp/blacklist

MAXCOUNT="3"

for i in `cat /tmp/blacklist`

do

    IP=`echo $i | awk -F= '{print $1}'`

    NUM=`echo $i | awk -F= '{print $2}'`

if [ $NUM -gt $MAXCOUNT ];then

   grep $IP /etc/hosts.deny > /dev/null

   if [ $? -gt 0 ];then

       echo "sshd:$IP" >> /etc/hosts.deny

   fi

fi

done

###################################################

#授權

[root@localhost]# chmod -R 777 kill.sh 

#運行

[root@localhost]# nohup ./kill.sh &

[1] 13893

#查看拉黑的IP

[root@localhost]# cat /etc/hosts.deny

联系我们
返回顶部