|
| 1 | +import json |
| 2 | +from stix2.sources.taxii import TAXIIDataSource |
| 3 | + |
| 4 | +# Flask TAXII server - developmental |
| 5 | +ROOT = 'http://localhost:5000' |
| 6 | +AUTH = {'user': 'mk', 'pass': 'Pass'} |
| 7 | + |
| 8 | + |
| 9 | +def main(): |
| 10 | + |
| 11 | + # instantiate TAXII data source |
| 12 | + taxii = TAXIIDataSource(api_root=ROOT, auth=AUTH) |
| 13 | + |
| 14 | + # get (file watch indicator) |
| 15 | + indicator_fw = taxii.get(id_="indicator--a932fcc6-e032-176c-126f-cb970a5a1ade") |
| 16 | + print("\n\n-------Queried for Indicator - got:") |
| 17 | + print(json.dumps(indicator_fw, indent=4)) |
| 18 | + |
| 19 | + # all versions (file watch indicator - currently only 1. maybe Emmanuelle can add a version) |
| 20 | + indicator_fw_versions = taxii.get(id_="indicator--a932fcc6-e032-176c-126f-cb970a5a1ade") |
| 21 | + print("\n\n------Queried for indicator (all_versions()) - got:") |
| 22 | + print(json.dumps(indicator_fw_versions, indent=4)) |
| 23 | + |
| 24 | + # add TAXII filter (ie filter should be passed to TAXII) |
| 25 | + taxii_filter_ids, status = taxii.add_filter( |
| 26 | + [ |
| 27 | + { |
| 28 | + "field": "type", |
| 29 | + "op": "in", |
| 30 | + "value": "malware" |
| 31 | + } |
| 32 | + ]) |
| 33 | + |
| 34 | + print("\n\n-------Added filter:") |
| 35 | + print("Filter ID: {0}".format(taxii_filter_ids[0])) |
| 36 | + print("Filter status: \n") |
| 37 | + print(json.dumps(status, indent=4)) |
| 38 | + print("filters: \n") |
| 39 | + print(json.dumps(taxii.get_filters(), indent=4)) |
| 40 | + |
| 41 | + # get() - but with filter attached |
| 42 | + malware = taxii.query() |
| 43 | + print("\n\n\n--------Queried for Malware string (with above filter attached) - got:") |
| 44 | + print(json.dumps(malware, indent=4)) |
| 45 | + |
| 46 | + # remove TAXII filter |
| 47 | + taxii.remove_filter(taxii_filter_ids) |
| 48 | + print("\n\n-------Removed filter(TAXII filter):") |
| 49 | + print("filters: \n") |
| 50 | + print(json.dumps(taxii.get_filters(), indent=4)) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + main() |
0 commit comments