Skip to content

Commit

Permalink
Flip wildcard for startswith and endswith
Browse files Browse the repository at this point in the history
When checking `startswith`, the wildcard should be at the end, and v.v.
for `endswith`.
  • Loading branch information
kelnage committed Nov 14, 2024
1 parent dcc780d commit 8131563
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sigma/modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def modify(
val.regexp = val.regexp + ".*"
val.compile()
elif isinstance(val, SigmaFieldReference):
val.wildcard_start = SpecialChars.WILDCARD_MULTI
val.wildcard_end = SpecialChars.WILDCARD_MULTI
return val


Expand All @@ -169,7 +169,7 @@ def modify(
val.regexp = ".*" + val.regexp
val.compile()
elif isinstance(val, SigmaFieldReference):
val.wildcard_end = SpecialChars.WILDCARD_MULTI
val.wildcard_start = SpecialChars.WILDCARD_MULTI
return val


Expand Down
4 changes: 2 additions & 2 deletions tests/test_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ def test_fieldref_startswith(dummy_detection_item):
SigmaStartswithModifier(dummy_detection_item, [SigmaFieldReferenceModifier]).modify(
fieldref
)
) == SigmaFieldReference("field", SpecialChars.WILDCARD_MULTI, None)
) == SigmaFieldReference("field", None, SpecialChars.WILDCARD_MULTI)


def test_fieldref_endswith(dummy_detection_item):
fieldref = SigmaFieldReferenceModifier(dummy_detection_item, []).modify(SigmaString("field"))
assert (
SigmaEndswithModifier(dummy_detection_item, [SigmaFieldReferenceModifier]).modify(fieldref)
) == SigmaFieldReference("field", None, SpecialChars.WILDCARD_MULTI)
) == SigmaFieldReference("field", SpecialChars.WILDCARD_MULTI, None)


def test_fieldref_wildcard(dummy_detection_item):
Expand Down

0 comments on commit 8131563

Please sign in to comment.