コンテンツにスキップ

Impacket reg.py

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

Remote Registry RPC を使い、レジストリの照会・変更・保存と、SAM/SYSTEM/SECURITY hive のバックアップを行います。

項目内容
実装examples/reg.py
カテゴリ秘密情報 / DPAPI / レジストリ / ファイル解析
規模703 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

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

subcommand: query、add、delete、save、backup

引数説明
target[[domain/]username[:password]@]
-debugTurn DEBUG output ON
-tsAdds timestamp to every logging output
-keyNameSpecifies the full path of the subkey. The keyName must include a valid root key. Valid root keys for the local computer are: HKLM, HKU, HKCU, HKCR.(必須)
-vSpecifies the registry value name that is to be queried. If omitted, all value names for keyName are returned.
-veQueries for the default value or empty value name
-sSpecifies to query all subkeys and value names recursively.
-vtSpecifies the registry type name that is to be set. Default is REG_SZ. Valid types are: REG_NONE, REG_SZ, REG_EXPAND_SZ, REG_BINARY, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_LINK, REG_MULTI_SZ, REG_QWORD
-vdSpecifies the registry value data that is to be set. In case of adding a REG_MULTI_SZ value, set this option once for each line you want to add.(複数回指定可)
--persistentSpecify that the created key is intended to be persistent through reboot. Default is volatile key creation
-vaDelete all values under this key.
-oOutput UNC path the target system must export the registry saves to(必須)
-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 omitted it will use the domain part (FQDN) specified in the target parameter
-target-ipIP Address of the target machine. If omitted 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 で winreg endpoint へ接続します。サービス停止中なら SCMR で RemoteRegistry の起動状態を一時変更します。subcommand が hive/key handle を開き、値の型変換、再帰列挙、save 等を実行します。終了時に handle を閉じ、必要なら service 状態を元へ戻します。

Remote Registry の操作は winreg RPC interface で行いますが、対象 service が 停止していることがあります。RemoteOperations は SCMR で RemoteRegistry の 現在の start/state を読み、必要な場合だけ一時的に enable/start します。 終了時に元の状態へ戻すため、service preparation と registry action を分離しています。

RegHandler は root hive と key path を解決し、query では subkey/value の 列挙と型別 decode、add/delete では key/value の作成・削除を行います。 REG_SZ、DWORD、binary、multi-string では CLI text から wire value への変換が 異なります。save は server 側の hive save API を呼び、local file 出力とは 違って対象上の path/権限が関係します。

backup は SAM/SYSTEM/SECURITY の組を一貫して取得する特殊経路です。key handle と service handle は action の成否にかかわらず閉じ、--persistent がない限り 開始した RemoteRegistry を戻します。再帰 query の途中で access denied が 起きても、取得済み branch と失敗 key を区別して表示します。

シンボル位置責務を追う入口
RemoteOperations50__init__()、getRRP()、connectWinReg()、enableRegistry()、finish()
RegHandler139__init__()、connect()、run()、triggerWinReg()、save()、query()、add()、delete()
モジュール使用する主な名前
impacketversion
impacket.dcerpc.v5rpcrt, rrp, scmr, transport
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.system_errorsERROR_NO_MORE_ITEMS
impacket.structurehexdump
impacket.winregistryformat_multi_sz
impacket.smbconnectionSMBConnection, SessionError
impacket.dcerpc.v5.dtypesREAD_CONTROL
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
  • remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 後始末に関係する実装として finish() があります。新しい早期 return や例外経路でも到達するか確認します。

dcerpc.v5.rrp / scmr / transport、SMBConnection、registry value formatter に依存します。RemoteOperations が service lifecycle、RegHandler が action を担当します。