ModSecurity: Path Confusion and really easy bypass on v2 and v3
ModSecurity implicitly URL-decodes the request path before setting variables such as REQUEST_FILENAME, so a %3f in the path makes the engine treat everything after it as a query string and drop it from the variable. Rules that inspect that variable then miss the payload, allowing a simple bypass of the WAF and the OWASP Core Rule Set, including SQL injection in the path.
Published on blog.sicuranext.com
TL;DR both ModSecurity v2 and v3 share a similar bug that can result in a really simple WAF bypass. The bug in the v3 branch has been fixed in version 3.0.12 and has been assigned the CVE number CVE-2024-1019.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the engine URL-decodes the request path before extracting the part before the question mark, so an encoded question mark is mistaken for the query string delimiter and the rest of the path is discarded from the variable.
Impact
An attacker could bypass the WAF and the Core Rule Set entirely and exploit a SQL injection in the request path, exfiltrating data such as a user's password; the v3 issue was fixed in 3.0.12, while the related v2 behaviour remains unfixed.
What the attacker needed
ModSecurity in front of the app; OWASP CRS or custom rules using the variable; Attacker can send crafted requests
The fix
The v3 bug was fixed in version 3.0.12; for custom rules the author advises always enabling the URL-decode transformation when inspecting these variables at phase 1, and the v2 issue remains unfixed.
How it was found
- Send a request whose path contains an encoded question mark followed by the attack payload.
- The engine decodes the path and stops reading at the resulting question mark.
- The variable holds only the harmless prefix, so the rules do not match the payload.
- The backend application still receives and processes the full path, executing the attack.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A web application firewall (WAF) is a filter that sits in front of a website and blocks requests that look like attacks. ModSecurity is a popular WAF engine, and it builds a variable holding the requested path so rules can inspect it. Here it decoded the path first, so a crafted character made the engine cut the path short and the attack part was never checked.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.