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

Commit 45ec602

Browse files
authored
[client] Addition of STIX Cyber Observables examples (#147)
* Added relevant CyberObservable examples * Removed empty example
1 parent dd9a2c6 commit 45ec602

File tree

5 files changed

+159
-10
lines changed

5 files changed

+159
-10
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = "https://demo.opencti.io"
7+
api_token = "YOUR_TOKEN"
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
# Create the observable
13+
url = opencti_api_client.stix_cyber_observable.create(
14+
observableData={
15+
"type": "url",
16+
"value": "http://johndoe.com"
17+
}
18+
)
19+
# Create the tag (if not exists)
20+
label = opencti_api_client.label.create(
21+
value="Suspicious",
22+
color="#ffa500",
23+
)
24+
25+
# Add the tag
26+
opencti_api_client.stix_cyber_observable.add_label(id=url["id"], label_id=label["id"])
27+
28+
# Read the observable
29+
obs = opencti_api_client.stix_cyber_observable.read(id=url["id"])
30+
print(obs)

examples/create_ip_address_resolves_domain.py

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = "https://demo.opencti.io"
7+
api_token = "YOUR_TOKEN"
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
observable = opencti_api_client.stix_cyber_observable.create(
13+
observableData={
14+
"type": "file",
15+
"hashes": {
16+
"md5": "16b3f663d0f0371a4706642c6ac04e42",
17+
"sha1": "3a1f908941311fc357051b5c35fd2a4e0c834e37",
18+
"sha256": "bcc70a49fab005b4cdbe0cbd87863ec622c6b2c656987d201adbb0e05ec03e56",
19+
},
20+
}
21+
)
22+
23+
process = opencti_api_client.stix_cyber_observable.create(
24+
observableData = {
25+
"type": "Process",
26+
"x_opencti_description": "A process",
27+
"cwd": "C:\Process.exe",
28+
"pid": "19000",
29+
"command_line": "--run exe",
30+
"x_opencti_score": 90
31+
}
32+
)
33+
34+
author = opencti_api_client.identity.create(
35+
name="John's Work",
36+
description="Automated Toolkit",
37+
type="Organization",
38+
)
39+
40+
opencti_api_client.stix_core_relationship.create(
41+
toId=observable["id"],
42+
toType="StixFile",
43+
fromId=process["id"],
44+
fromType="Process",
45+
confidence=90,
46+
createdBy=author["id"],
47+
relationship_type="related-to",
48+
description="Relation between the File and Process objects"
49+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = "https://demo.opencti.io"
7+
api_token = "YOUR_TOKEN"
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
process = opencti_api_client.stix_cyber_observable.create(
13+
observableData = {
14+
"type": "Process",
15+
"x_opencti_description": "A process",
16+
"cwd": "C:\Process.exe",
17+
"pid": "19000",
18+
"command_line": "--run exe",
19+
"x_opencti_score": 90
20+
}
21+
)
22+
23+
print(process)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = "https://demo.opencti.io"
7+
api_token = "YOUR_TOKEN"
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
# Create an observable
13+
observable = opencti_api_client.stix_cyber_observable.create(
14+
observableData = {
15+
"type": "file",
16+
"x_opencti_description":"A malicious file",
17+
"hashes": {
18+
"MD5": "348aefbb6142d4fff8cf26fc5dc97f8a",
19+
"SHA-1": "486e7e66c3a098c1c8f42e26c78f259d6b3108a6",
20+
"SHA-256": "42c5e1fe01e689e550ba700b3c5dd4a04a84798c1868ba53c02abcbe21491515"
21+
},
22+
"x_opencti_score": "90"
23+
})
24+
25+
# Update the fields
26+
27+
reference = opencti_api_client.external_reference.create(
28+
source_name="Jen",
29+
url="https://janedoe.com",
30+
description="Sample Report"
31+
)
32+
33+
opencti_api_client.stix_cyber_observable.add_external_reference(
34+
id=observable["id"],
35+
external_reference_id=reference["id"]
36+
)
37+
38+
label = opencti_api_client.label.create(
39+
value="Suspicious",
40+
color="#ffa500",
41+
)
42+
43+
opencti_api_client.stix_cyber_observable.add_marking_definition(
44+
id=observable["id"],
45+
marking_definition_id=label["id"]
46+
)
47+
48+
author = opencti_api_client.identity.create(
49+
name="John's Work",
50+
description="Automated Toolkit",
51+
type="Organization",
52+
)
53+
54+
opencti_api_client.stix_cyber_observable.update_created_by(
55+
id=observable["id"],
56+
identity_id=author["id"]
57+
)

0 commit comments

Comments
 (0)