首页 Linux

Linux+DDoS deflate预防DDoS

2021-09-02 14:13

DDoS概述:

分布式拒绝服务(DDoS:Distributed Denial of Service),指借助于客户/服务器技术,将多个计算机联合起来作为attack平台,对一个或多个目标发动DDoS,从而成倍地提高拒绝服务的威力。

如何查看是否受到DDoS?

通过netstat命令查看网络连接数,如果一个IP地址对服务器建立很多连接数(比如一分钟产生了100个连接),那么就认为发生了DDoS攻击。

模拟DDoS攻击:

使用ab命令模拟DDoS访问一个页面,页面越大,消耗服务器带宽就越大。

-n选项表示要产生的链接数总和,-c选项表示同时打开的客户端数量

在web服务器查看网络连接情况

可以发现来web服务器上自192.168.227.100这个IP的连接数有1000,说明服务器有DDoS攻击情况。

解决办法:

使用DDoS deflate解决服务器被DDOS的问题。DDoS deflate是用来防御和减轻DDoS的shell脚本,它通过netstat监测跟踪创建大量网络连接的IP地址,在检测到某个结点超过预设的限制时,该程序会通过APF或IPTABLES禁止或阻挡这些IP

下面开始安装DDos deflate:

[root@centos-7 sbin]# wget wget http://www.inetbase.com/scripts/ddos/install.sh

[root@centos-7 sbin]# chmod +x install.sh

[root@centos-7 sbin]# ./install.shInstalling

DOS-Deflate 0.6Downloading source files.........doneCreating cron to run script every minute.....(Default setting).....doneInstallation has completed.Config file is at /usr/local/ddos/ddos.confPlease send in your comments and/or suggestions to zaf@vsnl.com

#下面内容省略,输入q退出[root@centos-7 sbin]# cd /usr/local/ddos/[root@centos-7 sbin]# ls -la

配置DDoS deflate配置文件ddos.conf

[root@centos-7 sbin]# vim ddos.conf

PROGDIR="/usr/local/ddos"

PROG="/usr/local/ddos/ddos.sh"

IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list" # IP白名单,名单中的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 # 检查DDoS攻击时间间隔,默认一分钟

##### How many connections define a bad IP? Indicate that below.

NO_OF_CONNECTIONS=200 # 最大连接数,超过这个数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 mailsEMAIL_TO="root@admin.com" #当IP被屏蔽时给指定邮箱发送邮件报警,换成自己的邮箱即可

##### Number of seconds the banned ip should remain in blacklist.

BAN_PERIOD=600 # 禁用IP时间,默认600秒,可根据实际情况调整

查看周期任务:

系统级别的计划任务

每分钟执行一次计划任务,是不是有DDoS,如果发现就开始拒绝

测试:

使用ab命令模拟DDoS攻击

查看web服务器iptables策略

如果不想使用DDoS deflate,可以下载脚本进行卸载:

[root@centos-7 sbin]# wget http://www.inetbase.com/scripts/ddos/uninstall.ddos

[root@centos-7 sbin]# chmod +x uninstall.ddos

[root@centos-7 sbin]# ./uninstall.ddosUninstalling

DOS-DeflateDeleting script files.........doneDeleting cron job.......doneUninstall Complete

虽然说DDoS deflate的计划任务是系统级别的,hacker一样有办法去篡改一个系统级别的计划任务。

可能我们也看不出动了什么手脚,定期检查的时候看着还是跟往常一样,忽然某一天被DDoS还不知道怎么回事,所以我们还是先下手为强:

可以使用md5加密,因为md5加密算法是不可逆的,文件只要被改动过就能看得出来

[root@centos-7 sbin]# cat /usr/share/cronfile_md5

[root@centos-7 sbin]# echo " " >> /etc/cron.d/ddos.cron # 加一个空格进去

这样定期检查的时候就可以发现系统级别的计划任务是否被篡改。

返回首页
返回顶部