From 5a262f1afef830c1331997eac98bd289149f7b57 Mon Sep 17 00:00:00 2001 From: Tommy Beadle Date: Tue, 15 Oct 2024 13:10:36 -0400 Subject: [PATCH 1/4] Fix bug when download_file returns success. --- lib/cuckoo/common/web_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index f47fa29f80a..7f7068d67e6 100644 --- a/lib/cuckoo/common/web_utils.py +++ b/lib/cuckoo/common/web_utils.py @@ -1325,10 +1325,10 @@ def thirdpart_aux(samples, prefix, opt_filename, details, settings): details["content"] = content if not details.get("content", False): - status, task_ids_tmp = download_file(**details) + status, task_ids_tmp, *_ = download_file(**details) else: details["service"] = "Local" - status, task_ids_tmp = download_file(**details) + status, task_ids_tmp, *_ = download_file(**details) if status == "error": details["errors"].append({h: task_ids_tmp}) else: From 3e8f9eb1a984a2bb55ffdf741b31665d65c83292 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Tue, 15 Oct 2024 20:48:05 +0200 Subject: [PATCH 2/4] Update web_utils.py --- lib/cuckoo/common/web_utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index 7f7068d67e6..9b8e466a0ec 100644 --- a/lib/cuckoo/common/web_utils.py +++ b/lib/cuckoo/common/web_utils.py @@ -766,7 +766,7 @@ def download_file(**kwargs): if not onesuccess: return "error", {"error": f"Provided hash not found on {kwargs['service']}"} - return "ok", kwargs["task_ids"], extra_details.get("erros", []) + return "ok", {"task_ids": kwargs["task_ids"], "errors": extra_details.get("errors", [])} def save_script_to_storage(task_ids, kwargs): @@ -1324,15 +1324,19 @@ def thirdpart_aux(samples, prefix, opt_filename, details, settings): if content: details["content"] = content + errors = {} if not details.get("content", False): - status, task_ids_tmp, *_ = download_file(**details) + status, tasks_details = download_file(**details) else: details["service"] = "Local" - status, task_ids_tmp, *_ = download_file(**details) + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({h: task_ids_tmp}) + details["errors"].append({h: tasks_details}) else: - details["task_ids"] = task_ids_tmp + details["task_ids"] = tasks_details.get("task_ids") + errors = tasks_details.get("errors") + if errors: + details["errors"].extend(errors) return details From e70c7fc628f29a3fabef703465db7624f41c17f5 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Wed, 16 Oct 2024 07:47:48 +0200 Subject: [PATCH 3/4] update --- lib/cuckoo/common/web_utils.py | 2 +- web/apiv2/views.py | 34 ++++++++------------------- web/submission/views.py | 43 ++++++++++++---------------------- 3 files changed, 26 insertions(+), 53 deletions(-) diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index 9b8e466a0ec..eb10064548c 100644 --- a/lib/cuckoo/common/web_utils.py +++ b/lib/cuckoo/common/web_utils.py @@ -1333,7 +1333,7 @@ def thirdpart_aux(samples, prefix, opt_filename, details, settings): if status == "error": details["errors"].append({h: tasks_details}) else: - details["task_ids"] = tasks_details.get("task_ids") + details["task_ids"] = tasks_details.get("task_ids", []) errors = tasks_details.get("errors") if errors: details["errors"].extend(errors) diff --git a/web/apiv2/views.py b/web/apiv2/views.py index 293c968d090..58aaeda4b92 100644 --- a/web/apiv2/views.py +++ b/web/apiv2/views.py @@ -342,21 +342,13 @@ def tasks_create_file(request): if tmp_path: details["path"] = tmp_path details["content"] = content - demux_error_msgs = [] - - result = download_file(**details) - if len(result) == 2: - status, task_ids_tmp = result - elif len(result) == 3: - status, task_ids_tmp, demux_error_msgs = result - + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({os.path.basename(tmp_path).decode(): task_ids_tmp}) + details["errors"].append({os.path.basename(tmp_path).decode(): tasks_details}) else: - details["task_ids"] = task_ids_tmp - - if demux_error_msgs: - details["errors"].extend(demux_error_msgs) + details["task_ids"] = tasks_details.get("task_ids") + if tasks_details.get("errors"): + details["errors"].extend(tasks_details["errors"]) if details["task_ids"]: tasks_count = len(details["task_ids"]) @@ -576,19 +568,13 @@ def tasks_create_dlnexec(request): "user_id": request.user.id or 0, } - result = download_file(**details) - if len(result) == 2: - status, task_ids_tmp = result - elif len(result) == 3: - status, task_ids_tmp, demux_error_msgs = result - + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({os.path.basename(path).decode(): task_ids_tmp}) + details["errors"].append({os.path.basename(path).decode(): tasks_details}) else: - details["task_ids"] = task_ids_tmp - - if demux_error_msgs: - details["errors"].extend(demux_error_msgs) + details["task_ids"] = tasks_details.get("task_ids") + if tasks_details.get("errors"): + details["errors"].extend(tasks_details["errors"]) if details["task_ids"]: tasks_count = len(details["task_ids"]) diff --git a/web/submission/views.py b/web/submission/views.py index 0efc0db2ba0..47a83650dfc 100644 --- a/web/submission/views.py +++ b/web/submission/views.py @@ -508,17 +508,13 @@ def index(request, task_id=None, resubmit_hash=None): details["path"] = path details["content"] = content - result = download_file(**details) - if len(result) == 2: - status, task_ids_tmp = result - elif len(result) == 3: - status, task_ids_tmp, demux_error_msg = result - if demux_error_msg: - details["errors"].extend(demux_error_msg) + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({os.path.basename(filename): task_ids_tmp}) + details["errors"].append({os.path.basename(filename): tasks_details}) else: - details["task_ids"] = task_ids_tmp + details["task_ids"] = tasks_details.get("task_ids") + if tasks_details.get("errors"): + details["errors"].extend(tasks_details["errors"]) if web_conf.web_reporting.get("enabled", False) and web_conf.general.get("existent_tasks", False): records = perform_search("target_sha256", hash, search_limit=5) if records: @@ -543,23 +539,19 @@ def index(request, task_id=None, resubmit_hash=None): details["path"] = path details["content"] = content - result = download_file(**details) - if len(result) == 2: - status, task_ids_tmp = result - elif len(result) == 3: - status, task_ids_tmp, demux_error_msg = result - if demux_error_msg: - details["errors"].extend(demux_error_msg) + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({os.path.basename(path): task_ids_tmp}) + details["errors"].append({os.path.basename(path): tasks_details}) else: + details["task_ids"] = tasks_details.get("task_ids") + if tasks_details.get("errors"): + details["errors"].extend(tasks_details["errors"]) if web_conf.general.get("existent_tasks", False): records = perform_search("target_sha256", sha256, search_limit=5) if records: for record in records: if record.get("target").get("file", {}).get("sha256"): existent_tasks.setdefault(record["target"]["file"]["sha256"], []).append(record) - details["task_ids"] = task_ids_tmp elif task_category == "static": for content, path, sha256 in list_of_tasks: @@ -631,18 +623,13 @@ def index(request, task_id=None, resubmit_hash=None): details["content"] = content details["service"] = "DLnExec" details["source_url"] = samples - result = download_file(**details) - if len(result) == 2: - status, task_ids_tmp = result - elif len(result) == 3: - status, task_ids_tmp, demux_error_msg = result - if demux_error_msg: - details["errors"].extend(demux_error_msg) - + status, tasks_details = download_file(**details) if status == "error": - details["errors"].append({os.path.basename(path): task_ids_tmp}) + details["errors"].append({os.path.basename(path): tasks_details}) else: - details["task_ids"] = task_ids_tmp + details["task_ids"] = tasks_details.get("task_ids") + if tasks_details.get("errors"): + details["errors"].extend(tasks_details["errors"]) elif task_category == "vtdl": if not settings.VTDL_KEY: From 2008efc7d047d0263be7ae8550c7276817f61c67 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Wed, 16 Oct 2024 07:53:14 +0200 Subject: [PATCH 4/4] ruff --- web/apiv2/views.py | 1 - web/submission/views.py | 1 - 2 files changed, 2 deletions(-) diff --git a/web/apiv2/views.py b/web/apiv2/views.py index 58aaeda4b92..b744aafdb0a 100644 --- a/web/apiv2/views.py +++ b/web/apiv2/views.py @@ -287,7 +287,6 @@ def tasks_create_file(request): "user_id": request.user.id or 0, } - task_ids_tmp = [] task_machines = [] vm_list = [vm.label for vm in db.list_machines()] diff --git a/web/submission/views.py b/web/submission/views.py index 47a83650dfc..39c25136c3a 100644 --- a/web/submission/views.py +++ b/web/submission/views.py @@ -366,7 +366,6 @@ def index(request, task_id=None, resubmit_hash=None): opt_apikey = opts.get("apikey", False) status = "ok" - task_ids_tmp = [] existent_tasks = {} details = { "errors": [],