ctxis/CAPE

Missing example when submitting a file with parameters via Python

Godlance opened this issue · 3 comments

When submitting files via the REST API using python requests, we have found that there is no documentation explaining how to add options or change analysis parameters.

CAPE (https://github.com/ctxis/CAPE/blob/master/docs/book/src/usage/api.rst)
and Cuckoo (https://cuckoo.sh/docs/usage/api.html#tasks-create-file) docs about using the REST API via python is virtually the same, using the same void of additional options example.

Could you please add a full example to the documentation or at least provide a functional request to test that this is working?

I have tried the following without success:

example 1:

sandbox_file= {"file": (str(secure_filename(file_name_retrieved)), file_retrieved, 'application/octet-stream'), 'Content-Disposition': 'form-data; platform: "windows", options: {' + str(sandbox_send_options)+'}, package:'+ str(package_str), 'Content-Type': 'text/xml'}

example 2:

sandbox_file= {"file": (str(secure_filename(file_name_retrieved)), file_retrieved, 'application/octet-stream'), "platform": 'windows', "options": "{"+str(sandbox_send_options)+"}", "package": str(package_str)}

Where "sandbox_send_options" is a string of several options with the following syntax: option1=val1,option2=val2,option3=val3, etc.

you overcomplica that all,
just go and read code, https://github.com/ctxis/CAPE/blob/master/utils/api.py#L81
we don't have time for docs sorry, if you want feel free to PR updates to it

example
that is default post request
requests.post(url, files=files, data={"filename":X, "timeout":120, "options":"route=tor,another_options_going_here_too", "priority":3, })

pretty simple

and say hello to f00bar ;)

Thank you, in the end it was a simple issue: I wasn't using the data parameter to send the form with the requests option.

I ended up using the solution refered in the the code (creating a dict and assigning it to the data variable) and the sandbox receives the parameters, reflecting it on the log.

I'll run some additional tests and once I have a list of all working options I will drop an example on the documentation for future reference.

Thanks again!

my suggestion is to become more familiar with request library https://realpython.com/python-requests/

you are welcome and glad the issue is solved