Add rex extraction for scalar |re modifiers with named capture groups - #71
Open
SkxOverKill wants to merge 1 commit into
Open
Add rex extraction for scalar |re modifiers with named capture groups#71SkxOverKill wants to merge 1 commit into
SkxOverKill wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #70
Summary
Extends the regex conversion for scalar
|remodifiers (string values) so that regular expressions containing a named capture group ((?P<name>...)) are additionally converted to a Splunkrexextraction command, while preserving the existing matching semantics of theregexcommand.Previously, scalar
|revalues were always emitted solely as aregexmatching command, which cannot extract captured groups into fields. This change appends arex field=<field> "(?<name>...)"command when a Python-style named capture group is present, converting the group to Splunk's PCRE syntax ((?<name>...)) for consistency with the group names the backend already generates (e.g. in the OR path).Before
After
Design notes
regexmatching command is retained alongsiderex. Splunk'srexcommand only extracts fields and does not filter events; emittingrexon its own would silently broaden the result set and regress detection quality. Keeping both commands preserves the exact match semantics while making the captured fields available downstream.(?P<name>...)) to PCRE ((?<name>...)) so the extracted field names align with the conventions used bySplunkDeferredORRegularExpression.not <field>|re: ...), where a negated match has no usable capture, and for escaped group parentheses so literal matches are not rewritten.|remodifiers (the OR path) are left unchanged.Changes
sigma/backends/splunk/splunk.pySplunkDeferredRexExpression, a deferred expression producingrex field=<field> "<pattern>".|revalues and append arexextraction while keeping the existingregexmatching command.tests/test_backend_splunk.pyTesting
pytest tests— 129 passed (125 existing + 4 new), no warnings.