Skip to content

Commit aa02019

Browse files
committed
return file content in a json message when calling download endpoint
1 parent c87ad1b commit aa02019

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/utils/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,18 +598,20 @@ def download(taskid, target, filename):
598598
Download a certain file from the file system
599599
"""
600600
if taskid not in tasks:
601-
abort(500, "Invalid task ID")
601+
return jsonize({"success": False, "message": "Invalid task ID"})
602602

603603
# Prevent file path traversal - the lame way
604-
if target.startswith("."):
605-
abort(500)
604+
if ".." in target:
605+
return jsonize({"success": False, "message": "Forbidden path"})
606606

607607
path = os.path.join(paths.SQLMAP_OUTPUT_PATH, target)
608608

609609
if os.path.exists(path):
610-
return static_file(filename, root=path)
610+
with open(path, 'rb') as inf:
611+
file_content = inf.read()
612+
return jsonize({"success": True, "file": file_content.encode("base64")})
611613
else:
612-
abort(500, "File does not exist")
614+
return jsonize({"success": False, "message": "File does not exist"})
613615

614616

615617
def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT):

0 commit comments

Comments
 (0)