Impacket secretsdump.py
ローカルの hive/NTDS ファイルやリモートホストから、SAM、LSA、NTDS のハッシュと Kerberos 鍵などを抽出します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/secretsdump.py |
| カテゴリ | 秘密情報 / DPAPI / レジストリ / ファイル解析 |
| 規模 | 567 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/secretsdump.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-system | SYSTEM hive to parse (only binary REGF, as .reg text file lacks the metadata to compute the bootkey) |
-bootkey | bootkey for SYSTEM hive |
-security | SECURITY hive to parse |
-sam | SAM hive to parse |
-ntds | NTDS.DIT file to parse |
-resumefile | resume file name to resume NTDS.DIT session dump (only available to DRSUAPI approach). This file will also be used to keep updating the session’s state |
-skip-sam | Do NOT parse the SAM hive on remote system |
-skip-security | Do NOT parse the SECURITY hive on remote system |
-outputfile | base output filename. Extensions will be added for sam, secrets, cached and ntds |
-use-vss | Use the NTDSUTIL VSS method instead of default DRSUAPI |
-rodcNo | Number of the RODC krbtgt account (only avaiable for Kerb-Key-List approach) |
-rodcKey | AES key of the Read Only Domain Controller (only avaiable for Kerb-Key-List approach) |
-use-keylist | Use the Kerb-Key-List method instead of default DRSUAPI |
-exec-method | Remote exec method to use at target (only when using -use-vss). Default: smbexec(選択肢: smbexec, wmiexec, mmcexec) |
-use-remoteSSWMI | Remotely create Shadow Snapshot via WMI and download SAM, SYSTEM and SECURITY from it, the parse locally |
-use-remoteSSWMI-NTDS | Dump NTDS.DIT also when using the Remote Shadow Snapshot Method via WMI. Use it with dumping from a DC. IMPORTANT: this flag only works when also using -use-remoteSSWMI |
-remoteSSWMI-remote-volume | Remote Volume to perform the Shadow Snapshot and download SAM, SYSTEM and SECURITY. It defaults to C:\ |
-remoteSSWMI-local-path | Local path to download SAM, SYSTEM and SECURITY from Shadow Snapshot. It defaults to current path |
-just-dc-user | Extract only NTDS.DIT data for the user specified. Only available for DRSUAPI approach. Implies also -just-dc switch |
-ldapfilter | Extract only NTDS.DIT data for specific users based on an LDAP filter. Only available for DRSUAPI approach. Implies also -just-dc switch |
-just-dc | Extract only NTDS.DIT data (NTLM hashes and Kerberos keys) |
-just-dc-ntlm | Extract only NTDS.DIT data (NTLM hashes only) |
-trust-keys | Dump trusted domain object (TDO) secrets and derive the inter-realm Kerberos keys (AES + RC4) for each trust direction |
-just-trust-keys | Like -trust-keys but dump ONLY the trust keys, skipping every account secret |
-skip-user | Do NOT extract NTDS.DIT data for the user specified. Can provide comma-separated list of users to skip, or text file with one user per line |
-pwd-last-set | Shows pwdLastSet attribute for each NTDS.DIT account. Doesn’t apply to -outputfile data |
-user-status | Display whether or not the user is disabled |
-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 |
-ldaps / -use-ldaps | Use LDAPS instead of LDAP for directory queries |
関連技術: DPAPI / SAM / LSA / NTDS の boot key、PEK、取得経路と decoder の分離。
詳細な処理フロー
Section titled “詳細な処理フロー”LOCAL target では指定 hive/database を直接開きます。remote では SMB/LDAP へ接続し、Remote Registry、VSS、DRSUAPI、WMI shadow copy、Key List の選択経路で材料を取得します。LocalOperations / RemoteOperations が boot/system key を準備し、SAMHashes、LSASecrets、NTDSHashes、KeyListSecrets が各 record を decode・出力します。cleanup() が service、temp file、resume state を回収します。
仕組みの詳細
Section titled “仕組みの詳細”secretsdump は複数の acquisition method と複数の decoder を組み合わせる
orchestrator です。local mode は SAM/SYSTEM/SECURITY/NTDS file を直接読み、
remote mode は SMB/LDAP で対象を識別した後、Remote Registry、VSS、
DRSUAPI replication、WMI shadow copy、RODC Key List などから必要な raw data
を取得します。
SAM と LSA は boot key を起点に SAMHashes/LSASecrets が復号します。
NTDS は PEK を boot key で解き、各 account record の encrypted hash/key を
RID と PEK で復号します。DRSUAPI 経路では database file をコピーせず、
replication response の attribute ID/value を同じ logical record へ正規化します。
-just-dc* や LDAP filter は取得対象と decoder 出力の両方に影響します。
VSS/remote shadow copy と registry save は対象上に service、snapshot、temporary file を作る可能性があります。resume file は長い NTDS 処理の cursor を保持し、 再開時に対象/database と一致する必要があります。部分成功を許しつつ、どの source と decoder が成功したかを分けて記録します。
hash、Kerberos key、trust secret、history は出力 schema が異なります。
-trust-keys と -outputfile を併用した場合、trust key は通常の
<base>.ntds と分けて <base>.ntds.trustkeys に保存します。
-history は以前の trust secret も出力対象にし、-just-dc-ntlm は
trust key の Kerberos 鍵導出にも適用されます。
trust secret からの AES 鍵は、NetBIOS/flat 名が分かるとき二つの salt を使います。
on-the-wire の inter-realm 鍵は {REALM_FQDN}krbtgt{PARTNER_FQDN}、
<FLAT>$ の login 鍵は {REALM_FQDN}krbtgt{FLAT} で (trust account) と
ラベルされます。incoming trust は相手側の flat 名、outgoing trust は自ドメインの
flat 名を使います。flat 名が読めないときは DNS ラベルから推測せず、
trust-account 鍵を省略します。
decoder の byte 処理と formatting を分離し、cleanup() は例外経路でも remote
resource を戻します。新しい acquisition method を既存 decoder 内に埋め込まず、
同じ raw record contract へ接続する設計が保守性を保ちます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
DumpSecrets | 74 | __init__()、connect()、ldapConnect()、dump()、cleanup() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.smbconnection | SMBConnection |
impacket.ldap.ldap | LDAPConnection, LDAPSessionError |
impacket.examples.secretsdump | KeyListSecrets, LSASecrets, LocalOperations, NTDSHashes, RemoteOperations, SAMHashes |
impacket.krb5.keytab | Keytab |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
- remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 後始末に関係する実装として
cleanup()があります。新しい早期 return や例外経路でも到達するか確認します。
実装を変更するとき
Section titled “実装を変更するとき”impacket.examples.secretsdump の共有実装、SMB、LDAP、DRS/RPC、Kerberos keytab に依存します。CLI DumpSecrets は多経路の orchestration と option 整合性を担うため、新 acquisition method は decoder へ直接混ぜず境界を保ってください。
- 構文:
python -m py_compile examples/secretsdump.py - CLI:
python examples/secretsdump.py -h - 関連テスト:
tests/SMB_RPC/test_secretsdump.py - 関連テスト:
tests/SMB_RPC/test_ldap.py

