attacker (kali + slowhttptest) ip 169.254.227.182
victim(apache2 + wireshark) ip 169.254.227.283
实验内容
首先在attacker上安装slowhttptest,在victim上打开apache2服务 apt install slowhttptest service apache2 start
查看slowhttptest和apache2版本信息
#victim上apache2的版本信息
apache2 -version
Server version: Apache/2.4.34(Debian)
Server built:2018-07-27T19:37:37#attacker上slowhttptest版本信息
slowhttptest version 1.6
apt search apache-#首先搜索apache2 相关扩展模块 从输出结果中获取模块名称以后 直接下载
apt install libapache2-mod-qos #安装mod_qos 模块
vim /etc/apache2/mods-enabled/qos.conf #打开配置文件 进行如下配置<IfModule qos_module># minimum request rate (bytes/sec at request reading):
QS_SrvRequestRate 150#设置request最低传输速率# limits the connections for this virtual host: #设置服务器最多连接个数
QS_SrvMaxConn 50# allows keep-alive support till the server reaches 10 connections:
QS_SrvMaxConnClose 10# allows max 10 connections from a single ip address:
QS_SrvMaxConnPerIP 10#设置单个ip 最多的连接数</IfModule>
service apache2 restart # 重启apache2服务
tail -f /var/log/fail2ban.log
2018-12-2620:02:28,680 fail2ban.jail [7619]: INFO Jail 'http-error-dos' started
2018-12-2620:05:19,478 fail2ban.filter[7619]: INFO [http-error-dos] Found 169.254.227.182-2018-12-2620:05:142018-12-2620:05:19,479 fail2ban.filter[7619]: INFO [http-error-dos] Found 169.254.227.182-2018-12-2620:05:142018-12-2620:05:19,479 fail2ban.filter
nginx没有所谓的MaxClients限制,使用 vim /etc/nginx/nginx.conf查看nginx配置文件,可以发现虽然 worker_connections = 768,是一个固定的数值,但是worker_processes = auto ,这就决定了nginx不会有连接数被占满而导致的拒绝服务攻击。
HTTP POST DOS原理、攻击实验及对应防御措施
HTTP POST DOS原理
在2010年的OWASP大会上,Wong Onn Chee 和 Tom Brennan 演示了一种类似于 Slowlories的攻击方法,作者称之为HTTP POST DOS。
原理是在发送HTTP POST数据包时,指定一个非常大的 content-length,然后以很低的速度发包,以保持住这个连接而不断开。当客户端连接数占用了所有可用的服务器连接以后,就会导致拒绝服务攻击。
其攻击的本质也是针对像Apache这种服务器的MaxClients的配置参数限制的。
HTTP POST DOS 攻击实验和防御实验
实验环境
同上文中Slowloris攻击实验
attacker (kali + slowhttptest) ip 169.254.227.182
victim(apache2 + wireshark) ip 169.254.227.283
由于HTTP POST DOS和Slowloris的攻击思想的相似性,即都使用慢速发送数据包、保持tcp连接以占用连接数(而不是真的对服务器端内存资源完全消耗)的攻击方法,因此适用于Slowloris的防御手段也适用于HTTP POST DOS。具体使用以下三种手段
限制数据包最小发送速率
限制单个ip允许的tcp最大连接数
使用fail2ban阻止可疑ip的访问
使用和Slowloris相同的防御方式,选用apache2的扩展模块mod_reqtimeout 、mod_qos和fail2ban 对HTTP POST DOS进行有效的防御。
以上配置攻击完成,使用slowhttptest进行攻击,完成后查看输出数据,结果如下,可见HTTP POST DOS的攻击并未生效。
Server Limit DOS
原理
web server 对HTTP包头都有长度限制(如apache2服务器中的LimitRequestFieldSize和nginx中的large_client_header_buffers属性,都能限制Http header的长度),如果客户端发送的http包头超过这个大小,服务器就会返回一个4xx错误。
假如攻击者通过XSS攻击,恶意往客户端写入一个超长的cookie,则该客户端在该cookie失效之前,将再无法访问该cookie所在域的任何页面。因为cookie放在http header中发送,如果cookie过长,导致http header过长,服务器拒绝该用户的请求,导致拒绝服务攻击。
def attack():
print_status()
url_path = generate_url_path()
# Create a raw socket
dos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Open the connection on that raw socket
dos.connect((ip, port))
# Send the request according to HTTP spec
dos.send("GET /rand.php HTTP/1.1\r\nHost: 169.254.227.182\r\nUser-Agent: curl/7.61.0\r\nAccept: */*\r\n\r\n")
except socket.error, e:
print "\n [ No connection, server may be down ]: " + str(e)
finally:
# Close our socket gracefully
dos.shutdown(socket.SHUT_RDWR)
dos.close()