Skip to content

Commit ed84481

Browse files
author
Samuel Hassine
committed
[client] Implement missing methods and prepare exporting lists
1 parent 6c508b2 commit ed84481

27 files changed

+869
-681
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
import datetime
4+
from dateutil.parser import parse
5+
6+
from pycti import OpenCTIApiClient
7+
8+
# Variables
9+
api_url = 'https://demo.opencti.io'
10+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
11+
12+
# OpenCTI initialization
13+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
14+
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# coding: utf-8
2+
3+
import json
4+
from pycti import OpenCTIApiClient
5+
6+
# Variables
7+
api_url = 'http://localhost:4000'
8+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
9+
10+
# OpenCTI initialization
11+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# coding: utf-8
2+
3+
import json
4+
from pycti import OpenCTIApiClient
5+
6+
# Variables
7+
api_url = 'http://localhost:4000'
8+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
9+
10+
# OpenCTI initialization
11+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
File renamed without changes.

examples/create_indicator_of_campaign.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
)
3838
print(indicator)
3939

40+
# Create the relation
41+
relation = opencti_api_client.stix_relation.create(
42+
fromType='Indicator',
43+
fromId=indicator['id'],
44+
toType='Campaign',
45+
toId=campaign['id'],
46+
relationship_type='indicates',
47+
first_seen=date,
48+
last_seen=date,
49+
description='This is the C2 server of the campaign.'
50+
)
51+
print(relation)
52+
4053
# Create the observables (optional)
4154
observable_1 = opencti_api_client.stix_observable.create(
4255
type='Domain',
@@ -55,16 +68,3 @@
5568
id=indicator['id'],
5669
stix_observable_id=observable_2['id']
5770
)
58-
59-
# Create the relation
60-
relation = opencti_api_client.stix_relation.create(
61-
fromType='Indicator',
62-
fromId=indicator['id'],
63-
toType='Campaign',
64-
toId=campaign['id'],
65-
relationship_type='indicates',
66-
first_seen=date,
67-
last_seen=date,
68-
description='This is the C2 server of the campaign.'
69-
)
70-
print(relation)

examples/export_incident_stix2.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# coding: utf-8
2+
3+
import json
4+
from pycti import OpenCTIApiClient
5+
6+
# Variables
7+
api_url = 'http://localhost:4000'
8+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
9+
10+
# OpenCTI initialization
11+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
12+
13+
# Get the incident created in the create_incident_with_ttps_and_indicators.py
14+
incident = opencti_api_client.incident.read(filters=[{'key': 'name', 'values': ['My new incident']}])
15+
16+
# Create the bundle
17+
bundle = opencti_api_client.stix2.export_entity('incident', incident['id'], 'full')
18+
json_bundle = json.dumps(bundle, indent=4)
19+
20+
# Write the bundle
21+
f = open('My new incident.json', 'w')
22+
f.write(json_bundle)
23+
f.close()

examples/export_incidents_stix2.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding: utf-8
2+
3+
import json
4+
from pycti import OpenCTIApiClient
5+
6+
# Variables
7+
api_url = 'http://localhost:4000'
8+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
9+
10+
# OpenCTI initialization
11+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
12+
13+
# Create the bundle
14+
bundle = opencti_api_client.stix2.export_list('incident')
15+
json_bundle = json.dumps(bundle, indent=4)
16+
17+
# Write the bundle
18+
f = open('Incidents.json', 'w')
19+
f.write(json_bundle)
20+
f.close()

examples/search_attack_pattern.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = 'https://demo.opencti.io'
7+
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+
12+
# Searcj
13+
attack_patterns = opencti_api_client.attack_pattern.list(search='localgroup')
14+
15+
# Print
16+
print(attack_patterns)

0 commit comments

Comments
 (0)