文档首页> Linux系统教程> Linux_ssh防爆破教程(Shell脚本)

Linux_ssh防爆破教程(Shell脚本)

发布时间:2022-11-06 23:27       

命名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

扫一扫访问手机版
30+ 高防云产品
1000+企业的共同选择