コンテンツにスキップ

Impacket wmipersist.py

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

WMI のイベントフィルター、コンシューマー、バインディングを作成・削除し、イベントを契機に VBScript を実行します。

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

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

subcommand: install、remove

引数説明
target[domain/][username[:password]@]
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-com-versionDCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7
-nameevent name(必須)
-vbsVBS filename containing the script you want to run(必須)
-filterthe WQL filter string that will trigger the script
-timerthe amount of milliseconds after the script will be triggered
-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

DCOM/WMI で root\\subscription へ接続します。install は event filter、ActiveScript consumer、両者の binding を名前付きで作成し、失敗時は作成済み object を戻します。remove は指定名から関連 object を検索して削除します。

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、削除後の参照残りを個別に確認します。

シンボル位置責務を追う入口
WMIPERSISTENCE64__init__()、checkError()、run()
モジュール使用する主な名前
impacket.exampleslogger
impacket.examples.utilsparse_target
impacketversion
impacket.dcerpc.v5.dcomrtCOMVERSION, DCOMConnection
impacket.dcerpc.v5.dcomwmi
impacket.dcerpc.v5.dtypesNULL
impacket.dcerpc.v5.dcom.wmiWBEMSTATUS
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

dcerpc.v5.dcomrt / dcom.wmi に依存し、WMIPERSISTENCE.run() が action を処理します。三 object の lifecycle と名前衝突、rollback は一体として変更してください。