oasis-open / cti-taxii-client

OASIS TC Open Repository: TAXII 2 Client Library Written in Python
https://taxii2client.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
107 stars 51 forks source link

'get' method bug using ATT&CK TAXII server #87

Closed sparrow-k closed 3 years ago

sparrow-k commented 3 years ago

Hello! I am trying to pull data from the ATT&CK TAXII server, and I'm following the recipe code from their github: https://github.com/mitre/cti/blob/master/USAGE.md#access-from-the-attck-taxii-server

This is the code I'm running:

from stix2 import TAXIICollectionSource
from taxii2client.v20 import Collection # only specify v20 if your installed version is >= 2.0.0

collections = {
    "enterprise_attack": "95ecc380-afe9-11e4-9b6c-751b66dd541e",
    "pre_attack": "062767bd-02d2-4b72-84ba-56caef0f8658",
    "mobile_attack": "2f669986-b40b-4423-b720-4396ca6a462b"
}

collection = Collection(f"https://cti-taxii.mitre.org/stix/collections/{collections['enterprise_attack']}/")
src = TAXIICollectionSource(collection)

src.get('x-mitre-tactic--ffd5bcee-6e16-4dd2-8eca-7b3beedf33ca')

But I'm getting this error:

  File "C:\Users\MY_USERNAME\AppData\Local\Programs\Python\Python39\lib\site-packages\stix2\datastore\taxii.py", line 213, in get
    if stix_obj.id != stix_id:
AttributeError: 'dict' object has no attribute 'id'

When I'm trying to use a local filesystem, it works fine. IE:

import stix2
src = stix2.FileSystemSource(r"C:\Git\cti\enterprise-attack")
src.get('x-mitre-tactic--ffd5bcee-6e16-4dd2-8eca-7b3beedf33ca')

Is this a bug or am I missing something? Thanks :)

emmanvg commented 3 years ago

Hi @sparrow-k, this issue has been resolved on the cti-python-stix2 repo. The reason why you see this behavior happen in the TAXIICollectionSource and not the FileSystemSource is because each DataStore class implements their own methods for the abstract class they subclass. You can read a bit more about it in the issue referenced below. I will be closing this since the fix is already present on master and will be available in the next release.

I should note for awareness that the client also implements a similar .get() method. Since you opened the issue on the client repo :)

from taxii2client.v20 import Collection # only specify v20 if your installed version is >= 2.0.0

collections = {
    "enterprise_attack": "95ecc380-afe9-11e4-9b6c-751b66dd541e",
    "pre_attack": "062767bd-02d2-4b72-84ba-56caef0f8658",
    "mobile_attack": "2f669986-b40b-4423-b720-4396ca6a462b"
}

collection = Collection(f"https://cti-taxii.mitre.org/stix/collections/{collections['enterprise_attack']}/")
collection.get_object("x-mitre-tactic--ffd5bcee-6e16-4dd2-8eca-7b3beedf33ca")

duplicate oasis-open/cti-python-stix2#459