Skip to content
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

Re2 support 942130 #2425

Merged
merged 4 commits into from Apr 4, 2022
Merged

Re2 support 942130 #2425

merged 4 commits into from Apr 4, 2022

Conversation

fzipi
Copy link
Member

@fzipi fzipi commented Mar 7, 2022

This is an implementation for the idea described in #2353.

These is a summary of the changes:

  • splitted rule rule into chain
  • set the first match to transaction variable
  • checks in the chained rule using regex
  • commented the meaning of 942130 data

⚠️ There was a change in the regexp, in particular, inequalities. It doesn't need to be different to obtain a logical output from the query.

@fzipi fzipi marked this pull request as ready for review March 8, 2022 13:13
@fzipi fzipi force-pushed the re2-support-942130 branch 2 times, most recently from 37b138a to 15dbc90 Compare March 8, 2022 13:22
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
util/regexp-assemble/data/942130.data Show resolved Hide resolved
util/regexp-assemble/data/942130.data Outdated Show resolved Hide resolved
@theseion
Copy link
Contributor

theseion commented Mar 8, 2022

As discussed with @fzipi, this is our plan for going forward:

  1. Complete this PR for "true" tautologies (e.g. 1 = 1) and "false" tautologies (e.g. 1 != 2)
  2. The "false" tautologies need a second rule (i.e., the same base rule plus an adjusted chain rule), where we use an inverted match (!@rx) instead of negative lookahead. That will allow us to convert this rule into a non-backtracking compatible rule
  3. Create an additional rule for general tautology attacks at a higher paranoia level, accepting more FP's. The idea behind this is that, in general, tautology attacks don't have to come in the simple formats shown above; example: j not in [some,thing,silly]. They also don't necessarily need to produce true as their value; example SELECT * FROM x WHERE y NOT IN [], will return all records.

@fzipi
Copy link
Member Author

fzipi commented Mar 12, 2022

@theseion First take on splitting this rule. Tests are failing still.

Copy link
Contributor

@theseion theseion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good already.

util/regexp-assemble/data/942131.data Outdated Show resolved Hide resolved
@fzipi fzipi force-pushed the re2-support-942130 branch 2 times, most recently from bc0c527 to 1839894 Compare March 14, 2022 21:09
@theseion
Copy link
Contributor

After digging through the source code of ModSecurity v2.9.5, we have identified a bug that effectively breaks all but the simplest use of macro expansion in @rx. ModSecurity will correctly expand the macros but will then escape the entire expression. Even though the escaping method has a _log prefix, the result of this method is then passed to PCRE, instead of the "raw" expanded expression.

ModSecurity v3 is fine, no escaping happens at all in that version.

Unfortunately, I think that means the idea is off the table for now. Even if this bug were fixed in a short amount of time, it would mean that older installations of Apache httpd would not get this rule. Unless we implement this technique "for future use" and retain fallback rules.

@dune73 What's your take?

@fzipi fzipi force-pushed the re2-support-942130 branch 3 times, most recently from dd94784 to 9afbf38 Compare March 22, 2022 22:34
@fzipi
Copy link
Member Author

fzipi commented Mar 22, 2022

Ok, this looks like it might work.

Pushed the use of within in both rules. Do we need additional tests maybe?

@fzipi fzipi force-pushed the re2-support-942130 branch 2 times, most recently from 14751c2 to 533e9db Compare March 22, 2022 23:20
@fzipi
Copy link
Member Author

fzipi commented Mar 22, 2022

Added more tests. I'm sorry to say: it works like a charm!

Other than some changes in logging style, I think this is good to go!

Example:

Message: Warning. Match of "within /%{TX.2}/" against "TX:lhs_942131" required. [file "/etc/modsecurity.d/owasp-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf"] [line "636"] [id "942131"] [msg "SQL Injection Attack: SQL Boolean-based attack detected"] [data "Matched Data: 1 is not 2 found within TX:lhs_942131"] [severity "CRITICAL"] [ver "OWASP_CRS/3.4.0-dev"] [tag "modsecurity"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-sqli"] [tag "OWASP_CRS"] [tag "capec/1000/152/248/66"] [tag "PCI/6.5.2"] [tag "paranoia-level/2"]

The match is going to be on the chained rule I guess....

@theseion
Copy link
Contributor

Yay! Great stuff! I'll see whether I can review it later today.

@fzipi fzipi force-pushed the re2-support-942130 branch 2 times, most recently from 02d5a28 to 40ac6ec Compare March 24, 2022 20:39
@fzipi fzipi requested a review from theseion March 24, 2022 20:40
Copy link
Contributor

@theseion theseion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what the state is of this PR. Are we still assessing the URL decoding issue?

rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
util/regexp-assemble/data/942130.data Show resolved Hide resolved
util/regexp-assemble/data/942130.data Show resolved Hide resolved
util/regexp-assemble/data/942131.data Show resolved Hide resolved
util/regexp-assemble/data/942131.data Outdated Show resolved Hide resolved
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
Co-authored-by: Max Leske <th3s3ion@gmail.com>
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
@theseion
Copy link
Contributor

theseion commented Apr 3, 2022

Not sure whether you're done yet, but there are more unresolved comments (hidden again...).

@fzipi fzipi requested a review from theseion April 3, 2022 14:07
@fzipi
Copy link
Member Author

fzipi commented Apr 3, 2022

Not entirely sure what the state is of this PR. Are we still assessing the URL decoding issue?

No. In the end I just removed the problematic part and kept the compatibility with the previous rule in that regard. We can take a second look after we merge this one.

Copy link
Contributor

@theseion theseion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good. Only a couple small changes left.

rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf Outdated Show resolved Hide resolved
Co-authored-by: Max Leske <th3s3ion@gmail.com>
@fzipi
Copy link
Member Author

fzipi commented Apr 4, 2022

@theseion Suggestions commited.

Copy link
Contributor

@theseion theseion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dune73
Copy link
Member

dune73 commented Apr 4, 2022

Sorry I did not respond here. Overlooked it in a huge pile of mail.

@fzipi fzipi merged commit e66ffd3 into coreruleset:v3.4/dev Apr 4, 2022
@fzipi fzipi deleted the re2-support-942130 branch April 4, 2022 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants