Skip to content

Commit 4261e4b

Browse files
frack113phantinuss
andauthored
feat: ✨ Add SigmahqMitreLinkValidator (#35)
* feat: ✨ Add SigmahqMitreLinkValidator * Apply suggestions from code review Co-authored-by: phantinuss <79651203+phantinuss@users.noreply.github.com> --------- Co-authored-by: phantinuss <79651203+phantinuss@users.noreply.github.com>
1 parent 1a550c0 commit 4261e4b

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

sigma/validators/sigmahq/metadata.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,24 @@ def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
290290
if re.match(r".*/[0-9a-z]{40}/.*", link) is None:
291291
result.append(SigmahqGithubLinkIssue([rule], link))
292292
return result
293+
294+
295+
@dataclass
296+
class SigmahqMitreLinkIssue(SigmaValidationIssue):
297+
description: ClassVar[str] = (
298+
"Rule has a MITRE link instead of a MITRE attack tag. Use e.g. - attack.t1053.003"
299+
)
300+
severity: ClassVar[SigmaValidationIssueSeverity] = SigmaValidationIssueSeverity.MEDIUM
301+
link: str
302+
303+
304+
class SigmahqMitreLinkValidator(SigmaRuleValidator):
305+
"""Checks if a rule uses a MITRE link instead of tag"""
306+
307+
def validate(self, rule: SigmaRule) -> List[SigmaValidationIssue]:
308+
result = []
309+
if rule.references is not None:
310+
for link in rule.references:
311+
if link.startswith("https://attack.mitre.org/"):
312+
result.append(SigmahqMitreLinkIssue([rule], link))
313+
return result

tests/test_metadata.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
SigmahqStatusToHighValidator,
3434
SigmahqGithubLinkIssue,
3535
SigmahqGithubLinkValidator,
36+
SigmahqMitreLinkIssue,
37+
SigmahqMitreLinkValidator,
3638
)
3739

3840

@@ -620,3 +622,47 @@ def test_validator_SigmahqStatusToHigh():
620622
"""
621623
)
622624
assert validator.validate(rule) == []
625+
626+
627+
def test_validator_SigmahqMitreLink():
628+
validator = SigmahqMitreLinkValidator()
629+
rule = SigmaRule.from_yaml(
630+
"""
631+
title: Test
632+
description: Test
633+
status: stable
634+
references:
635+
- https://attack.mitre.org/techniques/T1588/007/
636+
logsource:
637+
category: test
638+
detection:
639+
sel:
640+
candle|exists: true
641+
condition: sel
642+
"""
643+
)
644+
assert validator.validate(rule) == [
645+
SigmahqMitreLinkIssue(rule, "https://attack.mitre.org/techniques/T1588/007/")
646+
]
647+
648+
649+
def test_validator_SigmahqMitreLink_valid():
650+
validator = SigmahqMitreLinkValidator()
651+
rule = SigmaRule.from_yaml(
652+
"""
653+
title: Test
654+
description: Test
655+
status: stable
656+
references:
657+
- http://some-blog.org
658+
tag:
659+
- attack.t1588.007
660+
logsource:
661+
category: test
662+
detection:
663+
sel:
664+
candle|exists: true
665+
condition: sel
666+
"""
667+
)
668+
assert validator.validate(rule) == []

0 commit comments

Comments
 (0)