Skip to main content

Your First Impacket Script

This guide walks you through creating a simple script that connects to a remote SMB server and lists available shares.
1

Import Impacket

Start by importing the necessary modules:
2

Create an SMB Connection

Establish a connection to the target server:
The sess_port parameter defaults to 445 (SMB over TCP). Use 139 for SMB over NetBIOS.
3

Authenticate

Log in with credentials:
4

Interact with SMB

Once authenticated, you can interact with the server:
5

Clean Up

Always close the connection when done:

Complete Example

Here’s a complete working example that lists SMB shares:
smb_list_shares.py

Running the Example

Authentication Methods

Impacket supports multiple authentication methods:
Standard password authentication:

Working with DCERPC

Impacket provides powerful DCERPC capabilities. Here’s an example using the DCERPCTransportFactory:
detect_architecture.py

Common Patterns

Error Handling

Always implement proper error handling:

Using the Examples Logger

Impacket includes a logger utility for consistent output:

Next Steps

Authentication

Learn about NTLM, Kerberos, and credential formats

SMB Protocol

Dive deeper into SMB/CIFS functionality

MS-RPC

Explore MSRPC and DCERPC capabilities

Examples

Browse complete example scripts and use cases
Always ensure you have proper authorization before connecting to remote systems. Unauthorized access is illegal.