Original Post: WAF bypasses via 0days
This vulnerability was analyzed during Episode 153 on 26 September 2022
Cool research post introducing a few ModSecurity rule bypasses abusing different parser errors in the ModSecurity Code Rule Set. While those specific to ModSecurity are probably patched by now. In some cases the same sorts of parsing issues can occur on the backend.
Content-TypeConfusion - This abuses the regex matching used to decide what body parser to use. A content-type header likeapplication/x-www-form-urlencoded;boundary="application/xml"gets interpreted as XML because of the presence ofapplication/xmlin the header. Similarly usingapplication/jsonwill trick the parser into parsing as a JSON body. The XML case was most useful as ModSecurity would ignore comments in the XML allowing content to be smuggled through.multipart/form-dataparsing issues. The first issue presented isn’t actually an issue in ModSecurity but is a potential issue in the backend parser and whether or not they parse empty body sections correctly. ModSecurity does, but on some backends (the author calls out PHP here) the parser will continue over the empty body joining it with the next header and body until the next separator. The second issue was ModSecurity treating a single\nas a\r\n. Leading to parsing two (or more) parameters where most backends would only see one.- Charset Confusion (CVE-2022-39955). ModSecurity only looks at the first
charsetand blocks anything that isn’tutf-8. Using aContent-Typeheader ofapplication/json;charset=utf-8;charset=utf-7the author was able to smuggle in UTF-7 content that would be opaque to ModSecurity but decoded properly by theexpressbackend.