标签:黑名单 出现 lse failed 次数 pass 通过 登录 pre
编写脚本/root/bin/checkip.sh,每 5 分钟检查一次,如果发现通过 ssh 登录失败 次数超过 10 次,
自动将此远程 IP 放入 Tcp Wrapper 的黑名单中予以禁止防问
#!/bin/bash
while true;do
    mounth=$(date +%b)
    mday=$(date +%d)
    hour=$(date +%H)
    min=$(date +%M)
    IP=`awk '
/sshd.*Failed password/ {
  if("'$mounth'" == $1 && "'$mday'" == $2){
    split($3,array,":")
# 时间判断5min内出现错误的次数
    if("'$hour'" == array[1]){
      if("'$min'" < array[2] + 5)
        allert[$11]++;
    }
    else{
      if("'$min'"+60-array[2] < 5)
        allert[$11]++;
    }
  }
}
END{
# 打印结果: 出现大于10次的 IP
  for(IP in allert){
     if(allert[IP]>10)
       print(IP)
  }
}
' /var/log/secure
`
    for I in $IP;do
        echo "sshd: ${I}" >> /etc/hosts.deny
    done
    sleep $((5*60))
done配置 magedu 用户的 sudo 权限,允许 magedu 用户拥有 root 权限
visudo
magedu    ALL=(ALL)       ALL标签:黑名单 出现 lse failed 次数 pass 通过 登录 pre
原文地址:https://www.cnblogs.com/chaoyiyang/p/12042194.html