Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Add API to download specific file from analysis task #3057

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cuckoo/apps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ def task_screenshots(task_id=0, screenshot=None):
response.headers["Content-Type"] = "application/zip"
return response

@app.route("/tasks/files/<int:task_id>/<file_name>")
@app.route("/v1/tasks/files/<int:task_id>/<file_name>")
def task_files(task_id, file_name):
folder_path = cwd("storage", "analyses", "%s" % task_id, "files")

if not os.path.exists(folder_path):
return json_error(404, "Task not found")

file_path = os.path.join(folder_path, file_name)
if not os.path.exists(file_path) or os.path.dirname(file_path) != folder_path:
return json_error(404, "File not found!")

# TODO: Add content disposition.
response = make_response(open(file_path, "rb").read())
response.headers["Content-Type"] = "application/octet-stream"
return response

@app.route("/tasks/rereport/<int:task_id>")
def rereport(task_id):
task = db.view_task(task_id)
Expand Down
26 changes: 26 additions & 0 deletions docs/book/usage/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ each one. For details click on the resource name.
+-------------------------------------+------------------------------------------------------------------------------------------------------------------+
| ``GET`` :ref:`tasks_shots` | Retrieves one or all screenshots associated with a given analysis task ID. |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------+
| ``GET`` :ref:`tasks_files` | Retrieves one of dropped files associated with a given analysis task ID. |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------+
| ``GET`` :ref:`tasks_rereport` | Re-run reporting for task associated with a given analysis task ID. |
+-------------------------------------+------------------------------------------------------------------------------------------------------------------+
| ``GET`` :ref:`tasks_reboot` | Reboot a given analysis task ID. |
Expand Down Expand Up @@ -731,6 +733,30 @@ Returns one or all screenshots associated with the specified task ID.

* ``404`` - file or folder not found

.. _tasks_files:

/tasks/files
------------------

**GET /tasks/files/** *(int: id)* **/** *(str: file_name)*

Retrieves one of dropped files associated with a given analysis task ID.

**Example request**.

.. code-block:: bash

wget http://localhost:8090/tasks/files/1/0000000000000000_dropped_malware.exe

**Parameters**:

* ``id`` *(required)* *(int)* - ID of the task to get the report for
* ``file_name`` *(required)* - file name that you want to retrieve

**Status codes**:

* ``404`` - file or folder not found

.. _tasks_rereport:

/tasks/rereport
Expand Down