限制暴力破解

#!/bin/bash
date=`date +%Y%m%d_%H%M`
for i in `cat /var/log/secure |awk '/Failed/{print $(NF-3)}'|sort |uniq -c|sort -nr|awk '{print $2"="$1}'`
do
 IP=`echo $i|awk -F"=" '{print $1}'`
 NUM=`echo $i |awk -F"=" '{print $2}'`
  if [ ${NUM} -gt 2000 ];
  	then
	ipExist=`grep ${IP} /etc/hosts.deny|grep -v grep|wc -l` 
		if
			[ ${ipExist} -lt 1 ];	
			then
			echo "sshd:$IP:deny" >> /etc/hosts.deny
			echo "Date: ${date} IP: ${IP} Num: ${NUM}" >> /tmp/deny_ip.log
		fi
  fi
		
done

猜你喜欢

转载自blog.csdn.net/wangshui898/article/details/80236404