コンテンツにスキップ

Impacket services.py

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

Service Control Manager の RPC を使い、サービスの一覧表示、状態確認、作成、設定変更、起動、停止、削除を行います。

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

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

subcommand: start、stop、delete、status、config、list、create、change

引数説明
target[[domain/]username[:password]@]
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-nameservice name(必須)
-displaydisplay name(必須)
-pathbinary path(必須)
-service_typeservice type
-start_typeservice start type
-start_namestring that specifies the name of the account under which the service should run
-passwordstring that contains the password of the account whose name was specified by the start_name parameter
-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 ommited it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it
-portDestination port to connect to SMB Server(選択肢: 139, 445、既定値: 445)

SMB/RPC transport で SCMR へ bind し、manager handle を開きます。subcommand に応じて service handle の取得、状態照会、制御 code、作成または構成変更を行い、結果を表示して各 handle を閉じます。

Windows service は Service Control Manager の database entry と、現在の実行 state を持ちます。このコマンドは SCMR へ bind し、まず manager handle、 必要な action では service handle を開きます。start/stop は state transition、 create/delete/change は database 変更、status/config/list は読み取りです。

start は引数配列を service start request へ渡し、stop は control code を 送ります。要求が受理されたことと最終 state に到達したことは同じではないため、 status field の pending/running/stopped を解釈する必要があります。create と change は service type、start type、account、binary path を RPC の enum と Unicode field へ変換します。

service account password は RPC session key を使う protocol 固有形式へ暗号化 して送る必要があり、平文を structure に直接置くものではありません。handle access mask は action ごとに最小化でき、list の paging、既に存在する/削除済み service、dependent service による stop failure をそれぞれ扱います。

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

dcerpc.v5.scmr / transport、NDR NULL、service password の encryptSecret に依存します。SVCCTL.run() / doStuff() が dispatch と protocol 操作を担当します。service type と start type の CLI 値を RPC 定数へ変換する箇所が主な拡張点です。