全球中文玩家俱乐部 Chinese players club of the Global .

侠外游戏论坛

 找回密码
 立即注册
快捷导航
搜索
视听
视听
图片
图片
段子
段子
小说
小说
查看: 1732|回复: 3
收起左侧

[闲聊技术] 为CentOS安装防DDOS攻击软件DDoS-Deflate

[复制链接]
ミ蒙面侠客ミ
ミ蒙面侠客ミ  发表于 2017-9-4 16:30:11 |阅读模式

马上注册,结交更多侠客,享用更多功能,让你轻松玩转侠外论坛。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
DDoS-Deflate是一款非常小巧的防御和减轻DDoS攻击的工具,它可以通过监测netstat来跟踪来创建大量互联网连接的IP地址信息,通过APF或IPTABLES禁止或阻档这些非常IP地址。

我们可以使用netstat命令查看当前系统连接的状态,是否有受到DDOS攻击

[root@localhost ~]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
&http://www.aliyun.com/zixun/aggregation/37954.html">nbsp;     1 101.226.66.172
      1 103.29.134.193
      1 110.85.249.85
      1 115.150.118.203
      1 116.22.233.25
      1 119.254.227.106
      1 122.224.152.139
      1 123.126.68.35
      1 123.151.136.225
      1 124.202.164.10
      1 124.202.164.16
      1 14.29.112.87
      1 14.29.127.218
      1 157.55.33.124
      1 170.130.24.152
      1 180.149.143.11
      1 182.118.19.201
      1 182.118.20.40
      1 183.39.201.142
      1 199.30.24.33
      1 210.242.215.195
      1 210.242.215.211
      1 210.242.215.212
      1 210.242.215.213
      1 210.242.215.215
      1 210.242.215.216
      1 210.242.215.218
      1 210.6.198.12
      1 219.239.26.13
      1 220.181.51.62
      1 23.94.20.3
      1 27.28.7.0
      1 42.120.160.95
      1 42.156.137.95
      1 58.51.180.34
      1 60.220.197.225
      1 61.135.189.43
      1 61.135.249.202
      1 61.164.170.222
      1 66.249.67.163
      1 Address
      1 servers)
      2 124.202.164.11
      2 218.109.165.44
      2 220.181.125.20
      2 223.104.20.49
      2 42.156.136.95
      2 61.51.249.58
      2 72.52.94.226
      3 210.242.215.210
      3 222.76.109.133
      4 120.39.165.97
      4 123.113.42.119
      5 110.244.82.238
      5 118.72.107.112
      5 222.141.238.211
      6 110.153.48.75
      6 111.206.125.33
      6 124.117.235.163
      6 60.215.180.43
      7 101.226.89.117
      9 111.20.119.234
      9 119.126.238.114
      9 183.32.67.179
     10 121.35.228.194
     10 122.141.235.146
     11 183.63.97.42
     12 106.125.11.78
     13 114.228.158.82
     13 118.228.151.171
     14 222.129.186.143
     15 113.231.87.141
     17 113.137.204.201
     20 119.251.38.134
     20 61.164.36.34
     30 58.215.136.89
     44 58.215.136.105
    101 127.0.0.1

查看iptables的状态

[root@localhost ~]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination        
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0         
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0         
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:21
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:58416
8    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination        
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination      

安装DDoS-Deflate

[root@localhost ~]# wget http://www.inetbase.com/scripts/ddos/install.sh
[root@localhost ~]# chmod +x install.sh
[root@localhost ~]# ./install.sh

Installing DOS-Deflate 0.6


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

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

Installation has completed.
Config file is at /usr/local/ddos/ddos.conf
Please send in your comments and/or suggestions to [email protected]

DOS-Deflate已经安装好了。

DOS-Deflate卸载

wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
chmod 0700 uninstall.ddos
./uninstall.ddos

DOS-Deflate文件的说明:

[root@localhost ~]# cd /usr/local/ddos/
[root@localhost ddos]# ll
总用量 4
-rw-r--r-- 1 root root   971 1月  10 2006 ddos.conf
-rwxr-xr-x 1 root root  3945 1月  10 2006 ddos.sh
-rw-r--r-- 1 root root    10 1月  10 2006 ignore.ip.list
-rw-r--r-- 1 root root 10113 1月  10 2006 LICENSE

DOS-Deflate安装好之后,全部的文件是放在/usr/local/ddos文件夹中。

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

配置ddos.conf

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

##### frequency in minutes for running the script
##### Caution: Every time this setting is changed, run the script with --cron
#####          option so that the new frequency takes effect
FREQ=1  #DDoS-Deflate通过linux的计划任务执行,默认为每分钟一次

##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150 #定义单个IP达到多少连接时规定为这是一次ddos攻击

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

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

##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO="[email protected]"  #事件通知人的邮件地址

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

ddos.sh文件内容:

[root@localhost ddos]# ./ddos.sh -h
DDoS-Deflate version 0.6
Copyright (C) 2005, Zaf <[email protected]>

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

测试防ddos攻击效果

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

DROP all -- 31.210.16.29.broad.cs.gd.dynamic.163data.com.cn anywhere

说明确实生效了,当10分钟后,iptables上这条策略会被取消的

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

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

ddos攻击很常见,攻击效果也很好,比如像前段时间由于维基创始人引发的那次大范围的攻击。
如果有专门防止ddos的硬件设备的话最好,没有的话就利用DDoS-Deflate结合iptables在一定程度上防范ddos攻击也是一种很好的策略。
ミ蒙面侠客ミ
ミ蒙面侠客ミ  发表于 2017-9-4 16:31:10
低调是最好的选择。尽量不在某些地方显摆,不要过于招摇,也算做了一道安全防御吧!话说人在江湖飘,哪有不挨刀?防患于未然,是很有必要的。好了,废话说了一堆,现在安装DDos deflate。

在说到DDos deflate之前,我们还需要了解一个东西:iptables

iptables是linux内核集成的IP信息包过滤系统,他可以简单的添加、编辑和除去规则,而这些规则是在做信息包过滤决定时,防火墙所遵循和组成的规则。

我们首选确认iptables服务状态
# service iptables staus

确认之后,安装DDos deflate
# wget http://www.inetbase.com/scripts/ddos/install.sh
# chmod +x install.sh
# ./install.sh

安装完成后,还需要修改配置文件,达到利用iptables自动锁定IP的目的。
# vi /usr/local/ddos/ddos.conf

接下来修改,这里主要是APF_BAN=1修改为0(使用iptables),另外EMAIL_TO="root"可以将root修改为你的一个Email地址,这样系统办掉哪个IP,会有邮件提示你。
-----------------------------------------
##### Paths of the script and other files
PROGDIR=”/usr/local/ddos”
PROG=”/usr/local/ddos/ddos.sh”
IGNORE_IP_LIST=”/usr/local/ddos/ignore.ip.list”  //IP地址白名单
CRON=”/etc/cron.d/ddos.cron”    //定时执行程序
APF=”/etc/apf/apf”
IPT=”/sbin/iptables”
##### frequency in minutes for running the script
##### Caution: Every time this setting is changed, run the script with –cron
#####          option so that the new frequency takes effect
FREQ=1   //检查时间间隔,默认1分钟
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150     //最大连接数,超过这个数IP就会被屏蔽,一般默认即可
##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
##### APF_BAN=0 (Uses iptables for banning ips instead of APF)
APF_BAN=0        //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。
##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1   //是否屏蔽IP,默认即可
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
[email protected]   //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600    //禁用IP时间,默认600秒,可根据情况调整

-------------------------------------------------------------

由于这个系统默认白名单有些问题,经常会有失误,所以,我们最好再设定手工设置白名单并不可修改。

# vi /usr/local/ddos/ignore.ip.list  #手工设置白名单IP
# chattr +i /usr/local/ddos/ignore.ip.list    #强制不允许修改
# chattr -i /usr/local/ddos/ignore.ip.list     #解除不允许修改

卸载DDos deflate方法。

# wget http://www.inetbase.com/scripts/ddos/uninstall.ddos
# chmod 700 uninstall.ddos
# ./uninstall.ddos
发表于 2021-6-18 02:49:18 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

发表于 2022-2-20 02:08:12 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
这里是你的个性签名位置,可在“设置”-“个人信息”-“个人签名”处修改。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


发布主题 上个主题 下个主题 快速回复 收藏帖子 返回列表 搜索

联系我们|Archiver|手机版|小黑屋|侠外网 ( 豫ICP备13018943号-1 )

GMT+8, 2024-3-29 22:08 , Processed in 0.041740 second(s), 17 queries , Gzip On, Memcache On.

Copyright © 2001-2023 侠外游戏论坛 Powered by !Zucsud X3.5

Support By A mysterious team , A great team ! Email:

快速回复 返回顶部 返回列表