Skip to content

Commit 6b66d47

Browse files
authored
Fix bug when download_file returns success. (#2356)
1 parent 0b7eee8 commit 6b66d47

File tree

3 files changed

+34
-59
lines changed

3 files changed

+34
-59
lines changed

lib/cuckoo/common/web_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def download_file(**kwargs):
766766
if not onesuccess:
767767
return "error", {"error": f"Provided hash not found on {kwargs['service']}"}
768768

769-
return "ok", kwargs["task_ids"], extra_details.get("errors", [])
769+
return "ok", {"task_ids": kwargs["task_ids"], "errors": extra_details.get("errors", [])}
770770

771771

772772
def save_script_to_storage(task_ids, kwargs):
@@ -1324,15 +1324,19 @@ def thirdpart_aux(samples, prefix, opt_filename, details, settings):
13241324
if content:
13251325
details["content"] = content
13261326

1327+
errors = {}
13271328
if not details.get("content", False):
1328-
status, task_ids_tmp = download_file(**details)
1329+
status, tasks_details = download_file(**details)
13291330
else:
13301331
details["service"] = "Local"
1331-
status, task_ids_tmp = download_file(**details)
1332+
status, tasks_details = download_file(**details)
13321333
if status == "error":
1333-
details["errors"].append({h: task_ids_tmp})
1334+
details["errors"].append({h: tasks_details})
13341335
else:
1335-
details["task_ids"] = task_ids_tmp
1336+
details["task_ids"] = tasks_details.get("task_ids", [])
1337+
errors = tasks_details.get("errors")
1338+
if errors:
1339+
details["errors"].extend(errors)
13361340

13371341
return details
13381342

web/apiv2/views.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ def tasks_create_file(request):
287287
"user_id": request.user.id or 0,
288288
}
289289

290-
task_ids_tmp = []
291290
task_machines = []
292291
vm_list = [vm.label for vm in db.list_machines()]
293292

@@ -342,21 +341,13 @@ def tasks_create_file(request):
342341
if tmp_path:
343342
details["path"] = tmp_path
344343
details["content"] = content
345-
demux_error_msgs = []
346-
347-
result = download_file(**details)
348-
if len(result) == 2:
349-
status, task_ids_tmp = result
350-
elif len(result) == 3:
351-
status, task_ids_tmp, demux_error_msgs = result
352-
344+
status, tasks_details = download_file(**details)
353345
if status == "error":
354-
details["errors"].append({os.path.basename(tmp_path).decode(): task_ids_tmp})
346+
details["errors"].append({os.path.basename(tmp_path).decode(): tasks_details})
355347
else:
356-
details["task_ids"] = task_ids_tmp
357-
358-
if demux_error_msgs:
359-
details["errors"].extend(demux_error_msgs)
348+
details["task_ids"] = tasks_details.get("task_ids")
349+
if tasks_details.get("errors"):
350+
details["errors"].extend(tasks_details["errors"])
360351

361352
if details["task_ids"]:
362353
tasks_count = len(details["task_ids"])
@@ -576,19 +567,13 @@ def tasks_create_dlnexec(request):
576567
"user_id": request.user.id or 0,
577568
}
578569

579-
result = download_file(**details)
580-
if len(result) == 2:
581-
status, task_ids_tmp = result
582-
elif len(result) == 3:
583-
status, task_ids_tmp, demux_error_msgs = result
584-
570+
status, tasks_details = download_file(**details)
585571
if status == "error":
586-
details["errors"].append({os.path.basename(path).decode(): task_ids_tmp})
572+
details["errors"].append({os.path.basename(path).decode(): tasks_details})
587573
else:
588-
details["task_ids"] = task_ids_tmp
589-
590-
if demux_error_msgs:
591-
details["errors"].extend(demux_error_msgs)
574+
details["task_ids"] = tasks_details.get("task_ids")
575+
if tasks_details.get("errors"):
576+
details["errors"].extend(tasks_details["errors"])
592577

593578
if details["task_ids"]:
594579
tasks_count = len(details["task_ids"])

web/submission/views.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ def index(request, task_id=None, resubmit_hash=None):
366366
opt_apikey = opts.get("apikey", False)
367367

368368
status = "ok"
369-
task_ids_tmp = []
370369
existent_tasks = {}
371370
details = {
372371
"errors": [],
@@ -508,17 +507,13 @@ def index(request, task_id=None, resubmit_hash=None):
508507

509508
details["path"] = path
510509
details["content"] = content
511-
result = download_file(**details)
512-
if len(result) == 2:
513-
status, task_ids_tmp = result
514-
elif len(result) == 3:
515-
status, task_ids_tmp, demux_error_msg = result
516-
if demux_error_msg:
517-
details["errors"].extend(demux_error_msg)
510+
status, tasks_details = download_file(**details)
518511
if status == "error":
519-
details["errors"].append({os.path.basename(filename): task_ids_tmp})
512+
details["errors"].append({os.path.basename(filename): tasks_details})
520513
else:
521-
details["task_ids"] = task_ids_tmp
514+
details["task_ids"] = tasks_details.get("task_ids")
515+
if tasks_details.get("errors"):
516+
details["errors"].extend(tasks_details["errors"])
522517
if web_conf.web_reporting.get("enabled", False) and web_conf.general.get("existent_tasks", False):
523518
records = perform_search("target_sha256", hash, search_limit=5)
524519
if records:
@@ -543,23 +538,19 @@ def index(request, task_id=None, resubmit_hash=None):
543538

544539
details["path"] = path
545540
details["content"] = content
546-
result = download_file(**details)
547-
if len(result) == 2:
548-
status, task_ids_tmp = result
549-
elif len(result) == 3:
550-
status, task_ids_tmp, demux_error_msg = result
551-
if demux_error_msg:
552-
details["errors"].extend(demux_error_msg)
541+
status, tasks_details = download_file(**details)
553542
if status == "error":
554-
details["errors"].append({os.path.basename(path): task_ids_tmp})
543+
details["errors"].append({os.path.basename(path): tasks_details})
555544
else:
545+
details["task_ids"] = tasks_details.get("task_ids")
546+
if tasks_details.get("errors"):
547+
details["errors"].extend(tasks_details["errors"])
556548
if web_conf.general.get("existent_tasks", False):
557549
records = perform_search("target_sha256", sha256, search_limit=5)
558550
if records:
559551
for record in records:
560552
if record.get("target").get("file", {}).get("sha256"):
561553
existent_tasks.setdefault(record["target"]["file"]["sha256"], []).append(record)
562-
details["task_ids"] = task_ids_tmp
563554

564555
elif task_category == "static":
565556
for content, path, sha256 in list_of_tasks:
@@ -631,18 +622,13 @@ def index(request, task_id=None, resubmit_hash=None):
631622
details["content"] = content
632623
details["service"] = "DLnExec"
633624
details["source_url"] = samples
634-
result = download_file(**details)
635-
if len(result) == 2:
636-
status, task_ids_tmp = result
637-
elif len(result) == 3:
638-
status, task_ids_tmp, demux_error_msg = result
639-
if demux_error_msg:
640-
details["errors"].extend(demux_error_msg)
641-
625+
status, tasks_details = download_file(**details)
642626
if status == "error":
643-
details["errors"].append({os.path.basename(path): task_ids_tmp})
627+
details["errors"].append({os.path.basename(path): tasks_details})
644628
else:
645-
details["task_ids"] = task_ids_tmp
629+
details["task_ids"] = tasks_details.get("task_ids")
630+
if tasks_details.get("errors"):
631+
details["errors"].extend(tasks_details["errors"])
646632

647633
elif task_category == "vtdl":
648634
if not settings.VTDL_KEY:

0 commit comments

Comments
 (0)