XXDD0S 攻击防御方案

当突然有大量的链接骚扰你的Web服务器,然后这样的攻击会持续几天。

 

你去网上,查找应对方案,一般是通过netstat 将top 10的大于XX数量的IP 拒绝。那些脚本都不太完善,而且会反复重复添加到iptables。

 

我遇到的这次攻击,在http Referer 含有  XXDD0S 还有在access, 比较好处理

 

写了下面的脚本,分成两个部分:

1. 收集器

2. 处理器

 

收集器,用于持续收集攻击IP地址。然后重定向到管道

处理器,从管道中获取收集到的IP地址,如果是新IP 就通过iptables 封杀,如果已经添加过,就跳过

 

 

 

 

Neo代码   收藏代码
  1. #!/bin/bash           
  2. ########################################  
  3. # Homepage: http://netkiller.github.com  
  4. # Author: neo <openunix@163.com>  
  5. ########################################  
  6. BLACK=/tmp/black.lst  
  7. PIPE=/tmp/pipe  
  8. pidfile=/tmp/firewall.pid  
  9. KEYWORD=XXDD0S  
  10. ########################################  
  11. if [ -z $1 ]; then  
  12.     echo "$0 clear|fw|collect|process|close"  
  13. fi  
  14.   
  15. if [ "$1" == "clear" ]; then  
  16.     rm -rf $BLACK  
  17.     rm -rf $PIPE  
  18.     echo "Clear OK!!!"  
  19. fi  
  20.   
  21. if [ "$1" == "close" ]; then  
  22.         kill `cat $pidfile`  
  23.     echo > $pidfile  
  24. fi  
  25.   
  26. if [ ! -f $BLACK ]; then  
  27.     touch $BLACK  
  28. fi  
  29.   
  30. if [ ! -e $PIPE ]; then  
  31.     mkfifo $PIPE  
  32. fi  
  33.   
  34. if [ "$1" == 'fw' ]; then  
  35.     iptables -A OUTPUT -p tcp --dport 2049 -j REJECT  
  36.     iptables -A OUTPUT -p tcp -m multiport --dports 22,21 -j REJECT  
  37. fi  
  38.   
  39. if [ "$1" == "collect" ]; then  
  40.     killall tail   
  41.     ACCESSLOG=/www/logs/www.example.com/access.$(date +'%Y-%m-%d').log  
  42.     for (( ; ; ))  
  43.     do  
  44.         tail -f $ACCESSLOG | grep $KEYWORD | cut -d ' ' -f1 > $PIPE  
  45.     done &  
  46.     echo $! > $pidfile  
  47. fi  
  48.   
  49. if [ "$1" == "process" ]; then  
  50. for (( ; ; ))  
  51. do  
  52.     while read line   
  53.     do  
  54.         grep $line ${BLACK}  
  55.         if [ $? -eq 1 ] ; then  
  56.             echo $line >> ${BLACK}      
  57.             iptables -I INPUT -p tcp --dport 80 -s $line -j DROP      
  58.         fi  
  59.     done < $PIPE  
  60. done &  
  61. echo $! >> $pidfile  
  62. fi  

 

同时有做了一些限制

 

iptables -A INPUT -i eth0 -p tcp --dport 80 --syn -m connlimit --connlimit-above 20 -j DROP

 

也常是使用:

iptables -A INPUT -p tcp --dport 80 -m string --algo bm --string "XXDD0S" -j DROP

但效果不好,无论DROP,还是REJECT 都不能立即拒绝掉,仍然对服务器有影响

 

另外上面收集到的IP地址。

通过脚本转换成Cisco ASA Firewall 命令,然后添加到硬件防火墙中。

 

Java代码   收藏代码
  1. object-group network blacklist  
  2.  description deny ip to example.com  
  3.  network-object host 61.190.10.181  
  4.  network-object host 61.190.10.182  
  5.  network-object host 61.190.10.183  
  6.  network-object host 61.191.55.248  
  7.  network-object host 61.190.10.181  
  8.  network-object host 61.185.114.87  
  9.  network-object host 60.210.111.236  
  10.  network-object host 218.64.182.105  
  11.  network-object host 210.51.51.157  
  12.  network-object host 63.221.138.204  
  13.  network-object host 119.188.10.163  
  14.     
  15. access-list outside extended deny tcp object-group blacklist host xxx.xxx.xxx.xxx  
 

 

如果有兴趣还可一看看这篇文章:

 

http://netkiller-github-com.iteye.com/blogs/1319293

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值