Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4bb4c3

Browse files
committed
Fixes file path traversal issue on win platform.
POC: GET /download/b31146dcdb92e5db/C:\windows\win.ini/a
1 parent d69ef5e commit b4bb4c3

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

lib/utils/api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,13 @@ def download(taskid, target, filename):
622622
logger.warning("[%s] Invalid task ID provided to download()" % taskid)
623623
return jsonize({"success": False, "message": "Invalid task ID"})
624624

625-
# Prevent file path traversal - the lame way
626-
if ".." in target:
625+
path = os.path.abspath(os.path.join(paths.SQLMAP_OUTPUT_PATH, target, filename))
626+
# Prevent file path traversal
627+
if not path.startswith(paths.SQLMAP_OUTPUT_PATH):
627628
logger.warning("[%s] Forbidden path (%s)" % (taskid, target))
628629
return jsonize({"success": False, "message": "Forbidden path"})
629630

630-
path = os.path.join(paths.SQLMAP_OUTPUT_PATH, target)
631-
632-
if os.path.exists(path):
631+
if os.path.isfile(path):
633632
logger.debug("[%s] Retrieved content of file %s" % (taskid, target))
634633
with open(path, 'rb') as inf:
635634
file_content = inf.read()

0 commit comments

Comments
 (0)