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

Commit b9045e4

Browse files
author
Samuel Hassine
committed
[examples] Add an example to link hashes together
1 parent 0cd68dd commit b9045e4

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

examples/link_hashes_together.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# coding: utf-8
2+
3+
import datetime
4+
from pycti import OpenCTIApiClient
5+
6+
# Variables
7+
api_url = 'http://localhost:4000'
8+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
9+
10+
# OpenCTI initialization
11+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
12+
13+
# Create observables
14+
hash_md5 = opencti_api_client.stix_observable.create(
15+
type='File-MD5',
16+
observable_value='16b3f663d0f0371a4706642c6ac04e42',
17+
description='Hash linked to Emotet',
18+
update=True
19+
)
20+
print(hash_md5)
21+
hash_sha1 = opencti_api_client.stix_observable.create(
22+
type='File-SHA1',
23+
observable_value='3a1f908941311fc357051b5c35fd2a4e0c834e37',
24+
description='Hash linked to Emotet',
25+
update=True
26+
)
27+
print(hash_sha1)
28+
hash_sha256 = opencti_api_client.stix_observable.create(
29+
type='File-SHA256',
30+
observable_value='bcc70a49fab005b4cdbe0cbd87863ec622c6b2c656987d201adbb0e05ec03e56',
31+
description='Hash linked to Emotet',
32+
update=True
33+
)
34+
print(hash_sha256)
35+
36+
# Create relations
37+
opencti_api_client.stix_observable_relation.create(
38+
relationship_type='corresponds',
39+
fromType='File-MD5',
40+
fromId=hash_md5['id'],
41+
toType='File-SHA1',
42+
toId=hash_sha1['id'],
43+
ignore_dates=True
44+
)
45+
opencti_api_client.stix_observable_relation.create(
46+
relationship_type='corresponds',
47+
fromType='File-MD5',
48+
fromId=hash_md5['id'],
49+
toType='File-SHA256',
50+
toId=hash_sha256['id'],
51+
ignore_dates=True
52+
)
53+
opencti_api_client.stix_observable_relation.create(
54+
relationship_type='corresponds',
55+
fromType='File-SHA1',
56+
fromId=hash_sha1['id'],
57+
toType='File-SHA256',
58+
toId=hash_sha256['id'],
59+
ignore_dates=True
60+
)

pycti/entities/opencti_stix_observable.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ def create_raw(self, **kwargs):
179179
query = """
180180
mutation StixObservableAdd($input: StixObservableAddInput) {
181181
stixObservableAdd(input: $input) {
182-
id
183-
entity_type
184-
observable_value
182+
""" + self.properties + """
185183
}
186184
}
187185
"""

pycti/entities/opencti_stix_observable_relation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def create_raw(self, **kwargs):
241241
query = """
242242
mutation StixObservableRelationAdd($input: StixObservableRelationAddInput!) {
243243
stixObservableRelationAdd(input: $input) {
244-
id
244+
""" + self.properties + """
245245
}
246246
}
247247
"""

0 commit comments

Comments
 (0)