Skip to content

Commit 4188f3f

Browse files
author
Samuel Hassine
committed
[client] Update examples
1 parent c23002e commit 4188f3f

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

examples/create_incident_with_ttps_and_indicators.py

+14-26
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
observable_refs = []
2020

2121
# Create the incident
22-
incident = opencti_api_client.x_opencti_incident.create(
22+
incident = opencti_api_client.incident.create(
2323
name="My new incident",
2424
description="We have been compromised",
2525
objective="Espionage",
@@ -39,15 +39,13 @@
3939
ttp1 = opencti_api_client.attack_pattern.read(
4040
filters=[{"key": "external_id", "values": ["T1193"]}]
4141
)
42-
ttp1_relation = opencti_api_client.stix_domain_object.create(
43-
fromType="Incident",
42+
ttp1_relation = opencti_api_client.stix_core_relationship.create(
4443
fromId=incident["id"],
45-
toType="Attack-Pattern",
4644
toId=ttp1["id"],
4745
relationship_type="uses",
4846
description="We saw the attacker use Spearphishing Attachment.",
49-
first_seen=date,
50-
last_seen=date,
47+
start_time=date,
48+
stop_time=date,
5149
)
5250
# Add kill chain phases to the relation
5351
for kill_chain_phase_id in ttp1["killChainPhasesIds"]:
@@ -64,14 +62,12 @@
6462
indicator_ttp1 = observable_ttp1["indicators"][0]
6563
# Indicates the relation Incident => uses => TTP
6664
indicator_ttp1_relation = opencti_api_client.stix_core_relationship.create(
67-
fromType="Indicator",
6865
fromId=indicator_ttp1["id"],
69-
toType="stix_relation",
7066
toId=ttp1_relation["id"],
7167
relationship_type="indicates",
7268
description="This email address is the sender of the spearphishing.",
73-
first_seen=date,
74-
last_seen=date,
69+
start_time=date,
70+
stop_time=date,
7571
)
7672

7773
# Prepare elements for the report
@@ -91,14 +87,12 @@
9187
)
9288
# Create the relation
9389
ttp2_relation = opencti_api_client.stix_core_relationship.create(
94-
fromType="Incident",
9590
fromId=incident["id"],
96-
toType="Attack-Pattern",
9791
toId=ttp2["id"],
9892
relationship_type="uses",
9993
description="We saw the attacker use Registry Run Keys / Startup Folder.",
100-
first_seen=date,
101-
last_seen=date,
94+
start_time=date,
95+
stop_time=date,
10296
)
10397
# Add kill chain phases to the relation
10498
for kill_chain_phase_id in ttp2["killChainPhasesIds"]:
@@ -115,14 +109,12 @@
115109
indicator_ttp2 = observable_ttp2["indicators"][0]
116110
# Indicates the relation Incident => uses => TTP
117111
indicator_ttp2_relation = opencti_api_client.stix_core_relationship.create(
118-
fromType="Indicator",
119112
fromId=indicator_ttp2["id"],
120-
toType="stix_relation",
121113
toId=ttp2_relation["id"],
122114
relationship_type="indicates",
123115
description="This registry key is used for persistence of tools.",
124-
first_seen=date,
125-
last_seen=date,
116+
start_time=date,
117+
stop_time=date,
126118
)
127119
# Elements for the report
128120
object_refs.extend(
@@ -140,14 +132,12 @@
140132
filters=[{"key": "external_id", "values": ["T1022"]}]
141133
)
142134
ttp3_relation = opencti_api_client.stix_core_relationship.create(
143-
fromType="Incident",
144135
fromId=incident["id"],
145-
toType="Attack-Pattern",
146136
toId=ttp3["id"],
147137
relationship_type="uses",
148138
description="We saw the attacker use Data Encrypted.",
149-
first_seen=date,
150-
last_seen=date,
139+
start_time=date,
140+
stop_time=date,
151141
)
152142
# Add kill chain phases to the relation
153143
for kill_chain_phase_id in ttp3["killChainPhasesIds"]:
@@ -167,12 +157,10 @@
167157
id=report["id"], report=report, stix_observable_id=observable_ref
168158
)
169159
opencti_api_client.stix_core_relationship.create(
170-
fromType="Stix-Observable",
171160
fromId=observable_ref,
172-
toType="Incident",
173161
toId=incident["id"],
174162
relationship_type="related-to",
175163
description="This observable is related to the incident.",
176-
first_seen=date,
177-
last_seen=date,
164+
start_time=date,
165+
stop_time=date,
178166
)

0 commit comments

Comments
 (0)