Skip to main content

SMB Protocol

Impacket provides comprehensive support for the Server Message Block (SMB) protocol family, including SMB1 (CIFS), SMB2, and SMB3 with advanced features like signing and encryption.

Overview

The SMB implementation in Impacket consists of three main modules:
  • smb.py - SMB1 (CIFS) protocol implementation
  • smb3.py - SMB2 and SMB3 protocol implementation
  • smbconnection.py - High-level unified interface for all SMB versions

Protocol Versions

SMB1 uses the ‘NT LM 0.12’ dialect, while SMB2/3 support multiple dialects including 2.002, 2.1, 3.0, and 3.11 with progressively enhanced security and performance features.

SMBConnection Class

The SMBConnection class provides a unified, version-agnostic interface for SMB operations.

Basic Connection

Authentication Methods

File Operations

Reading Files

Writing Files

Delete and Rename

Access Masks and File Attributes

Common Access Masks

Access masks control file permissions. These constants are defined in smb.py:284-300:

File Attributes

SMB Signing and Encryption

SMB Signing

SMB signing ensures message integrity and authenticity. It’s automatically negotiated during connection establishment.

SMB3 Encryption

Protocol Dialects

Supported Dialects

Dialect Negotiation

From smbconnection.py:95-163, Impacket negotiates the highest supported dialect:

Share Types and Permissions

Share Types

Enumerate Shares

Advanced Features

Tree Connect Management

Named Pipes (IPC$)

Session Information

Error Handling

Always handle SMB exceptions to gracefully manage connection issues, authentication failures, and access denied errors.

Complete Example

Performance Tuning

Buffer Sizes

Timeouts

Security Considerations

Best Practices

  • Always use SMB3 when possible for encryption support
  • Enable signing for message integrity
  • Use Kerberos authentication over NTLM when available
  • Close connections properly to clean up resources
  • Handle credentials securely (avoid hardcoding)

References

  • Source Files: impacket/smb.py, impacket/smb3.py, impacket/smbconnection.py
  • [MS-SMB]: SMB 1.0 Protocol Specification
  • [MS-SMB2]: SMB 2.0/3.0 Protocol Specification
  • [MS-CIFS]: Common Internet File System Protocol