Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 08e374f

Browse files
author
Samuel Hassine
committed
[client] Fix the export of incident
1 parent 5861cdc commit 08e374f

13 files changed

+107
-46
lines changed

examples/add_organization_to_sector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Variables
88
api_url = 'https://demo.opencti.io'
9-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
9+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
1010

1111
# OpenCTI initialization
1212
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/create_incident_with_ttps_and_observables.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66
from pycti import OpenCTIApiClient
77

88
# Variables
9-
api_url = 'https://demo.opencti.io'
10-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
9+
api_url = 'http://localhost:4000'
10+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
1111

1212
# OpenCTI initialization
1313
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1414

1515
# Define the date
1616
date = parse('2019-12-01').strftime('%Y-%m-%dT%H:%M:%SZ')
1717

18+
# Prepare all the elements of the report
19+
object_refs = []
20+
1821
# Create the incident
1922
incident = opencti_api_client.incident.create(
2023
name="My new incident",
2124
description="We have been compromised",
2225
objective="Espionage"
2326
)
2427
print(incident)
28+
object_refs.append(incident['id'])
2529

2630
# Create the associated report
2731
report = opencti_api_client.report.create(
@@ -32,9 +36,6 @@
3236
)
3337
print(report)
3438

35-
# Prepare all the elements of the report
36-
object_refs = []
37-
3839
# Associate the TTPs to the incident
3940

4041
# Spearphishing Attachment
@@ -43,7 +44,7 @@
4344
ttp1_relation = opencti_api_client.stix_relation.create(
4445
fromType='Incident',
4546
fromId=incident['id'],
46-
toType='Incident',
47+
toType='Attack-Pattern',
4748
toId=ttp1['id'],
4849
relationship_type='uses',
4950
description='We saw the attacker use Spearphishing Attachment.',
@@ -56,11 +57,24 @@
5657
id=ttp1_relation['id'],
5758
kill_chain_phase_id=kill_chain_phase_id
5859
)
59-
# Add observables to the relation
60+
61+
# Create the observable
6062
observable_ttp1 = opencti_api_client.stix_observable.create(
61-
type='Email-Addr',
63+
type='Email-Address',
6264
observable_value='[email protected]'
6365
)
66+
# Indicates the incident itself
67+
observable_ttp1_incident_relation = opencti_api_client.stix_relation.create(
68+
fromType='Stix-Observable',
69+
fromId=observable_ttp1['id'],
70+
toType='Incident',
71+
toId=incident['id'],
72+
relationship_type='indicates',
73+
description='This email address is the sender of the spearphishing in this incident.',
74+
first_seen=date,
75+
last_seen=date
76+
)
77+
# Indicates the relation Incident => uses => TTP
6478
observable_ttp1_relation = opencti_api_client.stix_relation.create(
6579
fromType='Stix-Observable',
6680
fromId=observable_ttp1['id'],
@@ -72,7 +86,12 @@
7286
last_seen=date
7387
)
7488
# Elements for the report
75-
object_refs.extend([ttp1['id'], ttp1_relation['id'], observable_ttp1['id'], observable_ttp1_relation['id']])
89+
object_refs.extend([
90+
ttp1['id'],
91+
ttp1_relation['id'],
92+
observable_ttp1['id'],
93+
observable_ttp1_incident_relation['id']
94+
])
7695

7796
# Registry Run Keys / Startup Folder
7897
ttp2 = opencti_api_client.attack_pattern.read(filters=[{'key': 'external_id', 'values': ['T1060']}])
@@ -81,7 +100,7 @@
81100
ttp2_relation = opencti_api_client.stix_relation.create(
82101
fromType='Incident',
83102
fromId=incident['id'],
84-
toType='Incident',
103+
toType='Attack-Pattern',
85104
toId=ttp2['id'],
86105
relationship_type='uses',
87106
description='We saw the attacker use Registry Run Keys / Startup Folder.',
@@ -99,6 +118,18 @@
99118
type='Registry-Key',
100119
observable_value='Disk security'
101120
)
121+
# Indicates the incident itself
122+
observable_ttp2_incident_relation = opencti_api_client.stix_relation.create(
123+
fromType='Stix-Observable',
124+
fromId=observable_ttp2['id'],
125+
toType='Incident',
126+
toId=incident['id'],
127+
relationship_type='indicates',
128+
description='This registry key is used for persistence of tools in this incident.',
129+
first_seen=date,
130+
last_seen=date
131+
)
132+
# Indicates the relation Incident => uses => TTP
102133
observable_ttp2_relation = opencti_api_client.stix_relation.create(
103134
fromType='Stix-Observable',
104135
fromId=observable_ttp2['id'],
@@ -110,15 +141,20 @@
110141
last_seen=date
111142
)
112143
# Elements for the report
113-
object_refs.extend([ttp2['id'], ttp2_relation['id'], observable_ttp2['id'], observable_ttp2_relation['id']])
144+
object_refs.extend([
145+
ttp2['id'],
146+
ttp2_relation['id'],
147+
observable_ttp2['id'],
148+
observable_ttp2_incident_relation['id']
149+
])
114150

115151
# Data Encrypted
116152
ttp3 = opencti_api_client.attack_pattern.read(filters=[{'key': 'external_id', 'values': ['T1022']}])
117153
print(ttp3)
118154
ttp3_relation = opencti_api_client.stix_relation.create(
119155
fromType='Incident',
120156
fromId=incident['id'],
121-
toType='Incident',
157+
toType='Attack-Pattern',
122158
toId=ttp3['id'],
123159
relationship_type='uses',
124160
description='We saw the attacker use Data Encrypted.',

examples/create_intrusion_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Variables
77
api_url = 'https://demo.opencti.io'
8-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
8+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/export_intrusion_set_stix2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Variables
77
api_url = 'https://demo.opencti.io'
8-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
8+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/export_report_stix2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from pycti import OpenCTIApiClient
55

66
# Variables
7-
api_url = 'https://demo.opencti.io'
8-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_url = 'http://localhost:4000'
8+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

1313
# Get the report
14-
report = opencti_api_client.report.read(id='b52201d6-8da3-4e98-a3f5-e53318d8fb52')
14+
report = opencti_api_client.report.read(id='f465e240-9bfe-41dd-888c-70d7d85143c1')
1515

1616
# Create the bundle
1717
bundle = opencti_api_client.stix2.export_entity('report', report['id'], 'full')

examples/get_attack_pattern_by_mitre_id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_malwares_of_intrusion_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_marking_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/get_reports_about_intrusion_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/import_stix2_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Variables
66
api_url = 'https://demo.opencti.io'
7-
api_token = 'ab3c02bb-2849-4223-be5d-8f61207b4b43'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)

0 commit comments

Comments
 (0)