コンテンツにスキップ

Impacket wmiquery.py

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

WMI の名前空間に接続して WQL クエリを実行し、返されたオブジェクトの属性を表示します。

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

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

引数説明
target[[domain/]username[:password]@]
-namespacenamespace name (default //./root/cimv2)
-fileinput file with commands to execute in the WQL shell
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-com-versionDCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7
-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
-rpc-auth-leveldefault, integrity (RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) or privacy (RPC_C_AUTHN_LEVEL_PKT_PRIVACY). For example CIM path “root/MSCluster” would require privacy level by default)(選択肢: integrity, privacy, default)

DCOM connection を作り、指定 namespace(既定 root\\cimv2)へ login します。各 WQL を ExecQuery に渡し、enumerator から object を取り出して property 名・型・値を表示し、列挙終了 status まで反復します。RPC auth level を integrity/privacy から選択できます。

WMI query は SQL に似ていますが、WMI class instance/metadata を WQL で選ぶ 操作です。このコマンドは DCOM connection、namespace login、ExecQuery、 enumerator という段階を通ります。namespace は query が参照する class の scope であり、同じ WQL でも namespace が違えば結果や class の存在が変わります。

ExecQuery の結果は一括配列ではなく COM enumerator です。client は一定数ずつ Next を呼び、各 object の property set を取得し、列挙終了を示す HRESULT を 通常の終端として扱います。property value は scalar、array、NULL、embedded object などになり得るため、表示処理は型情報と欠落値を保持します。

-file は複数 query を同じ authenticated DCOM/WMI session で順に実行します。 一つの query syntax error で connection 全体を壊す必要はありません。RPC auth level は packet integrity/privacy を変え、WMI の authorization とは別の層です。 query object と enumerator の release も長い batch では重要になります。

シンボル位置責務を追う入口
module-level entry1トップレベルで引数解析と処理を実行
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.dcerpc.v5.dtypesNULL
impacket.dcerpc.v5.dcomwmi
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection
impacket.dcerpc.v5.rpcrtRPC_C_AUTHN_LEVEL_PKT_INTEGRITY, RPC_C_AUTHN_LEVEL_PKT_PRIVACY
  • 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

dcerpc.v5.dcomrt / dcom.wmi / rpcrt に依存します。現在はトップレベル CLI が orchestration を持つため、再利用機能を増やすなら query 実行と表示を class/function へ分離するのが変更点です。