Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

ModSecurity Request Body Parsing: Recent Bypass Issues

Overview

ModSecurity is an open-source web application firewall (WAF) engine maintained by Trustwave. This blog post discusses multiple input interpretation weaknesses in the ModSecurity project. Each input interpretation weakness could allow a malicious actor to evade some ModSecurity rules.

Both ModSecurity v2 and ModSecurity v3 were affected. The issues have been addressed in v2.9.6 and v3.0.8, respectively.

Introduction

Earlier this year an independent bug bounty program occurred with a primary focus on OWASP ModSecurity Core Rule Set (CRS), which is managed separately from the ModSecurity engine. Multiple issues separate from CRS were identified by Jan Gora (terjanq), with the information subsequently being passed on to the ModSecurity team. Thank you to the bug bounty hunter for the findings. Thanks also to our collaborators at CRS for their contribution, which included some additional validation of the completed fixes.

None of these issues created a direct vulnerability to either ModSecurity or any web server it is protecting. However, each resulted in the opportunity for a malicious user to evade some ModSecurity rules, hence weakening overall WAF protection.

The issues are summarized in the following sections, but full PoCs and information about the types of rules vulnerable to evasion will be omitted.

ModSecurity Parser Activation

ModSecurity includes built in parsers for request bodies of four types: x-www-form-urlencoded, multipart/form-data, JSON, and XML. At most, for any individual HTTP request, one of those four parsers will be active for the request.

The mechanism to activate either the JSON parser or the XML parser is an ordinary ModSecurity rule that includes the relevant action (e.g. ctl:requestBodyProcessor=XML). As such, the conditions under which each of those parsers may be activated is controlled by the administrator.

The ModSecurity project includes a file called ‘modsecurity.conf-recommended’ that includes a small number of basic rules and other configuration items that are typically desirable. Among these are rules for parser activation as described in the previous paragraph.

The core of the problem is that rules 200000 and 200001 each use a regular expression that is imprecise. A specially crafted Content-Type request header could be composed that would result in the incorrect body parser being activated. Having the incorrect parser active within ModSecurity can result in at least some malicious content bypassing rules which ordinarily would have detected it.

Also provided in the same file is a sample, commented-out rule (200006) that will engage the JSON parser for additional Content-Type values. Subsequent analysis by the ModSecurity team found that it suffered from a slightly different – but still comparable – weakness.

Each of the rules discussed here has been amended to make its regular expression more precise in what it will match. Users are advised to incorporate these changes into their installation’s configuration at the earliest opportunity.

Parsing of multipart/form-data

Two of the issues that were identified involve problems with how the ModSecurity engine parses the content of a request body of type multipart/form-data.

In both cases, a malicious actor could compose specially crafted input that could result in ModSecurity populating its argument collections with strings that are different from what the web server would see. This mismatch can result in some ModSecurity rules failing to detect content that it normally would have detected.

While one of these two issues is only known to be a problem when certain types of web servers are being protected (Apache Tomcat has been confirmed to be affected while neither Apache HTTP Server nor nginx appear to be), the second of the two is of more widespread potential impact.

The fixes in the ModSecurity engine for both issues involve additional use cases setting the MULTIPART_STRICT_ERROR variable. This variable is inspected by rule 200003 in ‘modsecurity.conf-recommended’. Users are advised to ensure that they have this rule, or an equivalent, in place in their installations.

Reference

The bug bounty hunter has recently posted a blog that contains additional information about the topics discussed here. It can be found at: https://terjanq.medium.com/waf-bypasses-via-0days-d4ef1f212ec

ABOUT TRUSTWAVE

Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo