技术文档

Linux防CC攻击脚本

 03-24  61

Linux防CC攻击脚本

多数CC攻击在web服务器日志中都有相同攻击的特征,我们可以根据这些特征过滤出攻击的ip,利用iptables来阻止

  1. #!/bin/bash
  2. #byyeho
  3. #BLOG:https://blog.
  4. OLD_IFS=$IFS
  5. IFS=$’\n’
  6. forstatusin`grep‘特征字符串’/data/wwwlogs/blog._nginx.log|awk‘{print$1}’
  7. |sort-n|uniq-c`
  8. do
  9. IFS=$OLD_IFS
  10. NUM=`echo$status|awk‘{print$1}’`
  11. IP=`echo$status|awk‘{print$2}’`
  12. #echo$status
  13. if[-z“`iptables-nvL|grep“dpt:80”|awk‘{print$8}’|grep“$IP”`”];then
  14. if[$NUM-gt250];then
  15. #echoIP:$IPisover$NUM,BANIT!
  16. /sbin/iptables-IINPUT-ptcp-s$IP–dport80-jDROP
  17. fi
  18. fi
  19. done
©2020-2024   万云SSL证书  (www.sslssl.com.cn)  万云科技   豫ICP备2020034358号-10