Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix 7.11 -> 7.10 ATT&CK downgrade logic for optional techiques #736

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions detection_rules/schemas/v7_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,29 @@ def downgrade(cls, target_cls, document, role=None):
"""Remove 7.11 additions from the rule."""
# ignore when this method is inherited by subclasses
if cls == ApiSchema711 and "threat" in document:
threat_field = list(document["threat"])
for threat in threat_field:
if "technique" in threat:
threat["technique"] = [t.copy() for t in threat["technique"]]
v711_threats = document.get("threat", [])
v710_threats = []

for technique in threat["technique"]:
technique.pop("subtechnique", None)
for threat in v711_threats:
# drop tactic without threat
if "technique" not in threat:
continue

threat = threat.copy()
threat["technique"] = [t.copy() for t in threat["technique"]]

# drop subtechniques
for technique in threat["technique"]:
technique.pop("subtechnique", None)

v710_threats.append(threat)

document = document.copy()
document["threat"] = threat_field
document.pop("threat")

# only add if the array is not empty
if len(v710_threats) > 0:
document["threat"] = v710_threats

# now strip any any unrecognized properties
return target_cls.strip_additional_properties(document, role)
8 changes: 8 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def setUpClass(cls):
"name": "PowerShell",
"reference": "https://attack.mitre.org/techniques/T1059/001/"
}]
cls.v711_kql["threat"].append({
"framework": "MITRE ATT&CK",
"tactic": {
"id": "TA0008",
"name": "Lateral Movement",
"reference": "https://attack.mitre.org/tactics/TA0008/"
},
})

cls.versioned_rule = Rule("test.toml", copy.deepcopy(cls.v79_kql))
cls.versioned_rule.contents["version"] = 10
Expand Down