Skip to content

Commit e02eda5

Browse files
author
Samuel Hassine
authored
[client] Migration to STIX 2.1, IDs generation rules (new schema, OpenCTI v4) (OpenCTI-Platform#105)
1 parent cb4b09d commit e02eda5

File tree

58 files changed

+9303
-8086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9303
-8086
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=============================================
2-
``pycti.entities.opencti_stix_domain_entity``
2+
``pycti.entities.opencti_stix_domain_object``
33
=============================================
44

5-
.. automodule:: pycti.entities.opencti_stix_domain_entity
5+
.. automodule:: pycti.entities.opencti_stix_domain_object
66

77
.. contents::
88
:local:
99

10-
.. currentmodule:: pycti.entities.opencti_stix_domain_entity
10+
.. currentmodule:: pycti.entities.opencti_stix_domain_object

docs/pycti/pycti.entities.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Submodules
2727
pycti.entities.opencti_note
2828
pycti.entities.opencti_opinion
2929
pycti.entities.opencti_report
30-
pycti.entities.opencti_stix_domain_entity
30+
pycti.entities.opencti_stix_domain_object
3131
pycti.entities.opencti_stix_entity
3232
pycti.entities.opencti_stix_observable
3333
pycti.entities.opencti_stix_observable_relation

examples/add_external_reference_to_report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828

2929
# Add the external reference to the report
30-
opencti_api_client.stix_entity.add_external_reference(
30+
opencti_api_client.stix_domain_object.add_external_reference(
3131
id=report["id"], external_reference_id=external_reference["id"]
3232
)
3333

examples/add_tag_to_malware.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
)
1616

1717
# Create the tag (if not exists)
18-
tag = opencti_api_client.tag.create(
18+
tag = opencti_api_client.label.create(
1919
tag_type="Malware-Type", value="Ranswomware", color="#ffa500",
2020
)
2121

2222
# Add the tag
23-
opencti_api_client.stix_entity.add_tag(id=malware["id"], tag_id=tag["id"])
23+
opencti_api_client.stix_domain_object.add_tag(id=malware["id"], tag_id=tag["id"])
2424

2525
# Print
2626
malware = opencti_api_client.malware.read(id=malware["id"])

examples/create_file_with_hashes.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = "https://demo.opencti.io"
7+
api_token = "2b4f29e3-5ea8-4890-8cf5-a76f61f1e2b2"
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
# Create observable
13+
observable = opencti_api_client.stix_cyber_observable.create(
14+
observableData={
15+
"type": "file",
16+
"hashes": {
17+
"md5": "16b3f663d0f0371a4706642c6ac04e42",
18+
"sha1": "3a1f908941311fc357051b5c35fd2a4e0c834e37",
19+
"sha256": "bcc70a49fab005b4cdbe0cbd87863ec622c6b2c656987d201adbb0e05ec03e56",
20+
},
21+
}
22+
)
23+
24+
print(observable)

examples/create_hashes_and_link_together.py

-59
This file was deleted.

examples/create_incident_with_ttps_and_indicators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
# Create the observable and indicator and indicates to the relation
5959
# Create the observable
60-
observable_ttp1 = opencti_api_client.stix_observable.create(
60+
observable_ttp1 = opencti_api_client.stix_cyber_observable.create(
6161
type="Email-Address", observable_value="phishing@mail.com", createIndicator=True
6262
)
6363
# Get the indicator
@@ -108,7 +108,7 @@
108108

109109
# Create the observable and indicator and indicates to the relation
110110
# Create the observable
111-
observable_ttp2 = opencti_api_client.stix_observable.create(
111+
observable_ttp2 = opencti_api_client.stix_cyber_observable.create(
112112
type="Registry-Key", observable_value="Disk security", createIndicator=True
113113
)
114114
# Get the indicator
@@ -159,7 +159,7 @@
159159

160160
# Add all element to the report
161161
for object_ref in object_refs:
162-
opencti_api_client.report.add_stix_entity(
162+
opencti_api_client.report.add_opencti_stix_object_or_stix_relationship(
163163
id=report["id"], report=report, entity_id=object_ref
164164
)
165165
for observable_ref in observable_refs:

examples/create_indicator_of_campaign.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
print(relation)
5050

5151
# Create the observables (optional)
52-
observable_1 = opencti_api_client.stix_observable.create(
52+
observable_1 = opencti_api_client.stix_cyber_observable.create(
5353
type="Domain", observable_value="www.5z8.info"
5454
)
55-
observable_2 = opencti_api_client.stix_observable.create(
55+
observable_2 = opencti_api_client.stix_cyber_observable.create(
5656
type="IPv4-Addr", observable_value="198.51.100.1"
5757
)
5858
# Create the relation between observables and the indicator

examples/create_marking_definition.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
# Create the marking definition
1313
marking_definition = opencti_api_client.marking_definition.create(
14-
definition_type="TLP", definition="TLP:BLACK", level=10, color="#000000"
14+
definition_type="TLP",
15+
definition="TLP:BLACK",
16+
x_opencti_order=10,
17+
x_opencti_color="#000000",
1518
)
1619

1720
# Print

examples/create_report_with_author.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
name="My new report of my organization",
2727
description="A report wrote by my organization",
2828
published=date,
29-
report_class="Internal Report",
30-
createdByRef=organization["id"],
29+
report_types=["internal-report"],
30+
createdBy=organization["id"],
3131
)
3232

3333
# Print

examples/delete_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
)
1616

1717
# Delete the intrusion set
18-
opencti_api_client.stix_domain_entity.delete(id=intrusion_set["id"])
18+
opencti_api_client.stix_domain_object.delete(id=intrusion_set["id"])

examples/delete_relation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
)
2121

2222
# Get the relations between APT28 and DealersChoice
23-
relations = opencti_api_client.stix_relation.list(
23+
relations = opencti_api_client.stix_core_relationship.list(
2424
fromId=intrusion_set["id"],
2525
fromTypes=["Intrusion-Set"],
2626
toId=malware["id"],
2727
toTypes=["Malware"],
28-
relationType="uses",
28+
relationship_type="uses",
2929
)
3030

3131
# Delete the relations
3232
for relation in relations:
33-
opencti_api_client.stix_relation.delete(id=relation["id"])
33+
opencti_api_client.stix_core_relationship.delete(id=relation["id"])

examples/export_intrusion_set_stix2.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

13-
# Get the intrusion set APT28
14-
intrusion_set = opencti_api_client.intrusion_set.read(
15-
filters=[{"key": "name", "values": ["APT28"]}]
16-
)
17-
1813
# Create the bundle
1914
bundle = opencti_api_client.stix2.export_entity(
20-
"indicator", "356fea34-f7f5-4110-937c-47c9a5abb8fa", "full"
15+
"Intrusion-Set", "4ecc2f52-d10a-4e10-bb9b-1ab5df2b282e", "full"
2116
)
2217
json_bundle = json.dumps(bundle, indent=4)
2318

2419
# Write the bundle
25-
f = open("APT28_STIX2.json", "w")
20+
f = open("intrusion-set.json", "w")
2621
f.write(json_bundle)
2722
f.close()

examples/export_report_stix2.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

13-
# Get the report
14-
report = opencti_api_client.report.read(id="5a3878d7-2949-4fd9-87c7-2a38c65bfa59")
15-
1613
# Create the bundle
17-
bundle = opencti_api_client.stix2.export_entity("report", report["id"], "full")
14+
bundle = opencti_api_client.stix2.export_entity(
15+
"Report", "e7c349a7-9809-4e98-87a2-ad39f32aef19", "full"
16+
)
1817
json_bundle = json.dumps(bundle, indent=4)
1918

2019
# Write the bundle

examples/get_entity_by_name_or_alias.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1111

1212
# Get the ANSSI entity
13-
anssi = opencti_api_client.stix_domain_entity.get_by_stix_id_or_name(name="ANSSI")
13+
anssi = opencti_api_client.stix_domain_object.get_by_stix_id_or_name(name="ANSSI")
1414

1515
# Print
1616
print(anssi)

examples/get_malwares_of_intrusion_set.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
)
1616

1717
# Get the relations from APT28 to malwares
18-
stix_relations = opencti_api_client.stix_relation.list(
18+
stix_relations = opencti_api_client.stix_core_relationship.list(
1919
fromId=intrusion_set["id"], toTypes=["Malware"], inferred=True
2020
)
2121

2222
# Print
2323
for stix_relation in stix_relations:
24-
print("[" + stix_relation["to"]["stix_id_key"] + "] " + stix_relation["to"]["name"])
24+
print("[" + stix_relation["to"]["stix_id"] + "] " + stix_relation["to"]["name"])

examples/get_reports_about_intrusion_set.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Get all reports
1818
reports = opencti_api_client.report.list(
19-
filters=[{"key": "knowledgeContains", "values": [intrusion_set["id"]]}],
19+
filters=[{"key": "objectContains", "values": [intrusion_set["id"]]}],
2020
orderBy="published",
2121
orderMode="asc",
2222
)
@@ -25,7 +25,7 @@
2525
for report in reports:
2626
print(
2727
"["
28-
+ report["stix_id_key"]
28+
+ report["stix_id"]
2929
+ "] "
3030
+ report["name"]
3131
+ " ("

examples/import_stix2_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1111

1212
# File to import
13-
file_to_import = "./test.json"
13+
file_to_import = "./enterprise-attack.json"
1414

1515
# Import the bundle
1616
opencti_api_client.stix2.import_bundle_from_file(file_to_import, True)

examples/update_entity_attribute.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
)
1616

1717
# Update the description
18-
opencti_api_client.stix_domain_entity.update_field(
18+
opencti_api_client.stix_domain_object.update_field(
1919
id=intrusion_set["id"], key="description", value="This is APT28!"
2020
)

examples/upload_file_to_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
print(intrusion_set)
2424

2525
# Upload the file
26-
file = opencti_api_client.stix_domain_entity.add_file(
26+
file = opencti_api_client.stix_domain_object.add_file(
2727
id=intrusion_set["id"], file_name="./file.pdf",
2828
)
2929
print(file)

0 commit comments

Comments
 (0)