Impacket ntlmrelayx.py
受け取った NTLM 認証を選択した対象へリレーし、対応する攻撃モジュールを実行します。複数の受信・転送プロトコルに対応します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/ntlmrelayx.py |
| カテゴリ | SMB / MSRPC / NTLM |
| 規模 | 611 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/ntlmrelayx.py -h で確認できます。
| 引数 | 説明 |
|---|---|
-h / --help | show this help message and exit |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-t / --target | Target to relay the credentials to, can be an IP, hostname or URL like domain\username@host:port (domain\username and port are optional, and don’t forget to escape the ”). If unspecified, it will relay back to the client’) |
-tf | File that contains targets by hostname or full URL, one per line |
-w | Watch the target file for changes and update target list automatically (only valid with -tf) |
-i / --interactive | Launch an smbclient, LDAP console or SQL shell insteadof executing a command after a successful relay. This console will listen locally on a tcp port and can be reached with for example netcat. |
-ip / --interface-ip | IP address of interface to bind relay servers (“0.0.0.0” or ”::” if omitted) |
--no-smb-server | Disables the SMB server |
--no-http-server | Disables the HTTP server |
--no-wcf-server | Disables the WCF server |
--no-raw-server | Disables the RAW server |
--no-rpc-server | Disables the RPC server |
--no-winrm-server | Disables the WinRM server |
--no-mssql-server | Disables the MSSQL server |
--no-rdp-server | Disables the RDP server |
--smb-port | Port to listen on smb server(既定値: 445) |
--http-port | Port(s) to listen on HTTP server. Can specify multiple ports by separating them with `,`, and ranges with `-`. Ex: `80,8000-8010`(既定値: 80) |
--https | HTTP listener で TLS を有効にします。--certfile の指定が必要です。 |
--certfile | HTTPS listener の PEM 証明書。 |
--keyfile | 証明書ファイルに秘密鍵が含まれない場合の PEM 秘密鍵。 |
--wcf-port | Port to listen on wcf server(既定値: 9389) |
--raw-port | Port to listen on raw server(既定値: 6666) |
--rpc-port | Port to listen on rpc server(既定値: 135) |
--mssql-port | Port to listen on mssql server(既定値: 1433) |
--rdp-port | Port to listen on rdp server(既定値: 3389) |
--no-multirelay | If set, disable multi-host relay (SMB and HTTP servers) |
--keep-relaying | If set, keeps relaying to a target even after a successful connection on it |
-ra / --random | Randomize target selection |
-r | Redirect HTTP requests to a file:// path on SMBSERVER |
-l / --lootdir | Loot directory in which gathered loot such as SAM hashes and optional LSA secrets will be stored (default: current directory). |
-of / --output-file | base output filename for encrypted hashes. Suffixes will be added for ntlm and ntlmv2 |
-dh / --dump-hashes | show encrypted hashes in the console |
-codec | 実行時の値を使って動的に生成される help |
-smb2support | SMB2 Support |
-ntlmchallenge | Specifies the NTLM server challenge used by the SMB Server (16 hex bytes long. eg: 1122334455667788) |
-socks | Launch a SOCKS proxy for the connection relayed |
-socks-address | SOCKS5 server address (also used for HTTP API)(既定値: 127.0.0.1) |
-socks-port | SOCKS5 server port(既定値: 1080) |
-http-api-port | SOCKS5 HTTP API port(既定値: 9090) |
-wh / --wpad-host | Enable serving a WPAD file for Proxy Authentication attack, setting the proxy host to the one supplied. |
-wa / --wpad-auth-num | Prompt for authentication N times for clients without MS16-077 installed before serving a WPAD file. (default=1) |
-6 / --ipv6 | Listen on IPv6 |
--remove-mic | Remove MIC (exploit CVE-2019-1040) |
--remove-sign-seal | Remove SIGN/SEAL-related NTLM negotiate flags (exploit CVE-2025-33073) |
--serve-image | local path of the image that will we returned to clients |
-c | Command to execute on target system (for SMB and RPC). If not specified for SMB, SAM hashes will be dumped; use --dump-lsa to also dump LSA secrets. For RPC no output will be provided. |
--mssql-db | Database for MSSQL relay |
-e | File to execute on the target system. If not specified, SAM hashes will be dumped; use --dump-lsa to also dump LSA secrets |
--dump-lsa | Dump LSA secrets in addition to SAM hashes |
--enum-local-admins | If relayed user is not admin, attempt SAMR lookup to see who is (only works pre Win 10 Anniversary) |
--rpc-attack | Select the attack to perform over RPC over named pipes.(選択肢: None, TSCH, ICPR) |
-rpc-mode | Protocol to attack(選択肢: TSCH, ICPR、既定値: TSCH) |
-rpc-use-smb | Relay DCE/RPC to SMB pipes |
-auth-smb | Use this credential to authenticate to SMB (low-privilege account) |
-hashes-smb | ソースの引数定義を参照 |
-rpc-smb-port | Destination port to connect to SMB(選択肢: 139, 445、既定値: 445) |
-icpr-ca-name | Name of the CA for ICPR attack |
-q / --query | MSSQL query to execute(can specify multiple) |
-machine-account | Domain machine account to use when interacting with the domain to grab a session key for signing, format is domain/machine_name |
-machine-hashes | Domain machine hashes, format is LMHASH:NTHASH |
-domain | Domain FQDN or IP to connect using NETLOGON |
-remove-target | Try to remove the target in the challenge message (in case CVE-2019-1019 patch is not installed) |
--no-dump | Do not attempt to dump LDAP information |
--no-da | Do not attempt to add a Domain Admin |
--no-acl | Disable ACL attacks |
--no-validate-privs | Do not attempt to enumerate privileges, assume permissions are granted to escalate a user via ACL attacks |
--escalate-user | Escalate privileges of this user instead of creating a new one |
--delegate-access | Delegate access on relayed computer account to the specified account |
--sid | Use a SID to delegate access rather than an account name |
--dump-laps | Attempt to dump any LAPS passwords readable by the user |
--dump-gmsa | Attempt to dump any gMSA passwords readable by the user |
--dump-adcs | Attempt to dump ADCS enrollment services and certificate templates info |
--dump-info-attr | Attempt to dump the info attribute of all user and group domain objects (may contain credentials) |
--dump-pre2k | pre-Windows 2000 認証に使われる推測可能なパスワードの computer account を LDAP で列挙します。 |
--add-dns-record | Add the |
--add-computer | Attempt to add a new computer account via SMB or LDAP, depending on the specified target. This argument can be used either with the LDAP or the SMB service, as long as the target is a domain controller. |
-k / --keyword | IMAP keyword to search for. If not specified, will search for mails containing “password”(既定値: password) |
-m / --mailbox | Mailbox name to dump. Default: INBOX |
-a / --all | Instead of searching for keywords, dump all emails |
-im / --imap-max | Max number of emails to dump (0 = unlimited, default: no limit) |
--adcs | Enable AD CS relay attack |
--template | AD CS template. Defaults to Machine or User whether relayed account name ends with `$`. Relaying a DC should require specifying `DomainController` |
--altname | Subject Alternative Name to use when performing ESC1 or ESC6 attacks. |
--altsid | Object 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-templates | Enumerate enabled AD CS templates that the relayed account has access to |
--shadow-credentials | Enable Shadow Credentials relay attack (msDS-KeyCredentialLink manipulation for PKINIT pre-authentication) |
--shadow-target | target account (user or computer$) to populate msDS-KeyCredentialLink from |
--pfx-password | password for the PFX stored self-signed certificate (will be random if not set, not needed when exporting to PEM) |
--export-type | choose to export cert+private key in PEM or PFX (i.e. #PKCS12) (default: PFX))(選択肢: PEM, PFX) |
--cert-outfile-path | filename to store the generated self-signed PEM or PFX certificate and key |
--shadow-replace | Shadow Credentials の既存 KeyCredentials を JSON にバックアップしてから置き換えます。 |
--backup-path | --shadow-replace が保存するバックアップ JSON のパス。 |
--sccm-policies | Enable SCCM policies attack. Performs SCCM secret policies dump from a Management Point by registering a device. Works best when relaying a machine account. Expects as target ‘http:// |
--sccm-policies-clientname | The name of the client that will be registered in order to dump secret policies. Defaults to the relayed account’s name |
--sccm-policies-sleep | The number of seconds to sleep after the client registration before requesting secret policies |
--sccm-dp | Enable SCCM Distribution Point attack. Perform package file dump from an SCCM Distribution Point. Expects as target ‘http:// |
--sccm-dp-extensions | A custom list of extensions to look for when downloading files from the SCCM Distribution Point. If not provided, defaults to .ps1,.bat,.xml,.txt,.pfx |
--sccm-dp-files | The path to a file containing a list of specific URLs to download from the Distribution Point, instead of downloading by extensions. Providing this argument will skip file indexing |
関連技術: NTLM / SPNEGO の Type1/2/3・MIC・CBT、SMB、DCE/RPC。
詳細な処理フロー
Section titled “詳細な処理フロー”CLI から NTLMRelayxConfig を構築し、target processor と有効な listener server を起動します。server は inbound negotiation を protocol client へ relay し、認証成功後に attack plugin または SOCKS session へ渡します。target file watcher、mini shell、API thread は同じ config/state を参照し、終了時に server を停止します。
仕組みの詳細
Section titled “仕組みの詳細”NTLM relay は inbound client と outbound target の二つの authentication conversation を結びます。listener は client へ server として negotiate/ challenge を返しつつ、target へは client として接続します。client の AUTHENTICATE message を target session に渡し、target が受理した場合だけ その authenticated connection を attack または SOCKS 層へ引き渡します。
ntlmrelayx.py 自体は protocol 実装を一枚岩で持たず、servers が inbound、
clients が outbound、attacks が認証後処理、TargetsProcessor が target
選択を担当します。NTLMRelayxConfig は CLI option を各 component へ渡す
共有設定です。SMB/HTTP/RPC/MSSQL 等で message framing は異なりますが、
認証 token と relay lifecycle はこの共通 orchestration に揃えられます。
target は成功済みか、試行中か、再利用可能かという状態を持ちます。
multi-relay/random/watch file はこの状態遷移を変えます。SOCKS mode では
認証済み connection を閉じず、protocol plugin が後続 request を多重化します。
通常 attack mode は認証直後に module を実行し、loot/output と終了状態を記録します。
既定の SMB attack は SAM hash を dump し、LSA secret は --dump-lsa を付けたときだけ dump します。
MIC/sign/seal、channel binding、EPA、SMB signing、target name validation は relay 成否に直接影響します。option を増やすときは単に config field を足す だけでなく、対応する inbound server、outbound client、attack capability の どこが消費するかを明示します。listener thread、watcher、SOCKS/API server の 停止と共有 target state の同期も一つの機能です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
MiniShell | 63 | __init__()、printTable()、emptyline()、do_targets()、do_finished_attacks()、do_socks()、do_startservers()、do_stopservers()、do_exit()、do_EOF() |
start_servers() | 179 | モジュール関数 |
stop_servers() | 267 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.ntlmrelayx.servers | HTTPRelayServer, MSSQLRelayServer, RAWRelayServer, RDPRelayServer, RPCRelayServer, SMBRelayServer, WCFRelayServer, WinRMRelayServer, WinRMSRelayServer |
impacket.examples.ntlmrelayx.utils.config | NTLMRelayxConfig, parse_listening_ports |
impacket.examples.ntlmrelayx.utils.targetsutils | TargetsFileWatcher, TargetsProcessor |
impacket.examples.ntlmrelayx.servers.socksserver | SOCKS |
impacket.examples.ntlmrelayx.clients | PROTOCOL_CLIENTS |
impacket.examples.ntlmrelayx.attacks | PROTOCOL_ATTACKS |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
- 待受 socket または長時間 loop を開始します。bind address、port、停止方法、同時接続時の共有状態を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 後始末に関係する実装として
stop_servers(),do_finished_attacks(),do_stopservers()があります。新しい早期 return や例外経路でも到達するか確認します。 - 停止要求、client 切断、partial read/write、worker 例外で listener 全体が不整合にならないことを確認します。
実装を変更するとき
Section titled “実装を変更するとき”impacket.examples.ntlmrelayx.servers / clients / attacks / utils、SOCKS server、flask 等に依存します。CLI は巨大な configuration surface なので、option 追加時は対応 server/client/attack の capability と validation を同時に更新してください。
- 構文:
python -m py_compile examples/ntlmrelayx.py - CLI:
python examples/ntlmrelayx.py -h - 関連テスト:
tests/misc/test_socksserver.py - 関連テスト:
tests/misc/test_tds.py

