@@ -33,27 +33,33 @@ def getEnrichmentByMitreID(self, mitre_id:Annotated[str, Field(pattern=r"^T\d{4}
33
33
else :
34
34
raise Exception (f"Error, Unable to find Mitre Enrichment for MitreID { mitre_id } " )
35
35
36
-
37
- def addMitreID (self , technique :dict , tactics :list [str ], groups :list [dict [str ,Any ]])-> None :
36
+ def addMitreIDViaGroupNames (self , technique :dict , tactics :list [str ], groupNames :list [str ])-> None :
37
+ technique_id = technique ['technique_id' ]
38
+ technique_obj = technique ['technique' ]
39
+ tactics .sort ()
38
40
41
+ if technique_id in self .data :
42
+ raise Exception (f"Error, trying to redefine MITRE ID '{ technique_id } '" )
43
+ self .data [technique_id ] = MitreAttackEnrichment (mitre_attack_id = technique_id ,
44
+ mitre_attack_technique = technique_obj ,
45
+ mitre_attack_tactics = tactics ,
46
+ mitre_attack_groups = groupNames ,
47
+ mitre_attack_group_objects = [])
48
+
49
+ def addMitreIDViaGroupObjects (self , technique :dict , tactics :list [str ], groupObjects :list [dict [str ,Any ]])-> None :
39
50
technique_id = technique ['technique_id' ]
40
51
technique_obj = technique ['technique' ]
41
52
tactics .sort ()
42
- group_names_only :list [str ] = sorted ([group ['group' ] for group in groups ])
43
53
44
- import pprint
45
- print (technique_id )
46
- print (technique_obj )
47
- print (tactics )
48
- print (group_names_only )
49
- pprint .pprint (groups )
54
+ groupNames :list [str ] = sorted ([group ['group' ] for group in groupObjects ])
55
+
50
56
if technique_id in self .data :
51
57
raise Exception (f"Error, trying to redefine MITRE ID '{ technique_id } '" )
52
58
self .data [technique_id ] = MitreAttackEnrichment (mitre_attack_id = technique_id ,
53
59
mitre_attack_technique = technique_obj ,
54
60
mitre_attack_tactics = tactics ,
55
- mitre_attack_groups = group_names_only ,
56
- mitre_attack_group_objects = groups )
61
+ mitre_attack_groups = groupNames ,
62
+ mitre_attack_group_objects = groupObjects )
57
63
58
64
59
65
def get_attack_lookup (self , input_path : str , store_csv : bool = False , force_cached_or_offline : bool = False , skip_enrichment :bool = False ) -> dict :
@@ -105,7 +111,7 @@ def get_attack_lookup(self, input_path: str, store_csv: bool = False, force_cach
105
111
for tactic in technique ['tactic' ]:
106
112
tactics .append (tactic .replace ('-' ,' ' ).title ())
107
113
108
- self .addMitreID (technique , tactics , apt_groups )
114
+ self .addMitreIDViaGroupObjects (technique , tactics , apt_groups )
109
115
attack_lookup [technique ['technique_id' ]] = {'technique' : technique ['technique' ], 'tactics' : tactics , 'groups' : apt_groups }
110
116
111
117
if store_csv :
@@ -138,7 +144,7 @@ def get_attack_lookup(self, input_path: str, store_csv: bool = False, force_cach
138
144
technique_input = {'technique_id' : key , 'technique' : attack_lookup [key ]['technique' ] }
139
145
tactics_input = attack_lookup [key ]['tactics' ]
140
146
groups_input = attack_lookup [key ]['groups' ]
141
- self .addMitreID (technique = technique_input , tactics = tactics_input , groups = groups_input )
147
+ self .addMitreIDViaGroupNames (technique = technique_input , tactics = tactics_input , groups = groups_input )
142
148
143
149
144
150
0 commit comments