pycti 6.5.11__py3-none-any.whl → 6.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pycti might be problematic. Click here for more details.
- pycti/__init__.py +13 -1
- pycti/api/opencti_api_client.py +13 -0
- pycti/connector/opencti_connector_helper.py +24 -6
- pycti/entities/opencti_capability.py +52 -0
- pycti/entities/opencti_group.py +716 -0
- pycti/entities/opencti_indicator.py +6 -0
- pycti/entities/opencti_role.py +408 -0
- pycti/entities/opencti_settings.py +385 -0
- pycti/entities/opencti_user.py +803 -0
- pycti/utils/opencti_stix2.py +90 -22
- {pycti-6.5.11.dist-info → pycti-6.6.1.dist-info}/METADATA +1 -1
- {pycti-6.5.11.dist-info → pycti-6.6.1.dist-info}/RECORD +15 -10
- {pycti-6.5.11.dist-info → pycti-6.6.1.dist-info}/WHEEL +0 -0
- {pycti-6.5.11.dist-info → pycti-6.6.1.dist-info}/licenses/LICENSE +0 -0
- {pycti-6.5.11.dist-info → pycti-6.6.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
from typing import Dict, Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Settings:
|
|
5
|
+
"""Represents the Settings object in OpenCTI
|
|
6
|
+
|
|
7
|
+
These are the properties which are viewable in the customization and
|
|
8
|
+
security policies views on OpenCTI platform. This also includes all
|
|
9
|
+
messages on the platform.
|
|
10
|
+
|
|
11
|
+
See the properties attribute to understand which properties are fetched by
|
|
12
|
+
default on graphql queries.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, opencti):
|
|
16
|
+
self.opencti = opencti
|
|
17
|
+
self.properties = """
|
|
18
|
+
id
|
|
19
|
+
standard_id
|
|
20
|
+
entity_type
|
|
21
|
+
parent_types
|
|
22
|
+
platform_organization {
|
|
23
|
+
id, name, description
|
|
24
|
+
}
|
|
25
|
+
platform_title
|
|
26
|
+
platform_favicon
|
|
27
|
+
platform_email
|
|
28
|
+
platform_url
|
|
29
|
+
platform_language
|
|
30
|
+
platform_cluster {
|
|
31
|
+
instances_number
|
|
32
|
+
}
|
|
33
|
+
platform_modules {
|
|
34
|
+
id, enable, warning
|
|
35
|
+
}
|
|
36
|
+
platform_providers {
|
|
37
|
+
name, type, strategy, provider
|
|
38
|
+
}
|
|
39
|
+
platform_user_statuses {
|
|
40
|
+
status, message
|
|
41
|
+
}
|
|
42
|
+
platform_theme
|
|
43
|
+
platform_theme_dark_background
|
|
44
|
+
platform_theme_dark_paper
|
|
45
|
+
platform_theme_dark_nav
|
|
46
|
+
platform_theme_dark_primary
|
|
47
|
+
platform_theme_dark_secondary
|
|
48
|
+
platform_theme_dark_accent
|
|
49
|
+
platform_theme_dark_logo
|
|
50
|
+
platform_theme_dark_logo_collapsed
|
|
51
|
+
platform_theme_dark_logo_login
|
|
52
|
+
platform_theme_light_background
|
|
53
|
+
platform_theme_light_paper
|
|
54
|
+
platform_theme_light_nav
|
|
55
|
+
platform_theme_light_primary
|
|
56
|
+
platform_theme_light_secondary
|
|
57
|
+
platform_theme_light_accent
|
|
58
|
+
platform_theme_light_logo
|
|
59
|
+
platform_theme_light_logo_collapsed
|
|
60
|
+
platform_theme_light_logo_login
|
|
61
|
+
platform_map_tile_server_dark
|
|
62
|
+
platform_map_tile_server_light
|
|
63
|
+
platform_openbas_url
|
|
64
|
+
platform_openbas_disable_display
|
|
65
|
+
platform_openerm_url
|
|
66
|
+
platform_openmtd_url
|
|
67
|
+
platform_ai_enabled
|
|
68
|
+
platform_ai_type
|
|
69
|
+
platform_ai_model
|
|
70
|
+
platform_ai_has_token
|
|
71
|
+
platform_login_message
|
|
72
|
+
platform_consent_message
|
|
73
|
+
platform_consent_confirm_text
|
|
74
|
+
platform_banner_text
|
|
75
|
+
platform_banner_level
|
|
76
|
+
platform_session_idle_timeout
|
|
77
|
+
platform_session_timeout
|
|
78
|
+
platform_whitemark
|
|
79
|
+
platform_demo
|
|
80
|
+
platform_reference_attachment
|
|
81
|
+
platform_feature_flags {
|
|
82
|
+
id, enable, warning
|
|
83
|
+
}
|
|
84
|
+
platform_critical_alerts {
|
|
85
|
+
message, type
|
|
86
|
+
details {
|
|
87
|
+
groups {
|
|
88
|
+
id, name, description
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
platform_trash_enabled
|
|
93
|
+
platform_protected_sensitive_config {
|
|
94
|
+
enabled
|
|
95
|
+
markings {
|
|
96
|
+
enabled, protected_ids
|
|
97
|
+
}
|
|
98
|
+
groups {
|
|
99
|
+
enabled, protected_ids
|
|
100
|
+
}
|
|
101
|
+
roles {
|
|
102
|
+
enabled, protected_ids
|
|
103
|
+
}
|
|
104
|
+
rules {
|
|
105
|
+
enabled, protected_ids
|
|
106
|
+
}
|
|
107
|
+
ce_ee_toggle {
|
|
108
|
+
enabled, protected_ids
|
|
109
|
+
}
|
|
110
|
+
file_indexing {
|
|
111
|
+
enabled, protected_ids
|
|
112
|
+
}
|
|
113
|
+
platform_organization {
|
|
114
|
+
enabled, protected_ids
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
created_at
|
|
118
|
+
updated_at
|
|
119
|
+
platform_enterprise_edition {
|
|
120
|
+
license_enterprise
|
|
121
|
+
license_by_configuration
|
|
122
|
+
license_customer
|
|
123
|
+
license_validated
|
|
124
|
+
license_valid_cert
|
|
125
|
+
license_expired
|
|
126
|
+
license_expiration_prevention
|
|
127
|
+
license_start_date
|
|
128
|
+
license_expiration_date
|
|
129
|
+
license_platform
|
|
130
|
+
license_type
|
|
131
|
+
license_platform_match
|
|
132
|
+
license_creator
|
|
133
|
+
license_global
|
|
134
|
+
}
|
|
135
|
+
analytics_google_analytics_v4
|
|
136
|
+
activity_listeners {
|
|
137
|
+
id, name, entity_type
|
|
138
|
+
}
|
|
139
|
+
"""
|
|
140
|
+
self.messages_properties = """
|
|
141
|
+
entity_type
|
|
142
|
+
platform_messages {
|
|
143
|
+
id, message, activated, dismissible, updated_at, color
|
|
144
|
+
recipients {
|
|
145
|
+
id, name, entity_type
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
messages_administration {
|
|
149
|
+
id, message, activated, dismissible, updated_at, color
|
|
150
|
+
recipients {
|
|
151
|
+
id, name, entity_type
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
"""
|
|
155
|
+
self.password_policy_properties = """
|
|
156
|
+
otp_mandatory
|
|
157
|
+
password_policy_min_length
|
|
158
|
+
password_policy_max_length
|
|
159
|
+
password_policy_min_symbols
|
|
160
|
+
password_policy_min_numbers
|
|
161
|
+
password_policy_min_words
|
|
162
|
+
password_policy_min_lowercase
|
|
163
|
+
password_policy_min_uppercase
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
self.editable_properties = (
|
|
167
|
+
"""
|
|
168
|
+
id
|
|
169
|
+
platform_organization {
|
|
170
|
+
id
|
|
171
|
+
}
|
|
172
|
+
platform_title
|
|
173
|
+
platform_favicon
|
|
174
|
+
platform_email
|
|
175
|
+
platform_language
|
|
176
|
+
platform_theme
|
|
177
|
+
platform_theme_dark_background
|
|
178
|
+
platform_theme_dark_paper
|
|
179
|
+
platform_theme_dark_nav
|
|
180
|
+
platform_theme_dark_primary
|
|
181
|
+
platform_theme_dark_secondary
|
|
182
|
+
platform_theme_dark_accent
|
|
183
|
+
platform_theme_dark_logo
|
|
184
|
+
platform_theme_dark_logo_collapsed
|
|
185
|
+
platform_theme_dark_logo_login
|
|
186
|
+
platform_theme_light_background
|
|
187
|
+
platform_theme_light_paper
|
|
188
|
+
platform_theme_light_nav
|
|
189
|
+
platform_theme_light_primary
|
|
190
|
+
platform_theme_light_secondary
|
|
191
|
+
platform_theme_light_accent
|
|
192
|
+
platform_theme_light_logo
|
|
193
|
+
platform_theme_light_logo_collapsed
|
|
194
|
+
platform_theme_light_logo_login
|
|
195
|
+
platform_login_message
|
|
196
|
+
platform_consent_message
|
|
197
|
+
platform_consent_confirm_text
|
|
198
|
+
platform_banner_text
|
|
199
|
+
platform_banner_level
|
|
200
|
+
platform_whitemark
|
|
201
|
+
analytics_google_analytics_v4
|
|
202
|
+
"""
|
|
203
|
+
+ self.password_policy_properties
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
def read(self, **kwargs) -> Dict:
|
|
207
|
+
"""Reads settings from the platform
|
|
208
|
+
|
|
209
|
+
:param customAttributes: Custom attribues to return from query
|
|
210
|
+
:type customAttributes: str, optional
|
|
211
|
+
:param include_password_policy: Defaults to False. Whether to include
|
|
212
|
+
password policy properties in response.
|
|
213
|
+
:type include_password_policy: bool, optional
|
|
214
|
+
:param include_messages: Defaults to False. Whether to include messages
|
|
215
|
+
in query response.
|
|
216
|
+
:type include_messages: bool, optional
|
|
217
|
+
:return: Representation of the platform settings
|
|
218
|
+
:rtype: Dict
|
|
219
|
+
"""
|
|
220
|
+
custom_attributes = kwargs.get("customAttributes", None)
|
|
221
|
+
include_password_policy = kwargs.get("include_password_policy", False)
|
|
222
|
+
include_messages = kwargs.get("include_messages", False)
|
|
223
|
+
|
|
224
|
+
self.opencti.admin_logger.info("Reading platform settings")
|
|
225
|
+
query = (
|
|
226
|
+
"""
|
|
227
|
+
query PlatformSettings {
|
|
228
|
+
settings {
|
|
229
|
+
"""
|
|
230
|
+
+ (self.properties if custom_attributes is None else custom_attributes)
|
|
231
|
+
+ (self.password_policy_properties if include_password_policy else "")
|
|
232
|
+
+ (self.messages_properties if include_messages else "")
|
|
233
|
+
+ """
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
"""
|
|
237
|
+
)
|
|
238
|
+
result = self.opencti.query(query)
|
|
239
|
+
return self.opencti.process_multiple_fields(result["data"]["settings"])
|
|
240
|
+
|
|
241
|
+
def update_field(self, **kwargs) -> Optional[Dict]:
|
|
242
|
+
"""Update settings using input to fieldPatch
|
|
243
|
+
|
|
244
|
+
:param id: ID of the settings object to update
|
|
245
|
+
:type id: str
|
|
246
|
+
:param input: List of EditInput objects
|
|
247
|
+
:type input: List[Dict]
|
|
248
|
+
:param customAttributes: Custom attribues to return from query
|
|
249
|
+
:type customAttributes: str, optional
|
|
250
|
+
:param include_password_policy: Defaults to False. Whether to include
|
|
251
|
+
password policy properties in response.
|
|
252
|
+
:type include_password_policy: bool, optional
|
|
253
|
+
:param include_messages: Defaults to False. Whether to include messages
|
|
254
|
+
in query response.
|
|
255
|
+
:type include_messages: bool, optional
|
|
256
|
+
:return: Representation of the platform settings
|
|
257
|
+
:rtype: Optional[Dict]
|
|
258
|
+
"""
|
|
259
|
+
id = kwargs.get("id", None)
|
|
260
|
+
input = kwargs.get("input", None)
|
|
261
|
+
custom_attributes = kwargs.get("customAttributes", None)
|
|
262
|
+
include_password_policy = kwargs.get("include_password_policy", False)
|
|
263
|
+
include_messages = kwargs.get("include_messages", False)
|
|
264
|
+
|
|
265
|
+
if id is None or input is None:
|
|
266
|
+
self.opencti.admin_logger.error(
|
|
267
|
+
"[opencti_settings] Missing parameters: id and input"
|
|
268
|
+
)
|
|
269
|
+
return None
|
|
270
|
+
|
|
271
|
+
self.opencti.admin_logger.info(
|
|
272
|
+
"Updating settings with input", {"id": id, "input": input}
|
|
273
|
+
)
|
|
274
|
+
query = (
|
|
275
|
+
"""
|
|
276
|
+
mutation SettingsUpdateField($id: ID!, $input: [EditInput]!) {
|
|
277
|
+
settingsEdit(id: $id) {
|
|
278
|
+
fieldPatch(input: $input) {
|
|
279
|
+
"""
|
|
280
|
+
+ (self.properties if custom_attributes is None else custom_attributes)
|
|
281
|
+
+ (self.password_policy_properties if include_password_policy else "")
|
|
282
|
+
+ (self.messages_properties if include_messages else "")
|
|
283
|
+
+ """
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
"""
|
|
288
|
+
)
|
|
289
|
+
result = self.opencti.query(query, {"id": id, "input": input})
|
|
290
|
+
return self.opencti.process_multiple_fields(
|
|
291
|
+
result["data"]["settingsEdit"]["fieldPatch"]
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
def edit_message(self, **kwargs) -> Optional[Dict]:
|
|
295
|
+
"""Edit or add a message to the platform
|
|
296
|
+
|
|
297
|
+
To add a message, don't include an ID in the input object. To edit a
|
|
298
|
+
message an ID must be provided.
|
|
299
|
+
|
|
300
|
+
:param id: ID of the settings object on the platform
|
|
301
|
+
:type id: str
|
|
302
|
+
:param input: SettingsMessageInput object
|
|
303
|
+
:type input: Dict
|
|
304
|
+
:return: Settings ID and message objects
|
|
305
|
+
:rtype: Optional[Dict]
|
|
306
|
+
"""
|
|
307
|
+
id = kwargs.get("id", None)
|
|
308
|
+
input = kwargs.get("input", None)
|
|
309
|
+
if id is None or input is None:
|
|
310
|
+
self.opencti.admin_logger.error(
|
|
311
|
+
"[opencti_settings] Missing parameters: id and input"
|
|
312
|
+
)
|
|
313
|
+
return None
|
|
314
|
+
self.opencti.admin_logger.info("Editing message", {"id": id, "input": input})
|
|
315
|
+
|
|
316
|
+
query = (
|
|
317
|
+
"""
|
|
318
|
+
mutation SettingsEditMessage($id: ID!, $input: SettingsMessageInput!) {
|
|
319
|
+
settingsEdit(id: $id) {
|
|
320
|
+
editMessage(input: $input) {
|
|
321
|
+
id
|
|
322
|
+
"""
|
|
323
|
+
+ self.messages_properties
|
|
324
|
+
+ """
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
"""
|
|
329
|
+
)
|
|
330
|
+
result = self.opencti.query(query, {"id": id, "input": input})
|
|
331
|
+
return self.opencti.process_multiple_fields(
|
|
332
|
+
result["data"]["settingsEdit"]["editMessage"]
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
def delete_message(self, **kwargs) -> Optional[Dict]:
|
|
336
|
+
"""Delete a message from the platform
|
|
337
|
+
|
|
338
|
+
:param id: ID of the settings object on the platform
|
|
339
|
+
:type id: str
|
|
340
|
+
:param input: ID of the message to delete
|
|
341
|
+
:type input: str
|
|
342
|
+
:return: Settings ID and message objects
|
|
343
|
+
:rtype: Optional[Dict]
|
|
344
|
+
"""
|
|
345
|
+
id = kwargs.get("id", None)
|
|
346
|
+
input = kwargs.get("input", None)
|
|
347
|
+
if id is None:
|
|
348
|
+
self.opencti.admin_logger.info("[opencti_settings] Missing parameters: id")
|
|
349
|
+
return None
|
|
350
|
+
|
|
351
|
+
query = (
|
|
352
|
+
"""
|
|
353
|
+
mutation SettingsEditDeleteMessage($id: ID!, $input: String!) {
|
|
354
|
+
settingsEdit(id: $id) {
|
|
355
|
+
deleteMessage(input: $input) {
|
|
356
|
+
id
|
|
357
|
+
"""
|
|
358
|
+
+ self.messages_properties
|
|
359
|
+
+ """
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
"""
|
|
364
|
+
)
|
|
365
|
+
result = self.opencti.query(query, {"id": id, "input": input})
|
|
366
|
+
return self.opencti.process_multiple_fields(
|
|
367
|
+
result["data"]["settingsEdit"]["deleteMessage"]
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
def process_multiple_fields(self, data):
|
|
371
|
+
if "platform_messages" in data:
|
|
372
|
+
data["platform_messages"] = self.opencti.process_multiple(
|
|
373
|
+
data["platform_messages"]
|
|
374
|
+
)
|
|
375
|
+
data["platform_messages_ids"] = self.opencti.process_multiple_ids(
|
|
376
|
+
data["platform_messages"]
|
|
377
|
+
)
|
|
378
|
+
if "messages_administration" in data:
|
|
379
|
+
data["messages_administration"] = self.opencti.process_multiple(
|
|
380
|
+
data["messages_administration"]
|
|
381
|
+
)
|
|
382
|
+
data["messages_administration_ids"] = self.opencti.process_multiple_ids(
|
|
383
|
+
data["messages_administration"]
|
|
384
|
+
)
|
|
385
|
+
return data
|