|
| 1 | +from stix2 import TAXIICollectionSource, Filter |
| 2 | +from taxii2client import Collection |
| 3 | +import argparse |
| 4 | + |
| 5 | +# Establish TAXII2 Collection instance for Enterprise ATT&CK collection |
| 6 | +collection = Collection("https://cti-taxii.mitre.org/stix/collections/95ecc380-afe9-11e4-9b6c-751b66dd541e/") |
| 7 | +# Supply the collection to TAXIICollection |
| 8 | +tc_src = TAXIICollectionSource(collection) |
| 9 | + |
| 10 | +def data_sources(): |
| 11 | + """returns all data sources in Enterprise ATT&CK""" |
| 12 | + all_data_srcs = [] |
| 13 | + |
| 14 | + # Get all techniques in Enterprise ATT&CK |
| 15 | + techniques = tc_src.query([Filter("type", "=", "attack-pattern")]) |
| 16 | + |
| 17 | + # Get all data sources in Enterprise ATT&CK |
| 18 | + for tech in techniques: |
| 19 | + if 'x_mitre_data_sources' in tech: |
| 20 | + all_data_srcs += [ |
| 21 | + data_src for data_src in tech.x_mitre_data_sources |
| 22 | + if data_src not in all_data_srcs |
| 23 | + ] |
| 24 | + |
| 25 | + return all_data_srcs |
| 26 | + |
| 27 | +def techniques(data_source): |
| 28 | + """returns all techniques which contain the given data source.""" |
| 29 | + # Get all techniques that have Windows Registry as a data source |
| 30 | + techs_with_data_src = tc_src.query([ |
| 31 | + Filter("type", "=", "attack-pattern"), |
| 32 | + Filter("x_mitre_data_sources", "in", data_source) |
| 33 | + ]) |
| 34 | + |
| 35 | + return techs_with_data_src |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + |
| 41 | + parser = argparse.ArgumentParser( |
| 42 | + description="Fetches the current ATT&CK STIX 2.0 objects from the ATT&CK TAXII server, prints all of the data sources listed in Enterprise ATT&CK, and then lists all the Enterprise techniques containing a given data source." |
| 43 | + ) |
| 44 | + parser.add_argument("-data_source", |
| 45 | + type=str, |
| 46 | + default="Windows Registry", |
| 47 | + help="the datasource by which to filter techniques. Default value is '%(default)s'." |
| 48 | + ) |
| 49 | + |
| 50 | + args = parser.parse_args() |
| 51 | + |
| 52 | + print("All data sources in Enterprise ATT&CK:\n") |
| 53 | + print("\n".join(data_sources())) |
| 54 | + print("\n") |
| 55 | + |
| 56 | + selected_ds = "Windows Registry" |
| 57 | + technique_list = techniques(args.data_source) |
| 58 | + # Get names of techniques |
| 59 | + tech_names = [tech.name for tech in technique_list] |
| 60 | + |
| 61 | + print(f"The following {len(tech_names)} techniques use '{args.data_source}' as a data source:\n") |
| 62 | + print("\n".join(tech_names)) |
0 commit comments