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

Commit b469030

Browse files
author
Samuel Hassine
committed
[client] Allow sightings with observables
1 parent d5b3ac1 commit b469030

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

pycti/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
from .utils.opencti_stix2 import OpenCTIStix2
4444
from .utils.opencti_stix2_splitter import OpenCTIStix2Splitter
4545
from .utils.opencti_stix2_update import OpenCTIStix2Update
46-
from .utils.opencti_stix2_utils import OpenCTIStix2Utils, SimpleObservable
46+
from .utils.opencti_stix2_utils import (
47+
OpenCTIStix2Utils,
48+
SimpleObservable,
49+
StixXOpenCTIIncident,
50+
)
4751
from .utils.constants import StixCyberObservableTypes
4852

4953
__all__ = [
@@ -87,4 +91,5 @@
8791
"OpenCTIStix2Utils",
8892
"StixCyberObservableTypes",
8993
"SimpleObservable",
94+
"StixXOpenCTIIncident",
9095
]

pycti/entities/opencti_stix_core_relationship.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,19 @@ def import_from_stix2(self, **kwargs):
10251025
stix_relation["relationship_type"] = "part-of"
10261026
elif stix_relation["relationship_type"] == "localization":
10271027
stix_relation["relationship_type"] = "located-at"
1028-
1028+
source_ref = (
1029+
stix_relation["x_opencti_source_ref"]
1030+
if "x_opencti_source_ref" in stix_relation
1031+
else stix_relation["source_ref"]
1032+
)
1033+
target_ref = (
1034+
stix_relation["x_opencti_target_ref"]
1035+
if "x_opencti_target_ref" in stix_relation
1036+
else stix_relation["target_ref"]
1037+
)
10291038
return self.create(
1030-
fromId=stix_relation["source_ref"],
1031-
toId=stix_relation["target_ref"],
1039+
fromId=source_ref,
1040+
toId=target_ref,
10321041
stix_id=stix_relation["id"],
10331042
relationship_type=stix_relation["relationship_type"],
10341043
description=self.opencti.stix2.convert_markdown(

pycti/utils/opencti_stix2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,13 +1490,15 @@ def import_bundle(self, stix_bundle, update=False, types=None) -> List:
14901490
if "where_sighted_refs" in item:
14911491
for where_sighted_ref in item["where_sighted_refs"]:
14921492
to_ids.append(where_sighted_ref)
1493-
14941493
# Import sighting_of_ref
1495-
from_id = item["sighting_of_ref"]
1494+
from_id = (
1495+
item["x_opencti_sighting_of_ref"]
1496+
if "x_opencti_sighting_of_ref" in item
1497+
else item["sighting_of_ref"]
1498+
)
14961499
if len(to_ids) > 0:
14971500
for to_id in to_ids:
14981501
self.import_sighting(item, from_id, to_id, update)
1499-
15001502
# Import observed_data_refs
15011503
if "observed_data_refs" in item:
15021504
for observed_data_ref in item["observed_data_refs"]:

pycti/utils/opencti_stix2_utils.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
EqualityComparisonExpression,
55
ObservationExpression,
66
CustomObservable,
7+
CustomObject,
78
ExternalReference,
89
properties,
910
)
@@ -89,3 +90,32 @@ def generate_random_stix_id(stix_type):
8990
)
9091
class SimpleObservable:
9192
pass
93+
94+
95+
@CustomObject(
96+
"x-opencti-incident",
97+
[
98+
("name", properties.StringProperty(required=True)),
99+
("description", properties.StringProperty()),
100+
("aliases", properties.ListProperty(contained=properties.StringProperty())),
101+
("first_seen", properties.TimestampProperty()),
102+
("last_seen", properties.TimestampProperty()),
103+
("objective", properties.StringProperty()),
104+
(
105+
"created_by_ref",
106+
properties.ReferenceProperty(valid_types="identity", spec_version="2.1"),
107+
),
108+
("labels", properties.ListProperty(properties.StringProperty)),
109+
("external_references", properties.ListProperty(ExternalReference)),
110+
(
111+
"object_marking_refs",
112+
properties.ListProperty(
113+
properties.ReferenceProperty(
114+
valid_types="marking-definition", spec_version="2.1"
115+
)
116+
),
117+
),
118+
],
119+
)
120+
class StixXOpenCTIIncident:
121+
pass

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.2.1"
8+
VERSION = "4.2.2"
99

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

0 commit comments

Comments
 (0)