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

Commit cd13554

Browse files
SouadHadjiatSarahBocognanorichard-julien
authored
[client] Renaming Threat-Actor into Threat-Actor-Group (#3166)
Co-authored-by: sarahBocognano <[email protected]> Co-authored-by: Julien Richard <[email protected]>
1 parent 3a54dd5 commit cd13554

File tree

10 files changed

+511
-166
lines changed

10 files changed

+511
-166
lines changed

pycti/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from .entities.opencti_stix_sighting_relationship import StixSightingRelationship
4646
from .entities.opencti_task import Task
4747
from .entities.opencti_threat_actor import ThreatActor
48+
from .entities.opencti_threat_actor_group import ThreatActorGroup
4849
from .entities.opencti_tool import Tool
4950
from .entities.opencti_vulnerability import Vulnerability
5051
from .utils.constants import (
@@ -111,6 +112,7 @@
111112
"StixObjectOrStixRelationship",
112113
"StixSightingRelationship",
113114
"ThreatActor",
115+
"ThreatActorGroup",
114116
"Tool",
115117
"Vulnerability",
116118
"get_config_variable",

pycti/api/opencti_api_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from pycti.entities.opencti_stix_sighting_relationship import StixSightingRelationship
6060
from pycti.entities.opencti_task import Task
6161
from pycti.entities.opencti_threat_actor import ThreatActor
62+
from pycti.entities.opencti_threat_actor_group import ThreatActorGroup
6263
from pycti.entities.opencti_tool import Tool
6364
from pycti.entities.opencti_vocabulary import Vocabulary
6465
from pycti.entities.opencti_vulnerability import Vulnerability
@@ -181,6 +182,7 @@ def __init__(
181182
self.event = Event(self)
182183
self.location = Location(self)
183184
self.threat_actor = ThreatActor(self)
185+
self.threat_actor_group = ThreatActorGroup(self)
184186
self.intrusion_set = IntrusionSet(self)
185187
self.infrastructure = Infrastructure(self)
186188
self.campaign = Campaign(self)
@@ -407,7 +409,8 @@ def health_check(self):
407409
test = self.threat_actor.list(first=1)
408410
if test is not None:
409411
return True
410-
except:
412+
except Exception as err: # pylint: disable=broad-except
413+
LOGGER.error("%s", err)
411414
return False
412415
return False
413416

pycti/entities/opencti_stix_core_object.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ def __init__(self, opencti, file):
349349
resource_level
350350
primary_motivation
351351
secondary_motivations
352-
personal_motivations
352+
... on ThreatActorGroup {
353+
personal_motivations
354+
}
353355
}
354356
... on Tool {
355357
name

pycti/entities/opencti_stix_domain_object.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ def __init__(self, opencti, file):
437437
resource_level
438438
primary_motivation
439439
secondary_motivations
440-
personal_motivations
440+
... on ThreatActorGroup {
441+
personal_motivations
442+
}
441443
}
442444
... on Tool {
443445
name

pycti/entities/opencti_stix_object_or_stix_relationship.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def __init__(self, opencti):
288288
resource_level
289289
primary_motivation
290290
secondary_motivations
291-
personal_motivations
291+
... on ThreatActorGroup {
292+
personal_motivations
293+
}
292294
}
293295
... on Tool {
294296
name

pycti/entities/opencti_threat_actor.py

Lines changed: 4 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from stix2.canonicalization.Canonicalize import canonicalize
88

99
from pycti.entities import LOGGER
10+
from pycti.entities.opencti_threat_actor_group import ThreatActorGroup
1011

1112

1213
class ThreatActor:
@@ -19,6 +20,7 @@ def __init__(self, opencti):
1920
"""Create an instance of ThreatActor"""
2021

2122
self.opencti = opencti
23+
self.threat_actor_group = ThreatActorGroup(opencti)
2224
self.properties = """
2325
id
2426
standard_id
@@ -130,7 +132,6 @@ def __init__(self, opencti):
130132
resource_level
131133
primary_motivation
132134
secondary_motivations
133-
personal_motivations
134135
importFiles {
135136
edges {
136137
node {
@@ -299,87 +300,9 @@ def create(self, **kwargs):
299300
:param str resource_level: (optional) describe the actors resource_level in text
300301
:param str primary_motivation: (optional) describe the actors primary_motivation in text
301302
:param list secondary_motivations: (optional) describe the actors secondary_motivations in list of string
302-
:param list personal_motivations: (optional) describe the actors personal_motivations in list of strings
303303
:param bool update: (optional) choose to updated an existing Threat-Actor entity, default `False`
304304
"""
305-
306-
stix_id = kwargs.get("stix_id", None)
307-
created_by = kwargs.get("createdBy", None)
308-
object_marking = kwargs.get("objectMarking", None)
309-
object_label = kwargs.get("objectLabel", None)
310-
external_references = kwargs.get("externalReferences", None)
311-
revoked = kwargs.get("revoked", None)
312-
confidence = kwargs.get("confidence", None)
313-
lang = kwargs.get("lang", None)
314-
created = kwargs.get("created", None)
315-
modified = kwargs.get("modified", None)
316-
name = kwargs.get("name", None)
317-
description = kwargs.get("description", None)
318-
aliases = kwargs.get("aliases", None)
319-
threat_actor_types = kwargs.get("threat_actor_types", None)
320-
first_seen = kwargs.get("first_seen", None)
321-
last_seen = kwargs.get("last_seen", None)
322-
goals = kwargs.get("goals", None)
323-
sophistication = kwargs.get("sophistication", None)
324-
resource_level = kwargs.get("resource_level", None)
325-
primary_motivation = kwargs.get("primary_motivation", None)
326-
secondary_motivations = kwargs.get("secondary_motivations", None)
327-
personal_motivations = kwargs.get("personal_motivations", None)
328-
x_opencti_stix_ids = kwargs.get("x_opencti_stix_ids", None)
329-
granted_refs = kwargs.get("objectOrganization", None)
330-
update = kwargs.get("update", False)
331-
332-
if name is not None:
333-
LOGGER.info("Creating Threat-Actor {%s}.", name)
334-
query = """
335-
mutation ThreatActorAdd($input: ThreatActorAddInput!) {
336-
threatActorAdd(input: $input) {
337-
id
338-
standard_id
339-
entity_type
340-
parent_types
341-
}
342-
}
343-
"""
344-
result = self.opencti.query(
345-
query,
346-
{
347-
"input": {
348-
"stix_id": stix_id,
349-
"createdBy": created_by,
350-
"objectMarking": object_marking,
351-
"objectLabel": object_label,
352-
"objectOrganization": granted_refs,
353-
"externalReferences": external_references,
354-
"revoked": revoked,
355-
"confidence": confidence,
356-
"lang": lang,
357-
"created": created,
358-
"modified": modified,
359-
"name": name,
360-
"description": description,
361-
"aliases": aliases,
362-
"threat_actor_types": threat_actor_types,
363-
"first_seen": first_seen,
364-
"last_seen": last_seen,
365-
"goals": goals,
366-
"sophistication": sophistication,
367-
"resource_level": resource_level,
368-
"primary_motivation": primary_motivation,
369-
"secondary_motivations": secondary_motivations,
370-
"personal_motivations": personal_motivations,
371-
"x_opencti_stix_ids": x_opencti_stix_ids,
372-
"update": update,
373-
}
374-
},
375-
)
376-
return self.opencti.process_multiple_fields(
377-
result["data"]["threatActorAdd"]
378-
)
379-
else:
380-
LOGGER.error(
381-
"[opencti_threat_actor] Missing parameters: name and description"
382-
)
305+
return self.threat_actor_group.create(**kwargs)
383306

384307
"""
385308
Import an Threat-Actor object from a STIX2 object
@@ -389,80 +312,4 @@ def create(self, **kwargs):
389312
"""
390313

391314
def import_from_stix2(self, **kwargs):
392-
stix_object = kwargs.get("stixObject", None)
393-
extras = kwargs.get("extras", {})
394-
update = kwargs.get("update", False)
395-
if stix_object is not None:
396-
# Search in extensions
397-
if "x_opencti_stix_ids" not in stix_object:
398-
stix_object[
399-
"x_opencti_stix_ids"
400-
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
401-
if "granted_refs" not in stix_object:
402-
stix_object["granted_refs"] = self.opencti.get_attribute_in_extension(
403-
"granted_refs", stix_object
404-
)
405-
406-
return self.create(
407-
stix_id=stix_object["id"],
408-
createdBy=extras["created_by_id"]
409-
if "created_by_id" in extras
410-
else None,
411-
objectMarking=extras["object_marking_ids"]
412-
if "object_marking_ids" in extras
413-
else None,
414-
objectLabel=extras["object_label_ids"]
415-
if "object_label_ids" in extras
416-
else None,
417-
externalReferences=extras["external_references_ids"]
418-
if "external_references_ids" in extras
419-
else None,
420-
revoked=stix_object["revoked"] if "revoked" in stix_object else None,
421-
confidence=stix_object["confidence"]
422-
if "confidence" in stix_object
423-
else None,
424-
lang=stix_object["lang"] if "lang" in stix_object else None,
425-
created=stix_object["created"] if "created" in stix_object else None,
426-
modified=stix_object["modified"] if "modified" in stix_object else None,
427-
name=stix_object["name"],
428-
description=self.opencti.stix2.convert_markdown(
429-
stix_object["description"]
430-
)
431-
if "description" in stix_object
432-
else None,
433-
aliases=self.opencti.stix2.pick_aliases(stix_object),
434-
threat_actor_types=stix_object["threat_actor_types"]
435-
if "threat_actor_types" in stix_object
436-
else None,
437-
first_seen=stix_object["first_seen"]
438-
if "first_seen" in stix_object
439-
else None,
440-
last_seen=stix_object["last_seen"]
441-
if "last_seen" in stix_object
442-
else None,
443-
goals=stix_object["goals"] if "goals" in stix_object else None,
444-
sophistication=stix_object["sophistication"]
445-
if "sophistication" in stix_object
446-
else None,
447-
resource_level=stix_object["resource_level"]
448-
if "resource_level" in stix_object
449-
else None,
450-
primary_motivation=stix_object["primary_motivation"]
451-
if "primary_motivation" in stix_object
452-
else None,
453-
secondary_motivations=stix_object["secondary_motivations"]
454-
if "secondary_motivations" in stix_object
455-
else None,
456-
personal_motivations=stix_object["personal_motivations"]
457-
if "personal_motivations" in stix_object
458-
else None,
459-
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
460-
if "x_opencti_stix_ids" in stix_object
461-
else None,
462-
objectOrganization=stix_object["granted_refs"]
463-
if "granted_refs" in stix_object
464-
else None,
465-
update=update,
466-
)
467-
else:
468-
LOGGER.error("[opencti_threat_actor] Missing parameters: stixObject")
315+
return self.threat_actor_group.import_from_stix2(**kwargs)

0 commit comments

Comments
 (0)