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

fix: false positives from PHP config directives and functions (933120 PL1, 933151 PL2) #3638

Merged
merged 10 commits into from
May 17, 2024

Conversation

ssigwart
Copy link
Contributor

@ssigwart ssigwart commented Apr 1, 2024

Closes #3637

@dune73 dune73 added the ⚠️ do not merge Additional work is needed despite passing tests label Apr 2, 2024
@dune73
Copy link
Member

dune73 commented Apr 2, 2024

Thank you for the PR @ssigwart.

Don't merge just yet. Maybe there are alternatives to simply kicking out the keywords.

@ssigwart ssigwart changed the title Remove false positives from PHP config directives fix: False positives from PHP config directives Apr 2, 2024
@dune73
Copy link
Member

dune73 commented Apr 3, 2024

I like your update. Did not play around with it so far, but I think this could be a good workaround.

Also: Performance in chained rules is less of an issue since they are only executed if the original rule matches.

Copy link
Contributor Author

@ssigwart ssigwart left a comment

Choose a reason for hiding this comment

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

Thanks. I removed the extra capture.

I've been using this rule on a production site since yesterday and it seems to be working well.

rules/REQUEST-933-APPLICATION-ATTACK-PHP.conf Outdated Show resolved Hide resolved
@EsadCetiner
Copy link
Member

Is there anything blocking this pr? An alternative has been found to outright kicking out the false positive keywords.

@ssigwart
Copy link
Contributor Author

ssigwart commented May 7, 2024

@EsadCetiner, I don't think your question was directed towards me, but just in case, I'm not aware of anyone waiting on changes from me on this.

@dune73 dune73 removed the ⚠️ do not merge Additional work is needed despite passing tests label May 8, 2024
@dune73
Copy link
Member

dune73 commented May 8, 2024

No, this was addressed towards the team, @ssigwart. I removed the label. Ready for review.

@azurit azurit changed the title fix: False positives from PHP config directives fix: false positives from PHP config directives May 11, 2024
@azurit azurit changed the title fix: false positives from PHP config directives fix: false positives from PHP config directives (933120 PL1) May 11, 2024
@azurit
Copy link
Member

azurit commented May 11, 2024

We probably don't need to set variable tx.933120_possible_directive and use tx.1 directly. @ssigwart Can you test it?

In the current form of the rule we may simplify the logging with these changes:

  • replace %{TX.933120_TX_0} with %{TX.0} in logdata action
  • remove line setvar:'tx.933120_tx_0=%{tx.0}',\
  • add capture action to the last rule

By the way, we probably can do the similar with rule 933151.

@ssigwart
Copy link
Contributor Author

@azurit, I updated it. I did noticed that the log message wasn't showing the most useful information, so I added variables to capture the original matched variable name and value.

I'm looking into rule 933151 now. I have to figure out how to trigger it first before I make updates to the rule.

The following will work:
http://localhost:8080/?test=great%20ceiling%20heights%20(9ft)

The following will still trigger rule:
http://localhost:8080/?test=ceiling%20(9ft)
@ssigwart
Copy link
Contributor Author

I updated rule 933151 too now.

The following will work:
http://localhost:8080/?test=great%20ceiling%20heights%20(9ft)

The following will still trigger rule:
http://localhost:8080/?test=ceiling%20(9ft)

@ssigwart
Copy link
Contributor Author

@azurit, what do you think of the test failure? It's no longer detecting array_diff foo (, which seems correct since it's not array_diff (.

@azurit
Copy link
Member

azurit commented May 14, 2024

@azurit, what do you think of the test failure? It's no longer detecting array_diff foo (, which seems correct since it's not array_diff (.

Payload array_diff foo ( definitely should not be part of this rule and i doubt if it's a valid PHP syntax at all.

@azurit
Copy link
Member

azurit commented May 14, 2024

Test for array_diff foo ( was added 7 years ago by @lifeforms and i believe it's a bug. @ssigwart pls fix it - remove foo.

@azurit
Copy link
Member

azurit commented May 14, 2024

Hmm, all tests for 933151 should be rechecked, i see multiple problems in there, for example:

  • duplicate tests 1 and 6
  • test 6 is searching \( found within in the logs but that will never happen as logging was already fixed
  • i don't understand why all tests are sending input data (which in few cases are also payloads)

@theseion What do you think about tests for 933151? See above.

@azurit azurit changed the title fix: false positives from PHP config directives (933120 PL1) fix: false positives from PHP config directives and functions (933120 PL1, 933151 PL2) May 14, 2024
@theseion
Copy link
Contributor

I agree, the tests should be fixed. @theMiddleBlue did a huge clean up of other tests that had the same issue (body data + URI). I think it's copy pasta. The tests should also be properly separated into URI and body data tests. And test 6 should be dropped.

@ssigwart
Copy link
Contributor Author

I updated the tests, so they're all passing now.

@azurit
Copy link
Member

azurit commented May 15, 2024

Looks good. I suggest you to add yourself into the author field of the tests header (lifeforms, ssigwart).

@ssigwart
Copy link
Contributor Author

Looks good. I suggest you to add yourself into the author field of the tests header (lifeforms, ssigwart).

Thanks. I updated the author field.

@azurit
Copy link
Member

azurit commented May 17, 2024

LGTM!

@Xhoenix Can you merge this one? Thanks.

@Xhoenix Xhoenix added this pull request to the merge queue May 17, 2024
Merged via the queue into coreruleset:main with commit 73cce8c May 17, 2024
4 checks passed
@ssigwart ssigwart deleted the patch-1 branch May 18, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule 933120 FP: Common Words
7 participants