owasp-modsecurity / ModSecurity

ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
https://www.modsecurity.org
Apache License 2.0
8.06k stars 1.58k forks source link

Sorted collections #903

Open marcstern opened 9 years ago

marcstern commented 9 years ago

For some collections (ARGS, REQUEST_COOKIES), it may be necessary to have them sorted in order to concatenate them in an intelligent way (i.e. concatenated all ARGS named "a" without others in the middle). Think about HTTP parameter pollution... SORTED_MATCHED_VARS should be sufficient to handle sorting of any collection with an intermediate rule. The sorting should be alphabetically (case-insensitive for the name) but keep the entries with the same name in the original order.

zimmerle commented 3 years ago

@marcstern can you give a concrete example where such sort will be needed?

marcstern commented 3 years ago

/req?p=cmd&p=/c&p=... The previous line leads to "p=cmd,/c,..." is ASP (and others) which can be used to perform an attack (in this concrete example, the comma is a valid separator in Windows commands). We currently can detect this by concatenated all values and adding a comma between these.

However, the following evasion rendres this impossible: /req?p=cmd&a=xyz***&p=/c&p=...

By having a sorted collection, we can perform the same concatenation to check for patterns.

Note that having the ability to create custom collections would be much more powerful and can be used to created sorted collections if needed. So I'd vote for the latter.

martinhsv commented 3 years ago

Based on the example, it doesn't seem like this proposal actually has anything to do with sorting per se. I.e. there is no processing difference between varying orders of unlike-named arguments.

Your example seems to only be about aggregating like-named arguments.

(For anyone following this who is unfamiliar with the concatentation being referred to, some backends (chiefly IIS) will concatenate like-named parameters. See for more detail (particularly the chart): https://www.acunetix.com/blog/whitepaper-http-parameter-pollution/ )

Or am I missing something?

Assuming I'm correct, yes ModSecurity could implement code to either:

However before implementing new functionality, we should note that:

marcstern commented 3 years ago

As I explained, if you try (like in the CRS rules) to do it on unsorted ARGS, you can evade it. This is why we need (also) a sorted collection. But, as I said, being able to create our own collection would be much better (and allows a lot of other use cases).