Overview
TheSMBConnection class provides a unified, high-level interface for SMB communication that automatically handles protocol negotiation between SMB1, SMB2, and SMB3. It abstracts away protocol-specific details and provides a consistent API regardless of the underlying SMB version.
Class Definition
SMBConnection
Main class for SMB client operations with automatic protocol negotiation.NetBIOS name of the remote host. Use
'*SMBSERVER' for automatic detection, or provide the actual hostname.IP address or hostname of the target server
Local NetBIOS name. If
None, uses the local hostname.SMB session port. Use
445 for direct TCP or 139 for NetBIOSConnection timeout in seconds
Preferred SMB dialect. Options:
SMB_DIALECT- SMB1 (NT LM 0.12)SMB2_DIALECT_002- SMB 2.0.2SMB2_DIALECT_21- SMB 2.1SMB2_DIALECT_30- SMB 3.0SMB2_DIALECT_311- SMB 3.1.1
None, negotiates the highest supported version.Authentication Methods
login()
Authenticate using NTLM.Username for authentication
User password (not used if hashes are provided)
Domain name for the account
LM hash for pass-the-hash authentication (hex string)
NT hash for pass-the-hash authentication (hex string)
Allow fallback to NTLMv1 if NTLMv2 fails (SMB1 only)
Raised if authentication fails
kerberosLogin()
Authenticate using Kerberos.Username for authentication
User password
Domain name (required for Kerberos)
LM hash for RC4-HMAC if AES not supported
NT hash for RC4-HMAC if AES not supported
AES key (aes256-cts-hmac-sha1-96 or aes128-cts-hmac-sha1-96)
Hostname or IP of the KDC. If
None, uses DNS to resolve the domain.Pre-obtained Ticket Granting Ticket
Pre-obtained Ticket Granting Service ticket
Use credential cache for ticket lookup
File and Directory Operations
connectTree()
Connect to a network share.Share name (e.g.,
'ADMIN$', 'C$', 'IPC$')Tree ID for use in subsequent operations
listPath()
List files and directories in a share.Name of the share to list
Path pattern (e.g.,
'*' for all files, '*.txt' for text files)Password for password-protected shares
List of
SharedFile objectscreateFile()
Create or open a file.Tree ID from
connectTree()Path to the file relative to share root
Access mask (e.g.,
FILE_READ_DATA, FILE_WRITE_DATA, GENERIC_ALL)Share access mode
File creation options
Action to take if file exists
File attributes to set
File ID (FID) for subsequent operations
openFile()
Open an existing file.Tree ID
Path to the file
Access rights requested
Sharing mode
File ID for the opened file
readFile()
Read data from a file.Tree ID
File ID from
openFile() or createFile()Byte offset to start reading from
Number of bytes to read. If
None, reads maximum buffer size.If
True, reads only once. If False, continues reading until bytesToRead is satisfied.Data read from the file
writeFile()
Write data to a file.Tree ID
File ID
Data to write
Byte offset to write at
Number of bytes written
closeFile()
Close an open file.Tree ID
File ID to close
deleteFile()
Delete a file from the share.Share name
Path to the file to delete
getFile()
Download a file using a callback.Share name
Remote file path
Function to call with file data chunks (receives bytes)
Share access mode
putFile()
Upload a file using a callback.Share name
Remote file path
Function to call to get file data (receives int size, returns bytes)
createDirectory()
Create a directory.Share name
Directory path to create
deleteDirectory()
Delete a directory.Share name
Directory path to delete
rename()
Rename a file or directory.Share name
Current path
New path
Information Retrieval
listShares()
List available shares on the server.List of share dictionaries with keys like
'shi1_netname', 'shi1_type', 'shi1_remark'getDialect()
Get the negotiated SMB dialect.The negotiated dialect (e.g.,
SMB2_DIALECT_311)getServerName()
Get the server’s NetBIOS name.Server NetBIOS name
getServerDomain()
Get the server’s domain.Server domain name
getServerOS()
Get the server’s operating system.Operating system string (e.g.,
"Windows 10 Build 19041")isGuestSession()
Check if logged in as guest.True if guest session, False otherwiseNamed Pipe Operations
waitNamedPipe()
Wait for a named pipe to become available.Tree ID (usually for IPC$ share)
Name of the pipe (e.g.,
'\\PIPE\\srvsvc')Timeout in seconds
transactNamedPipe()
Perform a transaction on a named pipe.Tree ID
File ID of the opened pipe
Data to send
Wait for response