コンテンツにスキップ

Impacket ntlmrelayx.py

カテゴリ目次へ戻る / コマンド全体目次へ戻る

受け取った NTLM 認証を選択した対象へリレーし、対応する攻撃モジュールを実行します。複数の受信・転送プロトコルに対応します。

項目内容
実装examples/ntlmrelayx.py
カテゴリSMB / MSRPC / NTLM
規模611 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

オプションの最新の定義は python examples/ntlmrelayx.py -h で確認できます。

引数説明
-h / --helpshow this help message and exit
-tsAdds timestamp to every logging output
-debugTurn DEBUG output ON
-t / --targetTarget 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’)
-tfFile that contains targets by hostname or full URL, one per line
-wWatch the target file for changes and update target list automatically (only valid with -tf)
-i / --interactiveLaunch 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-ipIP address of interface to bind relay servers (“0.0.0.0” or ”::” if omitted)
--no-smb-serverDisables the SMB server
--no-http-serverDisables the HTTP server
--no-wcf-serverDisables the WCF server
--no-raw-serverDisables the RAW server
--no-rpc-serverDisables the RPC server
--no-winrm-serverDisables the WinRM server
--no-mssql-serverDisables the MSSQL server
--no-rdp-serverDisables the RDP server
--smb-portPort to listen on smb server(既定値: 445)
--http-portPort(s) to listen on HTTP server. Can specify multiple ports by separating them with `,`, and ranges with `-`. Ex: `80,8000-8010`(既定値: 80)
--httpsHTTP listener で TLS を有効にします。--certfile の指定が必要です。
--certfileHTTPS listener の PEM 証明書。
--keyfile証明書ファイルに秘密鍵が含まれない場合の PEM 秘密鍵。
--wcf-portPort to listen on wcf server(既定値: 9389)
--raw-portPort to listen on raw server(既定値: 6666)
--rpc-portPort to listen on rpc server(既定値: 135)
--mssql-portPort to listen on mssql server(既定値: 1433)
--rdp-portPort to listen on rdp server(既定値: 3389)
--no-multirelayIf set, disable multi-host relay (SMB and HTTP servers)
--keep-relayingIf set, keeps relaying to a target even after a successful connection on it
-ra / --randomRandomize target selection
-rRedirect HTTP requests to a file:// path on SMBSERVER
-l / --lootdirLoot directory in which gathered loot such as SAM hashes and optional LSA secrets will be stored (default: current directory).
-of / --output-filebase output filename for encrypted hashes. Suffixes will be added for ntlm and ntlmv2
-dh / --dump-hashesshow encrypted hashes in the console
-codec実行時の値を使って動的に生成される help
-smb2supportSMB2 Support
-ntlmchallengeSpecifies the NTLM server challenge used by the SMB Server (16 hex bytes long. eg: 1122334455667788)
-socksLaunch a SOCKS proxy for the connection relayed
-socks-addressSOCKS5 server address (also used for HTTP API)(既定値: 127.0.0.1)
-socks-portSOCKS5 server port(既定値: 1080)
-http-api-portSOCKS5 HTTP API port(既定値: 9090)
-wh / --wpad-hostEnable serving a WPAD file for Proxy Authentication attack, setting the proxy host to the one supplied.
-wa / --wpad-auth-numPrompt for authentication N times for clients without MS16-077 installed before serving a WPAD file. (default=1)
-6 / --ipv6Listen on IPv6
--remove-micRemove MIC (exploit CVE-2019-1040)
--remove-sign-sealRemove SIGN/SEAL-related NTLM negotiate flags (exploit CVE-2025-33073)
--serve-imagelocal path of the image that will we returned to clients
-cCommand 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-dbDatabase for MSSQL relay
-eFile to execute on the target system. If not specified, SAM hashes will be dumped; use --dump-lsa to also dump LSA secrets
--dump-lsaDump LSA secrets in addition to SAM hashes
--enum-local-adminsIf relayed user is not admin, attempt SAMR lookup to see who is (only works pre Win 10 Anniversary)
--rpc-attackSelect the attack to perform over RPC over named pipes.(選択肢: None, TSCH, ICPR)
-rpc-modeProtocol to attack(選択肢: TSCH, ICPR、既定値: TSCH)
-rpc-use-smbRelay DCE/RPC to SMB pipes
-auth-smbUse this credential to authenticate to SMB (low-privilege account)
-hashes-smbソースの引数定義を参照
-rpc-smb-portDestination port to connect to SMB(選択肢: 139, 445、既定値: 445)
-icpr-ca-nameName of the CA for ICPR attack
-q / --queryMSSQL query to execute(can specify multiple)
-machine-accountDomain machine account to use when interacting with the domain to grab a session key for signing, format is domain/machine_name
-machine-hashesDomain machine hashes, format is LMHASH:NTHASH
-domainDomain FQDN or IP to connect using NETLOGON
-remove-targetTry to remove the target in the challenge message (in case CVE-2019-1019 patch is not installed)
--no-dumpDo not attempt to dump LDAP information
--no-daDo not attempt to add a Domain Admin
--no-aclDisable ACL attacks
--no-validate-privsDo not attempt to enumerate privileges, assume permissions are granted to escalate a user via ACL attacks
--escalate-userEscalate privileges of this user instead of creating a new one
--delegate-accessDelegate access on relayed computer account to the specified account
--sidUse a SID to delegate access rather than an account name
--dump-lapsAttempt to dump any LAPS passwords readable by the user
--dump-gmsaAttempt to dump any gMSA passwords readable by the user
--dump-adcsAttempt to dump ADCS enrollment services and certificate templates info
--dump-info-attrAttempt to dump the info attribute of all user and group domain objects (may contain credentials)
--dump-pre2kpre-Windows 2000 認証に使われる推測可能なパスワードの computer account を LDAP で列挙します。
--add-dns-recordAdd the record to DNS via LDAP pointing to
--add-computerAttempt 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 / --keywordIMAP keyword to search for. If not specified, will search for mails containing “password”(既定値: password)
-m / --mailboxMailbox name to dump. Default: INBOX
-a / --allInstead of searching for keywords, dump all emails
-im / --imap-maxMax number of emails to dump (0 = unlimited, default: no limit)
--adcsEnable AD CS relay attack
--templateAD CS template. Defaults to Machine or User whether relayed account name ends with `$`. Relaying a DC should require specifying `DomainController`
--altnameSubject Alternative Name to use when performing 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 that the relayed account has access to
--shadow-credentialsEnable Shadow Credentials relay attack (msDS-KeyCredentialLink manipulation for PKINIT pre-authentication)
--shadow-targettarget account (user or computer$) to populate msDS-KeyCredentialLink from
--pfx-passwordpassword for the PFX stored self-signed certificate (will be random if not set, not needed when exporting to PEM)
--export-typechoose to export cert+private key in PEM or PFX (i.e. #PKCS12) (default: PFX))(選択肢: PEM, PFX)
--cert-outfile-pathfilename to store the generated self-signed PEM or PFX certificate and key
--shadow-replaceShadow Credentials の既存 KeyCredentials を JSON にバックアップしてから置き換えます。
--backup-path--shadow-replace が保存するバックアップ JSON のパス。
--sccm-policiesEnable 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:///ccm_system_windowsauth/request’
--sccm-policies-clientnameThe name of the client that will be registered in order to dump secret policies. Defaults to the relayed account’s name
--sccm-policies-sleepThe number of seconds to sleep after the client registration before requesting secret policies
--sccm-dpEnable SCCM Distribution Point attack. Perform package file dump from an SCCM Distribution Point. Expects as target ‘http:///sms_dp_smspkg$/Datalib’
--sccm-dp-extensionsA 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-filesThe 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。

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 を停止します。

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 の同期も一つの機能です。

シンボル位置責務を追う入口
MiniShell63__init__()、printTable()、emptyline()、do_targets()、do_finished_attacks()、do_socks()、do_startservers()、do_stopservers()、do_exit()、do_EOF()
start_servers()179モジュール関数
stop_servers()267モジュール関数
モジュール使用する主な名前
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
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 待受 socket または長時間 loop を開始します。bind address、port、停止方法、同時接続時の共有状態を確認してください。
  • 後始末に関係する実装として stop_servers(), do_finished_attacks(), do_stopservers() があります。新しい早期 return や例外経路でも到達するか確認します。
  • 停止要求、client 切断、partial read/write、worker 例外で listener 全体が不整合にならないことを確認します。

impacket.examples.ntlmrelayx.servers / clients / attacks / utils、SOCKS server、flask 等に依存します。CLI は巨大な configuration surface なので、option 追加時は対応 server/client/attack の capability と validation を同時に更新してください。