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

Commit 03858dd

Browse files
author
Samuel Hassine
committed
[client] Killchain management
1 parent 85cc620 commit 03858dd

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

pycti/entities/opencti_tool.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,47 @@ def create(self, **kwargs):
332332
tags=tags,
333333
)
334334

335+
"""
336+
Import an Tool object from a STIX2 object
337+
338+
:param stixObject: the Stix-Object Tool
339+
:return Tool object
340+
"""
341+
342+
def import_from_stix2(self, **kwargs):
343+
stix_object = kwargs.get("stixObject", None)
344+
extras = kwargs.get("extras", {})
345+
update = kwargs.get("update", False)
346+
if stix_object is not None:
347+
return self.opencti.tool.create(
348+
name=stix_object["name"],
349+
description=self.opencti.stix2.convert_markdown(stix_object["description"])
350+
if "description" in stix_object
351+
else "",
352+
alias=self.opencti.stix2.pick_aliases(stix_object),
353+
id=stix_object[CustomProperties.ID]
354+
if CustomProperties.ID in stix_object
355+
else None,
356+
stix_id_key=stix_object["id"] if "id" in stix_object else None,
357+
created=stix_object["created"] if "created" in stix_object else None,
358+
modified=stix_object["modified"] if "modified" in stix_object else None,
359+
createdByRef=extras["created_by_ref_id"]
360+
if "created_by_ref_id" in extras
361+
else None,
362+
markingDefinitions=extras["marking_definitions_ids"]
363+
if "marking_definitions_ids" in extras
364+
else None,
365+
killChainPhases=extras["kill_chain_phases_ids"]
366+
if "kill_chain_phases_ids" in extras
367+
else None,
368+
tags=extras["tags_ids"] if "tags_ids" in extras else [],
369+
update=update,
370+
)
371+
else:
372+
self.opencti.log(
373+
"error", "[opencti_tool] Missing parameters: stixObject"
374+
)
375+
335376
"""
336377
Export an Tool object in STIX2
337378

pycti/utils/opencti_stix2.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,13 @@ def extract_embedded_relationships(self, stix_object, types=None) -> dict:
270270
kill_chain_phases_ids = []
271271
if "kill_chain_phases" in stix_object:
272272
for kill_chain_phase in stix_object["kill_chain_phases"]:
273-
if kill_chain_phase["phase_name"] in self.mapping_cache:
273+
if (
274+
kill_chain_phase["kill_chain_name"] + kill_chain_phase["phase_name"]
275+
in self.mapping_cache
276+
):
274277
kill_chain_phase = self.mapping_cache[
275-
kill_chain_phase["phase_name"]
278+
kill_chain_phase["kill_chain_name"]
279+
+ kill_chain_phase["phase_name"]
276280
]
277281
else:
278282
kill_chain_phase = self.opencti.kill_chain_phase.create(
@@ -294,7 +298,10 @@ def extract_embedded_relationships(self, stix_object, types=None) -> dict:
294298
if CustomProperties.MODIFIED in kill_chain_phase
295299
else None,
296300
)
297-
self.mapping_cache[kill_chain_phase["phase_name"]] = {
301+
self.mapping_cache[
302+
kill_chain_phase["kill_chain_name"]
303+
+ kill_chain_phase["phase_name"]
304+
] = {
298305
"id": kill_chain_phase["id"],
299306
"type": kill_chain_phase["entity_type"],
300307
}
@@ -1883,31 +1890,9 @@ def create_malware(self, stix_object, extras, update=False):
18831890
update=update,
18841891
)
18851892

1886-
# TODO move in Tool
18871893
def create_tool(self, stix_object, extras, update=False):
1888-
return self.opencti.tool.create(
1889-
name=stix_object["name"],
1890-
description=self.convert_markdown(stix_object["description"])
1891-
if "description" in stix_object
1892-
else "",
1893-
alias=self.pick_aliases(stix_object),
1894-
id=stix_object[CustomProperties.ID]
1895-
if CustomProperties.ID in stix_object
1896-
else None,
1897-
stix_id_key=stix_object["id"] if "id" in stix_object else None,
1898-
created=stix_object["created"] if "created" in stix_object else None,
1899-
modified=stix_object["modified"] if "modified" in stix_object else None,
1900-
createdByRef=extras["created_by_ref_id"]
1901-
if "created_by_ref_id" in extras
1902-
else None,
1903-
markingDefinitions=extras["marking_definitions_ids"]
1904-
if "marking_definitions_ids" in extras
1905-
else None,
1906-
killChainPhases=extras["kill_chain_phases_ids"]
1907-
if "kill_chain_phases_ids" in extras
1908-
else None,
1909-
tags=extras["tags_ids"] if "tags_ids" in extras else [],
1910-
update=update,
1894+
return self.opencti.tool.import_from_stix2(
1895+
stixObject=stix_object, extras=extras, update=update
19111896
)
19121897

19131898
# TODO move in Vulnerability

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ requests==2.23.0
22
PyYAML==5.3.1
33
setuptools==47.1.1
44
python-dateutil==2.8.1
5-
datefinder==0.7.1
5+
datefinder==0.7.0
66
stix2==1.4.0
77
pytz==2020.1
88
pika==1.1.0

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 = "3.3.1"
8+
VERSION = "3.3.2"
99

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

0 commit comments

Comments
 (0)