7
7
import logging
8
8
from pydantic import BaseModel , Field
9
9
from dataclasses import field
10
- from typing import Annotated
10
+ from typing import Annotated , Any
11
11
from contentctl .objects .mitre_attack_enrichment import MitreAttackEnrichment
12
12
from contentctl .objects .config import validate
13
13
logging .getLogger ('taxii2client' ).setLevel (logging .CRITICAL )
@@ -33,21 +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 [str ])-> None :
38
-
36
+ def addMitreIDViaGroupNames (self , technique :dict , tactics :list [str ], groupNames :list [str ])-> None :
39
37
technique_id = technique ['technique_id' ]
40
38
technique_obj = technique ['technique' ]
41
39
tactics .sort ()
42
- groups .sort ()
43
-
40
+
44
41
if technique_id in self .data :
45
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 :
50
+ technique_id = technique ['technique_id' ]
51
+ technique_obj = technique ['technique' ]
52
+ tactics .sort ()
46
53
54
+ groupNames :list [str ] = sorted ([group ['group' ] for group in groupObjects ])
55
+
56
+ if technique_id in self .data :
57
+ raise Exception (f"Error, trying to redefine MITRE ID '{ technique_id } '" )
47
58
self .data [technique_id ] = MitreAttackEnrichment (mitre_attack_id = technique_id ,
48
59
mitre_attack_technique = technique_obj ,
49
60
mitre_attack_tactics = tactics ,
50
- mitre_attack_groups = groups )
61
+ mitre_attack_groups = groupNames ,
62
+ mitre_attack_group_objects = groupObjects )
51
63
52
64
53
65
def get_attack_lookup (self , input_path : str , store_csv : bool = False , force_cached_or_offline : bool = False , skip_enrichment :bool = False ) -> dict :
@@ -86,19 +98,20 @@ def get_attack_lookup(self, input_path: str, store_csv: bool = False, force_cach
86
98
progress_percent = ((index + 1 )/ len (all_enterprise_techniques )) * 100
87
99
if (sys .stdout .isatty () and sys .stdin .isatty () and sys .stderr .isatty ()):
88
100
print (f"\r \t { 'MITRE Technique Progress' .rjust (23 )} : [{ progress_percent :3.0f} %]..." , end = "" , flush = True )
89
- apt_groups = []
101
+ apt_groups : list [ dict [ str , Any ]] = []
90
102
for relationship in enterprise_relationships :
91
103
if (relationship ['target_object' ] == technique ['id' ]) and relationship ['source_object' ].startswith ('intrusion-set' ):
92
104
for group in enterprise_groups :
93
105
if relationship ['source_object' ] == group ['id' ]:
94
- apt_groups .append (group ['group' ])
106
+ apt_groups .append (group )
107
+ #apt_groups.append(group['group'])
95
108
96
109
tactics = []
97
110
if ('tactic' in technique ):
98
111
for tactic in technique ['tactic' ]:
99
112
tactics .append (tactic .replace ('-' ,' ' ).title ())
100
113
101
- self .addMitreID (technique , tactics , apt_groups )
114
+ self .addMitreIDViaGroupObjects (technique , tactics , apt_groups )
102
115
attack_lookup [technique ['technique_id' ]] = {'technique' : technique ['technique' ], 'tactics' : tactics , 'groups' : apt_groups }
103
116
104
117
if store_csv :
@@ -131,7 +144,7 @@ def get_attack_lookup(self, input_path: str, store_csv: bool = False, force_cach
131
144
technique_input = {'technique_id' : key , 'technique' : attack_lookup [key ]['technique' ] }
132
145
tactics_input = attack_lookup [key ]['tactics' ]
133
146
groups_input = attack_lookup [key ]['groups' ]
134
- self .addMitreID (technique = technique_input , tactics = tactics_input , groups = groups_input )
147
+ self .addMitreIDViaGroupNames (technique = technique_input , tactics = tactics_input , groups = groups_input )
135
148
136
149
137
150
0 commit comments