pySigma-backend-splunk icon indicating copy to clipboard operation
pySigma-backend-splunk copied to clipboard

Prepend necessary conditions to query

Open arblade opened this issue 7 months ago • 2 comments

As tackled in #52 and #51, this PR is a proposal for fixing errors encountered in regex oring and in correlations rules. For details see these issues.

Description

To summarize, we have two problems:

  • correlation rules delete deferred expressions (ex: if you put a |re in a correlation rule, the field targeted will disappear in the result query)
  • oring regex (and cidr regex) need to compute custom fields using | eval parts, and then handle the logic using a final | search. However, splunk need to get something at the beginning of the query (just before the first |)

for instance, currently, regex oring is giving use something like | rex .. | eval ... | rex ... | eval ... | search ..., and we need to get some expressions in front of the | rex to get some logs to work on, without that this will always return nothing.

Proposal

So, I implemented a way to detect necessary conditions (understand conditions which doesn't have an OR in their parents), and as AND operator is commutative, deferred them and add them at the start of the query in the finalize_query process.

This will :

  • fix correlations rules with deferred parts
  • fix oring regex and cidr
  • make them more efficient (by for instance computing regexes only on a smaller batch of logs)

[!CAUTION] This PR need pysigma to reactivate the finalize_query for rules that are part of correlation rules, as described in #52.

arblade avatar Apr 04 '25 12:04 arblade