diff --git a/examples/analytic_extractor.py b/examples/analytic_extractor.py new file mode 100644 index 0000000..8ae55ce --- /dev/null +++ b/examples/analytic_extractor.py @@ -0,0 +1,94 @@ +# ATT&CK Analytic Extractor +# Extracts Analytics from an ATT&CK STIX 2.0 file +# Writes output to attack_analytics.md +# Example usage: python3 analytic_extractor.py --in_file enterprise-attack-14.1.json + +import argparse +import json +import re + +from mitreattack.stix20 import MitreAttackData + +# Prune an input string to remove any non-analytic text +# This assumes that all analytics start the
" in desc:
+ # Get the ID of the parent technique
+ tech_id = technique_map[rel["target_ref"]]
+ # Get the name of the data component
+ data_comp = dc_map[rel["source_ref"]]
+ if tech_id not in technique_analytics:
+ technique_analytics[tech_id] = {}
+ technique_analytics[tech_id][data_comp] = desc
+ else:
+ if data_comp not in technique_analytics[tech_id]:
+ technique_analytics[tech_id][data_comp] = desc
+
+ # Write the output to markdown
+ with open("attack_analytics.md", "w") as md_file:
+ md_file.write("# Analytics Extracted from ATT&CK STIX\n\n")
+
+ for tech_id, data_comps in dict(sorted(technique_analytics.items())).items():
+ tech_header = "## " + tech_id + "\n"
+ md_file.write(tech_header)
+ for data_comp, desc in data_comps.items():
+ data_comp_header = "### " + data_comp + "\n"
+ md_file.write(data_comp_header)
+ md_file.write(pruneString(desc))
+ md_file.write("\n")
+ if not str(desc).endswith("\n"):
+ md_file.write("\n")
+
+ print("DONE. Results written to attack_analytics.md")