Impacket regsecrets.py
Remote Registry 経由で SAM ハッシュと LSA の秘密情報・キャッシュを取得します。NTDS は対象にしません。
| 項目 | 内容 |
|---|---|
| 実装 | examples/regsecrets.py |
| カテゴリ | 秘密情報 / DPAPI / レジストリ / ファイル解析 |
| 規模 | 251 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/regsecrets.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-system | SYSTEM hive to parse |
-bootkey | bootkey for SYSTEM hive |
-nosam | Do not retrieve SAM information |
-nocache | Do not retrieve MSCache information |
-nolsa | Do not retrieve LSASecrets |
-throttle | Throttle in seconds between operations |
-outputfile | base output filename. Extensions will be added for sam, secrets and cached |
-history | Dump password history (NTDS and SAM hashes), and LSA secrets OldVal |
-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) |
-keytab | Read keys for SPN from keytab file |
-dc-ip | IP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameter |
-target-ip | IP 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 |
詳細な処理フロー
Section titled “詳細な処理フロー”SMB 接続後、RemoteOperations が boot key と registry data へのアクセスを準備します。指定済み SYSTEM/bootkey を優先し、SAMHashes と LSASecrets を option に応じて実行、履歴や出力 file を処理します。最後に temp hive、RemoteRegistry 状態、connection を cleanup します。
仕組みの詳細
Section titled “仕組みの詳細”SAM/LSA secret の復号には対象 machine 固有の boot key が必要です。
DumpSecrets は SMB session を作り、RemoteOperations で SYSTEM hive の
LSA class dataから boot key を再構成します。明示 -bootkey や local SYSTEM
file があれば、remote 取得を省く経路へ切り替わります。
SAMHashes は SAM domain account encryption key を boot key から導出し、
各 user の RID を使って LM/NT hash field を復号します。LSASecrets は
SECURITY policy key を導出し、LSA secret と cached domain logon record を
version/algorithm に応じて解きます。SAM と LSA cache は同じ hiveでも同じ
暗号形式ではありません。
remote 取得では Registry service と temporary hive/file access を使う場合が
あります。-nosam、-nocache、-nolsa は decoder だけでなく不要な remote
操作も省くべきです。output file は秘密情報を含むため、部分成功時に何を保存
したかを明示し、cleanup() で service state と temp resource を戻します。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
DumpSecrets | 66 | __init__()、connect()、dump()、cleanup() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.smbconnection | SMBConnection |
impacket.examples.regsecrets | LSASecrets, RemoteOperations, SAMHashes |
impacket.krb5.keytab | Keytab |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
- remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 後始末に関係する実装として
cleanup()があります。新しい早期 return や例外経路でも到達するか確認します。
実装を変更するとき
Section titled “実装を変更するとき”SMBConnection、impacket.examples.regsecrets の RemoteOperations / SAMHashes / LSASecrets、keytab に依存します。CLI DumpSecrets は secret decoder 自体ではなく orchestration を所有します。
- 構文:
python -m py_compile examples/regsecrets.py - CLI:
python examples/regsecrets.py -h - このコマンド専用のテストは見つかりません。共有モジュールのテストと、必要に応じて隔離環境での動作確認を選びます。

