Skip to content

Commit

Permalink
The tree command of "smbclient.py" does not parse the path correct. (f…
Browse files Browse the repository at this point in the history
…ortra#1614)

* Update smbclient.py

* Avoid closing down the connection if a folder does not exist
  • Loading branch information
trietend authored and abbra committed Nov 27, 2023
1 parent 32d3668 commit a392f00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
19 changes: 6 additions & 13 deletions impacket/examples/smbclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,13 @@ def do_tree(self, filepath):
LOG.error("No share selected")
return

if(not filepath.startswith("/")):
filepath = self.pwd + "/" + filepath + "/*"
if(filepath == "" or filepath == "./" or filepath == "./*"):
filepath = self.pwd + "/*"
if(filepath.startswith("./")):
filepath = self.pwd + filepath.strip(".")
if("./" in filepath and not filepath.startswith("./") and not filepath.endswith("./")):
filepath = filepath.replace("./","")
if(filepath.endswith("/") or not filepath.endswith("/*")):
filepath = filepath + "/*"
if(filepath.endswith("/*/*")):
filepath = filepath.replace("/*/*", "/*")
filepath = filepath.replace("\\", "/")

if not filepath.startswith("/"):
filepath = self.pwd.replace("\\", "/") + "/" + filepath
if(not filepath.endswith("/*")):
filepath = filepath + "/*"
filepath = os.path.abspath(filepath).replace("//","/")

for LINE in self.smb.listPath(self.share, filepath):
if(LINE.is_directory()):
if(LINE.get_longname() == "." or LINE.get_longname() == ".."):
Expand Down
3 changes: 3 additions & 0 deletions impacket/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ def findFirst2(path, fileName, level, searchAttributes, pktFlags=smb.SMB.FLAGS2_
files.append(os.path.join(dirName, '..'))

if pattern != '':
if not os.path.exists(dirName):
return None, 0, STATUS_OBJECT_NAME_NOT_FOUND

for file in os.listdir(dirName):
if fnmatch.fnmatch(file.lower(), pattern.lower()):
entry = os.path.join(dirName, file)
Expand Down

0 comments on commit a392f00

Please sign in to comment.