Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 9b1c34d

Browse files
committed
diff_stix now works with deleting subtechniques
1 parent b3d1a02 commit 9b1c34d

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

scripts/diff_stix.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,11 @@ def getSectionList(items, obj_type, section):
358358
parents = list(filter(lambda item: self.has_subtechniques(item, True) and not ("x_mitre_is_subtechnique" in item and item["x_mitre_is_subtechnique"]), items))
359359
children = { item["id"]: item for item in filter(lambda item: "x_mitre_is_subtechnique" in item and item["x_mitre_is_subtechnique"], items) }
360360

361-
361+
subtechnique_of_rels = self.new_subtechnique_of_rels if section != "deletions" else self.old_subtechnique_of_rels
362+
id_to_technique = self.new_id_to_technique if section != "deletions" else self.old_id_to_technique
362363

363364
parentToChildren = {} # stixID => [ children ]
364-
for relationship in self.new_subtechnique_of_rels:
365+
for relationship in subtechnique_of_rels:
365366
if relationship["target_ref"] in parentToChildren:
366367
if relationship["source_ref"] in children:
367368
parentToChildren[relationship["target_ref"]].append(children[relationship["source_ref"]])
@@ -384,7 +385,7 @@ def getSectionList(items, obj_type, section):
384385

385386
for parentID in parentToChildren:
386387
groupings.append({
387-
"parent": self.new_id_to_technique[parentID],
388+
"parent": id_to_technique[parentID],
388389
"parentInSection": False,
389390
"children": parentToChildren[parentID]
390391
})
@@ -397,8 +398,8 @@ def placard(item):
397398
revoker = item['revoked_by']
398399
if "x_mitre_is_subtechnique" in revoker and revoker["x_mitre_is_subtechnique"]:
399400
# get revoking technique's parent for display
400-
parentID = list(filter(lambda rel: rel["source_ref"] == revoker["id"], self.new_subtechnique_of_rels))[0]["target_ref"]
401-
parentName = self.new_id_to_technique[parentID]["name"] if parentID in self.new_id_to_technique else "ERROR NO PARENT"
401+
parentID = list(filter(lambda rel: rel["source_ref"] == revoker["id"], subtechnique_of_rels))[0]["target_ref"]
402+
parentName = id_to_technique[parentID]["name"] if parentID in id_to_technique else "ERROR NO PARENT"
402403
return f"{item['name']} (revoked by { parentName}: [{revoker['name']}]({self.site_prefix}/{self.getUrlFromStix(revoker)}))"
403404
else:
404405
return f"{item['name']} (revoked by [{revoker['name']}]({self.site_prefix}/{self.getUrlFromStix(revoker)}))"

0 commit comments

Comments
 (0)