Skip to content

Impacket smbserver.py

Back to the category index / Back to the command index

Exposes a local directory as an SMB1/SMB2 share. NTLM/Kerberos authentication and read-only access can also be configured.

ItemDetails
Implementationexamples/smbserver.py
CategorySMB / MSRPC / NTLM
Size138 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Run python examples/smbserver.py -h for the current option definitions.

ArgumentDescription
shareNameName of the share to add.
sharePathPath of the share to add.
-commentShare comment displayed when shares are requested.
-usernameUsername used to authenticate clients.
-passwordPassword for that username.
-computeraccountnameComputer account name used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-computeraccounthashComputer account NT hash used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-computeraccountaesComputer account AES key used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-computeraccountpasswordComputer account NT hash used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-computeraccountdomainComputer account domain used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-dc-ipDomain controller IP address used to authenticate arbitrary clients with signing through NetLogon/Kerberos.
-hashesNTLM hashes for the username in LMHASH:NTHASH format.
-tsAdd a timestamp to each log message.
-debugEnable debug output.
-ip / --interface-addressListening interface IP address (defaults to “0.0.0.0” or ”::”).
-readonlyAllow file reads only.
-disablekerberosDo not offer Kerberos authentication.
-disablentlmDo not offer NTLM authentication.
-portTCP port for incoming connections (default: 445).
-dropsspDisable NTLM ESS/SSP during negotiation.
-6 / --ipv6Listen over IPv6.
-smb2supportEnable experimental SMB2 support.
-outputfileFile in which to log smbserver output messages.

The tool builds a SimpleSMBServer from the share name, path, and server options, then configures credentials and hashes, SMB2, listen address and port, and authentication policy. For Kerberos, it registers machine account and domain controller details before entering the request loop with start().

SimpleSMBServer maps a local directory into the share namespace and handles SMB negotiation, session setup, tree connections, and file operations on the server side. The CLI translates the share name and path, listen address and port, SMB2 support, read-only setting, and authentication policy into server configuration, then starts the request loop.

For NTLM authentication, it registers a user and LM/NT hashes in the credential database and verifies client challenge/response messages. Kerberos requires a machine account key representing the server SPN, plus domain and DC details. -disablekerberos and -disablentlm change the available negotiation mechanisms; the behavior when both are disabled needs to be defined explicitly.

File operations must safely resolve client paths to local paths beneath the share root. Check .., symlinks, case sensitivity, and read-only enforcement against the local filesystem as well as the protocol access mask. Permission to bind port 445, IPv4/IPv6 support, session and file IDs for multiple clients, and secrets in log files are also part of the server lifecycle.

SymbolLocationWhere to trace its responsibility
module-level entry1Parses arguments and runs processing at the top level
ModuleMain names used
impacket.exampleslogger
impacketsmbserver, version
impacket.ntlmcompute_lmhash, compute_nthash

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • The tool primarily makes queries and authentication attempts. Frequent runs can affect audit logs, account lockouts, and target load.
  • The tool starts a listening socket or a long-running loop. Check the bind address, port, shutdown method, and shared state under concurrent connections.
  • Check that shutdown requests, client disconnections, partial reads or writes, and worker exceptions do not leave the whole listener inconsistent.

The code depends on impacket.smbserver and ntlm.compute_*hash. The top-level CLI builds the server configuration directly. Handle authentication enable/disable combinations and failures to bind a privileged port explicitly.