-
-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite/rethink rule 942260 with re2 compatibility #2355
Comments
I would drop it. Fortunately, the |
Ok, but we can't drop it for pcre, right? So the solution is to have two different rules? Or just drop it for good? |
I don't see why we'd need it for PCRE. As I wrote above: no ReDOS, and performance shouldn't be impacted (in general; implementation dependent of course). |
I retract that comment. I did not realise that the expression in the rule was much longer. Removing the possessive quantifier actually completely destroys performance. This has already been discussed in SpiderLabs/owasp-modsecurity-crs#1359. I'm trying to understand what it is that we are trying to match. The description says "SQL authentication bypass"... Unfortunately, there's no test for this rule that tests what Side note: getting rid of Let's try to analyse possible inputs.
It is likely that the excluded characters from 3 are supposed to be matched in 8. For example: I went looking for actual payloads and the most promising source (https://github.com/payloadbox/sql-injection-payload-list) had ```'&&SLEEP(5)&&'1` as pretty much the only thing that looks promising. This kind of injection should be handled by other rules though, I believe, so I'm not sure if this really is what we're looking for. @theMiddleBlue any ideas? |
Thanks for this analysis Max! We need to keep digging and something will come up. Will take a deeper look also. |
@jptosso any ideas? |
Taking a look at this one. Ugh. This rule is nothing but pain.
We don't really know what is exactly trying to match. There is no clear documentation on the rule, other than the
Tests in 942260 from 1-6 looks reasonable. But then from 7-21 they have nothing to do with "authentication bypass attempts". Mostly they are about Can you enlighten us a bit on this @dune73 ? Maybe you are aware, maybe not. Moving forward So there is some room here. First, we need to move the tests on shell execution to a different rule, probably. This one should not be, IMHO, about shell execution, right? With that, we might be able to trim this regexp a bit, or move some parts to a different rule. I am thinking on moving in particular these two:
From reading the whole data file, looks like they don't belong here. |
Good thinking. Maybe those statements aren't for SQL injection. Or are the SQL dialects that allow shell calls as part of a query? |
Even if there is that possibility, I would treat those as shell injections, not SQL injections. We should mostly block anything that targets shell execution. But on the "shell side", not on the "SQL side" I mean. |
OK. Here is the oldest version of the rule I have: CRS 2.2.7, 2012-12-19
Somehow similar, but not quite. 0 documentation about the rule in said release. Likely one of the early rules Ofer Shezaf added when we started with CRS in 2007 by googling for SQL injections. I inquired if we had anything backed up from back then, but he responded negative after checking some old disks. So we need to do with what we have. The sad truth about the tests of this rule and may others is that we were lacking tests for a lot of rules and I just grabbed alerts that I had for certain rules. From a big body of alerts that a 4.5M request burp run created. In my defense I can say that many of the SQL rules are not overly clear cut. They also catch non-SQL stuff, and apparently this rule also catches RCEs, so I am simply testing the status quo. However, I agree there is no reason to continue to trigger non-SQL stuff with this particular regex, namely if we can confirm other rules catch a certain non-sqli-payload. If that's the case the test could be moved, or simply removed if need be. |
Thanks @dune73! I checked your old rule and the current rule is just written a bit nicer but the basic building blocks are the same (no additional or removed parts, AFAICT). I agree with @fzipi that we should move those two statements out of the rule, possibly adding them somewhere else (although I highly suspect that our shell injection rules are much better than what those two statements can cover). Then we move the tests that have nothing to do with SQL injection to where they make sense and, finally, add tests that cover the different cases represented by the rule. |
The disassembly was done by @franbuehler. The splitting and removal of nonsense certainly makes sense. If you feel our existing shell rules cover everything present here, then I see no reason to keep it around. Redundant coverage is not a core feature. :) |
There is no test that covers The following tests cover
As of now I think that we need to have a statement that covers 19 and 20. The others don't belong in this rule. |
Oh and BTW, we should do the same deconstruction for 942180 and 942340, which are both part of the same "sql authentication bypass" group. |
The tests are covered as follows:
|
Is this for v4? |
Not strictly, but I though it would make sense to clean those up as well. Since I'm in the flow... ;) |
I've also removed matches for find_in_set and union ... all, since they are already covered by other rules: find_in_set\s*?( -> covered by 942150 |
@fzipi you're right. It's not a good idea to do everything now. I've opened a separate issue for clean up rules 942180 and 942340. |
Motivation
Rule 942260 is using
++
(possesive quantifier) and it is not supported.[\"'`]\s*?[^?\w\s=.,;)(]++\s*?[(@\"'`]*?\s*?\w+\W+\w
We need to see if we can find a viable alternative or that can be dropped somehow.
Proposed solution
None yet.
Alternatives
Additional context
Possessive matching isn't supported in re2 (
(?>re) | possessive match of re (NOT SUPPORTED)
).The text was updated successfully, but these errors were encountered: