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

Commit 1f67999

Browse files
author
Samuel Hassine
committed
Add new methods
1 parent 157acdb commit 1f67999

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ build
55
dist
66
pycti.egg-info
77
logs
8-
test.py
8+
test.py
9+
.idea

pycti/opencti.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def update_connector_config(self, identifier, config):
121121
"""
122122
self.query(query, {
123123
'identifier': identifier,
124-
'config': base64.b64encode(json.dumps(config).encode('ascii'))
124+
'config': base64.b64encode(json.dumps(config).encode('ascii')).decode('ascii')
125125
})
126126

127127
def get_stix_domain_entity(self, id):
@@ -3470,6 +3470,9 @@ def stix2_export_entity(self, entity_type, entity_id, mode='simple'):
34703470
}
34713471
if entity_type == 'report':
34723472
bundle['objects'] = stix2.export_report(self.parse_stix(self.get_report(entity_id)), mode)
3473+
if entity_type == 'threat-actor':
3474+
bundle['objects'] = stix2.export_threat_actor(self.parse_stix(self.get_threat_actor(entity_id)))
3475+
34733476
return bundle
34743477

34753478
def stix2_export_bundle(self, types=[]):

pycti/stix2.py

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,27 @@ def import_object(self, stix_object, update=False):
311311
else:
312312
published = datetime.datetime.today().strftime('%Y-%m-%dT%H:%M:%SZ')
313313

314-
title = source_name
314+
if 'mitre-attack (' in source_name and 'name' in stix_object:
315+
title = '[MITRE ATT&CK] ' + stix_object['name']
316+
else:
317+
title = source_name
318+
315319
if 'external_id' in external_reference:
316320
title = title + ' (' + external_reference['external_id'] + ')'
317321
report_id = self.opencti.create_report_if_not_exists_from_external_reference(
318322
external_reference_id,
319323
title,
320324
external_reference['description'] if 'description' in external_reference else None,
321325
published,
322-
'external'
326+
'external',
327+
2
323328
)['id']
324329

330+
# Resolve author
331+
author_id = self.resolve_author(title)
332+
if author_id is not None:
333+
self.opencti.update_stix_domain_entity_created_by_ref(report_id, author_id)
334+
325335
# Add marking
326336
if 'marking_tlpwhite' in self.mapping_cache:
327337
object_marking_ref_result = self.mapping_cache['marking_tlpwhite']
@@ -910,9 +920,15 @@ def import_relationship(self, stix_relation):
910920
title,
911921
external_reference['description'] if 'description' in external_reference else None,
912922
published,
913-
'external'
923+
'external',
924+
2
914925
)['id']
915926

927+
# Resolve author
928+
author_id = self.resolve_author(title)
929+
if author_id is not None:
930+
self.opencti.update_stix_domain_entity_created_by_ref(report_id, author_id)
931+
916932
# Add marking
917933
if 'marking_tlpwhite' in self.mapping_cache:
918934
object_marking_ref_result = self.mapping_cache['marking_tlpwhite']
@@ -930,6 +946,65 @@ def import_relationship(self, stix_relation):
930946
self.opencti.add_object_ref_to_report_if_not_exists(report_id, target_id)
931947
self.opencti.add_object_ref_to_report_if_not_exists(report_id, stix_relation_id)
932948

949+
def resolve_author(self, title):
950+
if 'fireeye' in title.lower():
951+
if 'FireEye' in self.mapping_cache:
952+
return self.mapping_cache['FireEye']
953+
else:
954+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'FireEye', '')['id']
955+
self.mapping_cache['FireEye'] = author_id
956+
return author_id
957+
if 'eset' in title.lower():
958+
if 'ESET' in self.mapping_cache:
959+
return self.mapping_cache['ESET']
960+
else:
961+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'ESET', '')['id']
962+
self.mapping_cache['ESET'] = author_id
963+
return author_id
964+
if 'unit 42' in title.lower():
965+
if 'PaloAlto' in self.mapping_cache:
966+
return self.mapping_cache['PaloAlto']
967+
else:
968+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'Palo Alto Networks', '')['id']
969+
self.mapping_cache['PaloAlto'] = author_id
970+
return author_id
971+
if 'accenture' in title.lower():
972+
if 'Accenture' in self.mapping_cache:
973+
return self.mapping_cache['Accenture']
974+
else:
975+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'Accenture', '')['id']
976+
self.mapping_cache['Accenture'] = author_id
977+
return author_id
978+
if 'symantec' in title.lower():
979+
if 'Symantec' in self.mapping_cache:
980+
return self.mapping_cache['Symantec']
981+
else:
982+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'Symantec', '')['id']
983+
self.mapping_cache['Symantec'] = author_id
984+
return author_id
985+
if 'mcafee' in title.lower():
986+
if 'McAfee' in self.mapping_cache:
987+
return self.mapping_cache['McAfee']
988+
else:
989+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'McAfee', '')['id']
990+
self.mapping_cache['McAfee'] = author_id
991+
return author_id
992+
if 'crowdstrike' in title.lower():
993+
if 'CrowdStrike' in self.mapping_cache:
994+
return self.mapping_cache['CrowdStrike']
995+
else:
996+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'CrowdStrike', '')['id']
997+
self.mapping_cache['CrowdStrike'] = author_id
998+
return author_id
999+
if 'mitre atta&ck' in title.lower():
1000+
if 'Mitre' in self.mapping_cache:
1001+
return self.mapping_cache['Mitre']
1002+
else:
1003+
author_id = self.opencti.create_identity_if_not_exists('Organization', 'The MITRE Corporation', '')['id']
1004+
self.mapping_cache['Mitre'] = author_id
1005+
return author_id
1006+
return None
1007+
9331008
def import_bundle(self, stix_bundle, update=False, types=[]):
9341009
# Check if the bundle is correctly formated
9351010
if 'type' not in stix_bundle or stix_bundle['type'] != 'bundle':

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
print("warning: pypandoc module not found, could not convert Markdown to RST")
1313
read_md = lambda f: open(f, 'r').read()
1414

15-
VERSION = "1.0.9"
15+
VERSION = "1.0.10"
1616

1717
class VerifyVersionCommand(install):
1818
description = 'verify that the git tag matches our version'

0 commit comments

Comments
 (0)