Skip to content

Commit cad0d7d

Browse files
authored
Merge pull request #11 from iSecNG/AIex-3-patch-1
add match_ocsf
2 parents 820afbf + 535471d commit cad0d7d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

sigma/processing/conditions/rule.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,31 @@ class LogsourceCondition(RuleProcessingCondition):
2828
the condition returns true if any of the associated rules have the required log source fields.
2929
"""
3030

31+
class_uid: Optional[str] = field(default=None)
3132
category: Optional[str] = field(default=None)
3233
product: Optional[str] = field(default=None)
3334
service: Optional[str] = field(default=None)
3435

3536
def __post_init__(self) -> None:
36-
self.logsource = SigmaLogSource(self.category, self.product, self.service)
37+
self.logsource = SigmaLogSource(
38+
self.category,
39+
self.product,
40+
self.service,
41+
custom_attributes={"class_uid": self.class_uid},
42+
)
3743

3844
def match(
3945
self,
4046
rule: Union[SigmaRule, SigmaCorrelationRule],
4147
) -> bool:
4248
if isinstance(rule, SigmaRule):
43-
return rule.logsource in self.logsource
49+
res = (
50+
str(rule.logsource.category) == str(self.logsource.category)
51+
and str(rule.logsource.product) == str(self.logsource.product)
52+
and str(rule.logsource.service) == str(self.logsource.service)
53+
)
54+
res = res and self.match_ocsf(rule=rule)
55+
return res
4456
elif isinstance(rule, SigmaCorrelationRule):
4557
# Will only return true if the rules have been resolved in advance
4658
for ref in rule.rules:
@@ -49,6 +61,14 @@ def match(
4961
return True
5062
return False
5163

64+
def match_ocsf(self, rule: SigmaRule) -> bool:
65+
rule_ocsf = rule.custom_attributes.get("ocsf")
66+
if rule_ocsf:
67+
res = str(rule_ocsf["class_uid"]) == str(self.logsource.custom_attributes["class_uid"])
68+
else:
69+
res = True
70+
return res
71+
5272

5373
@dataclass
5474
class RuleContainsFieldCondition(RuleDetectionItemCondition):

tests/test_processing_conditions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_processing_condition_multiple_pipelines_set(dummy_processing_pipeline):
9090

9191

9292
def test_logsource_match(sigma_rule):
93-
assert LogsourceCondition(category="test_category").match(
93+
assert not LogsourceCondition(category="test_category").match(
9494
sigma_rule,
9595
)
9696

153 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)