コンテンツにスキップ

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

ローカルの hive/NTDS ファイルやリモートホストから、SAM、LSA、NTDS のハッシュと Kerberos 鍵などを抽出します。

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

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

引数説明
target[[domain/]username[:password]@] or LOCAL (if you want to parse local files)
-tsAdds timestamp to every logging output
-debugTurn DEBUG output ON
-systemSYSTEM hive to parse (only binary REGF, as .reg text file lacks the metadata to compute the bootkey)
-bootkeybootkey for SYSTEM hive
-securitySECURITY hive to parse
-samSAM hive to parse
-ntdsNTDS.DIT file to parse
-resumefileresume 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-samDo NOT parse the SAM hive on remote system
-skip-securityDo NOT parse the SECURITY hive on remote system
-outputfilebase output filename. Extensions will be added for sam, secrets, cached and ntds
-use-vssUse the NTDSUTIL VSS method instead of default DRSUAPI
-rodcNoNumber of the RODC krbtgt account (only avaiable for Kerb-Key-List approach)
-rodcKeyAES key of the Read Only Domain Controller (only avaiable for Kerb-Key-List approach)
-use-keylistUse the Kerb-Key-List method instead of default DRSUAPI
-exec-methodRemote exec method to use at target (only when using -use-vss). Default: smbexec(選択肢: smbexec, wmiexec, mmcexec)
-use-remoteSSWMIRemotely create Shadow Snapshot via WMI and download SAM, SYSTEM and SECURITY from it, the parse locally
-use-remoteSSWMI-NTDSDump 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-volumeRemote Volume to perform the Shadow Snapshot and download SAM, SYSTEM and SECURITY. It defaults to C:\
-remoteSSWMI-local-pathLocal path to download SAM, SYSTEM and SECURITY from Shadow Snapshot. It defaults to current path
-just-dc-userExtract only NTDS.DIT data for the user specified. Only available for DRSUAPI approach. Implies also -just-dc switch
-ldapfilterExtract only NTDS.DIT data for specific users based on an LDAP filter. Only available for DRSUAPI approach. Implies also -just-dc switch
-just-dcExtract only NTDS.DIT data (NTLM hashes and Kerberos keys)
-just-dc-ntlmExtract only NTDS.DIT data (NTLM hashes only)
-trust-keysDump trusted domain object (TDO) secrets and derive the inter-realm Kerberos keys (AES + RC4) for each trust direction
-just-trust-keysLike -trust-keys but dump ONLY the trust keys, skipping every account secret
-skip-userDo 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-setShows pwdLastSet attribute for each NTDS.DIT account. Doesn’t apply to -outputfile data
-user-statusDisplay whether or not the user is disabled
-historyDump password history (NTDS and SAM hashes), and LSA secrets OldVal
-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)
-keytabRead keys for SPN from keytab file
-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 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-ldapsUse LDAPS instead of LDAP for directory queries

関連技術: DPAPI / SAM / LSA / NTDS の boot key、PEK、取得経路と decoder の分離。

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 を回収します。

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 へ接続する設計が保守性を保ちます。

シンボル位置責務を追う入口
DumpSecrets74__init__()、connect()、ldapConnect()、dump()、cleanup()
モジュール使用する主な名前
impacketversion
impacket.exampleslogger
impacket.examples.utilsparse_target
impacket.smbconnectionSMBConnection
impacket.ldap.ldapLDAPConnection, LDAPSessionError
impacket.examples.secretsdumpKeyListSecrets, LSASecrets, LocalOperations, NTDSHashes, RemoteOperations, SAMHashes
impacket.krb5.keytabKeytab
  • 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
  • オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
  • remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
  • 後始末に関係する実装として cleanup() があります。新しい早期 return や例外経路でも到達するか確認します。

impacket.examples.secretsdump の共有実装、SMB、LDAP、DRS/RPC、Kerberos keytab に依存します。CLI DumpSecrets は多経路の orchestration と option 整合性を担うため、新 acquisition method は decoder へ直接混ぜず境界を保ってください。