Repository navigation
Fix smbclient rget local path traversal - #2392
Conversation
|
@gabrielg5 - Nice work, thanks for the careful write-up and the tests! I verified the vuln is real on master: do_rget() reconstructs local output paths from the server's directory long names, and the existing 'if filename in [".", ".."]' filter does not stop a name like '..\\..\\outside', so a malicious server could write files outside the download directory. The two-layer fix (rejecting unsafe directory names up front + resolving every destination against os.getcwd() with realpath/commonpath before mkdir/write) looks correct and defense-in-depth, and the offline tests nicely cover the traversal, the normal nested-download happy path, and a local symlink escape. One small thing to consider: the containment check happens before makedirs()/open(), so a local race (TOCTOU) could in theory plant a symlink between the check and the write, probably not worth blocking on for a local tool, just flagging it. Otherwise this looks good to merge to me. Nice work catch! |
|
Tested in master and current PR:
|
|
no changes to be requested, merging now, thanks! |
Fixes a client-side path traversal in
MiniImpacketShell.do_rget().rgetused directory names returned by the SMB server to reconstruct local output paths. A malicious server could return a directory entry containing parent-directory components or path separators, causing downloaded files to be written outside the intended local download directory.This can result in attacker-controlled file creation or overwrite at locations writable by the operating-system user running
smbclient.py.Changes
.or../or\rgetstarts.do_rget()implementation and a fake SMB connection.