Impacket wmiquery.py
WMI の名前空間に接続して WQL クエリを実行し、返されたオブジェクトの属性を表示します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/wmiquery.py |
| カテゴリ | リモート実行 / WMI / サービス |
| 規模 | 219 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/wmiquery.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-namespace | namespace name (default //./root/cimv2) |
-file | input file with commands to execute in the WQL shell |
-debug | Turn DEBUG output ON |
-ts | Adds timestamp to every logging output |
-com-version | DCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7 |
-hashes | NTLM hashes, format is LMHASH:NTHASH |
-no-pass | don’t ask for password (useful for -k) |
-k | Use 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 |
-aesKey | AES key to use for Kerberos Authentication (128 or 256 bits) |
-dc-ip | IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter |
-rpc-auth-level | default, 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) |
詳細な処理フロー
Section titled “詳細な処理フロー”DCOM connection を作り、指定 namespace(既定 root\\cimv2)へ login します。各 WQL を ExecQuery に渡し、enumerator から object を取り出して property 名・型・値を表示し、列挙終了 status まで反復します。RPC auth level を integrity/privacy から選択できます。
仕組みの詳細
Section titled “仕組みの詳細”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 では重要になります。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
| module-level entry | 1 | トップレベルで引数解析と処理を実行 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | version |
impacket.dcerpc.v5.dtypes | NULL |
impacket.dcerpc.v5.dcom | wmi |
impacket.dcerpc.v5.dcomrt | COMVERSION, DCOMConnection |
impacket.dcerpc.v5.rpcrt | RPC_C_AUTHN_LEVEL_PKT_INTEGRITY, RPC_C_AUTHN_LEVEL_PKT_PRIVACY |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.dcomrt / dcom.wmi / rpcrt に依存します。現在はトップレベル CLI が orchestration を持つため、再利用機能を増やすなら query 実行と表示を class/function へ分離するのが変更点です。
- 構文:
python -m py_compile examples/wmiquery.py - CLI:
python examples/wmiquery.py -h - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/dcerpc/test_dcomrt.py

