11
11
import time
12
12
from urllib import parse
13
13
from warnings import warn
14
+ import json
14
15
15
16
from ReversingLabs .SDK .helper import ADVANCED_SEARCH_SORTING_CRITERIA , DEFAULT_USER_AGENT , RESPONSE_CODE_ERROR_MAP , \
16
17
MD5 , SHA1 , SHA256 , SHA512 , \
@@ -26,6 +27,8 @@ class A1000(object):
26
27
27
28
__TOKEN_ENDPOINT = "/api-token-auth/"
28
29
__UPLOAD_ENDPOINT = "/api/uploads/"
30
+ __SUBMIT_FILE_ENDPOINT = "/api/submit/file/"
31
+ __SUBMIT_URL_ENDPOINT = "/api/submit/url/"
29
32
__FILE_ANALYSIS_STATUS_ENDPOINT = "/api/samples/status/"
30
33
__URL_ANALYSIS_STATUS_ENDPOINT = "/api/uploads/v2/url-samples/{task_id}"
31
34
__RESULTS_ENDPOINT = "/api/samples/list/"
@@ -298,6 +301,101 @@ def submit_url_for_analysis(self, url_string, crawler=None, archive_password=Non
298
301
299
302
return response
300
303
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
+
301
399
def file_analysis_status (self , sample_hashes , sample_status = None ):
302
400
"""Accepts a list of file hashes and returns their analysis completion information.
303
401
:param sample_hashes: list of hash strings
0 commit comments