forked from SigmaHQ/pySigma-validators-sigmaHQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrelation.py
More file actions
56 lines (45 loc) · 2.15 KB
/
Copy pathcorrelation.py
File metadata and controls
56 lines (45 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from dataclasses import dataclass
from typing import ClassVar, List
from sigma.correlations import SigmaCorrelationRule, SigmaCorrelationType
from sigma.rule import SigmaRule
from sigma.validators.base import (
SigmaRuleValidator,
SigmaValidationIssue,
SigmaValidationIssueSeverity,
)
@dataclass
class SigmahqCorrelationRulesMinimumIssue(SigmaValidationIssue):
description: ClassVar[str] = (
"Correlation rule must reference at least 2 rules for temporal types"
)
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.HIGH
class SigmahqCorrelationRulesMinimumValidator(SigmaRuleValidator):
"""Checks if temporal correlation rules have at least 2 rules."""
def validate(self, rule: SigmaRule | SigmaCorrelationRule) -> List[SigmaValidationIssue]:
if isinstance(rule, SigmaCorrelationRule):
if rule.type in [
SigmaCorrelationType.TEMPORAL,
SigmaCorrelationType.TEMPORAL_ORDERED,
]:
if len(rule.rules) < 2: # type: ignore[arg-type] # noqa: PLR2004
return [SigmahqCorrelationRulesMinimumIssue([rule])]
return []
@dataclass
class SigmahqCorrelationGroupByExistenceIssue(SigmaValidationIssue):
description: ClassVar[str] = (
"Correlation rule is missing the group-by field in correlation section"
)
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.HIGH
class SigmahqCorrelationGroupByExistenceValidator(SigmaRuleValidator):
"""Checks if a correlation rule has a group-by field for types that require it."""
def validate(self, rule: SigmaRule | SigmaCorrelationRule) -> List[SigmaValidationIssue]:
if isinstance(rule, SigmaCorrelationRule):
if rule.type in [
SigmaCorrelationType.EVENT_COUNT,
SigmaCorrelationType.VALUE_COUNT,
SigmaCorrelationType.TEMPORAL,
SigmaCorrelationType.TEMPORAL_ORDERED,
]:
if rule.group_by is None or len(rule.group_by) == 0:
return [SigmahqCorrelationGroupByExistenceIssue([rule])]
return []