diff --git a/cuckoo/apps/api.py b/cuckoo/apps/api.py index ce383d2d58..8a305da624 100644 --- a/cuckoo/apps/api.py +++ b/cuckoo/apps/api.py @@ -454,6 +454,23 @@ def task_screenshots(task_id=0, screenshot=None): response.headers["Content-Type"] = "application/zip" return response +@app.route("/tasks/files//") +@app.route("/v1/tasks/files//") +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/") def rereport(task_id): task = db.view_task(task_id) diff --git a/docs/book/usage/api.rst b/docs/book/usage/api.rst index 2710bf8e17..eba48af8e2 100644 --- a/docs/book/usage/api.rst +++ b/docs/book/usage/api.rst @@ -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. | @@ -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