首页 技术 正文
技术 2022年11月20日
0 收藏 769 点赞 2,931 浏览 2770 个字

0x01 环境

attact作为攻击发起方,安装有hping
server作为被攻击方,修改内核TCP参数。使用操作系统CENTOS7

0x02 步骤

一、发起攻击

修改TCP最大SYN连接数
使用attact机发起TCP SYN攻击

注意修改IP与端口,端口一定要是服务器上开放的TCP端口

hping3 -S --flood --rand-source 192.168.164.136 -p 80

登录server服务器,查看当前受攻击情况
systemctl start httpd//启动http服务
netstat -an | grep SYN //查看SYN半连接
netstat -an | grep SYN | wc -l//统计SYN半连接数,默认为128*2
登录server,查看服务器默认设置
cat /proc/sys/net/ipv4/tcp_max_syn_backlog //默认为128
cat /proc/sys/net/core/somaxconn //默认为128
cat /proc/sys/net/ipv4/tcp_synack_retries//默认为5
cat /proc/sys/net/ipv4/tcp_syncookies//默认为1,表示开启
参数 解释
tcp_max_syn_backlog 表示TCY_SYN连接数
somaxconn 表示每个应用端口listen的队列

系统实际上会将上述两个值取较小值*2,来作为上限值,所以我们要修改这两个值

参数 解释
tcp_synack_retries 表示收到SYN后发送SYN+ACK的重传次数,默认为5
tcp_syncookies 表示启用SYNCOOKIES功能,默认1即启用

vi /etc/sysctl.conf,加入下面参数,并保存

net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries =2
net.core.somaxconn = 1024
保存文件后,执行以下命令,生效

sysctl -p

修改apached的listenbacklog

vi /etc/httpd/conf.modules.d/00-mpm.conf

加入下面行
ListenBacklog 1024
重启HTTP应用

systemctl restart httpd

查看当前队列数。需要注意的是,每个应用会有自己默认的最大队列。如SSH是128,APACHE是511,这个值,会与和我们设置的somaxconn取最小值。

查看当前端口的队列值,即SEND-Q

ss -lnt

再次发起攻击

hping3 -S --flood --rand-source 192.168.164.136 -p 80

再次查看状态

netstat -an | grep SYN | wc -l//统计SYN半连接数,这里应该为2048

二、DDOS防御—使用iptables限制SYN连接速度

登录server,启用iptables
systemctl stop firewalld.service\\停止firewall
systemctl disable firewalld.service\\禁止firewall开机启动
yum -y install iptables-services\\安装 iptables-service
systemctl start iptables\\启动IPTABLES服务
配置iptables
iptables -N syn-flood//新建一个表
iptables -I INPUT -p tcp --syn -j syn-flood//匹配syn到syn-flood
iptables -I syn-flood -p tcp -m limit --limit 3/s --limit-burst 6 -j RETURN//syn限速,超出后返回
iptables -A syn-flood -j REJECT//拒绝其它
配置后的iptables 显示如下

iptables -nL

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 syn-flood tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp flags:0x17/0x02
111 8244 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
2 569 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT 19 packets, 1892 bytes)
pkts bytes target prot opt in out source destination Chain syn-flood (1 references)
pkts bytes target prot opt in out source destination
0 0 RETURN tcp -- * * 0.0.0.0/0 0.0.0.0/0 limit: avg 3/sec burst 6
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
再使用 hping3发起SYN攻击,查看服务器SYN连接

三、DDOS防御—使用iptables限制同一源IP连接数

以80端口为例,开启服务器的http服务

systemctl start http

配置iptables如下
iptables -I INPUT  -p tcp -m tcp --dport 80 -j ACCEPT     //允许访问80端口
iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 15 -j REJECT //拒绝大于15个连接的IP
使用Attact机器发起模拟攻击

slowhttptest -c 1000 -B -g -i 10 -r 200 -u http://192.168.164.136 -x 1024 -p 3

攻击后,分别使用attact和其它计算机访问http://192.168.164.136,观察能否正常访问

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727