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

Commit 9834c63

Browse files
author
Samuel Hassine
committed
[client] Fix the export of STIX relationships (#134)
1 parent f433de6 commit 9834c63

File tree

3 files changed

+535
-1
lines changed

3 files changed

+535
-1
lines changed

pycti/utils/opencti_stix2.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,20 @@ def prepare_export(
10841084
if "objects" in entity:
10851085
del entity["objects"]
10861086
del entity["objectsIds"]
1087+
# Stix Sighting Relationship
1088+
if entity["type"] == "stix-sighting-relationship":
1089+
entity["type"] = "sighting"
1090+
entity["count"] = entity["attribute_count"]
1091+
del entity["attribute_count"]
1092+
entity["sighting_of_ref"] = entity["from"]["standard_id"]
1093+
objects_to_get.append(entity["from"]["standard_id"])
1094+
entity["where_sighted_refs"] = entity["to"]["standard_id"]
1095+
objects_to_get.append(entity["to"]["standard_id"])
1096+
del entity["from"]
1097+
del entity["to"]
10871098
# Stix Core Relationship
1099+
if "from" in entity or "to" in entity:
1100+
entity["type"] = "relationship"
10881101
if "from" in entity:
10891102
entity["source_ref"] = entity["from"]["standard_id"]
10901103
objects_to_get.append(entity["from"]["standard_id"])
@@ -1095,6 +1108,7 @@ def prepare_export(
10951108
objects_to_get.append(entity["to"]["standard_id"])
10961109
if "to" in entity:
10971110
del entity["to"]
1111+
# Stix Cyber Observable
10981112
if "observable_value" in entity:
10991113
del entity["observable_value"]
11001114

@@ -1141,6 +1155,41 @@ def prepare_export(
11411155
+ stix_core_relationship["id"]
11421156
+ '" are less than max definition, not exporting the relation AND the target entity.',
11431157
)
1158+
# Get sighting
1159+
stix_sighting_relationships = self.opencti.stix_sighting_relationship.list(
1160+
fromId=entity["x_opencti_id"]
1161+
)
1162+
for stix_sighting_relationship in stix_sighting_relationships:
1163+
if self.check_max_marking_definition(
1164+
max_marking_definition_entity,
1165+
stix_sighting_relationship["objectMarking"]
1166+
if "objectMarking" in stix_sighting_relationship
1167+
else None,
1168+
):
1169+
objects_to_get.append(
1170+
stix_sighting_relationship["to"]
1171+
if stix_sighting_relationship["to"]["id"] != entity["x_opencti_id"]
1172+
else stix_sighting_relationship["from"]
1173+
)
1174+
relation_object_data = self.prepare_export(
1175+
self.generate_export(stix_sighting_relationship),
1176+
"simple",
1177+
max_marking_definition_entity,
1178+
)
1179+
relation_object_bundle = self.filter_objects(
1180+
uuids, relation_object_data
1181+
)
1182+
uuids = uuids + [x["id"] for x in relation_object_bundle]
1183+
result = result + relation_object_bundle
1184+
else:
1185+
self.opencti.log(
1186+
"info",
1187+
"Marking definitions of "
1188+
+ stix_sighting_relationship["entity_type"]
1189+
+ ' "'
1190+
+ stix_sighting_relationship["id"]
1191+
+ '" are less than max definition, not exporting the relation AND the target entity.',
1192+
)
11441193
# Export
11451194
reader = {
11461195
"Attack-Pattern": self.opencti.attack_pattern.read,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from setuptools import setup
66
from setuptools.command.install import install
77

8-
VERSION = "4.0.7"
8+
VERSION = "4.1.0"
99

1010
with open("README.md", "r") as fh:
1111
long_description = fh.read()

0 commit comments

Comments
 (0)