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

Commit 391f9a9

Browse files
author
Samuel Hassine
committed
[client] Enhance observable export, artifact payload
1 parent 58d3950 commit 391f9a9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pycti/api/opencti_api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import json
55
import logging
6+
import base64
67
from typing import Union
78

89
import magic
@@ -319,7 +320,7 @@ def query(self, query, variables={}):
319320
logging.info(r.text)
320321
raise ValueError(r.text)
321322

322-
def fetch_opencti_file(self, fetch_uri, binary=False):
323+
def fetch_opencti_file(self, fetch_uri, binary=False, serialize=False):
323324
"""get file from the OpenCTI API
324325
325326
:param fetch_uri: download URI to use
@@ -332,7 +333,11 @@ def fetch_opencti_file(self, fetch_uri, binary=False):
332333

333334
r = self.session.get(fetch_uri, headers=self.request_headers)
334335
if binary:
336+
if serialize:
337+
return base64.b64encode(r.content).decode("utf-8")
335338
return r.content
339+
if serialize:
340+
return base64.b64encode(r.text).decode("utf-8")
336341
return r.text
337342

338343
def log(self, level, message):

pycti/utils/opencti_stix2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,15 @@ def prepare_export(
11651165
if "attribute_date" in entity:
11661166
entity["date"] = entity["attribute_date"]
11671167
del entity["attribute_date"]
1168+
# Artifact
1169+
if entity["type"] == "artifact" and "importFiles" in entity:
1170+
first_file = entity["importFiles"][0]["id"]
1171+
url = self.opencti.api_url.replace("graphql", "storage/get/") + first_file
1172+
file = self.opencti.fetch_opencti_file(url, binary=True, serialize=True)
1173+
if file:
1174+
entity["payload_bin"] = file
1175+
del entity["importFiles"]
1176+
del entity["importFilesIds"]
11681177

11691178
result.append(entity)
11701179

@@ -1400,7 +1409,10 @@ def export_entity(
14001409
"Tool": self.opencti.tool.read,
14011410
"Vulnerability": self.opencti.vulnerability.read,
14021411
"Incident": self.opencti.incident.read,
1412+
"Stix-Cyber-Observable": self.opencti.stix_cyber_observable.read,
14031413
}
1414+
if StixCyberObservableTypes.has_value(entity_type):
1415+
entity_type = "Stix-Cyber-Observable"
14041416
do_read = reader.get(
14051417
entity_type, lambda **kwargs: self.unknown_type({"type": entity_type})
14061418
)

0 commit comments

Comments
 (0)