pycti 5.12.14__py3-none-any.whl → 5.12.15__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 +1 -1
- pycti/api/__init__.py +0 -3
- pycti/api/opencti_api_client.py +10 -56
- pycti/api/opencti_api_connector.py +1 -2
- pycti/api/opencti_api_playbook.py +3 -4
- pycti/api/opencti_api_work.py +15 -12
- pycti/connector/__init__.py +0 -3
- pycti/connector/opencti_connector_helper.py +63 -58
- pycti/connector/opencti_metric_handler.py +8 -5
- pycti/entities/__init__.py +0 -3
- pycti/entities/opencti_attack_pattern.py +17 -11
- pycti/entities/opencti_campaign.py +15 -9
- pycti/entities/opencti_case_incident.py +39 -43
- pycti/entities/opencti_case_rfi.py +34 -46
- pycti/entities/opencti_case_rft.py +35 -44
- pycti/entities/opencti_channel.py +15 -9
- pycti/entities/opencti_course_of_action.py +15 -9
- pycti/entities/opencti_data_component.py +17 -14
- pycti/entities/opencti_data_source.py +12 -16
- pycti/entities/opencti_event.py +15 -9
- pycti/entities/opencti_external_reference.py +20 -15
- pycti/entities/opencti_feedback.py +36 -46
- pycti/entities/opencti_grouping.py +22 -20
- pycti/entities/opencti_identity.py +15 -8
- pycti/entities/opencti_incident.py +13 -9
- pycti/entities/opencti_indicator.py +18 -15
- pycti/entities/opencti_infrastructure.py +15 -9
- pycti/entities/opencti_intrusion_set.py +12 -8
- pycti/entities/opencti_kill_chain_phase.py +16 -12
- pycti/entities/opencti_label.py +16 -12
- pycti/entities/opencti_language.py +13 -9
- pycti/entities/opencti_location.py +13 -9
- pycti/entities/opencti_malware.py +15 -9
- pycti/entities/opencti_malware_analysis.py +17 -9
- pycti/entities/opencti_marking_definition.py +15 -11
- pycti/entities/opencti_narrative.py +15 -9
- pycti/entities/opencti_note.py +35 -20
- pycti/entities/opencti_observed_data.py +34 -19
- pycti/entities/opencti_opinion.py +37 -20
- pycti/entities/opencti_report.py +36 -20
- pycti/entities/opencti_stix.py +8 -19
- pycti/entities/opencti_stix_core_object.py +15 -9
- pycti/entities/opencti_stix_core_relationship.py +69 -52
- pycti/entities/opencti_stix_cyber_observable.py +78 -62
- pycti/entities/opencti_stix_domain_object.py +75 -55
- pycti/entities/opencti_stix_nested_ref_relationship.py +21 -14
- pycti/entities/opencti_stix_object_or_stix_relationship.py +4 -7
- pycti/entities/opencti_stix_sighting_relationship.py +34 -26
- pycti/entities/opencti_task.py +37 -44
- pycti/entities/opencti_threat_actor.py +7 -4
- pycti/entities/opencti_threat_actor_group.py +10 -8
- pycti/entities/opencti_threat_actor_individual.py +10 -9
- pycti/entities/opencti_tool.py +15 -9
- pycti/entities/opencti_vocabulary.py +11 -13
- pycti/entities/opencti_vulnerability.py +15 -9
- pycti/utils/opencti_logger.py +64 -0
- pycti/utils/opencti_stix2.py +30 -24
- pycti/utils/opencti_stix2_update.py +2 -6
- {pycti-5.12.14.dist-info → pycti-5.12.15.dist-info}/METADATA +1 -1
- pycti-5.12.15.dist-info/RECORD +68 -0
- pycti-5.12.14.dist-info/RECORD +0 -67
- {pycti-5.12.14.dist-info → pycti-5.12.15.dist-info}/LICENSE +0 -0
- {pycti-5.12.14.dist-info → pycti-5.12.15.dist-info}/WHEEL +0 -0
- {pycti-5.12.14.dist-info → pycti-5.12.15.dist-info}/top_level.txt +0 -0
pycti/entities/opencti_task.py
CHANGED
|
@@ -5,8 +5,6 @@ import uuid
|
|
|
5
5
|
from dateutil.parser import parse
|
|
6
6
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
7
7
|
|
|
8
|
-
from pycti.entities import LOGGER
|
|
9
|
-
|
|
10
8
|
|
|
11
9
|
class Task:
|
|
12
10
|
def __init__(self, opencti):
|
|
@@ -271,7 +269,9 @@ class Task:
|
|
|
271
269
|
if get_all:
|
|
272
270
|
first = 500
|
|
273
271
|
|
|
274
|
-
|
|
272
|
+
self.opencti.app_logger.info(
|
|
273
|
+
"Listing Tasks with filters", {"filters": json.dumps(filters)}
|
|
274
|
+
)
|
|
275
275
|
query = (
|
|
276
276
|
"""
|
|
277
277
|
query tasks($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: TasksOrdering, $orderMode: OrderingMode) {
|
|
@@ -311,7 +311,7 @@ class Task:
|
|
|
311
311
|
final_data = final_data + data
|
|
312
312
|
while result["data"]["tasks"]["pageInfo"]["hasNextPage"]:
|
|
313
313
|
after = result["date"]["tasks"]["pageInfo"]["endCursor"]
|
|
314
|
-
self.opencti.
|
|
314
|
+
self.opencti.app_logger.info("Listing Tasks", {"after": after})
|
|
315
315
|
result = self.opencti.query(
|
|
316
316
|
query,
|
|
317
317
|
{
|
|
@@ -344,7 +344,7 @@ class Task:
|
|
|
344
344
|
filters = kwargs.get("filters", None)
|
|
345
345
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
346
346
|
if id is not None:
|
|
347
|
-
self.opencti.
|
|
347
|
+
self.opencti.app_logger.info("Reading Task", {"id": id})
|
|
348
348
|
query = (
|
|
349
349
|
"""
|
|
350
350
|
query task($id: String!) {
|
|
@@ -415,13 +415,12 @@ class Task:
|
|
|
415
415
|
"stixObjectOrStixRelationshipId", None
|
|
416
416
|
)
|
|
417
417
|
if id is not None and stix_object_or_stix_relationship_id is not None:
|
|
418
|
-
self.opencti.
|
|
419
|
-
"
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
+ "}",
|
|
418
|
+
self.opencti.app_logger.info(
|
|
419
|
+
"Checking StixObjectOrStixRelationship in Task",
|
|
420
|
+
{
|
|
421
|
+
"stix_object_or_stix_relationship_id": stix_object_or_stix_relationship_id,
|
|
422
|
+
"id": id,
|
|
423
|
+
},
|
|
425
424
|
)
|
|
426
425
|
query = """
|
|
427
426
|
query taskContainsStixObjectOrStixRelationship($id: String!, $stixObjectOrStixRelationshipId: String!) {
|
|
@@ -437,9 +436,8 @@ class Task:
|
|
|
437
436
|
)
|
|
438
437
|
return result["data"]["taskContainsStixObjectOrStixRelationship"]
|
|
439
438
|
else:
|
|
440
|
-
self.opencti.
|
|
441
|
-
"
|
|
442
|
-
"[opencti_Task] Missing parameters: id or stixObjectOrStixRelationshipId",
|
|
439
|
+
self.opencti.app_logger.error(
|
|
440
|
+
"[opencti_Task] Missing parameters: id or stixObjectOrStixRelationshipId"
|
|
443
441
|
)
|
|
444
442
|
|
|
445
443
|
"""
|
|
@@ -464,7 +462,7 @@ class Task:
|
|
|
464
462
|
update = kwargs.get("update", False)
|
|
465
463
|
|
|
466
464
|
if name is not None:
|
|
467
|
-
self.opencti.
|
|
465
|
+
self.opencti.app_logger.info("Creating Task", {"name": name})
|
|
468
466
|
query = """
|
|
469
467
|
mutation TaskAdd($input: TaskAddInput!) {
|
|
470
468
|
taskAdd(input: $input) {
|
|
@@ -496,13 +494,10 @@ class Task:
|
|
|
496
494
|
)
|
|
497
495
|
return self.opencti.process_multiple_fields(result["data"]["taskAdd"])
|
|
498
496
|
else:
|
|
499
|
-
self.opencti.
|
|
500
|
-
"error",
|
|
501
|
-
"[opencti_task] Missing parameters: name",
|
|
502
|
-
)
|
|
497
|
+
self.opencti.app_logger.error("[opencti_task] Missing parameters: name")
|
|
503
498
|
|
|
504
499
|
def update_field(self, **kwargs):
|
|
505
|
-
self.opencti.
|
|
500
|
+
self.opencti.app_logger.info("Updating Task", {"data": json.dumps(kwargs)})
|
|
506
501
|
id = kwargs.get("id", None)
|
|
507
502
|
input = kwargs.get("input", None)
|
|
508
503
|
if id is not None and input is not None:
|
|
@@ -520,8 +515,8 @@ class Task:
|
|
|
520
515
|
result["data"]["taskFieldPatch"]
|
|
521
516
|
)
|
|
522
517
|
else:
|
|
523
|
-
self.opencti.
|
|
524
|
-
"
|
|
518
|
+
self.opencti.app_logger.error(
|
|
519
|
+
"[opencti_Task] Missing parameters: id and key and value"
|
|
525
520
|
)
|
|
526
521
|
return None
|
|
527
522
|
|
|
@@ -539,13 +534,12 @@ class Task:
|
|
|
539
534
|
"stixObjectOrStixRelationshipId", None
|
|
540
535
|
)
|
|
541
536
|
if id is not None and stix_object_or_stix_relationship_id is not None:
|
|
542
|
-
self.opencti.
|
|
543
|
-
"
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
+ "}",
|
|
537
|
+
self.opencti.app_logger.info(
|
|
538
|
+
"Adding StixObjectOrStixRelationship in Task",
|
|
539
|
+
{
|
|
540
|
+
"stix_object_or_stix_relationship_id": stix_object_or_stix_relationship_id,
|
|
541
|
+
"id": id,
|
|
542
|
+
},
|
|
549
543
|
)
|
|
550
544
|
query = """
|
|
551
545
|
mutation taskEditRelationAdd($id: ID!, $input: StixMetaRelationshipAddInput) {
|
|
@@ -566,8 +560,7 @@ class Task:
|
|
|
566
560
|
)
|
|
567
561
|
return True
|
|
568
562
|
else:
|
|
569
|
-
self.opencti.
|
|
570
|
-
"error",
|
|
563
|
+
self.opencti.app_logger.error(
|
|
571
564
|
"[opencti_task] Missing parameters: id and stixObjectOrStixRelationshipId",
|
|
572
565
|
)
|
|
573
566
|
return False
|
|
@@ -586,13 +579,12 @@ class Task:
|
|
|
586
579
|
"stixObjectOrStixRelationshipId", None
|
|
587
580
|
)
|
|
588
581
|
if id is not None and stix_object_or_stix_relationship_id is not None:
|
|
589
|
-
self.opencti.
|
|
590
|
-
"
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
+ "}",
|
|
582
|
+
self.opencti.app_logger.info(
|
|
583
|
+
"Removing StixObjectOrStixRelationship in Task",
|
|
584
|
+
{
|
|
585
|
+
"stix_object_or_stix_relationship_id": stix_object_or_stix_relationship_id,
|
|
586
|
+
"id": id,
|
|
587
|
+
},
|
|
596
588
|
)
|
|
597
589
|
query = """
|
|
598
590
|
mutation taskEditRelationDelete($id: ID!, $toId: StixRef!, $relationship_type: String!) {
|
|
@@ -611,8 +603,7 @@ class Task:
|
|
|
611
603
|
)
|
|
612
604
|
return True
|
|
613
605
|
else:
|
|
614
|
-
self.opencti.
|
|
615
|
-
"error",
|
|
606
|
+
self.opencti.app_logger.error(
|
|
616
607
|
"[opencti_task] Missing parameters: id and stixObjectOrStixRelationshipId",
|
|
617
608
|
)
|
|
618
609
|
return False
|
|
@@ -681,12 +672,14 @@ class Task:
|
|
|
681
672
|
update=update,
|
|
682
673
|
)
|
|
683
674
|
else:
|
|
684
|
-
self.opencti.
|
|
675
|
+
self.opencti.app_logger.error(
|
|
676
|
+
"[opencti_task] Missing parameters: stixObject"
|
|
677
|
+
)
|
|
685
678
|
|
|
686
679
|
def delete(self, **kwargs):
|
|
687
680
|
id = kwargs.get("id", None)
|
|
688
681
|
if id is not None:
|
|
689
|
-
|
|
682
|
+
self.opencti.app_logger.info("Deleting Task", {"id": id})
|
|
690
683
|
query = """
|
|
691
684
|
mutation TaskDelete($id: ID!) {
|
|
692
685
|
taskDelete(id: $id)
|
|
@@ -694,5 +687,5 @@ class Task:
|
|
|
694
687
|
"""
|
|
695
688
|
self.opencti.query(query, {"id": id})
|
|
696
689
|
else:
|
|
697
|
-
|
|
690
|
+
self.opencti.app_logger.error("[opencti_task] Missing parameters: id")
|
|
698
691
|
return None
|
|
@@ -6,7 +6,6 @@ from typing import Union
|
|
|
6
6
|
|
|
7
7
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
8
8
|
|
|
9
|
-
from pycti.entities import LOGGER
|
|
10
9
|
from pycti.entities.opencti_threat_actor_group import ThreatActorGroup
|
|
11
10
|
from pycti.entities.opencti_threat_actor_individual import ThreatActorIndividual
|
|
12
11
|
|
|
@@ -185,7 +184,9 @@ class ThreatActor:
|
|
|
185
184
|
if get_all:
|
|
186
185
|
first = 500
|
|
187
186
|
|
|
188
|
-
|
|
187
|
+
self.opencti.app_logger.info(
|
|
188
|
+
"Listing Threat-Actors with filters", {"filters": json.dumps(filters)}
|
|
189
|
+
)
|
|
189
190
|
query = (
|
|
190
191
|
"""
|
|
191
192
|
query ThreatActors($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: ThreatActorsOrdering, $orderMode: OrderingMode) {
|
|
@@ -241,7 +242,7 @@ class ThreatActor:
|
|
|
241
242
|
filters = kwargs.get("filters", None)
|
|
242
243
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
243
244
|
if id is not None:
|
|
244
|
-
|
|
245
|
+
self.opencti.app_logger.info("Reading Threat-Actor", {"id": id})
|
|
245
246
|
query = (
|
|
246
247
|
"""
|
|
247
248
|
query ThreatActor($id: String!) {
|
|
@@ -266,7 +267,9 @@ class ThreatActor:
|
|
|
266
267
|
else:
|
|
267
268
|
return None
|
|
268
269
|
else:
|
|
269
|
-
|
|
270
|
+
self.opencti.app_logger.error(
|
|
271
|
+
"[opencti_threat_actor] Missing parameters: id or filters"
|
|
272
|
+
)
|
|
270
273
|
return None
|
|
271
274
|
|
|
272
275
|
@DeprecationWarning
|
|
@@ -6,8 +6,6 @@ from typing import Union
|
|
|
6
6
|
|
|
7
7
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
8
8
|
|
|
9
|
-
from pycti.entities import LOGGER
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
class ThreatActorGroup:
|
|
13
11
|
"""Main ThreatActorGroup class for OpenCTI
|
|
@@ -182,7 +180,9 @@ class ThreatActorGroup:
|
|
|
182
180
|
if get_all:
|
|
183
181
|
first = 500
|
|
184
182
|
|
|
185
|
-
|
|
183
|
+
self.opencti.app_logger.info(
|
|
184
|
+
"Listing Threat-Actors-Group with filters", {"filters": json.dumps(filters)}
|
|
185
|
+
)
|
|
186
186
|
query = (
|
|
187
187
|
"""
|
|
188
188
|
query ThreatActorsGroup($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: ThreatActorsOrdering, $orderMode: OrderingMode) {
|
|
@@ -238,7 +238,7 @@ class ThreatActorGroup:
|
|
|
238
238
|
filters = kwargs.get("filters", None)
|
|
239
239
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
240
240
|
if id is not None:
|
|
241
|
-
|
|
241
|
+
self.opencti.app_logger.info("Reading Threat-Actor-Group", {"id": id})
|
|
242
242
|
query = (
|
|
243
243
|
"""
|
|
244
244
|
query ThreatActorGroup($id: String!) {
|
|
@@ -265,7 +265,7 @@ class ThreatActorGroup:
|
|
|
265
265
|
else:
|
|
266
266
|
return None
|
|
267
267
|
else:
|
|
268
|
-
|
|
268
|
+
self.opencti.app_logger.error(
|
|
269
269
|
"[opencti_threat_actor_group] Missing parameters: id or filters"
|
|
270
270
|
)
|
|
271
271
|
return None
|
|
@@ -334,7 +334,7 @@ class ThreatActorGroup:
|
|
|
334
334
|
update = kwargs.get("update", False)
|
|
335
335
|
|
|
336
336
|
if name is not None:
|
|
337
|
-
|
|
337
|
+
self.opencti.app_logger.info("Creating Threat-Actor-Group", {"name": name})
|
|
338
338
|
query = """
|
|
339
339
|
mutation ThreatActorGroupAdd($input: ThreatActorGroupAddInput!) {
|
|
340
340
|
threatActorGroupAdd(input: $input) {
|
|
@@ -381,7 +381,7 @@ class ThreatActorGroup:
|
|
|
381
381
|
result["data"]["threatActorGroupAdd"]
|
|
382
382
|
)
|
|
383
383
|
else:
|
|
384
|
-
|
|
384
|
+
self.opencti.app_logger.error(
|
|
385
385
|
"[opencti_threat_actor_group] Missing parameters: name and description"
|
|
386
386
|
)
|
|
387
387
|
|
|
@@ -469,4 +469,6 @@ class ThreatActorGroup:
|
|
|
469
469
|
update=update,
|
|
470
470
|
)
|
|
471
471
|
else:
|
|
472
|
-
|
|
472
|
+
self.opencti.app_logger.error(
|
|
473
|
+
"[opencti_threat_actor_group] Missing parameters: stixObject"
|
|
474
|
+
)
|
|
@@ -6,8 +6,6 @@ from typing import Union
|
|
|
6
6
|
|
|
7
7
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
8
8
|
|
|
9
|
-
from pycti.entities import LOGGER
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
class ThreatActorIndividual:
|
|
13
11
|
"""Main ThreatActorIndividual class for OpenCTI
|
|
@@ -182,8 +180,9 @@ class ThreatActorIndividual:
|
|
|
182
180
|
if get_all:
|
|
183
181
|
first = 500
|
|
184
182
|
|
|
185
|
-
|
|
186
|
-
"Listing Threat-Actors-Individual with filters
|
|
183
|
+
self.opencti.app_logger.info(
|
|
184
|
+
"Listing Threat-Actors-Individual with filters",
|
|
185
|
+
{"filters": json.dumps(filters)},
|
|
187
186
|
)
|
|
188
187
|
query = (
|
|
189
188
|
"""
|
|
@@ -240,7 +239,7 @@ class ThreatActorIndividual:
|
|
|
240
239
|
filters = kwargs.get("filters", None)
|
|
241
240
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
242
241
|
if id is not None:
|
|
243
|
-
|
|
242
|
+
self.opencti.app_logger.info("Reading Threat-Actor-Individual", {"id": id})
|
|
244
243
|
query = (
|
|
245
244
|
"""
|
|
246
245
|
query ThreatActorIndividual($id: String!) {
|
|
@@ -267,7 +266,7 @@ class ThreatActorIndividual:
|
|
|
267
266
|
else:
|
|
268
267
|
return None
|
|
269
268
|
else:
|
|
270
|
-
|
|
269
|
+
self.opencti.app_logger.error(
|
|
271
270
|
"[opencti_threat_actor_individual] Missing parameters: id or filters"
|
|
272
271
|
)
|
|
273
272
|
return None
|
|
@@ -336,7 +335,9 @@ class ThreatActorIndividual:
|
|
|
336
335
|
update = kwargs.get("update", False)
|
|
337
336
|
|
|
338
337
|
if name is not None:
|
|
339
|
-
|
|
338
|
+
self.opencti.app_logger.info(
|
|
339
|
+
"Creating Threat-Actor-Individual", {"name": name}
|
|
340
|
+
)
|
|
340
341
|
query = """
|
|
341
342
|
mutation ThreatActorIndividualAdd($input: ThreatActorIndividualAddInput!) {
|
|
342
343
|
threatActorIndividualAdd(input: $input) {
|
|
@@ -383,7 +384,7 @@ class ThreatActorIndividual:
|
|
|
383
384
|
result["data"]["threatActorIndividualAdd"]
|
|
384
385
|
)
|
|
385
386
|
else:
|
|
386
|
-
|
|
387
|
+
self.opencti.app_logger.error(
|
|
387
388
|
"[opencti_threat_actor_individual] Missing parameters: name and description"
|
|
388
389
|
)
|
|
389
390
|
|
|
@@ -471,6 +472,6 @@ class ThreatActorIndividual:
|
|
|
471
472
|
update=update,
|
|
472
473
|
)
|
|
473
474
|
else:
|
|
474
|
-
|
|
475
|
+
self.opencti.app_logger.error(
|
|
475
476
|
"[opencti_threat_actor_individual] Missing parameters: stixObject"
|
|
476
477
|
)
|
pycti/entities/opencti_tool.py
CHANGED
|
@@ -5,8 +5,6 @@ import uuid
|
|
|
5
5
|
|
|
6
6
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
7
7
|
|
|
8
|
-
from pycti.entities import LOGGER
|
|
9
|
-
|
|
10
8
|
|
|
11
9
|
class Tool:
|
|
12
10
|
def __init__(self, opencti):
|
|
@@ -175,7 +173,9 @@ class Tool:
|
|
|
175
173
|
if get_all:
|
|
176
174
|
first = 100
|
|
177
175
|
|
|
178
|
-
|
|
176
|
+
self.opencti.app_logger.info(
|
|
177
|
+
"Listing Tools with filters", {"filters": json.dumps(filters)}
|
|
178
|
+
)
|
|
179
179
|
query = (
|
|
180
180
|
"""
|
|
181
181
|
query Tools($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: ToolsOrdering, $orderMode: OrderingMode) {
|
|
@@ -215,7 +215,7 @@ class Tool:
|
|
|
215
215
|
final_data = final_data + data
|
|
216
216
|
while result["data"]["tools"]["pageInfo"]["hasNextPage"]:
|
|
217
217
|
after = result["data"]["tools"]["pageInfo"]["endCursor"]
|
|
218
|
-
|
|
218
|
+
self.opencti.app_logger.info("Listing Tools", {"after": after})
|
|
219
219
|
result = self.opencti.query(
|
|
220
220
|
query,
|
|
221
221
|
{
|
|
@@ -248,7 +248,7 @@ class Tool:
|
|
|
248
248
|
filters = kwargs.get("filters", None)
|
|
249
249
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
250
250
|
if id is not None:
|
|
251
|
-
|
|
251
|
+
self.opencti.app_logger.info("Reading Tool", {"id": id})
|
|
252
252
|
query = (
|
|
253
253
|
"""
|
|
254
254
|
query Tool($id: String!) {
|
|
@@ -273,7 +273,9 @@ class Tool:
|
|
|
273
273
|
else:
|
|
274
274
|
return None
|
|
275
275
|
else:
|
|
276
|
-
|
|
276
|
+
self.opencti.app_logger.error(
|
|
277
|
+
"[opencti_tool] Missing parameters: id or filters"
|
|
278
|
+
)
|
|
277
279
|
return None
|
|
278
280
|
|
|
279
281
|
"""
|
|
@@ -305,7 +307,7 @@ class Tool:
|
|
|
305
307
|
update = kwargs.get("update", False)
|
|
306
308
|
|
|
307
309
|
if name is not None:
|
|
308
|
-
|
|
310
|
+
self.opencti.app_logger.info("Creating Tool", {"name": name})
|
|
309
311
|
query = """
|
|
310
312
|
mutation ToolAdd($input: ToolAddInput!) {
|
|
311
313
|
toolAdd(input: $input) {
|
|
@@ -344,7 +346,9 @@ class Tool:
|
|
|
344
346
|
)
|
|
345
347
|
return self.opencti.process_multiple_fields(result["data"]["toolAdd"])
|
|
346
348
|
else:
|
|
347
|
-
|
|
349
|
+
self.opencti.app_logger.error(
|
|
350
|
+
"[opencti_tool] Missing parameters: name and description"
|
|
351
|
+
)
|
|
348
352
|
|
|
349
353
|
"""
|
|
350
354
|
Import an Tool object from a STIX2 object
|
|
@@ -414,4 +418,6 @@ class Tool:
|
|
|
414
418
|
update=update,
|
|
415
419
|
)
|
|
416
420
|
else:
|
|
417
|
-
|
|
421
|
+
self.opencti.app_logger.error(
|
|
422
|
+
"[opencti_tool] Missing parameters: stixObject"
|
|
423
|
+
)
|
|
@@ -17,8 +17,8 @@ class Vocabulary:
|
|
|
17
17
|
|
|
18
18
|
def list(self, **kwargs):
|
|
19
19
|
filters = kwargs.get("filters", None)
|
|
20
|
-
self.opencti.
|
|
21
|
-
"
|
|
20
|
+
self.opencti.app_logger.info(
|
|
21
|
+
"Listing Vocabularies with filters", {"filters": json.dumps(filters)}
|
|
22
22
|
)
|
|
23
23
|
query = (
|
|
24
24
|
"""
|
|
@@ -47,7 +47,7 @@ class Vocabulary:
|
|
|
47
47
|
id = kwargs.get("id", None)
|
|
48
48
|
filters = kwargs.get("filters", None)
|
|
49
49
|
if id is not None:
|
|
50
|
-
self.opencti.
|
|
50
|
+
self.opencti.app_logger.info("Reading vocabulary", {"id": id})
|
|
51
51
|
query = (
|
|
52
52
|
"""
|
|
53
53
|
query Vocabulary($id: String!) {
|
|
@@ -68,8 +68,8 @@ class Vocabulary:
|
|
|
68
68
|
else:
|
|
69
69
|
return None
|
|
70
70
|
else:
|
|
71
|
-
self.opencti.
|
|
72
|
-
"
|
|
71
|
+
self.opencti.app_logger.error(
|
|
72
|
+
"[opencti_vocabulary] Missing parameters: id or filters"
|
|
73
73
|
)
|
|
74
74
|
return None
|
|
75
75
|
|
|
@@ -98,8 +98,8 @@ class Vocabulary:
|
|
|
98
98
|
update = kwargs.get("update", False)
|
|
99
99
|
|
|
100
100
|
if name is not None and category is not None:
|
|
101
|
-
self.opencti.
|
|
102
|
-
"
|
|
101
|
+
self.opencti.app_logger.info(
|
|
102
|
+
"Creating or Getting aliased Vocabulary", {"name": name}
|
|
103
103
|
)
|
|
104
104
|
query = (
|
|
105
105
|
"""
|
|
@@ -130,8 +130,7 @@ class Vocabulary:
|
|
|
130
130
|
)
|
|
131
131
|
return result["data"]["vocabularyAdd"]
|
|
132
132
|
else:
|
|
133
|
-
self.opencti.
|
|
134
|
-
"error",
|
|
133
|
+
self.opencti.app_logger.error(
|
|
135
134
|
"[opencti_vocabulary] Missing parameters: name or category",
|
|
136
135
|
)
|
|
137
136
|
|
|
@@ -155,7 +154,7 @@ class Vocabulary:
|
|
|
155
154
|
id = kwargs.get("id", None)
|
|
156
155
|
input = kwargs.get("input", None)
|
|
157
156
|
if id is not None and input is not None:
|
|
158
|
-
self.opencti.
|
|
157
|
+
self.opencti.app_logger.info("Updating Vocabulary", {"id": id})
|
|
159
158
|
query = """
|
|
160
159
|
mutation VocabularyEdit($id: ID!, $input: [EditInput!]!) {
|
|
161
160
|
vocabularyFieldPatch(id: $id, input: $input) {
|
|
@@ -176,8 +175,7 @@ class Vocabulary:
|
|
|
176
175
|
result["data"]["vocabularyFieldPatch"]
|
|
177
176
|
)
|
|
178
177
|
else:
|
|
179
|
-
self.opencti.
|
|
180
|
-
"
|
|
181
|
-
"[opencti_vocabulary] Missing parameters: id and key and value",
|
|
178
|
+
self.opencti.app_logger.error(
|
|
179
|
+
"[opencti_vocabulary] Missing parameters: id and key and value"
|
|
182
180
|
)
|
|
183
181
|
return None
|
|
@@ -5,8 +5,6 @@ import uuid
|
|
|
5
5
|
|
|
6
6
|
from stix2.canonicalization.Canonicalize import canonicalize
|
|
7
7
|
|
|
8
|
-
from pycti.entities import LOGGER
|
|
9
|
-
|
|
10
8
|
|
|
11
9
|
class Vulnerability:
|
|
12
10
|
def __init__(self, opencti):
|
|
@@ -165,7 +163,9 @@ class Vulnerability:
|
|
|
165
163
|
if get_all:
|
|
166
164
|
first = 100
|
|
167
165
|
|
|
168
|
-
|
|
166
|
+
self.opencti.app_logger.info(
|
|
167
|
+
"Listing Vulnerabilities with filters", {"filters": json.dumps(filters)}
|
|
168
|
+
)
|
|
169
169
|
query = (
|
|
170
170
|
"""
|
|
171
171
|
query Vulnerabilities($filters: FilterGroup, $search: String, $first: Int, $after: ID, $orderBy: VulnerabilitiesOrdering, $orderMode: OrderingMode) {
|
|
@@ -206,7 +206,9 @@ class Vulnerability:
|
|
|
206
206
|
final_data = final_data + data
|
|
207
207
|
while result["data"]["vulnerabilities"]["pageInfo"]["hasNextPage"]:
|
|
208
208
|
after = result["data"]["vulnerabilities"]["pageInfo"]["endCursor"]
|
|
209
|
-
|
|
209
|
+
self.opencti.app_logger.info(
|
|
210
|
+
"Listing Vulnerabilities", {"after": after}
|
|
211
|
+
)
|
|
210
212
|
result = self.opencti.query(
|
|
211
213
|
query,
|
|
212
214
|
{
|
|
@@ -239,7 +241,7 @@ class Vulnerability:
|
|
|
239
241
|
filters = kwargs.get("filters", None)
|
|
240
242
|
custom_attributes = kwargs.get("customAttributes", None)
|
|
241
243
|
if id is not None:
|
|
242
|
-
|
|
244
|
+
self.opencti.app_logger.info("Reading Vulnerability", {"id": id})
|
|
243
245
|
query = (
|
|
244
246
|
"""
|
|
245
247
|
query Vulnerability($id: String!) {
|
|
@@ -264,7 +266,9 @@ class Vulnerability:
|
|
|
264
266
|
else:
|
|
265
267
|
return None
|
|
266
268
|
else:
|
|
267
|
-
|
|
269
|
+
self.opencti.app_logger.error(
|
|
270
|
+
"[opencti_tool] Missing parameters: id or filters"
|
|
271
|
+
)
|
|
268
272
|
return None
|
|
269
273
|
|
|
270
274
|
"""
|
|
@@ -303,7 +307,7 @@ class Vulnerability:
|
|
|
303
307
|
update = kwargs.get("update", False)
|
|
304
308
|
|
|
305
309
|
if name is not None:
|
|
306
|
-
|
|
310
|
+
self.opencti.app_logger.info("Creating Vulnerability", {"name": name})
|
|
307
311
|
query = """
|
|
308
312
|
mutation VulnerabilityAdd($input: VulnerabilityAddInput!) {
|
|
309
313
|
vulnerabilityAdd(input: $input) {
|
|
@@ -347,7 +351,7 @@ class Vulnerability:
|
|
|
347
351
|
result["data"]["vulnerabilityAdd"]
|
|
348
352
|
)
|
|
349
353
|
else:
|
|
350
|
-
|
|
354
|
+
self.opencti.app_logger.error(
|
|
351
355
|
"[opencti_vulnerability] Missing parameters: name and description"
|
|
352
356
|
)
|
|
353
357
|
|
|
@@ -471,4 +475,6 @@ class Vulnerability:
|
|
|
471
475
|
update=update,
|
|
472
476
|
)
|
|
473
477
|
else:
|
|
474
|
-
|
|
478
|
+
self.opencti.app_logger.error(
|
|
479
|
+
"[opencti_vulnerability] Missing parameters: stixObject"
|
|
480
|
+
)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
from pythonjsonlogger import jsonlogger
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CustomJsonFormatter(jsonlogger.JsonFormatter):
|
|
8
|
+
def add_fields(self, log_record, record, message_dict):
|
|
9
|
+
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
|
|
10
|
+
if not log_record.get("timestamp"):
|
|
11
|
+
# This doesn't use record.created, so it is slightly off
|
|
12
|
+
now = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
13
|
+
log_record["timestamp"] = now
|
|
14
|
+
if log_record.get("level"):
|
|
15
|
+
log_record["level"] = log_record["level"].upper()
|
|
16
|
+
else:
|
|
17
|
+
log_record["level"] = record.levelname
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def logger(level, json_logging=True):
|
|
21
|
+
# Exceptions
|
|
22
|
+
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
|
23
|
+
logging.getLogger("pika").setLevel(logging.ERROR)
|
|
24
|
+
# Exceptions
|
|
25
|
+
if json_logging:
|
|
26
|
+
log_handler = logging.StreamHandler()
|
|
27
|
+
log_handler.setLevel(level)
|
|
28
|
+
formatter = CustomJsonFormatter("%(timestamp)s %(level)s %(name)s %(message)s")
|
|
29
|
+
log_handler.setFormatter(formatter)
|
|
30
|
+
logging.basicConfig(handlers=[log_handler], level=level, force=True)
|
|
31
|
+
else:
|
|
32
|
+
logging.basicConfig(level=level)
|
|
33
|
+
|
|
34
|
+
class AppLogger:
|
|
35
|
+
def __init__(self, name):
|
|
36
|
+
self.local_logger = logging.getLogger(name)
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def prepare_meta(meta=None):
|
|
40
|
+
return None if meta is None else {"attributes": meta}
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def setup_logger_level(lib, log_level):
|
|
44
|
+
logging.getLogger(lib).setLevel(log_level)
|
|
45
|
+
|
|
46
|
+
def debug(self, message, meta=None):
|
|
47
|
+
self.local_logger.debug(message, extra=AppLogger.prepare_meta(meta))
|
|
48
|
+
|
|
49
|
+
def info(self, message, meta=None):
|
|
50
|
+
self.local_logger.info(message, extra=AppLogger.prepare_meta(meta))
|
|
51
|
+
|
|
52
|
+
def warning(self, message, meta=None):
|
|
53
|
+
self.local_logger.warning(message, extra=AppLogger.prepare_meta(meta))
|
|
54
|
+
|
|
55
|
+
def error(self, message, meta=None):
|
|
56
|
+
# noinspection PyTypeChecker
|
|
57
|
+
self.local_logger.error(
|
|
58
|
+
message, exc_info=1, extra=AppLogger.prepare_meta(meta)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
return AppLogger
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
test_logger = logger("INFO")("test")
|