Impacket dpapidump.py
リモートホストから SYSTEM の DPAPI 資格情報と SCCM クライアントの秘密情報を取得し、DPAPI_SYSTEM 鍵で復号します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/dpapidump.py |
| カテゴリ | 秘密情報 / DPAPI / レジストリ / ファイル解析 |
| 規模 | 507 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/dpapidump.py -h で確認できます。
| 引数 | 説明 |
|---|---|
-creds | Extract SYSTEM user DPAPI credentials (default: all) |
-sccm | Extract SCCM client credentials (default: all) |
-userkey | dpapi_userkey for SYSTEM (e.g. if previously dumped using secretsdump). If not provided an LSA secrets dump will be performed to retrieve it. |
target | [[domain/]username[:password]@] |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-com-version | DCOM version, format is MAJOR_VERSION:MINOR_VERSION e.g. 5.7 |
-bootkey | bootkey for SYSTEM hive |
-throttle | Throttle in seconds between operations |
-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 |
-rpc-auth-level | default, integrity (RPC_C_AUTHN_LEVEL_PKT_INTEGRITY) or privacy (RPC_C_AUTHN_LEVEL_PKT_PRIVACY). For example CIM path “root/MSCluster” would require privacy level by default)(選択肢: integrity, privacy, default) |
-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 へ接続し、Remote Registry/LSA から boot key と DPAPI_SYSTEM を取得します。対象 directory/file または WMI の SCCM policy 情報を列挙し、master key GUID と blob を対応付けて復号・表示します。throttle を適用し、終了時に remote service/connection を戻します。
仕組みの詳細
Section titled “仕組みの詳細”SYSTEM DPAPI secret を remote host から読むには、まず machine の boot key と
LSA secret DPAPI_SYSTEM が必要です。connect() が SMB session を作り、
RemoteOperations が Remote Registry/LSA に必要な状態を準備し、
getDPAPI_SYSTEM() が machine/user DPAPI key material を取り出します。
credential 経路では system profile 以下の master key file と credential file を
SMB で列挙します。各 DPAPI_BLOB は master key GUID を持つため、
decideBlobMasterkey() が取得済み master key と対応付け、machine key で
master key を復号した後に個別 blob を復号します。GUID/cache の対応を誤ると
単なる padding error に見えるため、段階を分けています。
SCCM 経路では DCOM/WMI から policy/secret 情報を取得し、DPAPI で保護された
部分を同じ key hierarchy へ渡します。WMI、SMB、Remote Registry のどこまで
利用するかは option で変わります。remote service 状態、一時 file、DCOM
connection を cleanup() で戻し、throttle は WMI/SMB への連続要求を制御します。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
DumpCreds | 48 | __init__()、connect()、getDPAPI_SYSTEM()、getFileContent()、decryptBlob()、decideBlobMasterkey()、addPolicySecret()、dump()、cleanup() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | parse_target |
impacket.dcerpc.v5.dtypes | NULL |
impacket.dcerpc.v5.dcom | wmi |
impacket.dcerpc.v5.dcomrt | COMVERSION, DCOMConnection |
impacket.dcerpc.v5.dcom.wmi | DCERPCSessionError |
impacket.dcerpc.v5.rpcrt | RPC_C_AUTHN_LEVEL_PKT_INTEGRITY, RPC_C_AUTHN_LEVEL_PKT_PRIVACY |
impacket.smbconnection | SMBConnection |
impacket.dpapi | CREDENTIAL_BLOB, CredentialFile, DPAPI_BLOB, MasterKey, MasterKeyFile |
impacket.uuid | bin_to_string |
impacket.examples.regsecrets | LSASecrets, RemoteOperations |
impacket.krb5.keytab | Keytab |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
- remote service、task、file、share、WMI/RPC resource などの一時資源を利用する経路があります。異常終了時の回収も動作契約です。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
- 後始末に関係する実装として
cleanup()があります。新しい早期 return や例外経路でも到達するか確認します。
実装を変更するとき
Section titled “実装を変更するとき”SMBConnection、examples.regsecrets、impacket.dpapi、DCOM/WMI、RPC auth-level に依存します。DumpCreds.dump() が収集を、decideBlobMasterkey() / decryptBlob() が key 選択と復号を担当します。
- 構文:
python -m py_compile examples/dpapidump.py - CLI:
python examples/dpapidump.py -h - 関連テスト:
tests/SMB_RPC/test_rpcrt.py - 関連テスト:
tests/SMB_RPC/test_wmi.py - 関連テスト:
tests/dcerpc/test_dcomrt.py - 関連テスト:
tests/misc/test_dpapi.py

