forked from splunk-soar-connectors/reversinglabs-a1000v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreversinglabs_a1000v2_connector.py
425 lines (302 loc) · 16.3 KB
/
reversinglabs_a1000v2_connector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File: reversinglabs_a1000v2_connector.py
#
# Copyright (c) ReversingLabs, 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions
# and limitations under the License.
#
from __future__ import print_function, unicode_literals
import json
import os
# Phantom App imports
import phantom.app as phantom
from phantom import vault
from phantom.action_result import ActionResult
from phantom.base_connector import BaseConnector
from phantom.vault import Vault
from ReversingLabs.SDK.a1000 import A1000
# Our helper lib reversinglabs-sdk-py3 internally utilizes pypi requests (with named parameters) which is shadowed by Phantom
# requests (which has renamed parameters (url>>uri), hence this workarounds
old_get = phantom.requests.get
def new_get(url, **kwargs):
return old_get(url, **kwargs)
phantom.requests.get = new_get
old_post = phantom.requests.post
def new_post(url, **kwargs):
return old_post(url, **kwargs)
phantom.requests.post = new_post
old_delete = phantom.requests.delete
def new_delete(url, **kwargs):
return old_delete(url, **kwargs)
phantom.requests.delete = new_delete
class ReversinglabsA1000V2Connector(BaseConnector):
post_url = "post_url"
USER_AGENT = "ReversingLabs Splunk SOAR A1000 v1.0.0"
TITANIUM_CORE_FIELDS = "sha1, sha256, sha512, md5, imphash, info, application, protection, security, behaviour," \
" certificate, document, mobile, media, web, email, strings, interesting_strings," \
" classification, indicators, tags, attack, story"
# The actions supported by this connector
ACTION_ID_TEST_CONNECTIVITY = "test_connectivity"
ACTION_ID_DETONATE_FILE = "detonate_file"
ACTION_ID_DETONATE_FILE_FROM_URL = "detonate_file_from_url"
ACTION_ID_CHECK_SUBMITTED_URL_STATUS = "check_submitted_url_status"
ACTION_ID_CREATE_PDF_REPORT = "create_pdf_report"
ACTION_ID_CHECK_PDF_REPORT_CREATION = "check_pdf_report_creation"
ACTION_ID_DOWNLOAD_PDF_REPORT = "download_pdf_report"
ACTION_ID_GET_TITANIUMCORE_REPORT = "get_titaniumcore_report"
ACTION_ID_URL_REPUTATION = "url_reputation"
ACTION_ID_DOMAIN_REPUTATION = "domain_reputation"
ACTION_ID_IP_REPUTATION = "ip_reputation"
ACTION_ID_NETWORK_IP_TO_DOMAIN = "network_ip_to_domain"
ACTION_ID_NETWORK_URLS_FROM_IP = "network_urls_from_ip"
ACTION_ID_NETWORK_FILES_FROM_IP = "network_files_from_ip"
ACTION_ID_ADVANCED_SEARCH = "advanced_search"
ACTION_ID_CREATE_DYNAMIC_ANALYSIS_REPORT = "create_dynamic_analysis_report"
ACTION_ID_CHeck_DYNAMIC_ANALYSIS_REPORT_STATUS = "check_dynamic_analysis_report_status"
ACTION_ID_DOWNLOAD_DYNAMIC_ANALYSIS_REPORT = "download_dynamic_analysis_report"
ACTION_ID_GET_SUMMARY_REPORT = "get_summary_report"
ACTION_ID_GET_DETAILED_REPORT = "get_detailed_report"
ACTION_ID_GET_CLASSIFICATION = "get_classification"
def __init__(self):
# Call the BaseConnectors init first
super(ReversinglabsA1000V2Connector, self).__init__()
self.ACTIONS = {
self.ACTION_ID_TEST_CONNECTIVITY: self._handle_test_connectivity,
self.ACTION_ID_DETONATE_FILE: self._handle_detonate_file,
self.ACTION_ID_DETONATE_FILE_FROM_URL: self._handle_detonate_file_from_url,
self.ACTION_ID_CHECK_SUBMITTED_URL_STATUS: self._handle_check_submitted_url_status,
self.ACTION_ID_CREATE_PDF_REPORT: self._handle_create_pdf_report,
self.ACTION_ID_CHECK_PDF_REPORT_CREATION: self._handle_check_pdf_report_creation,
self.ACTION_ID_DOWNLOAD_PDF_REPORT: self._handle_download_pdf_report,
self.ACTION_ID_GET_TITANIUMCORE_REPORT: self._handle_get_titaniumcore_report,
self.ACTION_ID_URL_REPUTATION: self._handle_url_reputation,
self.ACTION_ID_DOMAIN_REPUTATION: self._handle_domain_reputation,
self.ACTION_ID_IP_REPUTATION: self._handle_ip_reputation,
self.ACTION_ID_NETWORK_IP_TO_DOMAIN: self._handle_network_ip_to_domain,
self.ACTION_ID_NETWORK_URLS_FROM_IP: self._handle_network_urls_from_ip,
self.ACTION_ID_NETWORK_FILES_FROM_IP: self._handle_network_files_from_ip,
self.ACTION_ID_ADVANCED_SEARCH: self._handle_advanced_search,
self.ACTION_ID_CREATE_DYNAMIC_ANALYSIS_REPORT: self._handle_create_dynamic_analysis_report,
self.ACTION_ID_CHeck_DYNAMIC_ANALYSIS_REPORT_STATUS: self._handle_check_dynamic_analysis_report_status,
self.ACTION_ID_DOWNLOAD_DYNAMIC_ANALYSIS_REPORT: self._handle_download_dynamic_analysis_report,
self.ACTION_ID_GET_SUMMARY_REPORT: self._handle_get_summary_report,
self.ACTION_ID_GET_DETAILED_REPORT: self._handle_get_detailed_report,
self.ACTION_ID_GET_CLASSIFICATION: self._handle_get_classification
}
self._state = None
def initialize(self):
# Load the state in initialize, use it to store data
# that needs to be accessed across actions
self._state = self.load_state()
# get the asset config
config = self.get_config()
self.a1000_url = config["url"]
self.a1000_token = config["token"]
self.a1000 = A1000(
host=self.a1000_url,
token=self.a1000_token,
verify=False,
user_agent=self.USER_AGENT,
)
return phantom.APP_SUCCESS
def finalize(self):
# Save the state, this data is saved across actions and app upgrades
self.save_state(self._state)
return phantom.APP_SUCCESS
def handle_action(self, param):
# Get the action that we are supposed to execute for this App Run
action_id = self.get_action_identifier()
action = self.ACTIONS.get(action_id)
if not action:
return
action_result = self.add_action_result(ActionResult(dict(param)))
try:
action(action_result, param)
except Exception as err:
return action_result.set_status(phantom.APP_ERROR, str(err))
return action_result.set_status(phantom.APP_SUCCESS)
def _handle_detonate_file(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
file_vault_id = param["vault_id"]
success, msg, files_array = vault.vault_info(container_id=self.get_container_id())
if not success:
raise Exception('Unable to get Vault item details. Error details: {0}'.format(msg))
file = next(filter(lambda x: x["vault_id"] == file_vault_id, files_array), None)
if not file:
raise Exception('Unable to get Vault item details. Error details: {0}'.format(msg))
self.a1000.upload_sample_from_path(file["path"])
self.debug_print("Executed", self.get_action_identifier())
def _handle_detonate_file_from_url(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.upload_sample_from_url(
file_url=param.get("file_url")
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_check_submitted_url_status(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.check_submitted_url_status(
task_id=param.get("task_id")
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_create_pdf_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.create_pdf_report(sample_hash=param.get('hash'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_check_pdf_report_creation(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.check_pdf_report_creation(sample_hash=param.get('hash'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_download_pdf_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.download_pdf_report(sample_hash=param.get('hash'))
self.debug_print("Executed", self.get_action_identifier())
file_path = os.path.join(Vault.get_vault_tmp_dir(), param.get("hash"))
with open(file_path, "wb") as file_obj:
file_obj.write(response.content)
success, msg, vault_id = vault.vault_add(file_location=file_path,
container=self.get_container_id(),
file_name="{0}.pdf".format(param.get("hash")))
if not success:
raise Exception('Unable to store file in Vault. Error details: {0}'.format(msg))
def _handle_url_reputation(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_url_report(requested_url=param.get('url'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_domain_reputation(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_domain_report(domain=param.get('domain'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_ip_reputation(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_ip_addr_report(ip_addr=param.get('ip'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_network_ip_to_domain(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_ip_to_domain(ip_addr=param.get('ip'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_network_urls_from_ip(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_urls_from_ip(ip_addr=param.get('ip'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_network_files_from_ip(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.network_files_from_ip(ip_addr=param.get('ip'))
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_advanced_search(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.advanced_search_v2_aggregated(query_string=param.get('query'),
max_results=param.get('limit'),
ticloud=param.get('only_cloud_results'))
self.debug_print("Executed", self.get_action_identifier())
for result in response:
action_result.add_data(result)
def _handle_create_dynamic_analysis_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.create_dynamic_analysis_report(
sample_hash=param.get('hash'),
report_format='pdf'
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_check_dynamic_analysis_report_status(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.check_dynamic_analysis_report_status(
sample_hash=param.get('hash'),
report_format='pdf'
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_download_dynamic_analysis_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.download_dynamic_analysis_report(
sample_hash=param.get('hash'),
report_format='pdf'
)
self.debug_print("Executed", self.get_action_identifier())
file_path = os.path.join(Vault.get_vault_tmp_dir(), param.get("hash"))
with open(file_path, "wb") as file_obj:
file_obj.write(response.content)
success, msg, vault_id = vault.vault_add(file_location=file_path,
container=self.get_container_id(),
file_name="dynamic-{0}.pdf".format(param.get('hash')))
if not success:
raise Exception('Unable to store file in Vault. Error details: {0}'.format(msg))
def _handle_get_summary_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
fields = None
if param.get('fields'):
fields = param.get('fields').split(",")
response = self.a1000.get_summary_report_v2(
sample_hashes=param.get('hash'),
retry=param.get('retry'),
fields=fields,
include_networkthreatintelligence=param.get('include_network_threat_intelligence'),
skip_reanalysis=param.get('skip_reanalysis')
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_get_detailed_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
fields = None
if param.get('fields'):
fields = param.get('fields').split(",")
response = self.a1000.get_detailed_report_v2(
sample_hashes=param.get('hash'),
retry=param.get('retry'),
fields=fields,
skip_reanalysis=param.get('skip_reanalysis')
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_get_classification(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.get_classification_v3(
sample_hash=param.get('hash'),
local_only=param.get('local_only'),
av_scanners=param.get('av_scanners')
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_get_titaniumcore_report(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
response = self.a1000.get_titanium_core_report_v2(
sample_hash=param.get("hash"),
fields=self.TITANIUM_CORE_FIELDS
)
self.debug_print("Executed", self.get_action_identifier())
action_result.add_data(response.json())
def _handle_test_connectivity(self, action_result, param):
self.debug_print("Action handler", self.get_action_identifier())
self.a1000.test_connection()
self.save_progress("Test Connectivity Passed")
def main():
import argparse
argparser = argparse.ArgumentParser()
args = argparser.parse_args()
with open(args.input_test_json) as f:
in_json = f.read()
in_json = json.loads(in_json)
connector = ReversinglabsA1000V2Connector()
connector.print_progress_message = True
connector._handle_action(json.dumps(in_json), None)
exit(0)
if __name__ == '__main__':
main()