Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from STIX 2.0 to STIX 2.1 - DRAFT #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/get_campaign_by_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def main():
mitre_attack_data = MitreAttackData("enterprise-attack.json")

C0001 = mitre_attack_data.get_campaign_by_alias("Frankenstein")
C0001 = mitre_attack_data.get_campaigns_by_alias("Frankenstein")

print(C0001.serialize(pretty=True))
print(C0001[0].serialize(pretty=True))


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/get_group_by_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def main():
mitre_attack_data = MitreAttackData("enterprise-attack.json")

G0016 = mitre_attack_data.get_group_by_alias("Cozy Bear")
G0016 = mitre_attack_data.get_groups_by_alias("Cozy Bear")

print(G0016.serialize(pretty=True))
print(G0016[0].serialize(pretty=True))


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/get_object_by_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def main():
mitre_attack_data = MitreAttackData("enterprise-attack.json")

T1082 = mitre_attack_data.get_object_by_name("System Information Discovery", "attack-pattern")
T1082 = mitre_attack_data.get_objects_by_name("System Information Discovery", "attack-pattern")

print(T1082.serialize(pretty=True))
print(T1082[0].serialize(pretty=True))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/get_software_by_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def main():

S0196 = mitre_attack_data.get_software_by_alias("ShellTea")

print(S0196.serialize(pretty=True))
print(S0196[0].serialize(pretty=True))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion mitreattack/collections/collection_to_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def generate_index(name, description, root_url, files=None, folders=None, sets=N
dict(
type="bundle",
id=f"bundle--{x.id}",
spec_version="2.0",
spec_version="2.1",
objects=x.source.query([Filter("type", "=", "x-mitre-collection")]),
)
for x in sets
Expand Down
4 changes: 2 additions & 2 deletions mitreattack/diffStix/changelog_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def get_datastore_from_mitre_cti(self, domain: str, datastore_version: str) -> s
s = requests.Session()
retries = Retry(total=10, backoff_factor=0.3, status_forcelist=[500, 502, 503, 504])
s.mount("http", HTTPAdapter(max_retries=retries))
stix_url = f"https://raw.githubusercontent.com/mitre/cti/master/{domain}/{domain}.json"
stix_url = f"https://raw.githubusercontent.com/mitre/attack-stix-data/master/{domain}/{domain}.json"
try:
stix_response = s.get(stix_url, timeout=60)
if stix_response.status_code != 200:
Expand All @@ -562,7 +562,7 @@ def get_datastore_from_mitre_cti(self, domain: str, datastore_version: str) -> s
attack_version = release_info.get_attack_version(domain=domain, stix_content=stix_response.content)
self.data[datastore_version][domain]["attack_release_version"] = attack_version

data_store = MemoryStore(stix_data=stix_json["objects"])
data_store = MemoryStore(stix_data=stix_json["objects"], version="2.1")
return data_store

def parse_extra_data(self, data_store: stix2.MemoryStore, domain: str, datastore_version: str):
Expand Down
2 changes: 1 addition & 1 deletion mitreattack/stix20/MitreAttackData.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from itertools import chain
from stix2 import MemoryStore, Filter
from stix2.utils import get_type_from_id
from mitreattack.stix20.custom_attack_objects import StixObjectFactory
from mitreattack.stix21.custom_attack_objects import StixObjectFactory


class MitreAttackData:
Expand Down
44 changes: 22 additions & 22 deletions mitreattack/stix20/custom_attack_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ def StixObjectFactory(data: dict) -> object:
"x-mitre-matrix",
[
# SDO Common Properties
("id", IDProperty("x-mitre-matrix", spec_version="2.0")),
("type", TypeProperty("x-mitre-matrix", spec_version="2.0")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("id", IDProperty("x-mitre-matrix", spec_version="2.1")),
("type", TypeProperty("x-mitre-matrix", spec_version="2.1")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("created", TimestampProperty(precision="millisecond")),
("modified", TimestampProperty(precision="millisecond")),
("revoked", BooleanProperty(default=lambda: False)),
("external_references", ListProperty(ExternalReference)),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.0"))),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.1"))),
("name", StringProperty(required=True)),
("description", StringProperty()),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("x_mitre_version", StringProperty()),
("x_mitre_attack_spec_version", StringProperty()),
# Matrix Properties
("tactic_refs", ListProperty(ReferenceProperty(valid_types="x-mitre-tactic", spec_version="2.0"))),
("tactic_refs", ListProperty(ReferenceProperty(valid_types="x-mitre-tactic", spec_version="2.1"))),
],
)
class Matrix(CustomStixObject, object):
Expand All @@ -90,18 +90,18 @@ class Matrix(CustomStixObject, object):
"x-mitre-tactic",
[
# SDO Common Properties
("id", IDProperty("x-mitre-tactic", spec_version="2.0")),
("type", TypeProperty("x-mitre-tactic", spec_version="2.0")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("id", IDProperty("x-mitre-tactic", spec_version="2.1")),
("type", TypeProperty("x-mitre-tactic", spec_version="2.1")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("created", TimestampProperty(precision="millisecond")),
("modified", TimestampProperty(precision="millisecond")),
("revoked", BooleanProperty(default=lambda: False)),
("external_references", ListProperty(ExternalReference)),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.0"))),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.1"))),
("name", StringProperty(required=True)),
("description", StringProperty()),
("x_mitre_domains", ListProperty(StringProperty())),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("x_mitre_version", StringProperty()),
("x_mitre_attack_spec_version", StringProperty()),
# Tactic Properties
Expand Down Expand Up @@ -131,19 +131,19 @@ def get_shortname(self) -> str:
"x-mitre-data-source",
[
# SDO Common Properties
("id", IDProperty("x-mitre-data-source", spec_version="2.0")),
("type", TypeProperty("x-mitre-data-source", spec_version="2.0")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("id", IDProperty("x-mitre-data-source", spec_version="2.1")),
("type", TypeProperty("x-mitre-data-source", spec_version="2.1")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("created", TimestampProperty(precision="millisecond")),
("modified", TimestampProperty(precision="millisecond")),
("revoked", BooleanProperty(default=lambda: False)),
("external_references", ListProperty(ExternalReference)),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.0"))),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.1"))),
("name", StringProperty(required=True)),
("description", StringProperty()),
("x_mitre_domains", ListProperty(StringProperty())),
("x_mitre_contributors", ListProperty(StringProperty())),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("x_mitre_version", StringProperty()),
("x_mitre_attack_spec_version", StringProperty()),
# Data Source Properties
Expand All @@ -167,21 +167,21 @@ class DataSource(CustomStixObject, object):
"x-mitre-data-component",
[
# SDO Common Properties
("id", IDProperty("x-mitre-data-component", spec_version="2.0")),
("type", TypeProperty("x-mitre-data-component", spec_version="2.0")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("id", IDProperty("x-mitre-data-component", spec_version="2.1")),
("type", TypeProperty("x-mitre-data-component", spec_version="2.1")),
("created_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("created", TimestampProperty(precision="millisecond")),
("modified", TimestampProperty(precision="millisecond")),
("revoked", BooleanProperty(default=lambda: False)),
("external_references", ListProperty(ExternalReference)),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.0"))),
("object_marking_refs", ListProperty(ReferenceProperty(valid_types="marking-definition", spec_version="2.1"))),
("name", StringProperty(required=True)),
("description", StringProperty()),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.0")),
("x_mitre_modified_by_ref", ReferenceProperty(valid_types="identity", spec_version="2.1")),
("x_mitre_version", StringProperty()),
("x_mitre_attack_spec_version", StringProperty()),
# Data Component Properties
("x_mitre_data_source_ref", ReferenceProperty(valid_types="x-mitre-data-source", spec_version="2.0")),
("x_mitre_data_source_ref", ReferenceProperty(valid_types="x-mitre-data-source", spec_version="2.1")),
],
)
class DataComponent(CustomStixObject, object):
Expand Down