Skip to content

Commit c30a048

Browse files
Merge branch '2.10.0-branch-new-endpoints' into 'develop'
Add new file and URL submission methods to A1000 class See merge request integrations/sdk/reversinglabs-sdk-py3!26
2 parents 2bef3ff + de56e39 commit c30a048

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

ReversingLabs/SDK/a1000.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212
from urllib import parse
1313
from warnings import warn
14+
import json
1415

1516
from ReversingLabs.SDK.helper import ADVANCED_SEARCH_SORTING_CRITERIA, DEFAULT_USER_AGENT, RESPONSE_CODE_ERROR_MAP, \
1617
MD5, SHA1, SHA256, SHA512, \
@@ -26,6 +27,8 @@ class A1000(object):
2627

2728
__TOKEN_ENDPOINT = "/api-token-auth/"
2829
__UPLOAD_ENDPOINT = "/api/uploads/"
30+
__SUBMIT_FILE_ENDPOINT = "/api/submit/file/"
31+
__SUBMIT_URL_ENDPOINT = "/api/submit/url/"
2932
__FILE_ANALYSIS_STATUS_ENDPOINT = "/api/samples/status/"
3033
__URL_ANALYSIS_STATUS_ENDPOINT = "/api/uploads/v2/url-samples/{task_id}"
3134
__RESULTS_ENDPOINT = "/api/samples/list/"
@@ -298,6 +301,101 @@ def submit_url_for_analysis(self, url_string, crawler=None, archive_password=Non
298301

299302
return response
300303

304+
def submit_file(self, file_path, metadata, analysis, custom_filename=None, archive_password=None,rl_cloud_sandbox_platform=None, tags=None, comment=None, cloud_analysis=True):
305+
"""Accepts a file path string for file upload and returns a response.
306+
Additional parameters can be provided.
307+
:param file_path: path to file
308+
:type file_path: str
309+
:param metadata: Optiona JSON metadata dictionary to include with the file
310+
:type metadata: dict
311+
:param analysis: Optional JSON analysis configuration dictionary (e.g. sandbox profiles)
312+
:type analysis: dict
313+
:param custom_filename: custom file name for upload
314+
:type custom_filename: str
315+
:param archive_password: password, if file is a password-protected archive
316+
:type archive_password: str
317+
:param rl_cloud_sandbox_platform: Cloud Sandbox platform (windows7, windows10 or macos_11)
318+
:type rl_cloud_sandbox_platform: str
319+
:param tags: a string of comma separated tags
320+
:type tags: str
321+
:param comment: comment string
322+
:type comment: str
323+
:param cloud_analysis: use cloud analysis
324+
:type cloud_analysis: bool
325+
:return: :class:`Response <Response>` object
326+
:rtype: requests.Response
327+
"""
328+
if not isinstance(file_path, str):
329+
raise WrongInputError("file_path must be a string.")
330+
try:
331+
file_handle = open(file_path, "rb")
332+
except IOError as error:
333+
raise WrongInputError("Error while opening file")
334+
335+
url = self._url.format(endpoint=self.__SUBMIT_FILE_ENDPOINT)
336+
data = self.__create_post_payload(
337+
custom_filename=custom_filename,
338+
archive_password=archive_password,
339+
rl_cloud_sandbox_platform=rl_cloud_sandbox_platform,
340+
tags=tags,
341+
comment=comment,
342+
cloud_analysis=cloud_analysis
343+
) or {}
344+
data["metadata"] = json.dumps(metadata)
345+
data["analysis"] = json.dumps(analysis)
346+
347+
response = self.__post_request(
348+
url=url,
349+
files={"file": file_handle},
350+
data=data
351+
)
352+
print(response.status_code, response.text)
353+
self.__raise_on_error(response)
354+
355+
return response
356+
357+
def submit_url(self, url_to_submit, metadata, analysis, crawler=None, archive_password=None, rl_cloud_sandbox_platform=None):
358+
"""Sends a URL for analysis on A1000.
359+
Additional parameters can be provided.
360+
:param url_to_submit: URL to analyze
361+
:type url_to_submit: str
362+
:param metadata: Optional JSON metadata dictionary to include with the file
363+
:type metadata: dict
364+
:param analysis: Optional JSON analysis configuration dictionary (e.g. sandbox profiles)
365+
:type analysis: dict
366+
:param crawler: crawler method (local or cloud)
367+
:type crawler: str
368+
:param archive_password: password, if it is a password-protected archive
369+
:type archive_password: str
370+
:param rl_cloud_sandbox_platform: Cloud Sandbox platform (windows7, windows10 or macos_11)
371+
:type rl_cloud_sandbox_platform: str
372+
:return: :class:`Response <Response>` object
373+
:rtype: requests.Response
374+
"""
375+
if not isinstance(url_to_submit, str):
376+
raise WrongInputError("url_to_submit parameter must be a string.")
377+
378+
url = self._url.format(endpoint=self.__SUBMIT_URL_ENDPOINT)
379+
380+
data = self.__create_post_payload(
381+
url_string=url_to_submit,
382+
crawler=crawler,
383+
archive_password=archive_password,
384+
rl_cloud_sandbox_platform=rl_cloud_sandbox_platform,
385+
) or {}
386+
data["metadata"] = json.dumps(metadata)
387+
data["analysis"] = json.dumps(analysis)
388+
389+
response = self.__post_request(
390+
url=url,
391+
data=data
392+
)
393+
394+
print(response.status_code, response.text)
395+
self.__raise_on_error(response)
396+
397+
return response
398+
301399
def file_analysis_status(self, sample_hashes, sample_status=None):
302400
"""Accepts a list of file hashes and returns their analysis completion information.
303401
:param sample_hashes: list of hash strings

0 commit comments

Comments
 (0)