常用的shell脚本(安全方向)

更多shell脚本参考:https://blog.51cto.com/zero01/2046242

1、拒绝密码撞库攻击的ip

shell脚本:实现对登录主机失败10次以上的ip进行拒绝登录

#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /usr/local/bin/black.txt
for i in `cat  /usr/local/bin/black.txt`
do
  IP=`echo $i |awk -F= '{print $1}'`
  NUM=`echo $i|awk -F= '{print $2}'`
   if [ $NUM -gt 10 ];then
      grep $IP /etc/hosts.deny > /dev/null
    if [ $? -gt 0 ];then
      echo "sshd:$IP:deny" >> /etc/hosts.deny
    fi  
  fi  
done

  

猜你喜欢

转载自www.cnblogs.com/andy9468/p/10654784.html