Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fortra/impacket/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thesmb module provides a complete implementation of the SMB (Server Message Block) protocol version 1. This module handles low-level SMB packet construction, authentication, file operations, and named pipe communication.
Key Classes
SMB
Main class for SMB protocol implementation.The NetBIOS name of the remote host. Use
'*SMBSERVER' for auto-detection.IP address or hostname of the remote server
Local NetBIOS name. Defaults to local hostname if not specified.
Port number for NetBIOS session service
Connection timeout in seconds
Methods
login()
Authenticate to the SMB server using NTLM.Username for authentication
Password for authentication (not used if hashes provided)
Domain name for authentication
LM hash for pass-the-hash authentication
NT hash for pass-the-hash authentication
Raises
SessionError if authentication failsconnect_tree()
Connect to a shared resource on the server.UNC path to the share (e.g.,
'\\\\server\\share')Tree ID (TID) used for subsequent file operations
list_path()
List files and directories in a share.Name of the share to list
Path relative to the share root (e.g.,
'*' for all files)Password for password-protected shares
List of
SharedFile objects containing file informationopen()
Open or create a file on the share.Tree ID from
connect_tree()Path to the file relative to share root
Access mask specifying desired operations (e.g.,
FILE_READ_DATA, FILE_WRITE_DATA)Share mode flags (e.g.,
FILE_SHARE_READ, FILE_SHARE_WRITE)Creation options (e.g.,
FILE_NON_DIRECTORY_FILE)Creation disposition (e.g.,
FILE_OPEN, FILE_CREATE, FILE_OVERWRITE_IF)File attributes (e.g.,
ATTR_NORMAL, ATTR_READONLY)File ID (FID) used for read/write operations
read_andx()
Read data from an open file.Tree ID
File ID from
open()Byte offset to start reading from
Maximum bytes to read. Defaults to server’s max buffer size.
Data read from the file
write_andx()
Write data to an open file.Tree ID
File ID from
open()Data to write to the file
Byte offset to start writing at
Number of bytes written
close()
Close an open file.Tree ID
File ID to close
logoff()
Log off from the SMB server.Constants
File Attributes
Access Masks
Share Access Modes
Creation Disposition
Supporting Classes
SharedFile
Represents file information returned bylist_path().
Returns the full filename
Returns the 8.3 short filename
Returns file size in bytes
Returns True if item is a directory
Returns True if file is read-only
Returns True if file is hidden
Returns creation time as Unix timestamp
Returns modification time as Unix timestamp
Returns access time as Unix timestamp
SessionError
Exception raised when SMB operations fail.Returns the SMB error code
Returns the error class
Usage Examples
Basic File Operations
Writing Files
Pass-the-Hash Authentication
Error Handling
Helper Functions
Time Conversion
See Also
- SMBConnection - High-level SMB client wrapper
- SMB3 - SMB2/SMB3 protocol implementation
- NTLM - NTLM authentication helpers