Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Conversation

@theseion
Copy link

The new rule is a sibling of rule 942100 that adds a libinjection
of the last path segment

Fixes #1328

The new rule is a sibling of rule 942100 that adds a libinjection
of the last path segment
Copy link
Contributor

@theMiddleBlue theMiddleBlue left a comment

Choose a reason for hiding this comment

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

Thanks @theseion

I've understood the problem and this seems to be a good start. You just need to fix a bit the rule, and idk if this is suitable for PL1 (let's see what others dev say about it).

setvar:'tx.msg=%{rule.msg}',\
setvar:'tx.%{rule.id}-OWASP_CRS/WEB_ATTACK/SQL_INJECTION-%{MATCHED_VAR_NAME}=%{MATCHED_VAR}',\
chain"
SecRule TX:1 "@detectSQLi"
Copy link
Contributor

Choose a reason for hiding this comment

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

missing action on the chained SecRule (3rd argument)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I've just pushed a commit where the setvar actions have been moved to the chained rule, as they would be evaluated every time otherwise.

I thought about putting the rule in PL1 but I don't know what the implications are for FP's.

@theseion
Copy link
Author

I don't understand why the test fails. Chained rules don't need ID's AFAIK.

@theMiddleBlue
Copy link
Contributor

if I'm not wrong, it always needs an action. for example, you can move setvar to the chained one

- only log when actually blocking and not on every request
- remove all slashes from the beginning of REQUEST_FILENAME (there may be more than one)
@theseion
Copy link
Author

Sorry about the noise. This should conclude any updates to the rule for now, I have it running in production.

@spartantri
Copy link
Contributor

Since this uses REQUEST_FILENAME and will not include the query string which is the one that usually triggers the false positives. The chained rule do not need multimatch as it is not doing any anti-evasion transformation over TX.1

Suggested by @spartantri, as the chained rule deosn't perform anti-evasion transformations.
@theseion
Copy link
Author

Thanks. I've pushed an update with multiMatch removed.

@fgsch
Copy link
Contributor

fgsch commented Mar 21, 2019

Tests please. Tons of them 😄

severity:'CRITICAL',\
chain"
SecRule TX:1 "@detectSQLi" \
"setvar:'tx.anomaly_score_pl1=+%{tx.critical_anomaly_score}',\
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is PL2 you need to increment pl2.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed, thanks.

#
# This is a sibling of rule 942100 that adds checking of the last path segment.
#
SecRule REQUEST_FILENAME "@rx ^/+(.*)$" \
Copy link
Contributor

@fgsch fgsch Mar 21, 2019

Choose a reason for hiding this comment

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

I don't think this do what you think it does. REQUEST_FILENAME will have the whole path, not the last segment.
Please update the comment.

Can you explain a bit more why you are using rx and not simply passing the path to detectSQLi?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I don't think there is a variable then, which holds that information, is there? I'll update the regular expression to parse out the last segment then.

libinjection is more likely to fail when passing the path, at least that is what my tests showed. E.g. the following string produces a match 999999.1 union select unhex(hex(version())) -- and 1=1 while this doesn't /999999.1 union select unhex(hex(version())) -- and 1=1 (tested directly with libinjection). So to be safe I don't want the slashes in there.

Maybe I could pass the entire path with the slashes replaced... But I don't know what that would do to the detection capabilities.

Copy link
Contributor

@fgsch fgsch Mar 21, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I pasted the wrong link. I've updated it now.
Can you use that instead and squash the commits?

@emphazer
Copy link
Contributor

put it in PL3 pls. this will lead to much FP. we run PL2 as default. for example: aggregation on js or css wont be supported anymore.

@theseion
Copy link
Author

Sure. Out of curiosity, could you give an example of what you mean by aggregation?

@emphazer
Copy link
Contributor

@theseion sure
look at this path here. its an aggregation of different java script files.

/sites/default/files/advagg_js/js__8Cefk7UudAKRWCZ23BiLQNs5GDGwHszGZfd5m3bBkno__2XMzkOnobbuTwYFViZn-Z2zlJnQLv6vUbBpBt-8Bpsw__dwrExSTRu6UuvuQxBPkJ0DQAptvitAf5_8JXXxvP9nQ.js

i can give you a lot of pages where stuff like that is very common.
its often used in drupal or typo3 for example.

take a look at the url https://www.land.nrw/ its the page for the state north rhine westphalia in germany hosted by the government.

@fgsch
Copy link
Contributor

fgsch commented Mar 21, 2019

@emphazer will this FP on sqli or xss?

- improved comment to state why we only use the last path segment (@fgsch)
- fixed regular expression to expect an arbitrary path (REQUEST_FILENAME holds the full path) (@fgsch)
- moved rule to PL3 (@emphazer)
@theseion
Copy link
Author

Thanks for the reviews and explanations evryone! I've pushed an update where all your concerns should be addressed.

@fgsch
Copy link
Contributor

fgsch commented Mar 22, 2019

I think this is on the right track but I'd like to see some tests.
Can you add a few positive and negative ones? Let us know if you need any help with that.

@emphazer
Copy link
Contributor

emphazer commented Mar 22, 2019

@fgsch sqli

@theseion thx for changes.

@fgsch
Copy link
Contributor

fgsch commented Mar 22, 2019

@emphazer are you saying libinjection will detect js__8Cefk7UudAKRWCZ23BiLQNs5GDGwHszGZfd5m3bBkno__2XMzkOnobbuTwYFViZn-Z2zlJnQLv6vUbBpBt-8Bpsw__dwrExSTRu6UuvuQxBPkJ0DQAptvitAf5_8JXXxvP9nQ.js as a sql injection?

@emphazer
Copy link
Contributor

@fgsch no, thats just an example.
this urls are always different they change several times a day.

@fgsch
Copy link
Contributor

fgsch commented Mar 22, 2019

@emphazer The format for this aggregator is fixed (js__[A-Za-z0-9-_]{43}__[A-Za-z0-9-_]{43}__[A-Za-z0-9-_]{43}.js(\.gz|\.br)). I don't see how this will ever FP.
I'd rather put it in PL2 and move it to PL3 if it indeed FP.

@emphazer
Copy link
Contributor

here are 2 examples which matched

Matched Data: 1c found within ARGS:token: 9--6nVTjusWqO8_f84sNRMwXlmDvt9J_JDLV6rWzoCc

Matched Data: 1c found within ARGS:AesGroup[_token]: 9--CeqpjEHcaUuZKr24FPQNqGeTfcl4yDkQitZKd_KQ

@fgsch
Copy link
Contributor

fgsch commented Mar 22, 2019

@emphazer I stand corrected. You are right.

@fgsch
Copy link
Contributor

fgsch commented Mar 29, 2019

@theseion have you seen my comment at #1329 (comment)?
Also, any chance you can add some tests?

@theseion
Copy link
Author

@theseion have you seen my comment at #1329 (comment)?
Also, any chance you can add some tests?

Yes but I hadn't seen the update. That edit makes more sense ;)
I'm in a bit of a pickle at the moment but I'll try to provide some tests ASAP.

@fgsch
Copy link
Contributor

fgsch commented Mar 29, 2019

@theseion great, thank you! let us know if you need a hand or two :)

@lifeforms
Copy link
Contributor

Very nice contribution @theseion, we'd love to include this in the next release. Paranoia Level 3 seems alright to prevent false positives in the default install. Let us know if you have any trouble with the tests.

@fgsch
Copy link
Contributor

fgsch commented Apr 16, 2019

@theseion any updates on this?

@theseion
Copy link
Author

Not yet, sorry. It's on my list though.

@dune73 dune73 self-requested a review July 1, 2019 19:57
@fgsch
Copy link
Contributor

fgsch commented Jul 5, 2019

Hey @theseion. Any way we can entice you to complete this? 😉

@theseion
Copy link
Author

theseion commented Jul 5, 2019

Hm... Wine? 😜 I know, I should be working on this... I haven't forgotten, I promise.

@fgsch
Copy link
Contributor

fgsch commented Jul 5, 2019

Here we go:

giphy

@dune73
Copy link
Contributor

dune73 commented Jul 17, 2019

This is a welcome PR and it's time we merge this.

Summing up the remaining issues:

  • Instead of a chained rule, the new rule should just use REQUEST_BASENAME (thanks @fgs)
  • We need tests

If you have time to do this within the next week, please do @theseion. If not, I'll take it over and probably push a new PR with the same functionality.

@dune73 dune73 self-assigned this Jul 17, 2019
@theseion
Copy link
Author

No, I won't have time this week, sorry.

Thanks for your help!

@dune73
Copy link
Contributor

dune73 commented Jul 18, 2019

OK.

Feel free to bring the wine to the next CRS meetup. ;)

@dune73
Copy link
Contributor

dune73 commented Aug 2, 2019

I have re-implemented this PR addressing the two item above in #1492.

Thank you for the PR @theseion.

Closing this in favour of #1492.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No libinjection check on last path segment

7 participants