8000 Problematic word boundary match in 932* rules · Issue #3401 · coreruleset/coreruleset · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Problematic word boundary match in 932* rules #3401

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

Closed
theseion opened this issue Dec 3, 2023 · 6 comments · Fixed by #3425
Closed

Problematic word boundary match in 932* rules #3401

theseion opened this issue Dec 3, 2023 · 6 comments · Fixed by #3425
Assignees
Labels
🐛 bug Something isn't working v4 Should go into release v4

Comments

@theseion
Copy link
Contributor
theseion commented Dec 3, 2023

The 932* rules, such as 932237 for example, use a word boundary match to ensure that "something" follows a command word. At a word boundary, two adjacent tokens must not both match \w and \W, i.e., one must be a word token and the other must not. This means that "something" must be a word token if the previous token was a space, redirect, etc. If "something" is not a word token, such as the dash character, then the word boundary match will fail.

Example: some-command --help would not match a search for some-command.

A possible solution to this problem might be to replace the word boundary match \b with \S.

This issue was discovered in #3394 by @EsadCetiner.

@theseion theseion added the 🐛 bug Something isn't working label Dec 3, 2023
@theseion theseion self-assigned this Dec 3, 2023
@theseion
Copy link
Contributor Author
theseion commented Dec 3, 2023

@theMiddleBlue Any thoughts on this one?

@theMiddleBlue
Copy link
Contributor

TBH I'm a bit confused by the original report, that points to 'test=settings' not detected. Is it related to this issue or the point has evolved to something else?

Talking about the command in querystring parameter, I'm always of the opinion that we can't protect the application from something like system($_GET["test"]) because of two main reasons:

  • there will always be a bypass, especially on bash/dash
  • it leads to a lot of false positive

I know that we are in a scenario in which command is blocked and command2 not. That's ugly and sounds like bypass.

But I think I'm not pointing to the right issue here, and I guess I need to understand better what's the problem here 😂

@theseion
Copy link
Contributor Author
theseion commented Dec 3, 2023

It's only related because set is a substring of setting, which produced a false positive. The issue here is about something else though, namely that set --help should be detected by 932237 but it isn't because of the \b at the end of the regular expression. set something on the other hand would be detected. I'm proposing to change \b to \S for 932237. This issue potentially affects other rules in 932* as well.

@theMiddleBlue
Copy link
Contributor

make sense to me, and it could work. The problem with matching whitespaces when we talk about RCE on bash/dash is always bypassable with ${IFS} like:

set${IFS}--help

@theseion
Copy link
Contributor Author

True, that kind of thing should be caught by other rules though right? So set --help would not be blocked but ${IFS} would be.

@dune73 dune73 added the v4 Should go into release v4 label Dec 12, 2023
@theseion theseion changed the title Problematic word boundary match int 932* rules Problematic word boundary match in 932* rules Dec 13, 2023
@theMiddleBlue
Copy link
Contributor

Yes, absolutely! Apologies for the late response!

theseion added a commit to theseion/coreruleset that referenced this issue Dec 14, 2023
Unix commands such as `dig` require options or they won't run. `dig`
uses the `@` anti-evasion pattern (e.g., for 932237). For a command such
as `dig --help`, the final word boundary (`\b`) in 932237 actually
prevents a match. The `@` causes `dig ` to be matched, but the word
boundary will not match because both the space character and the dash
character are in `\W` (for `\b` to match, one of them would have to be
in `\w`).

This commit modifies the final word boundary of 932237 to `(?:\b|\W)`, in
order to fix this.
Note that the final expression must work for commands without options,
commands with options (`@`) and for command prefixes (`~`, e.g., `gcc`
or `pip`).

Fixes coreruleset#3401
@dune73 dune73 closed this as completed in #3425 Jan 5, 2024 5A39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working v4 Should go into release v4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0