Impacket wmipersist.py
WMI のイベントフィルター、コンシューマー、バインディングを作成・削除し、イベントを契機に VBScript を実行します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/wmipersist.py |
| カテゴリ | リモート実行 / WMI / サービス |
| 規模 | 246 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/wmipersist.py -h で確認できます。
subcommand: install、remove
| 引数 | 説明 |
|---|---|
target | [domain/][username[:password]@] |
-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 |
-name | event name(必須) |
-vbs | VBS filename containing the script you want to run(必須) |
-filter | the WQL filter string that will trigger the script |
-timer | the amount of milliseconds after the script will be triggered |
-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 |
詳細な処理フロー
Section titled “詳細な処理フロー”DCOM/WMI で root\\subscription へ接続します。install は event filter、ActiveScript consumer、両者の binding を名前付きで作成し、失敗時は作成済み object を戻します。remove は指定名から関連 object を検索して削除します。
仕組みの詳細
Section titled “仕組みの詳細”WMI permanent event subscription は、イベント条件を表す __EventFilter、
実行内容を持つ consumer、両者を結ぶ binding の三 object で成立します。
このコマンドは root\subscription namespace に接続し、install で三者を
作り、remove で同じ名前に紐づく object を探して削除します。
filter は WQL event query または timer reference を持ち、consumer は VBScript text を保持します。binding が作られるまで filter と consumer は接続されないため、 途中失敗時には孤立 object が残り得ます。作成順と逆順の rollback を考え、 既存名との衝突時に他の subscription を削除しないことが重要です。
永久 subscription は command process の終了後も repository に残ります。 したがって成功の意味は「script が一度実行された」ではなく「今後 trigger を 満たすたびに consumer が起動可能な状態になった」です。filter query syntax、 namespace、consumer engine availability、削除後の参照残りを個別に確認します。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
WMIPERSISTENCE | 64 | __init__()、checkError()、run() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket | version |
impacket.dcerpc.v5.dcomrt | COMVERSION, DCOMConnection |
impacket.dcerpc.v5.dcom | wmi |
impacket.dcerpc.v5.dtypes | NULL |
impacket.dcerpc.v5.dcom.wmi | WBEMSTATUS |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”dcerpc.v5.dcomrt / dcom.wmi に依存し、WMIPERSISTENCE.run() が action を処理します。三 object の lifecycle と名前衝突、rollback は一体として変更してください。
- 構文:
python -m py_compile examples/wmipersist.py - CLI:
python examples/wmipersist.py -h - 関連テスト:
tests/SMB_RPC/test_wmi.py - 関連テスト:
tests/dcerpc/test_dcomrt.py

