Skip to content

Impacket ntlmrelayx.py

Back to the category index / Back to the command index

Relays received NTLM authentication to a selected target and runs the applicable attack module. It supports multiple inbound and outbound protocols.

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

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

ArgumentDescription
-h / --helpShow help and exit.
-tsAdd a timestamp to each log message.
-debugEnable debug output.
-t / --targetRelay target: an IP address, hostname, or URL such as domain\username@host:port. The domain\username and port are optional; escape the backslash. If omitted, relay back to the client.
-tfFile containing one target hostname or full URL per line.
-wWatch the target file and update the target list automatically (requires -tf).
-i / --interactiveAfter a successful relay, launch an smbclient, LDAP console, or SQL shell instead of running a command. The console listens on a local TCP port and can be reached with netcat, for example.
-ip / --interface-ipIP address on which relay servers bind (defaults to “0.0.0.0” or ”::”).
--no-smb-serverDisable the SMB server.
--no-http-serverDisable the HTTP server.
--no-wcf-serverDisable the WCF server.
--no-raw-serverDisable the RAW server.
--no-rpc-serverDisable the RPC server.
--no-winrm-serverDisable the WinRM server.
--no-mssql-serverDisable the MSSQL server.
--no-rdp-serverDisable the RDP server.
--smb-portSMB server listening port (default: 445)
--http-portHTTP server listening ports; separate ports with commas and ranges with a hyphen, for example 80,8000-8010 (default: 80)
--httpsEnable TLS for the HTTP listener. Requires --certfile.
--certfilePEM certificate for the HTTPS listener.
--keyfilePEM private key when the certificate file does not contain it.
--wcf-portWCF server listening port (default: 9389)
--raw-portRaw server listening port (default: 6666)
--rpc-portRPC server listening port (default: 135)
--mssql-portMSSQL server listening port (default: 1433)
--rdp-portRDP server listening port (default: 3389)
--no-multirelayDisable multi-host relay on the SMB and HTTP servers.
--keep-relayingKeep relaying to a target after a successful connection to it.
-ra / --randomSelect targets at random.
-rRedirect HTTP requests to a file:// path on SMBSERVER.
-l / --lootdirDirectory for gathered loot such as SAM hashes and optional LSA secrets (default: current directory).
-of / --output-fileBase filename for encrypted hash output; suffixes are added for NTLM and NTLMv2.
-dh / --dump-hashesShow encrypted hashes in the console.
-codecHelp generated dynamically from the runtime value.
-smb2supportEnable SMB2 support.
-ntlmchallengeNTLM server challenge used by the SMB server (16 hexadecimal bytes; for example, 1122334455667788).
-socksLaunch a SOCKS proxy for the relayed connection.
-socks-addressSOCKS5 server address, also used for the HTTP API (default: 127.0.0.1)
-socks-portSOCKS5 server port (default: 1080)
-http-api-portSOCKS5 HTTP API port (default: 9090)
-wh / --wpad-hostServe a WPAD file for a proxy authentication attack, using the supplied proxy host.
-wa / --wpad-auth-numBefore serving a WPAD file, prompt clients without MS16-077 for authentication N times (default: 1).
-6 / --ipv6Listen over IPv6.
--remove-micRemove the MIC (exploit CVE-2019-1040).
--remove-sign-sealRemove SIGN/SEAL-related NTLM negotiate flags (exploit CVE-2025-33073).
--serve-imageLocal path of the image returned to clients.
-cCommand to run on the target through SMB or RPC. If omitted for SMB, dump SAM hashes; use --dump-lsa to also dump LSA secrets. RPC provides no output.
--mssql-dbDatabase for MSSQL relay
-eFile to run on the target. If omitted, dump SAM hashes; use --dump-lsa to also dump LSA secrets.
--dump-lsaDump LSA secrets in addition to SAM hashes.
--enum-local-adminsIf the relayed user is not an administrator, use SAMR to look up who is (only before Windows 10 Anniversary Update).
--rpc-attackAttack to perform over RPC over named pipes (choices: None, TSCH, ICPR).
-rpc-modeProtocol to attack (choices: TSCH, ICPR; default: TSCH).
-rpc-use-smbRelay DCE/RPC to SMB pipes.
-auth-smbCredential for SMB authentication (a low-privilege account).
-hashes-smbSee the argument definition in the source.
-rpc-smb-portDestination SMB port (choices: 139, 445; default: 445)
-icpr-ca-nameCA name for the ICPR attack.
-q / --queryMSSQL query to run; may be specified multiple times.
-machine-accountDomain machine account used to obtain a session key for signing when interacting with the domain (format: domain/machine_name).
-machine-hashesDomain machine hashes in LMHASH:NTHASH format.
-domainDomain FQDN or IP address for NETLOGON.
-remove-targetTry to remove the target from the challenge message when the CVE-2019-1019 patch is absent.
--no-dumpDo not attempt to dump LDAP information.
--no-daDo not attempt to add a Domain Admin.
--no-aclDisable ACL attacks.
--no-validate-privsSkip privilege enumeration and assume permission to escalate a user through ACL attacks.
--escalate-userEscalate this user’s privileges instead of creating a new user.
--delegate-accessDelegate access on the relayed computer account to the specified account.
--sidIdentify the account for delegated access by SID instead of name.
--dump-lapsAttempt to dump LAPS passwords readable by the user.
--dump-gmsaAttempt to dump gMSA passwords readable by the user.
--dump-adcsAttempt to dump AD CS enrollment services and certificate template information.
--dump-info-attrAttempt to dump the info attribute of all domain user and group objects; it may contain credentials.
--dump-pre2kEnumerate computer accounts in LDAP that have predictable passwords used for pre-Windows 2000 authentication.
--add-dns-recordAdd a DNS record pointing to through LDAP.
--add-computerAttempt to add a computer account through SMB or LDAP, according to the target. Either service can be used if the target is a domain controller.
-k / --keywordIMAP keyword to search for; if omitted, search for mail containing “password” (default: password).
-m / --mailboxMailbox to dump (default: INBOX).
-a / --allDump all emails instead of searching for keywords.
-im / --imap-maxMaximum number of emails to dump (0 means unlimited; default: no limit).
--adcsEnable AD CS relay attacks.
--templateAD CS template; defaults to Machine or User depending on whether the relayed account name ends in $. Relaying a DC should require specifying DomainController.
--altnameSubject Alternative Name for ESC1 or ESC6 attacks.
--altsidObject SID to embed in szOID_NTDS_CA_SECURITY_EXT (1.3.6.1.4.1.311.25.2). Required when StrongCertificateBindingEnforcement >= 1 (default on updated DCs since Feb 2025). Obtain with: lookupsid.py DOMAIN/user:pass@DC | grep ” 500$”
--enum-templatesEnumerate enabled AD CS templates accessible to the relayed account.
--shadow-credentialsEnable a Shadow Credentials relay attack by modifying msDS-KeyCredentialLink for PKINIT pre-authentication.
--shadow-targetUser or computer account whose msDS-KeyCredentialLink to populate.
--pfx-passwordPassword for the PFX containing the self-signed certificate. Generated randomly if omitted; unnecessary when exporting PEM.
--export-typeExport the certificate and private key as PEM or PFX (PKCS#12); default: PFX (choices: PEM, PFX).
--cert-outfile-pathFilename for the generated self-signed PEM or PFX certificate and key.
--shadow-replaceBack up existing Shadow Credentials KeyCredentials to JSON, then replace them.
--backup-pathPath to the backup JSON saved by --shadow-replace.
--sccm-policiesEnable an SCCM policies attack by registering a device and dumping secret policies from a Management Point. Works best when relaying a machine account. Target: ‘http:///ccm_system_windowsauth/request’.
--sccm-policies-clientnameName of the client registered to dump secret policies (default: relayed account name).
--sccm-policies-sleepSeconds to wait after client registration before requesting secret policies.
--sccm-dpEnable an SCCM Distribution Point attack and dump package files. Target: ‘http:///sms_dp_smspkg$/Datalib’.
--sccm-dp-extensionsFile extensions to download from the Distribution Point (default: .ps1,.bat,.xml,.txt,.pfx).
--sccm-dp-filesFile containing specific URLs to download from the Distribution Point instead of downloading by extension; skips file indexing.

Related techniques: NTLM / SPNEGO Type 1/2/3, MIC, and CBT; SMB; DCE/RPC.

The CLI builds an NTLMRelayxConfig, then starts the target processor and enabled listener servers. A server relays inbound negotiation to a protocol client and, after successful authentication, hands the connection to an attack plugin or SOCKS session. The target file watcher, mini shell, and API thread share the same configuration and state. On exit, the tool stops the servers.

NTLM relay links two authentication conversations: one with an inbound client and one with an outbound target. The listener negotiates with the client as a server and returns a challenge, while connecting to the target as a client. It forwards the client’s AUTHENTICATE message to the target session and hands the authenticated connection to an attack or SOCKS layer only if the target accepts it.

ntlmrelayx.py does not implement all protocols in one place. The servers package handles inbound traffic, clients handles outbound traffic, attacks handles post-authentication actions, and TargetsProcessor selects targets. NTLMRelayxConfig passes CLI options to these components. SMB, HTTP, RPC, MSSQL, and other protocols frame messages differently, but share this authentication-token and relay lifecycle orchestration.

Targets track whether they have succeeded, are being attempted, or can be reused. Multi-relay, random selection, and target-file watching change these state transitions. In SOCKS mode, the authenticated connection stays open so a protocol plugin can multiplex later requests. In ordinary attack mode, the module runs immediately after authentication and records loot, output, and exit state. The default SMB attack dumps SAM hashes; LSA secrets are dumped only when --dump-lsa is set.

MIC, signing and sealing, channel binding, EPA, SMB signing, and target-name validation directly affect relay success. When adding an option, identify which inbound server, outbound client, or attack capability consumes it; adding a configuration field alone is insufficient. Stopping listener threads, the watcher, and SOCKS/API servers and synchronizing shared target state are part of the same feature.

SymbolLocationWhere to trace its responsibility
MiniShell63__init__(), printTable(), emptyline(), do_targets(), do_finished_attacks(), do_socks(), do_startservers(), do_stopservers(), do_exit(), do_EOF()
start_servers()179Module function
stop_servers()267Module function
ModuleMain names used
impacketversion
impacket.exampleslogger
impacket.examples.ntlmrelayx.serversHTTPRelayServer, MSSQLRelayServer, RAWRelayServer, RDPRelayServer, RPCRelayServer, SMBRelayServer, WCFRelayServer, WinRMRelayServer, WinRMSRelayServer
impacket.examples.ntlmrelayx.utils.configNTLMRelayxConfig, parse_listening_ports
impacket.examples.ntlmrelayx.utils.targetsutilsTargetsFileWatcher, TargetsProcessor
impacket.examples.ntlmrelayx.servers.socksserverSOCKS
impacket.examples.ntlmrelayx.clientsPROTOCOL_CLIENTS
impacket.examples.ntlmrelayx.attacksPROTOCOL_ATTACKS

Output, side effects, and required privileges

Section titled “Output, side effects, and required privileges”
  • Some operations change the target’s state. Check the target name, SID, and path before making changes.
  • The tool starts listening sockets or long-running loops. Check bind addresses, ports, shutdown behavior, and shared state under concurrent connections.
  • stop_servers(), do_finished_attacks(), and do_stopservers() participate in cleanup. Check that new early returns and exception paths still reach them.
  • 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.examples.ntlmrelayx.servers, clients, attacks, utils, the SOCKS server, flask, and others. The CLI has a large configuration surface, so when adding an option, update the corresponding server, client, or attack capability and validation at the same time.