@@ -31,15 +31,16 @@ def parse_stix_objects(self, stix_objects, stix_object_type):
3131 technique_dict = {
3232 'type' : technique ['type' ],
3333 'id' : technique ['id' ],
34- 'created_by_ref' : technique [ 'created_by_ref' ] ,
34+ 'created_by_ref' : self . try_except ( technique , 'created_by_ref' ) ,
3535 'created' : str (technique ['created' ]),
3636 'modified' : str (technique ['modified' ]),
37- 'object_marking_refs' : technique [ 'object_marking_refs' ] ,
37+ 'object_marking_refs' : self . try_except ( technique , 'object_marking_refs' ) ,
3838 'url' : technique ['external_references' ][0 ]['url' ],
3939 'matrix' : technique ['external_references' ][0 ]['source_name' ],
4040 'technique' : technique ['name' ],
41- 'technique_description' : technique ['description' ],
42- 'tactic' : self .handle_list (technique ,'kill_chain_phases' ),
41+ 'technique_description' : self .try_except (technique , 'description' ),
42+ #'tactic': self.handle_list(technique,'kill_chain_phases'),
43+ 'tactic' : self .try_except (technique ,'kill_chain_phases' ),
4344 'technique_id' : technique ['external_references' ][0 ]['external_id' ],
4445 'platform' : self .try_except (technique ,'x_mitre_platforms' ),
4546 'data_sources' : self .try_except (technique ,'x_mitre_data_sources' ),
@@ -417,8 +418,7 @@ def get_technique_by_name(self, name):
417418 mobile_stix_objects = self .TC_MOBILE_SOURCE .query (filter_objects )
418419 all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
419420 all_stix_objects = self .parse_stix_objects (all_stix_objects , "techniques" )
420- for o in all_stix_objects :
421- return o
421+ return all_stix_objects
422422
423423 def get_object_by_attack_id (self , object_type , attack_id ):
424424 valid_objects = {'attack-pattern' ,'course-of-action' ,'intrusion-set' ,'malware' ,'tool' }
@@ -443,8 +443,7 @@ def get_object_by_attack_id(self, object_type, attack_id):
443443 mobile_stix_objects = self .TC_MOBILE_SOURCE .query (filter_objects )
444444 mobile_stix_objects = self .parse_stix_objects (mobile_stix_objects , dictionary [object_type ])
445445 all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
446- for o in all_stix_objects :
447- return o
446+ return all_stix_objects
448447
449448 def get_group_by_alias (self , group_alias ):
450449 filter_objects = [
@@ -456,8 +455,7 @@ def get_group_by_alias(self, group_alias):
456455 mobile_stix_objects = self .TC_MOBILE_SOURCE .query (filter_objects )
457456 all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
458457 all_stix_objects = self .parse_stix_objects (all_stix_objects , 'groups' )
459- for o in all_stix_objects :
460- return o
458+ return all_stix_objects
461459
462460 def get_relationships_by_object (self , stix_object ):
463461 valid_objects = {'groups' ,'software' ,'mitigations' }
@@ -691,4 +689,28 @@ def get_all_used_by_group(self, group_name=None):
691689 software = self .get_software_used_by_group (group_name )
692690 techniques = self .get_techniques_used_by_group (group_name )
693691 all_used = software + techniques
694- return all_used
692+ return all_used
693+
694+ def get_techniques_by_datasources (self , data_sources ):
695+ techniques_results = []
696+ techniques = self .get_all_techniques ()
697+ if isinstance (data_sources , list ):
698+ for d in [x .lower () for x in data_sources ]:
699+ for t in techniques :
700+ if t ['data_sources' ] is not None and d in [x .lower () for x in t ['data_sources' ]]:
701+ techniques_results .append (t )
702+ elif isinstance (data_sources , str ):
703+ for t in techniques :
704+ if t ['data_sources' ] is not None and data_sources .lower () in [x .lower () for x in t ['data_sources' ]]:
705+ techniques_results .append (t )
706+ else :
707+ raise Exception ("Not a list or a string" )
708+ # Remove Duplicates
709+ already_seen = set ()
710+ results_dedup = []
711+ for d in techniques_results :
712+ i = str (d .items ())
713+ if i not in already_seen :
714+ already_seen .add (i )
715+ results_dedup .append (d )
716+ return results_dedup
0 commit comments