Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file length not matching file name because of multi-byte UTF-16 #1859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions impacket/smb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ def connectTree(self, share):

treeConnect = SMB2TreeConnect()
treeConnect['Buffer'] = path.encode('utf-16le')
treeConnect['PathLength'] = len(path)*2
treeConnect['PathLength'] = len(path.encode('utf-16le'))

packet = self.SMB_PACKET()
packet['Command'] = SMB2_TREE_CONNECT
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def create(self, treeId, fileName, desiredAccess, shareMode, creationOptions, cr
smb2Create['CreateDisposition'] = creationDisposition
smb2Create['CreateOptions'] = creationOptions

smb2Create['NameLength'] = len(fileName)*2
smb2Create['NameLength'] = len(fileName.encode('utf-16le'))
if fileName != '':
smb2Create['Buffer'] = fileName.encode('utf-16le')
else:
Expand Down Expand Up @@ -1470,7 +1470,7 @@ def queryDirectory(self, treeId, fileId, searchString = '*', resumeIndex = 0, in
if maxBufferSize is None:
maxBufferSize = self._Connection['MaxReadSize']
queryDirectory['OutputBufferLength'] = maxBufferSize
queryDirectory['FileNameLength'] = len(searchString)*2
queryDirectory['FileNameLength'] = len(searchString.encode('utf-16le'))
queryDirectory['Buffer'] = searchString.encode('utf-16le')

packet['Data'] = queryDirectory
Expand Down Expand Up @@ -1718,7 +1718,7 @@ def rename(self, shareName, oldPath, newPath):
renameReq = FILE_RENAME_INFORMATION_TYPE_2()
renameReq['ReplaceIfExists'] = 1
renameReq['RootDirectory'] = '\x00'*8
renameReq['FileNameLength'] = len(newPath)*2
renameReq['FileNameLength'] = len(newPath.encode('utf-16le'))
renameReq['FileName'] = newPath.encode('utf-16le')
self.setInfo(treeId, fileId, renameReq, infoType = SMB2_0_INFO_FILE, fileInfoClass = SMB2_FILE_RENAME_INFO)
finally:
Expand Down Expand Up @@ -1964,7 +1964,7 @@ def waitNamedPipe(self, treeId, pipename, timeout = 5):

pipeWait = FSCTL_PIPE_WAIT_STRUCTURE()
pipeWait['Timeout'] = timeout*100000
pipeWait['NameLength'] = len(pipename)*2
pipeWait['NameLength'] = len(pipename.encode('utf-16le'))
pipeWait['TimeoutSpecified'] = 1
pipeWait['Name'] = pipename.encode('utf-16le')

Expand Down