为防止服务器遭受ssh暴力破解,将尝试ssh暴力破解本机超过10次的IP封掉,禁止其登陆本机!
#!/bin/bash
cat /var/log/secure |awk ‘/Failed/{print $(NF-10)}‘| sort |uniq -c||awk ‘{print $2"="$1;}‘ > /home/test.list
for i in `cat /home/test.list`
do
IP=`echo $i |awk -F "=" ‘{print $1}‘`
n=`echo $i |awk -F "=" ‘{print $2}‘`
if [ ${n} -gt 10 ]; then
a=`grep $IP /etc/hosts.deny`
if [ -z $a ] ;then
echo "sshd:$IP:deny" >>/etc/hosts.deny
fi
fi
done
时间: 2024-10-13 14:47:14