日期:2018-05-28 21:41:59
更新:2019-07-05 23:15:21
做者:Bay0net
介绍:学习一下 slowHTTPtest 的攻击及防护。html
0x0一、 安装
下载连接
https://github.com/shekyan/slowhttptestgit
安装介绍
https://github.com/shekyan/slowhttptest/wiki/InstallationAndUsagegithub
KALIweb
git clone https://github.com/shekyan/slowhttptest cd slowhttptest ./configure make
MAC:
brew update && brew install slowhttptest
apache
0x0二、攻击模式
服务器在接收到请求时,彻底接收之后才会处理请求,若是攻击者发送的比较缓慢或者发送的不完整,服务器会保留其链接,占用资源池,若是请求数量较多,就会造成 DOS 攻击。服务器
2.1 三种攻击模式
一、slowloris
:完整的http请求是以 \r\n\r\n
结尾,攻击时仅发送 \r\n
,少发送一个 \r\n
,服务器认为请求还未发完,就会一直等待直至超时。tcp
slowhttptest -c 1000 -H -g -o my_header_stats -i 10 -r 200 -t GET -u "url" -x 24 -p 3
二、slow post
:经过声明一个较大的content-length后,body缓慢发送,致使服务器一直等待。工具
slowhttptest -c 3000 -B -g -o my_body_stats -i 110 -r 200 -s 8192 -t FAKEVERB -u "url" -x 10 -p 3
三、slow read
:向服务器发送一个正常合法的read请求,请求一个很大的文件,但把TCP滑动窗口设置得很小,服务器就会以滑动窗口的大小切割文件,而后发送,这是文件会长期存放在内存中,消耗资源。post
slowhttptest -c 8000 -X -r 200 -w 512 -y 1024 -n 5 -z 32 -k 3 -u "url" -p 3
四、Range Header test
:在 HTTP 请求的 RANGE HEADER 中包含大量字段,使得服务器在服务端将一个很小的文件分割成大量的更小的片断再压缩。分段压缩过程消耗大量的服务器资源,致使 DOS。学习
slowhttptest -R -u "url" -t HEAD -c 1000 -a 10 -b 3000 -r 500
五、测试的时候,添加代理
slowhttptest -c 1000 -X -r 1000 -w 10 -y 20 -n 5 -z 32 -u url -p 5 -l 350 -e lhost:lport
2.2 参数说明
-g 在测试完成后,以时间戳为名生成一个CVS和HTML文件的统计数据 -H SlowLoris模式 -B Slow POST模式 -R Range Header模式 -X Slow Read模式 -c number of connections 测试时创建的链接数 -d HTTP proxy host:port 为全部链接指定代理 -e HTTP proxy host:port 为探测链接指定代理 -i seconds 在slowrois和Slow POST模式中,指定发送数据间的间隔。 -l seconds 测试维持时间 -n seconds 在Slow Read模式下,指定每次操做的时间间隔。 -o file name 使用-g参数时,能够使用此参数指定输出文件名 -p seconds 指定等待时间来确认DoS攻击已经成功 -r connections per second 每秒链接个数 -s bytes 声明Content-Length header的值 -t HTTP verb 在请求时使用什么操做,默认GET -u URL 指定目标url -v level 日志等级(详细度) -w bytes slow read模式中指定tcp窗口范围下限 -x bytes 在slowloris and Slow POST tests模式中,指定发送的最大数据长度 -y bytes slow read模式中指定tcp窗口范围上限 -z bytes 在每次的read()中,从buffer中读取数据量
0x0三、netstat 的相关操做
查看链接数
netstat -ant | grep $ip:80 | wc -l
查看当前链接数
netstat -ant | grep $ip:80 | grep EST | wc -l
0x0四、修复方法
XAMPP 的配置路径
/opt/lampp/etc/httpd.conf /opt/lampp/etc/original/httpd.conf /opt/lampp/apache2/conf/httpd.conf
方法1:启用 Apache 的 reqtimeout_module 模块
配置文件里,默认启用了这个模块,
LoadModule reqtimeout_module modules/
在 httpd.conf 里面,添加上
mod_reqtimeout.so <IfModule reqtimeout_module> RequestReadTimeout header=5-40,MinRate=500 body=20,MinRate=500 </IfModule>

再攻击的话,提示

也能够安装两个新的模块 mod_qos
和 mod_security
<IfModule mod_qos.c> # handle connections from up to 100000 different IPs QS_ClientEntries 100000 # allow only 50 connections per IP QS_SrvMaxConnPerIP 50 # limit maximum number of active TCP connections limited to 256 MaxClients 256 # disables keep-alive when 180 (70%) TCP connections are occupied QS_SrvMaxConnClose 180 # minimum request/response speed (deny slow clients blocking the server, keeping connections open without requesting anything QS_SrvMinDataRate 150 1200 </IfModule>
方法2:设置每一个 IP 只能创建20个链接
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset
查看创建的链接数
netstat -ant | grep $ip:80 | grep EST | wc -l
设置完 iptables
后,当即生效,可是使用工具进行攻击的时候,仍是会提示攻击成功,由于攻击者本身只能与服务器创建20个链接,超过20个链接后,会提示服务不可用。

服务器创建的链接数

方法3:Tomcat 的修复
Tomcat 在 server.xml 中修改超时时间便可

修改之后,攻击以下:

修复的效果立竿见影,攻击对服务器基本没影响了。。。
方式4:weblogic 的修复
console 控制台修改两个参数。


Reference
How To Mitigate Slow HTTP DoS Attacks in Apache HTTP Server - Acunetix