@@ -382,7 +382,11 @@ def analyticsToDf(src):
382382 for ds in detection_strategies :
383383 for analytic_id in ds .get ("x_mitre_analytic_refs" , []):
384384 analytic_to_ds_map .setdefault (analytic_id , []).append (
385- {"detection_strategy_attack_id" : ds ["external_references" ][0 ]["external_id" ], "detection_strategy_id" : ds ["id" ], "detection_strategy_name" : ds .get ("name" , "" )}
385+ {
386+ "detection_strategy_attack_id" : ds ["external_references" ][0 ]["external_id" ],
387+ "detection_strategy_id" : ds ["id" ],
388+ "detection_strategy_name" : ds .get ("name" , "" ),
389+ }
386390 )
387391
388392 for analytic in tqdm (analytics , desc = "parsing analytics" ):
@@ -404,7 +408,7 @@ def analyticsToDf(src):
404408 "data_component_attack_id" : data_comp_attack_id ,
405409 "log_source_name" : logsrc .get ("name" , "" ),
406410 "channel" : logsrc .get ("channel" , "" ),
407- "platforms" : ", " .join (sorted (analytic .get ("x_mitre_platforms" , [])))
411+ "platforms" : ", " .join (sorted (analytic .get ("x_mitre_platforms" , []))),
408412 }
409413 )
410414
@@ -417,8 +421,7 @@ def analyticsToDf(src):
417421 "detection_strategy_id" : ds_info ["detection_strategy_id" ],
418422 "detection_strategy_attack_id" : ds_info ["detection_strategy_attack_id" ],
419423 "detection_strategy_name" : ds_info ["detection_strategy_name" ],
420- "platforms" : ", " .join (sorted (analytic .get ("x_mitre_platforms" , [])))
421-
424+ "platforms" : ", " .join (sorted (analytic .get ("x_mitre_platforms" , []))),
422425 }
423426 )
424427
@@ -463,8 +466,7 @@ def detectionstrategiesToDf(src):
463466 "detection_strategy_name" : detection_strategy .get ("name" , "" ),
464467 "analytic_id" : analytic_id ,
465468 "analytic_name" : analytic_obj ["external_references" ][0 ]["external_id" ],
466- "platforms" : ", " .join (sorted (analytic_obj .get ("x_mitre_platforms" , [])))
467-
469+ "platforms" : ", " .join (sorted (analytic_obj .get ("x_mitre_platforms" , []))),
468470 }
469471 )
470472
@@ -525,6 +527,7 @@ def softwareToDf(src):
525527
526528 return dataframes
527529
530+
528531def detectionStrategiesAnalyticsLogSourcesDf (src ):
529532 """Build a single DS -> LogSource -> Analytic dataframe directly from STIX."""
530533 detection_strategies = src .query ([Filter ("type" , "=" , "x-mitre-detection-strategy" )])
@@ -550,22 +553,25 @@ def detectionStrategiesAnalyticsLogSourcesDf(src):
550553 data_comp_id = logsrc .get ("x_mitre_data_component_ref" , "" )
551554 data_comp = src .get (data_comp_id )
552555
553- rows .append ({
554- "detection_strategy_attack_id" : ds_attack_id ,
555- "detection_strategy_id" : ds_id ,
556- "detection_strategy_name" : ds_name ,
557- "analytic_id" : analytic_id ,
558- "analytic_name" : analytic_attack_id ,
559- "platforms" : platforms ,
560- "log_source_name" : logsrc .get ("name" , "" ),
561- "channel" : logsrc .get ("channel" , "" ),
562- "data_component_id" : data_comp_id ,
563- "data_component_name" : (data_comp .get ("name" , "" ) if data_comp else "" ),
564- "data_component_attack_id" : data_comp ["external_references" ][0 ]["external_id" ]
565- })
556+ rows .append (
557+ {
558+ "detection_strategy_attack_id" : ds_attack_id ,
559+ "detection_strategy_id" : ds_id ,
560+ "detection_strategy_name" : ds_name ,
561+ "analytic_id" : analytic_id ,
562+ "analytic_name" : analytic_attack_id ,
563+ "platforms" : platforms ,
564+ "log_source_name" : logsrc .get ("name" , "" ),
565+ "channel" : logsrc .get ("channel" , "" ),
566+ "data_component_id" : data_comp_id ,
567+ "data_component_name" : (data_comp .get ("name" , "" ) if data_comp else "" ),
568+ "data_component_attack_id" : data_comp ["external_references" ][0 ]["external_id" ],
569+ }
570+ )
566571
567572 return pd .DataFrame (rows )
568573
574+
569575def groupsToDf (src ):
570576 """Parse STIX groups from the given data and return corresponding pandas dataframes.
571577
@@ -1309,4 +1315,4 @@ def _get_relationship_citations(object_dataframe, relationship_df):
13091315 else :
13101316 for i in range (0 , len (new_citations )):
13111317 new_citations [i ] = "," .join ([new_citations [i ], subset [i ]])
1312- return new_citations
1318+ return new_citations
0 commit comments