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

Add SMB2 attribute tag and fix SMB2 query results #1835

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions impacket/smb3structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,12 @@ class FILE_ALL_INFORMATION(Structure):
('NameInformation',':',FILE_NAME_INFORMATION),
)

class FILE_ATTRIBUTE_TAG_INFORMATION(Structure):
structure = (
('FileAttributes','<L'),
('ReparseTag','<L=0'),
)

# SMB2_SET_INFO
class SMB2SetInfo(Structure):
SIZE = 32
Expand Down
39 changes: 27 additions & 12 deletions impacket/smbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,38 @@ def queryPathInformation(path, filename, level):

if os.path.exists(pathName):
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(pathName)
if os.path.isdir(pathName):
fileAttributes = smb.ATTR_DIRECTORY
else:
fileAttributes = smb.ATTR_NORMAL | smb.ATTR_ARCHIVE

if level == smb.SMB_QUERY_FILE_BASIC_INFO:
infoRecord = smb.SMBQueryFileBasicInfo()
infoRecord['CreationTime'] = getFileTime(ctime)
infoRecord['LastAccessTime'] = getFileTime(atime)
infoRecord['LastWriteTime'] = getFileTime(mtime)
infoRecord['LastChangeTime'] = getFileTime(mtime)
infoRecord['ExtFileAttributes'] = fileAttributes
elif level == smb2.SMB2_FILE_BASIC_INFO:
infoRecord = smb2.FILE_BASIC_INFORMATION()
infoRecord['CreationTime'] = getFileTime(ctime)
infoRecord['LastAccessTime'] = getFileTime(atime)
infoRecord['LastWriteTime'] = getFileTime(mtime)
infoRecord['ChangeTime'] = getFileTime(mtime)
infoRecord['FileAttributes'] = fileAttributes
elif level == smb.SMB_QUERY_FILE_STANDARD_INFO:
infoRecord = smb.SMBQueryFileStandardInfo()
infoRecord['AllocationSize'] = size
infoRecord['EndOfFile'] = size
if os.path.isdir(pathName):
infoRecord['ExtFileAttributes'] = smb.ATTR_DIRECTORY
infoRecord['Directory'] = 1
else:
infoRecord['ExtFileAttributes'] = smb.ATTR_NORMAL | smb.ATTR_ARCHIVE
elif level == smb.SMB_QUERY_FILE_STANDARD_INFO or level == smb2.SMB2_FILE_STANDARD_INFO:
infoRecord = smb.SMBQueryFileStandardInfo()
infoRecord['Directory'] = 0
elif level == smb2.SMB2_FILE_STANDARD_INFO:
infoRecord = smb2.FILE_STANDARD_INFORMATION()
infoRecord['AllocationSize'] = size
infoRecord['EndOfFile'] = size
infoRecord['NumberOfLinks'] = 0
if os.path.isdir(pathName):
infoRecord['Directory'] = 1
else:
Expand All @@ -553,10 +571,7 @@ def queryPathInformation(path, filename, level):
infoRecord['LastAccessTime'] = getFileTime(atime)
infoRecord['LastWriteTime'] = getFileTime(mtime)
infoRecord['LastChangeTime'] = getFileTime(mtime)
if os.path.isdir(pathName):
infoRecord['ExtFileAttributes'] = smb.ATTR_DIRECTORY
else:
infoRecord['ExtFileAttributes'] = smb.ATTR_NORMAL | smb.ATTR_ARCHIVE
infoRecord['ExtFileAttributes'] = fileAttributes
infoRecord['AllocationSize'] = size
infoRecord['EndOfFile'] = size
if os.path.isdir(pathName):
Expand Down Expand Up @@ -606,14 +621,14 @@ def queryPathInformation(path, filename, level):
infoRecord['ChangeTime'] = getFileTime(mtime)
infoRecord['AllocationSize'] = size
infoRecord['EndOfFile'] = size
if os.path.isdir(pathName):
infoRecord['FileAttributes'] = smb.ATTR_DIRECTORY
else:
infoRecord['FileAttributes'] = smb.ATTR_NORMAL | smb.ATTR_ARCHIVE
infoRecord['FileAttributes'] = fileAttributes
elif level == smb.SMB_QUERY_FILE_EA_INFO or level == smb2.SMB2_FILE_EA_INFO:
infoRecord = smb.SMBQueryFileEaInfo()
elif level == smb.SMB_QUERY_FILE_STREAM_INFO or level == smb2.SMB2_FILE_STREAM_INFO:
infoRecord = smb.SMBFileStreamInformation()
elif level == smb2.SMB2_ATTRIBUTE_TAG_INFO:
infoRecord = smb2.FILE_ATTRIBUTE_TAG_INFORMATION()
infoRecord['FileAttributes'] = fileAttributes
else:
LOG.error('Unknown level for query path info! 0x%x' % level)
# UNSUPPORTED
Expand Down