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

[BUG] multiMatch lead to unexpected match #3183

Open
leveryd opened this issue Jul 15, 2024 · 1 comment
Open

[BUG] multiMatch lead to unexpected match #3183

leveryd opened this issue Jul 15, 2024 · 1 comment
Labels
3.x Related to ModSecurity version 3.x bug It is a confirmed bug

Comments

@leveryd
Copy link

leveryd commented Jul 15, 2024

Describe the bug

SecRule REQUEST_BODY "@rx abc" "id:111, msg:'test', t:base64DecodeExt,multiMatch, phase:2, block, capture, severity:'CRITICAL', tag:'attack-rce', tag:'paranoia-level/1', setvar:'tx.matched=%{MATCHED_VAR}', chain"
    SecRule REQUEST_BODY "@rx 123"

The above rule match request which body is 'abc'

curl 127.0.0.1:86 -d 'abc'

The match is not expected, because the rule is "chained" rule, the second rule require the body contains "123" string.

If i remove multiMatch ,then everything is expected.

SecRule REQUEST_BODY "@rx abc" "id:222, msg:'test', t:none, phase:2, block, capture, severity:'CRITICAL', tag:'attack-rce', tag:'paranoia-level/1', setvar:'tx.matched=%{MATCHED_VAR}', chain"
    SecRule REQUEST_BODY "@rx 123"
curl 127.0.0.1:86 -d 'abc'  // not match
curl 127.0.0.1:86 -d 'abc123'  // match

So i think the multiMatch flag has bug when it is used with chain rule

@leveryd leveryd added the 3.x Related to ModSecurity version 3.x label Jul 15, 2024
@airween
Copy link
Member

airween commented Jul 15, 2024

Hi @leveryd,

thanks for reporting.

I can confirm this is a bug. I tested this with Apache + mod_security2 and it worked as you expect.

Just one note: the rule above is wrong especially for libmodsecurity3. As I know, every rule (even it's a chained rule) must have some action. So I could have tested with this rule:

SecRule REQUEST_BODY "@rx abc" \
    "id:111,\
    msg:'test',\
    t:base64DecodeExt,\
    multiMatch,\
    phase:2,\
    block,\
    capture,\
    severity:'CRITICAL',\
    tag:'attack-rce',\
    tag:'paranoia-level/1',\
    setvar:'tx.matched=%{MATCHED_VAR}',\
    chain"
    SecRule REQUEST_BODY "@rx 123"
        "setvar:'tx.foo=1'"

@airween airween added the bug It is a confirmed bug label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x bug It is a confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants