コンテンツにスキップ

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

DCOM/WMI の Win32_Process.Create でコマンドや半対話シェルを実行します。

項目内容
実装examples/wmiexec.py
カテゴリリモート実行 / WMI / サービス
規模469 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

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

引数説明
target[[domain/]username[:password]@]
-shareshare where the output will be grabbed from (default ADMIN$)
-nooutputwhether or not to print the output (no SMB connection created)
-tsAdds timestamp to every logging output
-silentcommanddoes not execute cmd.exe to run given command (no output)
-debugTurn DEBUG output ON
-codec実行時の値を使って動的に生成される help
-shell-typechoose a command processor for the semi-interactive shell(選択肢: cmd, powershell、既定値: cmd)
-com-versionDCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7
commandcommand to execute at the target. If empty it will launch a semi-interactive shell
-hashesNTLM hashes, format is LMHASH:NTHASH
-no-passdon’t ask for password (useful for -k)
-kUse Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line
-aesKeyAES key to use for Kerberos Authentication (128 or 256 bits)
-dc-ipIP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter
-target-ipIP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it
-Asmbclient/mount.cifs-style authentication file. See smbclient man page’s -A option.
-keytabRead keys for SPN from keytab file

関連技術: DCE/RPC の DCOM / WMI、SMB の出力読み戻し。

DCOM へ接続し、WMI root\\cimv2 login、Win32_Process 取得、process create の順に進みます。出力ありでは command を share 上の一時ファイルへ redirect し SMB で読み戻します。-nooutput 相当の経路では SMB 接続を作らず fire-and-forget で実行できます。

WMIEXEC は DCOM で WMI service へ接続し、root\cimv2 namespace の Win32_Process class method Create を呼びます。SCMR service を作る方式と 異なり、Windows Management Instrumentation が process creation の制御面に なります。DCOM authentication と WMI namespace login は別段階です。

WMI method の戻り値には process creation status と PID は含まれますが、 stdout は含まれません。そのため出力ありの command は shell redirection で SMB share の一時 file へ書かせ、RemoteShell.get_output() が存在するまで 待って読み出します。-silentcommand/no-output 経路ではこの SMB dependency を省けますが、終了 code や完了の観測能力も減ります。

interactive shell の cd は remote current directory を local state として 保持し、次の command に prefix します。WMI process 自体に永続 current directory があるわけではありません。DCOM interface release、WMI login object、SMB session、一時 file の lifecycle を別々に管理することが重要です。

シンボル位置責務を追う入口
WMIEXEC49__init__()、run()
RemoteShell121__init__()、do_shell()、do_help()、do_lcd()、do_lget()、do_lput()、do_exit()、do_EOF()、emptyline()、do_cd()、default()、get_output() ほか
AuthFileSyntaxError305__init__()
load_smbclient_auth_file()319モジュール関数
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.smbconnectionSMB2_DIALECT_002, SMB2_DIALECT_21, SMBConnection, SMB_DIALECT
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection
impacket.dcerpc.v5.dcomwmi
impacket.dcerpc.v5.dtypesNULL
impacket.krb5.keytabKeytab
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 明示的な cleanup 名がなくても finally 相当の経路と protocol handle の close/delete を確認します。

dcerpc.v5.dcomrt / dcom.wmi、SMBConnection、keytab に依存します。WMIEXEC が WMI session、RemoteShell が command と file transfer を所有します。COM release と一時ファイル削除を維持します。