77from stix2 .canonicalization .Canonicalize import canonicalize
88
99from pycti .entities import LOGGER
10+ from pycti .entities .opencti_threat_actor_group import ThreatActorGroup
1011
1112
1213class 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