Skip to content

Commit 1ba2391

Browse files
author
Samuel Hassine
committed
[client] Fix return bundles on send_stix2
1 parent 8d36620 commit 1ba2391

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

examples/create_incident_with_ttps_and_observables.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@
6363
type='Email-Address',
6464
observable_value='phishing@mail.com'
6565
)
66-
# Indicates the incident itself
67-
observable_ttp1_incident_relation = opencti_api_client.stix_relation.create(
68-
fromType='Stix-Observable',
69-
fromId=observable_ttp1['id'],
70-
toType='Incident',
71-
toId=incident['id'],
72-
relationship_type='indicates',
73-
description='This email address is the sender of the spearphishing in this incident.',
74-
first_seen=date,
75-
last_seen=date
76-
)
7766
# Indicates the relation Incident => uses => TTP
7867
observable_ttp1_relation = opencti_api_client.stix_relation.create(
7968
fromType='Stix-Observable',
@@ -90,7 +79,7 @@
9079
ttp1['id'],
9180
ttp1_relation['id'],
9281
observable_ttp1['id'],
93-
observable_ttp1_incident_relation['id']
82+
observable_ttp1_relation['id']
9483
])
9584

9685
# Registry Run Keys / Startup Folder
@@ -118,17 +107,6 @@
118107
type='Registry-Key',
119108
observable_value='Disk security'
120109
)
121-
# Indicates the incident itself
122-
observable_ttp2_incident_relation = opencti_api_client.stix_relation.create(
123-
fromType='Stix-Observable',
124-
fromId=observable_ttp2['id'],
125-
toType='Incident',
126-
toId=incident['id'],
127-
relationship_type='indicates',
128-
description='This registry key is used for persistence of tools in this incident.',
129-
first_seen=date,
130-
last_seen=date
131-
)
132110
# Indicates the relation Incident => uses => TTP
133111
observable_ttp2_relation = opencti_api_client.stix_relation.create(
134112
fromType='Stix-Observable',
@@ -145,7 +123,7 @@
145123
ttp2['id'],
146124
ttp2_relation['id'],
147125
observable_ttp2['id'],
148-
observable_ttp2_incident_relation['id']
126+
observable_ttp2_relation['id']
149127
])
150128

151129
# Data Encrypted
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# coding: utf-8
2+
3+
from pycti import OpenCTIApiClient
4+
5+
# Variables
6+
api_url = 'https://demo.opencti.io'
7+
api_token = 'c2d944bb-aea6-4bd6-b3d7-6c10451e2256'
8+
9+
# OpenCTI initialization
10+
opencti_api_client = OpenCTIApiClient(api_url, api_token)
11+

pycti/connector/opencti_connector_helper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ def send_stix2_bundle(self, bundle, entities_types=None, update=False, split=Tru
177177
channel = pika_connection.channel()
178178
for bundle in bundles:
179179
self._send_bundle(channel, bundle, entities_types, update)
180+
channel.close()
181+
return bundles
180182
else:
181183
pika_connection = pika.BlockingConnection(pika.URLParameters(self.config['uri']))
182184
channel = pika_connection.channel()
183185
self._send_bundle(channel, bundle, entities_types, update)
184-
channel.close()
185-
return True
186+
channel.close()
187+
return [bundle]
186188

187189
def _send_bundle(self, channel, bundle, entities_types=None, update=False):
188190
"""

0 commit comments

Comments
 (0)