使用Ddos deflate 解决服务器被ddos攻击

1.DDOS概述
分布式拒绝服务(DDoS:Distributed Denial of Service)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DDoS攻击,从而成倍地提高拒绝服务攻击的威力。
2.编写查看DDOS攻击的脚本内容

[root@ localhost ~]# vim ddos-test.sh #写入以下内容
#!/bin/bash
netstat -ntu | awk '{print $5}' | cut -d: -f4 | sort | uniq -c | sort -n

[root@ localhost ~]# chmod +x ddos-test.sh
注释:
#!/bin/bash
netstat -ntu | awk '{print $5}' | cut -d: -f1       | sort |  uniq -c   | sort -n
截取外网IP和端口   截取外网的IP以:为分隔符  |排序 | 排除相同的记录  | 排序并统计
注:这个脚本在不同的机器上执行时,因为  print $5 取得的结果不一样,所以需要根据实际情况,改变cut -d: -f1 中fn的值。 如果-f1 不行,就使用f4
cut -d: -f1  #以冒号为分隔符,取第一列的值。

3.模拟DDOS攻击

安装Apache
[root@ localhost ~]# yum -y install httpd
[root@ localhost ~]# systemctl start httpd
[root@ localhost ~]#  ab -n 100 -c 10 http://192.168.1.63/index.html  #开始攻击
[root@ localhost ~]# ./ddos-test.sh  #查看已经建立的网络连接数

4.检测是否有DDOS攻击

执行:
[root@ localhost ~]# netstat -ntu | awk '{print $5}' | cut -d: -f4 | sort | uniq -c | sort -n

5.如果发现某个IP连接数据上百的链接,说明就有DDOS攻击。安装DDoS deflate

[root@ localhost ~]# wget http://www.inetbase.com/scripts/ddos/install.sh
下载DDoS  deflate,保证可以上网
[root@ localhost ~]# chmod 700 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]

6.修改配置文件

[root@ localhost ~]# vim /usr/local/ddos/ddos.conf
##### 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"
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
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150
##### 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=1
改: APF_BAN=1
为: APF_BAN=0
##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)
##### KILL=1 (Recommended setting)
KILL=1
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO=[[email protected]](mailto:[email protected])  #当IP被屏蔽时给指定邮箱发送邮件报警,换成自己的邮箱即可
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600  #禁用IP时间,默认600秒,可根据情况调整
用户可根据给默认配置文件加上的注释提示内容,修改配置文件。\****
注:安装后,不需要手动运行任何软件,因为有crontab计划任务,每过一分钟,会行自动执行一次。检查是否有不正常的访问量

7.在另一台centos7上模拟安装apache,并启动DDOS

[root@ localhost ~]# yum -y install httpd
[root@ localhost ~]# systemctl start httpd
[root@ localhost ~]# ab -n 1000 -c 10 http://10.0.0.73/index.html

8.等待一分钟后,在另一台虚拟机查看结果,多了一条规则成功

返回ddos主机执行
[root@ localhost ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  10.0.0.74            0.0.0.0/0           

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
You have mail in /var/spool/mail/root
发布了34 篇原创文章 · 获赞 13 · 访问量 511

猜你喜欢

转载自blog.csdn.net/qq_45019159/article/details/103890004