6
6
from pycti import OpenCTIApiClient
7
7
8
8
# Variables
9
- api_url = 'http ://localhost:4000 '
9
+ api_url = 'https ://demo.opencti.io '
10
10
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
11
11
12
12
# OpenCTI initialization
17
17
18
18
# Prepare all the elements of the report
19
19
object_refs = []
20
+ observable_refs = []
20
21
21
22
# Create the incident
22
23
incident = opencti_api_client .incident .create (
26
27
)
27
28
print (incident )
28
29
object_refs .append (incident ['id' ])
29
-
30
30
# Create the associated report
31
31
report = opencti_api_client .report .create (
32
32
name = "Report about my new incident" ,
58
58
kill_chain_phase_id = kill_chain_phase_id
59
59
)
60
60
61
+ # Create the observable and indicator and indicates to the relation
61
62
# Create the observable
62
63
observable_ttp1 = opencti_api_client .stix_observable .create (
63
64
type = 'Email-Address' ,
64
65
observable_value = 'phishing@mail.com'
65
66
)
67
+ print (observable_ttp1 )
68
+ # Get the indicator
69
+ indicator_ttp1 = observable_ttp1 ['indicators' ][0 ]
70
+ print (indicator_ttp1 )
66
71
# Indicates the relation Incident => uses => TTP
67
- observable_ttp1_relation = opencti_api_client .stix_relation .create (
68
- fromType = 'Stix-Observable ' ,
69
- fromId = observable_ttp1 ['id' ],
72
+ indicator_ttp1_relation = opencti_api_client .stix_relation .create (
73
+ fromType = 'Indicator ' ,
74
+ fromId = indicator_ttp1 ['id' ],
70
75
toType = 'stix_relation' ,
71
76
toId = ttp1_relation ['id' ],
72
77
relationship_type = 'indicates' ,
73
78
description = 'This email address is the sender of the spearphishing.' ,
74
79
first_seen = date ,
75
80
last_seen = date
76
81
)
77
- # Elements for the report
82
+
83
+ # Prepare elements for the report
78
84
object_refs .extend ([
79
85
ttp1 ['id' ],
80
86
ttp1_relation ['id' ],
81
- observable_ttp1 ['id' ],
82
- observable_ttp1_relation ['id' ]
87
+ indicator_ttp1 ['id' ],
88
+ indicator_ttp1_relation ['id' ]
83
89
])
90
+ observable_refs .append (observable_ttp1 ['id' ])
84
91
85
92
# Registry Run Keys / Startup Folder
86
93
ttp2 = opencti_api_client .attack_pattern .read (filters = [{'key' : 'external_id' , 'values' : ['T1060' ]}])
102
109
id = ttp2_relation ['id' ],
103
110
kill_chain_phase_id = kill_chain_phase_id
104
111
)
105
- # Add observables to the relation
112
+
113
+ # Create the observable and indicator and indicates to the relation
114
+ # Create the observable
106
115
observable_ttp2 = opencti_api_client .stix_observable .create (
107
116
type = 'Registry-Key' ,
108
117
observable_value = 'Disk security'
109
118
)
119
+ print (observable_ttp2 )
120
+ # Get the indicator
121
+ indicator_ttp2 = observable_ttp2 ['indicators' ][0 ]
122
+ print (indicator_ttp2 )
110
123
# Indicates the relation Incident => uses => TTP
111
- observable_ttp2_relation = opencti_api_client .stix_relation .create (
112
- fromType = 'Stix-Observable ' ,
113
- fromId = observable_ttp2 ['id' ],
124
+ indicator_ttp2_relation = opencti_api_client .stix_relation .create (
125
+ fromType = 'Indicator ' ,
126
+ fromId = indicator_ttp2 ['id' ],
114
127
toType = 'stix_relation' ,
115
128
toId = ttp2_relation ['id' ],
116
129
relationship_type = 'indicates' ,
122
135
object_refs .extend ([
123
136
ttp2 ['id' ],
124
137
ttp2_relation ['id' ],
125
- observable_ttp2 ['id' ],
126
- observable_ttp2_relation ['id' ]
138
+ indicator_ttp2 ['id' ],
139
+ indicator_ttp2_relation ['id' ]
127
140
])
141
+ observable_refs .append (observable_ttp2 ['id' ])
128
142
129
143
# Data Encrypted
130
144
ttp3 = opencti_api_client .attack_pattern .read (filters = [{'key' : 'external_id' , 'values' : ['T1022' ]}])
151
165
# Add all element to the report
152
166
for object_ref in object_refs :
153
167
opencti_api_client .report .add_stix_entity (id = report ['id' ], report = report , entity_id = object_ref )
168
+ for observable_ref in observable_refs :
169
+ opencti_api_client .report .add_stix_observable (id = report ['id' ], report = report , entity_id = observable_ref )
0 commit comments