@@ -269,6 +269,8 @@ def create_raw(self, **kwargs):
269269 valid_from = kwargs .get ("valid_from" , None )
270270 valid_until = kwargs .get ("valid_until" , None )
271271 score = kwargs .get ("score" , None )
272+ confidence = kwargs .get ("confidence" , 50 )
273+ detection = kwargs .get ("detection" , False )
272274 id = kwargs .get ("id" , None )
273275 stix_id_key = kwargs .get ("stix_id_key" , None )
274276 created = kwargs .get ("created" , None )
@@ -309,6 +311,8 @@ def create_raw(self, **kwargs):
309311 "valid_from" : valid_from ,
310312 "valid_until" : valid_until ,
311313 "score" : score ,
314+ "detection" : detection ,
315+ "confidence" : confidence ,
312316 "internal_id_key" : id ,
313317 "stix_id_key" : stix_id_key ,
314318 "created" : created ,
@@ -343,6 +347,8 @@ def create(self, **kwargs):
343347 valid_from = kwargs .get ("valid_from" , None )
344348 valid_until = kwargs .get ("valid_until" , None )
345349 score = kwargs .get ("score" , None )
350+ confidence = kwargs .get ("confidence" , 50 )
351+ detection = kwargs .get ("detection" , False )
346352 id = kwargs .get ("id" , None )
347353 stix_id_key = kwargs .get ("stix_id_key" , None )
348354 created = kwargs .get ("created" , None )
@@ -358,11 +364,13 @@ def create(self, **kwargs):
358364 name
359365 description
360366 score
367+ confidence
368+ detection
361369 createdByRef {
362370 node {
363371 id
364372 }
365- }
373+ }
366374 ... on Indicator {
367375 observableRefs {
368376 edges {
@@ -418,6 +426,18 @@ def create(self, **kwargs):
418426 id = object_result ["id" ], key = "score" , value = score
419427 )
420428 object_result ["score" ] = score
429+ # confidence
430+ if confidence is not None and object_result ["confidence" ] != confidence :
431+ self .opencti .stix_domain_entity .update_field (
432+ id = object_result ["id" ], key = "confidence" , value = confidence
433+ )
434+ object_result ["confidence" ] = confidence
435+ # detection
436+ if detection is not None and object_result ["detection" ] != detection :
437+ self .opencti .stix_domain_entity .update_field (
438+ id = object_result ["id" ], key = "detection" , value = detection
439+ )
440+ object_result ["detection" ] = detection
421441 return object_result
422442 else :
423443 return self .create_raw (
@@ -429,6 +449,8 @@ def create(self, **kwargs):
429449 valid_from = valid_from ,
430450 valid_until = valid_until ,
431451 score = score ,
452+ detection = detection ,
453+ confidence = confidence ,
432454 id = id ,
433455 stix_id_key = stix_id_key ,
434456 created = created ,
@@ -500,6 +522,75 @@ def add_stix_observable(self, **kwargs):
500522 )
501523 return False
502524
525+ """
526+ Import an Indicator object from a STIX2 object
527+
528+ :param stixObject: the Stix-Object Indicator
529+ :return Indicator object
530+ """
531+
532+ def import_from_stix2 (self , ** kwargs ):
533+ stix_object = kwargs .get ("stixObject" , None )
534+ extras = kwargs .get ("extras" , {})
535+ update = kwargs .get ("update" , False )
536+ if stix_object is not None :
537+ pattern_type = "stix"
538+ if CustomProperties .PATTERN_TYPE in stix_object :
539+ pattern_type = stix_object [CustomProperties .PATTERN_TYPE ]
540+ elif "pattern_type" in stix_object :
541+ pattern_type = stix_object ["pattern_type" ]
542+ return self .create (
543+ name = stix_object ["name" ] if "name" in stix_object else "" ,
544+ description = self .opencti .stix2 .convert_markdown (
545+ stix_object ["description" ]
546+ )
547+ if "description" in stix_object
548+ else "" ,
549+ indicator_pattern = stix_object [CustomProperties .INDICATOR_PATTERN ]
550+ if CustomProperties .INDICATOR_PATTERN in stix_object
551+ else stix_object ["pattern" ],
552+ main_observable_type = stix_object [CustomProperties .OBSERVABLE_TYPE ]
553+ if CustomProperties .OBSERVABLE_TYPE in stix_object
554+ else "Unknown" ,
555+ pattern_type = pattern_type ,
556+ valid_from = stix_object ["valid_from" ]
557+ if "valid_from" in stix_object
558+ else None ,
559+ valid_until = stix_object ["valid_until" ]
560+ if "valid_until" in stix_object
561+ else None ,
562+ score = stix_object [CustomProperties .SCORE ]
563+ if CustomProperties .SCORE in stix_object
564+ else None ,
565+ confidence = stix_object ["confidence" ]
566+ if "confidence" in stix_object
567+ else 50 ,
568+ detection = stix_object [CustomProperties .DETECTION ]
569+ if CustomProperties .DETECTION in stix_object
570+ else None ,
571+ id = stix_object [CustomProperties .ID ]
572+ if CustomProperties .ID in stix_object
573+ else None ,
574+ stix_id_key = stix_object ["id" ] if "id" in stix_object else None ,
575+ created = stix_object ["created" ] if "created" in stix_object else None ,
576+ modified = stix_object ["modified" ] if "modified" in stix_object else None ,
577+ createdByRef = extras ["created_by_ref_id" ]
578+ if "created_by_ref_id" in extras
579+ else None ,
580+ markingDefinitions = extras ["marking_definitions_ids" ]
581+ if "marking_definitions_ids" in extras
582+ else None ,
583+ tags = extras ["tags_ids" ] if "tags_ids" in extras else [],
584+ killChainPhases = extras ["kill_chain_phases_ids" ]
585+ if "kill_chain_phases_ids" in extras
586+ else [],
587+ update = update ,
588+ )
589+ else :
590+ self .opencti .log (
591+ "error" , "[opencti_attack_pattern] Missing parameters: stixObject"
592+ )
593+
503594 """
504595 Export an Indicator object in STIX2
505596
@@ -536,9 +627,9 @@ def to_stix2(self, **kwargs):
536627 entity ["valid_until" ]
537628 )
538629 if self .opencti .not_empty (entity ["pattern_type" ]):
539- indicator [CustomProperties . PATTERN_TYPE ] = entity ["pattern_type" ]
630+ indicator ["pattern_type" ] = entity ["pattern_type" ]
540631 else :
541- indicator [CustomProperties . PATTERN_TYPE ] = "stix"
632+ indicator ["pattern_type" ] = "stix"
542633 indicator ["created" ] = self .opencti .stix2 .format_date (entity ["created" ])
543634 indicator ["modified" ] = self .opencti .stix2 .format_date (entity ["modified" ])
544635 if self .opencti .not_empty (entity ["alias" ]):
0 commit comments