快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

LINUX/CentOS防CC攻击脚本

网站遭到别人的CC攻击很苦恼吧?说起CC攻击不得不说下其攻击原来,CC攻击主要利用瞬时多IP同时访问你网站,将服务器资源同时耗尽,从而让你网站打不开,目前主要是利用黑客工具自动收集代理IP,然后同时利用这些代理IP访问你的网站,从而产生CC攻击

CENTOS下,主要防御办法就是使用iptable防火墙,将高频率的访问暂时列入禁止访问IP,然后过几分钟后再解封,通过这个方法来缓解被攻击的压力,同时对正常访客影响较小

新建一个SH脚本
#vi limit.sh
脚本内容如下:
#!/bin/sh
 
  cd /var/log/httpd/
 
  cat access_log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -n 20 > a
 
  cp /dev/null access_log
 
  cp /dev/null error_log
 
  cp /dev/null limit.sh
 
  cp /dev/null c
 
  #awk '{print $2}' a|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
 
  cat a|while read num ip
 
  do
 
  if [ "$num" -gt "20" ]
 
  then
 
  echo $ip >> c
 
  fi
 
  done
 
  cat c|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
 
  #cat c|sort|uniq > b
 
  for i in `cat b`
 
  #cat b|sed 's/\./ /g'|while read i1 i2 i3 i4
 
  do
 
  if `cat ourip |grep $i > /dev/null 2>&1`
 
  then
 
  echo "`date` $i" >> test
 
  else
 
  echo "iptables -I INPUT -p tcp -dport 80 -s $i.0/24 -j DROP" >> limit.sh
 
  fi
 
  done
 
脚本结束,执行脚本:
#sh limit.sh

顶(1)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论