Chinaunix首页 | 论坛 | 博客
  • 博客访问: 204558
  • 博文数量: 39
  • 博客积分: 1057
  • 博客等级: 准尉
  • 技术积分: 926
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-27 20:13
文章分类

全部博文(39)

文章存档

2012年(24)

2011年(15)

分类: 网络与安全

2011-06-24 16:02:26

    DDoS-Deflate通过查看单个ip的连接数来判断这次连接是否是ddos攻击的一部分,被确定为是ddos攻击时,会调用iptables对该ip进行阻拦一段时间,以缓解攻击。

DDoS-Deflate 的配置很简单明了。

(一)安装DDoS-Deflate

(1)下载安装脚本

  1. wget http://www.inetbase.com/scripts/ddos/install.sh

(2)安装 DDoS-Deflate

  1. ./install.sh
.....下面是安装过程,很快....
Installing DOS-Deflate 0.6


Downloading source files.........done

Creating cron to run script every minute.....(Default setting)

....下面是发布协议....
....

这样 DDoS-Deflate,就安装好了

二)配置和使用

(1)了解 DDoS-Deflate 软件的文件分布

DDoS-Deflate 安装好之后,默认全部在 /usr/local/ddos/ 目录下

  1. # pwd
    /usr/local/ddos
  2. # ls
    ddos.conf  ddos.sh  ignore.ip.list  LICENSE

文件说明:
ddos.conf -- DDoS-Deflate 的配置文件,其中配置防止ddos时的各种行为
ddos.sh   -- DDoS-Deflate 的主程序,使用shell编写的,整个程序的功能模块
ignore.ip.list -- 白名单,该文件中的ip超过设定的连接数时,也不被 DDoS-Deflate 阻止
LICENSE   -- DDoS-Deflate 程序的发布协议


(2)配置 ddos.conf

  1. ##### Paths of the script and other files    #配置文件也是个shell脚本
  2. PROGDIR="/usr/local/ddos"
  3. PROG="/usr/local/ddos/ddos.sh"
  4. IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list" #存放白名单的文件
  5. CRON="/etc/cron.d/ddos.cron"                 #计划任务,默认是每分钟执行一次ddos.sh
  6. APF="/etc/apf/apf"
  7. IPT="/sbin/iptables"

  8. ##### frequency in minutes for running the script
  9. ##### Caution: Every time this setting is changed, run the script with --cron
  10. ##### option so that the new frequency takes effect
  11. FREQ=1                                       #DDoS-Deflate通过linux的计划任务执行,默认为每分钟一次
  12. d IP? Indicate that below.
  13. NO_OF_CONNECTIONS=150                        #定义单个IP达到多少连接时规定为这是一次ddos攻击

  14. ##### How many connections define a ba

  15. ##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
  16. ##### APF_BAN=0 (Uses iptables for banning ips instead of APF)
  17. APF_BAN=0                                   #这里为 “0”,表示使用iptables,而不是APF

  18. ##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
  19. ##### KILL=1 (Recommended setting)
  20. KILL=1                                      #是否阻止被定义为ddos攻击的ip,“1”为阻止

  21. ##### An email is sent to the following address when an IP is banned.
  22. ##### Blank would suppress sending of mails
  23. EMAIL_TO="xyzblood@163.com"                 #事件通知人的邮件地址

  24. ##### Number of seconds the banned ip should remain in blacklist.
  25. BAN_PERIOD=600                              #阻止被定义为ddos攻击者ip与本机通信时间,默认为600秒

(3)使用ddos.sh

  1. 使用“-h”选项显示该命令的提供的选项和功能简介
  2. 因为安装的时候默认就执行了: ./ddos --cron 了,所以我们什么也不需要做了
  3. # ./ddos.sh -h
    DDoS-Deflate version 0.6
    Copyright (C) 2005, Zaf

    Usage: ddos.sh [OPTIONS] [N]
    N : number of tcp/udp   connections (default 150)
    OPTIONS:
    -h | --help: Show       this help screen
    -c | --cron: Create cron job to run this script regularly (default 1 mins)
    -k | --kill: Block the offending ip making more than N connections
(4)测试防ddos攻击效果

  1. NO_OF_CONNECTIONS=3         #这里为了方便测试,设置为3。生产环境下,几十到几百都可以理解为正常,上千肯定就是不正常了,除非是应用内部各个服务器之间的通信
通过一台固定ip的机器ssh连接该服务器,当连接到超过3甚至更多时,不会立刻显示连不上,因为ddos.sh默认一分钟运行一次,当过不到一分钟时,会发现连接掉了,查看部署了防ddos软件的服务器上可以看到iptables的策略中多了:

  1. DROP all -- 31.210.16.29.broad.cs.gd.dynamic.163data.com.cn anywhere
说明确实生效了,当10分钟后,iptables上这条策略会被取消的

(5)关于如何查看单个IP的连接数目可以通过如下命令查看,依次排列:

  1. netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n
  2. ..............
     40 127.0.0.1
      1 121.9.252.28
      1 173.117.140.69

(三)后记
ddos攻击很常见,攻击效果也很好,比如像前段时间由于维基创始人引发的那次大范围的攻击。
如果有专门防止ddos的硬件设备的话最好,没有的话就利用DDoS-Deflate结合iptables在一定程度上防范ddos攻击也是一种很好的策略。
阅读(2322) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~