diff --git a/lib/cuckoo/common/web_utils.py b/lib/cuckoo/common/web_utils.py index 60b4eff6c70..eb10064548c 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("errors", []) + 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 diff --git a/web/apiv2/views.py b/web/apiv2/views.py index 293c968d090..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()] @@ -342,21 +341,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 +567,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..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": [], @@ -508,17 +507,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 +538,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 +622,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: