|
9 | 9 | SigmaValidationIssue, |
10 | 10 | SigmaValidationIssueSeverity, |
11 | 11 | ) |
| 12 | + |
| 13 | +from sigma.data.mitre_attack import mitre_attack_techniques_tactics_mapping |
| 14 | + |
12 | 15 | from .config import ConfigHQ |
13 | 16 |
|
14 | 17 | config = ConfigHQ() |
@@ -91,3 +94,56 @@ def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]: |
91 | 94 | if tag.namespace == "tlp" and tag.name not in self.allowed_tlp: |
92 | 95 | return [SigmahqTagsTlpIssue([rule], tlp=tag.name)] |
93 | 96 | return [] |
| 97 | + |
| 98 | + |
| 99 | +@dataclass |
| 100 | +class SigmahqTagsTechniquesWithoutTacticsIssue(SigmaValidationIssue): |
| 101 | + description: ClassVar[str] = ( |
| 102 | + "A MITRE ATT&CK technique tag was found without its corresponding tactic name. (e.g. when using 'attack.t1059' you have to add 'attack.execution' as well)" |
| 103 | + ) |
| 104 | + severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.HIGH |
| 105 | + techniques: List[str] |
| 106 | + missing_tactic: str |
| 107 | + |
| 108 | + |
| 109 | +class SigmahqTagsTechniquesWithoutTacticsValidator(SigmaRuleValidator): |
| 110 | + """Ensures that MITRE ATT&CK technique tags have their corresponding tactic tags.""" |
| 111 | + |
| 112 | + def validate(self, rule: SigmaRuleBase) -> List[SigmaValidationIssue]: |
| 113 | + issues = [] |
| 114 | + |
| 115 | + attack_tags = [tag for tag in rule.tags or [] if tag.namespace == "attack"] |
| 116 | + |
| 117 | + technique_tags = [ |
| 118 | + tag.name |
| 119 | + for tag in attack_tags |
| 120 | + if tag.name.startswith("t") and any(c.isdigit() for c in tag.name) |
| 121 | + ] |
| 122 | + tactic_tags = [tag.name for tag in attack_tags if not tag.name.startswith("t")] |
| 123 | + |
| 124 | + missing_tactics = [] |
| 125 | + for technique in technique_tags: |
| 126 | + technique_upper = technique.upper() |
| 127 | + |
| 128 | + if technique_upper in mitre_attack_techniques_tactics_mapping: |
| 129 | + required_tactics = mitre_attack_techniques_tactics_mapping[technique_upper] |
| 130 | + missing_tactics.extend( |
| 131 | + [tactic for tactic in required_tactics if tactic not in tactic_tags] |
| 132 | + ) |
| 133 | + |
| 134 | + if missing_tactics: |
| 135 | + for missing_tactic in set(missing_tactics): |
| 136 | + techniques = [ |
| 137 | + technique |
| 138 | + for technique in technique_tags |
| 139 | + if missing_tactic in mitre_attack_techniques_tactics_mapping[technique.upper()] |
| 140 | + ] |
| 141 | + issues.append( |
| 142 | + SigmahqTagsTechniquesWithoutTacticsIssue( |
| 143 | + [rule], |
| 144 | + techniques=["attack." + t for t in techniques], |
| 145 | + missing_tactic="attack." + missing_tactic, |
| 146 | + ) |
| 147 | + ) |
| 148 | + |
| 149 | + return issues |
0 commit comments