43

ModSecurity 拒绝服务漏洞 (CVE-2019-19886) 复现

 4 years ago
source link: https://gh0st.cn/archives/2020-01-24/1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ModSecurity 拒绝服务漏洞 (CVE-2019-19886) 复现

作者: key

本文利用Github Commit代码对比的方式进行跟踪复现

背景

2020年1月20日,Trustwave SpiderLabs公开了其维护的开源WAF引擎ModSecurity的1个拒绝服务(DoS)漏洞,漏洞编号为:CVE-2019-19886。此漏洞影响ModSecurity的3.0到3.0.3版本。

漏洞描述

ModSecurity是一个开源的、跨平台的Web应用防火墙(WAF),被称为WAF界的“瑞士军刀”。它可以通过检查Web服务接收到的数据,以及发送出去的数据来对网站进行安全防护。

2020年1月21日,ModSecurity的维护组织Trustwave公开了影响ModSecurity 3.0至3.0.3版本的1个拒绝服务漏洞,漏洞编号为 CVE-2019-19886,漏洞详情如下:

在ModSecurity 3.0到3.0.3版本中,存在cookie解析问题。通过构造格式错误的HTTP Cookie头发送到运行ModSecurity的Nginx的服务器,会导致out_of_range异常。在结合Nginx web服务器使用ModSecurity的常用情况下,该异常将使nginx工作线程(负责处理请求的线程)崩溃。不断向服务器发送此类请求将使工作线程反复崩溃。如果发送请求的速度快于工作线程恢复的速度,将导致服务器拒绝服务。

漏洞跟踪

通过Github项目的releases跟踪: https://github.com/SpiderLabs/ModSecurity/releases

NvUzMry.jpg!web

发现了airween的一个pr: https://github.com/SpiderLabs/ModSecurity/pull/2201

被官方采纳并归并到了 v3/master

7Rb6reA.jpg!web

来看看他究竟修改了什么: https://github.com/SpiderLabs/ModSecurity/pull/2201/commits/c7ad6c7613de3c1ac2ad1b4055f0ded22b522027

存在漏洞的代码如下:

BvqENfq.jpg!web

可以看见这里将Cookie的值带入代码,先以 ; 符号进行分割,进入for循环,再以 = 符号进行分割赋值,而后使用正常数组下标的表达方式进入功能中,那么问题出在了哪里?

我们再来看修复的代码:

YrYZNf2.jpg!web

简单阅读代码和注释就能了解到,它就是处理两种非正常的Cookie值: Cookie: ;;foo=bar \ Cookie: =bar;

换句话说就是ModSecurity原来在处理Cookie内容的时候过于信任用户的输入,这也是安全的一个大忌讳: 一切用户的输入都是不可信的

为什么会拒绝服务呢?可以理解为数组越界,类似:

Vjea2mA.jpg!web

漏洞测试

很明显,通过漏洞跟踪已经知道了漏洞攻击方式那就是构建恶意(畸形)的 Cookie

Curl命令测试: curl -s -H 'Cookie: =test' 'http://test/'

F7nARjR.jpg!web

根据奇安信CERT的描述: 不断向服务器发送此类请求将使工作线程反复崩溃 ,那我们可以重复这个请求造成拒绝服务效果。

Reference

奇安信CERT: https://mp.weixin.qq.com/s/MwGroFA_sKxzrwXa50XZgw

Github: https://github.com/SpiderLabs/ModSecurity/pull/2201/commits/c7ad6c7613de3c1ac2ad1b4055f0ded22b522027


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK