GhostPack/PSPKIAudit

GitHub: GhostPack/PSPKIAudit

基于PSPKI的PowerShell工具包,用于审计AD CS配置错误(ESC1-8)并分析已颁发证书请求,以发现权限提升风险。

Stars: 920 | Forks: 130

# PSPKIAudit 用于审计 Active Directory 证书服务 (AD CS) 的 PowerShell 工具包。 它构建在 [PKISolution](http://pkisolutions.com/) 的 [PSPKI](https://github.com/PKISolutions/PSPKI) 工具包(Microsoft Public License)之上。此仓库包含比 PSGallery 中可用版本更新的 PSPKI(参见 `PSPKI` 目录)。[Vadims Podans](https://github.com/Crypt32)(PSPKI 的创建者)慷慨地提供了此版本,因为它包含针对多个错误的补丁。 **此 README 仅作为起点——要获取完整的详细信息和防御指导,请参阅“[Certified Pre-Owned](https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf)”白皮书。** 该模块包含以下主要功能: 1. [Invoke-PKIAudit](#auditing-ad-cs-misconfigurations) - 审计当前 Forest 的 AD CS 设置,主要分析 CA 服务器和已发布的模板是否存在潜在的权限提升机会。 2. [Get-CertRequest](#triaging-existing-issued-certificate-requests) - 通过查询 CA 的数据库来检查 CA 颁发的证书。主要目的是发现可能滥用了证书模板权限提升漏洞的证书请求。此外,如果用户或计算机遭到入侵,事件响应人员可以使用它来查找 CA 服务器颁发给受损用户/计算机的证书(随后应将其吊销)。 **警告:** 此代码处于测试阶段!我们确信 `Invoke-PKIAudit` 不会影响环境,因为它查询的数据量非常有限。我们尚未在典型的 CA 服务器工作负载下对 `Get-CertRequest` 进行严格的测试。`Get-CertRequest` 直接查询 CA 的数据库,可能需要处理数千条结果,这可能会影响性能。 **如果没有结果,这并不能保证您的环境是安全的!!** **我们也无法保证我们的缓解建议会使您的环境安全或不会中断运营!** 与您的 Active Directory/PKI/架构团队沟通以确定适合您环境的最佳缓解措施是您的责任。 *如果代码出错,或者我们遗漏了什么,请提交 issue 或 pull request 请求修复!* - [安装设置](#setup) - [审计 AD CS 错误配置](#auditing-ad-cs-misconfigurations) - [输出解释](#output-explanation) - [ESC1 - 错误配置的证书模板](#esc1---misconfigured-certificate-templates) - [ESC2 - 错误配置的证书模板](#esc2---misconfigured-certificate-templates) - [ESC3 - 错误配置的注册代理模板](#esc3---misconfigured-enrollment-agent-templates) - [ESC4 - 易受攻击的证书模板访问控制](#esc4---vulnerable-certificate-template-access-control) - [ESC5 - 易受攻击的 PKI AD 对象访问控制](#esc5---vulnerable-pki-ad-object-access-control) - [ESC6 - EDITF_ATTRIBUTESUBJECTALTNAME2](#esc6---editf_attributesubjectaltname2) - [ESC7 - 易受攻击的证书颁发机构访问控制](#esc7---vulnerable-certificate-authority-access-control) - [ESC8 - NTLM 中继到 AD CS HTTP 端点](#esc8---ntlm-relay-to-ad-cs-http-endpoints) - [杂项 - 显式映射](#misc---explicit-mappings) - [分类现有已颁发的证书请求](#triaging-existing-issued-certificate-requests) # 安装设置 ## 要求 在 Windows 计算机上使用提升的 PowerShell 提示符(PowerShell 5.1 或更高版本)安装以下内容: * [RSAT 的](https://docs.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools) **Certificate Services** 和 **Active Directory** 功能。使用以下命令安装: ``` Get-WindowsCapability -Online -Name "Rsat.*" | where Name -match "CertificateServices|ActiveDirectory" | Add-WindowsCapability -Online ``` * [PSPKI PowerShell 模块](https://github.com/PKISolutions/PSPKI)。使用以下命令安装: ``` Install-Module -Name PSPKI ``` ## 导入 下载该模块并将其解压缩到一个文件夹中。然后,使用以下命令导入该模块: ``` cd PSPKIAudit Get-ChildItem -Recurse | Unblock-File Import-Module .\PSPKIAudit.psd1 ``` # 审计 AD CS 错误配置 运行 `Invoke-PKIAudit` 将对当前域中的 AD CS 运行所有审计检查,包括枚举各种证书颁发机构和证书模板设置。要审计特定的 CA,您可以运行 `Invoke-PKIAudit -CAComputerName CA.DOMAIN.COM` 或 `Invoke-PKIAudit -CAName X-Y-Z`。 任何错误配置 (ESC1-8) 都将作为属性显示在 CA/模板结果中,以识别发现的特定错误配置。 如果您想更改用于测试注册/访问控制的组/用户,请修改 `Invoke-PKIAudit.ps1` 顶部的 `$CommonLowprivPrincipals` 正则表达式。 如果要将所有 CA 信息导出到 csv,请运行:`Get-AuditCertificateAuthority [-CAComputerName CA.DOMAIN.COM | -CAName X-Y-Z] | Export-Csv -NoTypeInformation CAs.csv` 如果要将所有已发布的模板信息(不仅是易受攻击的模板)导出到 csv,请运行:`Get-AuditCertificateTemplate [-CAComputerName CA.DOMAIN.COM | -CAName X-Y-Z] | Export-Csv -NoTypeInformation templates.csv` ## 输出解释 输出有两个主要部分,有关发现的 CA 的详细信息和有关潜在易受攻击模板的详细信息。 对于证书颁发机构结果: | 证书颁发机构属性 | 描述 | | ------------------------------ | ------------------------------------------------------------------ | | ComputerName | CA 运行所在的系统。 | | CAName | CA 的名称。 | | ConfigString | 完整的 COMPUTER\CA_NAME 配置字符串。 | | IsRoot | CA 是否为根 CA。 | | AllowsUserSuppliedSans | CA 是否设置了 `EDITF_ATTRIBUTESUBJECTALTNAME2` 标志。 | | VulnerableACL | CA 是否具有易受攻击的 ACL 设置。 | | EnrollmentPrincipals | 在 CA 级别拥有 `Enroll` 权限的主体。 | | EnrollmentEndpoints | CA 的 Web 服务注册端点。 | | NTLMEnrollmentEndpoints | 启用了 NTLM 的 CA Web 服务注册端点。 | | DACL | 完整的访问控制信息。 | | Misconfigurations | 指示存在的特定错误配置的 ESCX(如果有)。 | 对于证书模板结果: | 属性 | 描述 | | ----------------------- | -------------------------------------------------------------------------------------------------------- | | CA | 发布模板的完整 CA ConfigString(未发布则为 null)。 | | Name | 模板名称。 | | SchemaVersion | 模板的架构版本 (1/2/3)。 | | OID | 模板的唯一对象标识符。 | | VulnerableTemplateACL | 如果模板具有易受攻击的 ACL 设置,则为 True。 | | LowPrivCanEnroll | 如果低权限用户可以注册该模板,则为 True。 | | EnrolleeSuppliesSubject | 如果存在 `CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT` 标志(即用户可以提供任意 SAN),则为 True。 | | EnhancedKeyUsage | 模板中启用的 EKU 用法。 | | HasAuthenticationEku | 如果模板具有允许身份验证的 EKU,则为 True。 | | HasDangerousEku | 如果模板具有“危险”(任何目的或 null)EKU,则为 True。 | | EnrollmentAgentTemplate | 如果模板具有“证书请求代理”EKU,则为 True。 | | CAManagerApproval | 如果注册需要管理员批准,则为 True。 | | IssuanceRequirements | 授权签名信息。 | | ValidityPeriod | 证书的有效期。 | | RenewalPeriod | 证书的续订期。 | | Owner | 拥有证书的主体。 | | DACL | 完整的访问控制信息。 | | Misconfigurations | 指示存在的特定错误配置的 ESCX(如果有)。 | ## ESC1 - 错误配置的证书模板 ### 详情 当满足以下条件时,会出现这种权限提升情况: 1. **Enterprise CA 授予低权限用户注册权限。** Enterprise CA 的配置必须允许低权限用户请求证书。有关更多详细信息,请参阅白皮书开头的“Background - Enrollment”部分。 2. **禁用了管理员批准。** 此设置要求具有证书“管理员”权限的用户在颁发证书之前审查并批准请求的证书。有关更多详细信息,请参阅白皮书开头的“Background - Issuance Requirements”部分。 3. **不需要授权签名。** 此设置要求任何 CSR 都必须由现有的授权证书签名。有关更多详细信息,请参阅白皮书开头的“Background - Issuance Requirements”部分。 4. **过度权限的证书模板安全描述符向低权限用户授予证书注册权限。** 拥有证书注册权限允许低权限攻击者根据模板请求并获取证书。注册权限是通过证书模板 AD 对象的安全描述符授予的。 5. **证书模板定义了启用身份验证的 EKU。** 适用的 EKU 包括客户端身份验证 (OID 1.3.6.1.5.5.7.3.2)、PKINIT 客户端身份验证 (OID 1.3.6.1.5.2.3.4) 或智能卡登录 (OID 1.3.6.1.4.1.311.20.2.2)。 6. **证书模板允许请求者在 CSR 中指定 subjectAltName (SAN)。** 如果请求者可以在 CSR 中指定 SAN,则请求者可以作为任何人(例如,域管理员用户)请求证书。证书模板的 AD 对象在其 mspki-certificate-name-flag 属性中指定请求者是否可以指定 SAN。mspki-certificate-name-flag 属性是一个位掩码,如果存在 CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT 标志,则请求者可以指定 SAN。 **TL;DR** 这种情况意味着非特权用户可以请求可用于域身份验证的证书,并且他们可以在其中指定任意备用名称(如域管理员)。这可能会导致获得域管理员等提权用户的有效证书! ### 示例 ``` [!] Potentially vulnerable Certificate Templates: CA : dc.theshire.local\theshire-DC-CA Name : ESC1Template SchemaVersion : 2 OID : ESC1 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.10657968.9897558) VulnerableTemplateACL : False LowPrivCanEnroll : True EnrolleeSuppliesSubject : True EnhancedKeyUsage : Client Authentication (1.3.6.1.5.5.7.3.2)|Secure Email (1.3.6.1.5.5.7.3.4)|Encrypting File System (1.3.6.1.4.1.311.10.3.4) HasAuthenticationEku : True HasDangerousEku : False EnrollmentAgentTemplate : False CAManagerApproval : False IssuanceRequirements : [Issuance Requirements] Authorized signature count: 0 Reenrollment requires: same criteria as for enrollment. ValidityPeriod : 1 years RenewalPeriod : 6 weeks Owner : THESHIRE\localadmin DACL : NT AUTHORITY\Authenticated Users (Allow) - Read THESHIRE\Domain Admins (Allow) - Read, Write, Enroll THESHIRE\Domain Users (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - Read, Write, Enroll THESHIRE\localadmin (Allow) - Read, Write Misconfigurations : ESC1 ``` ### 缓解措施 有几种选择。首先,在 Certificate Templates Console (certtmpl.msc) 中右键单击受影响的证书模板,然后单击“Properties” 1. 通过 “Subject Name” 移除 CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT 标志,取消选中 “Supply in Request”。 * 这可以防止在 CSR 中指定任意 SAN。**除非此模板确实需要备用名称,否则这可能是最好的修复方法。** 2. 通过 “Extensions” -> “Application Policies” 移除 “Client Authentication” 和/或 “Smart Card Logon” EKU。 * 这可以防止使用此模板进行域身份验证。 3. 在 “Issuance Requirements” 中启用 **“CA Certificate Manager Approval”**。 * 这会将此模板的请求放入 “Pending Requests” 队列,该队列必须由证书管理员手动批准。 4. 在 “Issuance Requirements” 中启用 **“Authorized Signatures”**(如果您知道自己在做什么)。 * 这会强制 CSR 由注册代理证书共同签名。 5. 通过 “Security” 移除低权限用户注册此模板的能力,并移除相应的 **Enroll** 权限。 ## ESC2 - 错误配置的证书模板 ### 详情 当满足以下条件时,会出现这种权限提升情况: 1. **Enterprise CA 授予低权限用户注册权限。** 详细信息与 ESC1 相同。 2. **禁用了管理员批准。** 详细信息与 ESC1 相同。 3. **不需要授权签名。** 详细信息与 ESC1 相同。 4. **过度权限的证书模板安全描述符向低权限用户授予证书注册权限。** 详细信息与 ESC1 相同。 5. **证书模板定义了任何目的 (Any Purpose) EKU 或没有 EKU。** 任何目的 (OID 2.5.29.37.0) 可用于(惊喜!)任何目的,包括客户端身份验证。如果未指定 EKU——即 pkiextendedkeyusage 为空或属性不存在——则证书等效于从属 CA 证书,并且可用于任何事情。 **TL;DR** 这与 ESC1 非常相似,但是对于 Any Purpose 或没有 EKU,不需要存在 CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT 标志。 ### 示例 ``` [!] Potentially vulnerable Certificate Templates: CA : dc.theshire.local\theshire-DC-CA Name : ESC2Template SchemaVersion : 2 OID : ESC2 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.7730030.4389735) VulnerableTemplateACL : False LowPrivCanEnroll : True EnrolleeSuppliesSubject : False EnhancedKeyUsage : HasAuthenticationEku : True HasDangerousEku : True EnrollmentAgentTemplate : False CAManagerApproval : False IssuanceRequirements : [Issuance Requirements] Authorized signature count: 0 Reenrollment requires: same criteria as for enrollment. ValidityPeriod : 1 years RenewalPeriod : 6 weeks Owner : THESHIRE\localadmin DACL : NT AUTHORITY\Authenticated Users (Allow) - Read THESHIRE\Domain Admins (Allow) - Read, Write, Enroll THESHIRE\Domain Users (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - Read, Write, Enroll THESHIRE\localadmin (Allow) - Read, Write Misconfigurations : ESC2 ``` ### 缓解措施 有几种选择。首先,在 Certificate Templates Console (certtmpl.msc) 中右键单击受影响的证书模板,然后单击 “Properties” 1. 通过 “Security” 移除低权限用户注册此模板的能力,并移除相应的 **Enroll** 权限。 * 这可能是最好的修复方法,因为这些敏感 EKU 不应提供给低权限用户! 2. 在 “Issuance Requirements” 中启用 **“CA Certificate Manager Approval”**。 * 这会将此模板的请求放入 “Pending Requests” 队列,该队列必须由证书管理员手动批准。 3. 在 “Issuance Requirements” 中启用 **“Authorized Signatures”**(如果您知道自己在做什么)。 * 这会强制 CSR 由注册代理证书共同签名。 ## ESC3 - 错误配置的注册代理模板 ### 详情 当满足以下条件时,会出现这种权限提升情况: 1. **Enterprise CA 授予低权限用户注册权限。** 详细信息与 ESC1 相同。 2. **禁用了管理员批准。** 详细信息与 ESC1 相同。 3. **不需要授权签名。** 详细信息与1 相同。 4. **过度权限的证书模板安全描述符向低权限用户授予证书注册权限。** 详细信息与 ESC1 相同。 5. **证书模板定义了证书请求代理 EKU。** 证书请求代理 EKU (OID 1.3.6.1.4.1.311.20.2.1) 允许主体代表另一个用户注册_另一个_证书模板。 6. **CA 上未实施注册代理限制。** **TL;DR** 拥有证书请求(又名注册)代理证书的人可以代表域中的任何用户注册其他证书,对于任何架构版本 1 模板或任何需要适当“Authorized Signatures/Application Policy”颁发要求的架构版本 2+ 模板,除非在 CA 级别实施了“Enrollment Agent Restrictions”。 ### 示例 ``` [!] Potentially vulnerable Certificate Templates: CA : dc.theshire.local\theshire-DC-CA Name : ESC3Template SchemaVersion : 2 OID : ESC3 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.4300342.10028552) VulnerableTemplateACL : False LowPrivCanEnroll : True EnrolleeSuppliesSubject : False EnhancedKeyUsage : Certificate Request Agent (1.3.6.1.4.1.311.20.2.1) HasAuthenticationEku : False HasDangerousEku : False EnrollmentAgentTemplate : True CAManagerApproval : False IssuanceRequirements : [Issuance Requirements] Authorized signature count: 0 Reenrollment requires: same criteria as for enrollment. ValidityPeriod : 1 years RenewalPeriod : 6 weeks Owner : THESHIRE\localadmin DACL : NT AUTHORITY\Authenticated Users (Allow) - Read THESHIRE\Domain Admins (Allow) - Read, Write, Enroll THESHIRE\Domain Users (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - Read, Write, Enroll THESHIRE\localadmin (Allow) - Read, Write Misconfigurations : ESC3 ``` ### 缓解措施 有几种选择。首先,在 Certificate Templates Console (certtmpl.msc) 中右键单击受影响的证书模板,然后单击 “Properties” 1. 通过 “Security” 移除低权限用户注册此模板的能力,并移除相应的 **Enroll** 权限。 * 这可能是最好的修复方法,因为此敏感 EKU 不应提供给低权限用户! 2. 在 “Issuance Requirements” 中启用 **“CA Certificate Manager Approval”**。 * 这会将此模板的请求放入 “Pending Requests” 队列,该队列必须由证书管理员手动批准。 您还可以通过 Certification Authority console (certsrv.msc) 实施 “Enrollment Agent Restrictions”。在受影响的 CA 上,右键单击 CA 名称,然后单击 “Properties” -> “Enrollment Agents”。[此处](https://social.technet.microsoft.com/wiki/contents/articles/10942.ad-cs-security-guidance.aspx#Establish_Restricted_Enrollment_Agents) 有关于此方法的更多信息。 ## ESC4 - 易受攻击的证书模板访问控制 ### 详情 证书模板是 Active Directory 中的安全对象,这意味着它们具有一个安全描述符,该描述符指定哪些 Active Directory 主体对模板具有特定权限。具有易受攻击访问控制的模板会授予非预期主体修改模板中设置的能力。拥有修改权限,攻击者可以设置易受攻击的 EKU (ESC1-ESC3),翻转 CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT (ESC1) 等设置,和/或移除 “Issuance Requirements”,如管理员批准或授权签名。 ### 示例 ``` [!] Potentially vulnerable Certificate Templates: CA : dc.theshire.local\theshire-DC-CA Name : ESC4Template SchemaVersion : 2 OID : ESC4 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.1768738.6205646) VulnerableTemplateACL : True LowPrivCanEnroll : True EnrolleeSuppliesSubject : False EnhancedKeyUsage : Client Authentication (1.3.6.1.5.5.7.3.2)|Secure Email (1.3.6.1.5.5.7.3.4)|Encrypting File System (1.3.6.1.4.1.311.10.3.4) HasAuthenticationEku : True HasDangerousEku : False EnrollmentAgentTemplate : False CAManagerApproval : False IssuanceRequirements : [Issuance Requirements] Authorized signature count: 0 Reenrollment requires: same criteria as for enrollment. ValidityPeriod : 1 years RenewalPeriod : 6 weeks Owner : THESHIRE\localadmin DACL : NT AUTHORITY\Authenticated Users (Allow) - Read, Write THESHIRE\Domain Admins (Allow) - Read, Write, Enroll THESHIRE\Domain Users (Allow) - Read, Enroll THESHIRE\Enterprise Admins (Allow) - Read, Write, Enroll THESHIRE\localadmin (Allow) - Read, Write Misconfigurations : ESC4 ``` ### 缓解措施 在 Certificate Templates Console (certtmpl.msc) 中右键单击受影响的证书模板,然后单击 “Properties”。 转到 “Security” 并移除易受攻击的访问控制条目。 ## ESC5 - 易受攻击的 PKI AD 对象访问控制 ### 详情 证书模板和证书颁发机构本身之外的许多对象都可能对整个 AD CS 系统产生安全影响。 这些可能性包括(但不限于): - CA 服务器的 AD 计算机对象(即,通过 RBCD 进行入侵) - CA 服务器的 RPC/DCOM 服务器 - PKI 相关的 AD 对象。容器 CN=Public Key Services,CN=Services,CN=Configuration,DC=,DC= 中的任何后代 AD 对象或容器(例如,证书模板容器、证书颁发机构容器、NTAuthCertificates 对象等) *由于此特定错误配置的范围广泛,我们目前默认不在此工具包中检查 ESC5。* 可以在当前的 BloodHound 收集中找到进入 CA 服务器本身的访问路径。 CA 服务器的 RPC/DCOM 服务器安全性需要手动分析。 以下命令输出用户列表以及用户对 PKI 相关 AD 对象拥有的控制/编辑权限。 ``` $Controllers = Get-AuditPKIADObjectControllers Format-PKIAdObjectControllers $Controllers ``` 确保结果中的所有主体绝对需要列出的权限。通常,非第 0 层帐户(无论是低权限用户/组还是较低权限的非 AD 服务器管理员)拥有对 PKI 相关 AD 对象的控制权。 ### 示例 ``` THESHIRE\Cert Publishers (S-1-5-21-3022474190-4230777124-3051344698-517) GenericAll CN=THESHIRE-DC-CA,CN=Certification Authorities,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=AIA,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=DC,CN=CDP,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=THESHIRE-DC-CA,CN=DC,CN=CDP,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL THESHIRE\DC$ (S-1-5-21-3022474190-4230777124-3051344698-1000) WriteOwner CN=THESHIRE-DC-CA,CN=Enrollment Services,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=THESHIRE-DC-CA,CN=AIA,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=THESHIRE-DC-CA,CN=DC,CN=CDP,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL GenericAll CN=THESHIRE-DC-CA,CN=KRA,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL THESHIRE\Domain Computers (S-1-5-21-3022474190-4230777124-3051344698-515) WriteDacl CN=MisconfiguredTemplate,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL THESHIRE\Domain Users (S-1-5-21-3022474190-4230777124-3051344698-513) WriteAllProperties CN=MisconfiguredTemplate,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL THESHIRE\john-sa (S-1-5-21-3022474190-4230777124-3051344698-1602) GenericAll CN=MisconfiguredTemplate,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL NT AUTHORITY\Authenticated Users (S-1-5-11) Owner CN=MisconfiguredTemplate,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL WriteOwner CN=MisconfiguredTemplate,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=THESHIRE,DC=LOCAL ``` ### 缓解措施 通过 Active Directory Users and Computers (*dsa.msc*) 或 ADSIEdit (*adsiedit.msc*) 移除配置对象的任何易受攻击的访问控制条目。 ## ESC6 - EDITF_ATTRIBUTESUBJECTALTNAME2 ### 详情 如果证书颁发机构的配置中开启了 **EDITF_ATTRIBUTESUBJECTALTNAME2** 标志,则*任何*证书请求都可以指定任意使用者备用名称 (SAN)。这意味着任何配置为域身份验证且允许非特权用户注册的模板(例如,默认的 **User** 模板)都可能被滥用以获取允许我们作为域管理员(或任何其他活动用户/计算机)进行身份验证的证书。 **您的环境中绝对不应设置此设置。** ### 示例 ``` === Certificate Authority === ComputerName : dc.theshire.local CAName : theshire-DC-CA ConfigString : dc.theshire.local\theshire-DC-CA IsRoot : True AllowsUserSuppliedSans : True VulnerableACL : False EnrollmentPrincipals : THESHIRE\Domain Users THESHIRE\Domain Computers THESHIRE\certmanager THESHIRE\certadmin THESHIRE\Nested3 EnrollmentEndpoints : NTLMEnrollmentEndpoints : DACL : BUILTIN\Administrators (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Admins (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Users (Allow) - Read, Enroll THESHIRE\Domain Computers (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - ManageCA, ManageCertificates THESHIRE\certmanager (Allow) - ManageCertificates, Enroll THESHIRE\certadmin (Allow) - ManageCA, Enroll THESHIRE\Nested3 (Allow) - ManageCertificates, Enroll Misconfigurations : ESC6 [!] The above CA is misconfigured! ...(snip)... [!] EDITF_ATTRIBUTESUBJECTALTNAME2 set on this CA, the following templates may be vulnerable: CA : dc.theshire.local\theshire-DC-CA Name : User SchemaVersion : 1 OID : 1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.1.1 VulnerableTemplateACL : False LowPrivCanEnroll : True EnrolleeSuppliesSubject : False EnhancedKeyUsage : Encrypting File System (1.3.6.1.4.1.311.10.3.4)|Secure Email (1.3.6.1.5.5.7.3.4)|Client Authentication (1.3.6.1.5.5.7.3.2) HasAuthenticationEku : True HasDangerousEku : False EnrollmentAgentTemplate : False CAManagerApproval : False IssuanceRequirements : [Issuance Requirements] Authorized signature count: 0 Reenrollment requires: same criteria as for enrollment. ValidityPeriod : 1 years RenewalPeriod : 6 weeks Owner : THESHIRE\Enterprise Admins DACL : NT AUTHORITY\Authenticated Users (Allow) - Read THESHIRE\Domain Admins (Allow) - Read, Write, Enroll THESHIRE\Domain Users (Allow) - Read, Enroll THESHIRE\Enterprise Admins (Allow) - Read, Write, Enroll Misconfigurations : ``` ### 缓解措施 立即移除此标志,并使用针对 CA 服务器的提升权限 PowerShell 提示符重新启动受影响的证书颁发机构: ``` PS C:\> certutil -config "CA_HOST\CA_NAME" -setreg policy\EditFlags -EDITF_ATTRIBUTESUBJECTALTNAME2 PS C:\> Get-Service -ComputerName CA_HOST certsvc | Restart-Service -Force ``` ## ESC7 - 易受攻击的证书颁发机构访问控制 ### 详情 除了证书模板之外,证书颁发机构本身还具有一组保护各种 CA 操作的权限。可以从 certsrv.msc 访问这些权限,右键单击 CA,选择属性,然后切换到 Security 选项卡。 有两项权利对安全敏感,如果非预期主体拥有它们则很危险: * **ManageCA**(又名“CA Administrator”)- 允许执行管理性 CA 操作,包括(远程)开启 EDITF_ATTRIBUTESUBJECTALTNAME2 位,从而导致 ESC6。 * **ManageCertificates**(又名“Certificate Manager/Officer”)- 允许主体批准挂起的证书请求,从而否定 “Manager Approval” 颁发要求/保护 ### 示例 ``` === Certificate Authority === ComputerName : dc.theshire.local CAName : theshire-DC-CA ConfigString : dc.theshire.local\theshire-DC-CA IsRoot : True AllowsUserSuppliedSans : False VulnerableACL : True EnrollmentPrincipals : THESHIRE\Domain Users THESHIRE\Domain Computers THESHIRE\certmanager THESHIRE\certadmin THESHIRE\Nested3 EnrollmentEndpoints : NTLMEnrollmentEndpoints : DACL : BUILTIN\Administrators (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Admins (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Users (Allow) - ManageCA, Read, Enroll THESHIRE\Domain Computers (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - ManageCA, ManageCertificates THESHIRE\certmanager (Allow) - ManageCertificates, Enroll THESHIRE\certadmin (Allow) - ManageCA, Enroll THESHIRE\Nested3 (Allow) - ManageCertificates, Enroll Misconfigurations : ESC7 [!] The above CA is misconfigured! ``` ### 缓解措施 在受影响的 CA 上打开 Certification Authority console (certsrv.msc),右键单击 CA 名称,然后单击 “Properties”。 转到 “Security” 并移除易受攻击的访问控制条目。 ## ESC8 - NTLM 中继到 AD CS HTTP 端点 **注意:** PSPKIAudit 中的此特定检查仅检查任何已发布注册端点是否存在 NTLM。*它不检查这些启用 NTLM 的端点是否存在扩展保护进行身份验证,因此可能会出现误报!* ### 详情 AD CS 通过管理员可以安装的其他 AD CS 服务器角色支持多种基于 HTTP 的注册方法。这些基于 HTTP 的证书注册接口都易受 NTLM 中继攻击。 使用 NTLM 中继,受损机器上的攻击者可以冒充任何入站 NTLM 身份验证的 AD 帐户。在冒充受害者帐户的同时,攻击者可以访问这些 Web 界面,并根据 User 或 Machine 证书模板请求客户端身份验证证书。 ### 示例 ``` === Certificate Authority === ComputerName : dc.theshire.local CAName : theshire-DC-CA ConfigString : dc.theshire.local\theshire-DC-CA IsRoot : True AllowsUserSuppliedSans : False VulnerableACL : False EnrollmentPrincipals : THESHIRE\Domain Users THESHIRE\Domain Computers THESHIRE\certmanager THESHIRE\certadmin THESHIRE\Nested3 EnrollmentEndpoints : http://dc.theshire.local/certsrv/ NTLMEnrollmentEndpoints : http://dc.theshire.local/certsrv/ DACL : BUILTIN\Administrators (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Admins (Allow) - ManageCA, ManageCertificates THESHIRE\Domain Users (Allow) - Read, Enroll THESHIRE\Domain Computers (Allow) - Enroll THESHIRE\Enterprise Admins (Allow) - ManageCA, ManageCertificates THESHIRE\certmanager (Allow) - ManageCertificates, Enroll THESHIRE\certadmin (Allow) - ManageCA, Enroll THESHIRE\Nested3 (Allow) - ManageCertificates, Enroll Misconfigurations : ESC8 [!] The above CA is misconfigured! ``` ### 缓解措施 移除 HTTP(S) 注册端点,禁用端点的 NTLM,或启用扩展保护进行身份验证。请参阅白皮书中的 **Harden AD CS HTTP Endpoints – PREVENT8** 以了解更多详细信息。 ## 杂项 - 显式映射 针对某些情况的另一种可能的缓解措施是对证书强制执行显式映射。这禁用了在向 Active Directory 进行身份验证时使用证书中的备用 SAN。 对于 Kerberos,将 **HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Kdc ! UseSubjectAltName** 键设置为 00000000 会强制执行显式映射。[KB4043463](https://mskb.pkisolutions.com/kb/4043463) 中有更多详细信息。 禁用 SChannel 的显式映射并没有真正的文档记录,但根据我们的研究,将 **HKEY_LOCAL_MACHINE\CurrentControlSet\Control\SecurityProviders\SCHANNEL ! CertificateMappingMethods** 键设置为 0x1 或 0x2 似乎会阻止 SAN,但需要更多测试。 # 分类现有已颁发的证书请求 **警告:** 此功能在大型环境中仅经过了最低限度的测试! **注意:** 请参阅白皮书中的 “Monitor User/Machine Certificate Enrollments - DETECT1” 以获取更多信息以及如何使用 certutil 执行这些搜索。 如果您想检查现有已颁发的证书请求,例如查看是否有任何请求指定了任意 SAN,或者是由特定主体/为特定模板请求的,`Get-CertRequest [-CAComputerName COMPUTER.DOMAIN.COM | -CAName X-Y-Z]` 函数建立在各种 PSPKI 函数之上,以提供更多上下文信息。 具体来说,将为域中当前颁发的每个证书提取原始证书签名请求 (CSR),并从请求中构建特定信息(即,是否指定了 SAN、请求者名称/机器/进程等),以丰富 CSR 对象。 以下标志可能很有用: | 标志 | 描述 | | --------------------------- | --------------------------------------------------------------------------------------------- | | **-HasSAN** | 仅返回在请求中指定了使用者备用名称的已颁发证书。 | | **-Requester DOMAIN\USER** | 仅返回特定请求用户的已颁发证书请求。 | | **-Template TEMPLATE_NAME** | 仅返回指定模板名称的已颁发证书请求。 |
要将所有已颁发的证书请求导出到 csv,请使用 `Get-CertRequest | Export-CSV -NoTypeInformation requests.csv`。 这是一个示例结果条目,显示了使用 Certify 指定了使用者备用名称 (SAN) 的情况: ``` CA : dc.theshire.local\theshire-DC-CA RequestID : 4602 RequesterName : THESHIRE\cody RequesterMachineName : dev.theshire.local RequesterProcessName : Certify.exe SubjectAltNamesExtension : SubjectAltNamesAttrib : Administrator SerialNumber : 55000011faef0fab5ffd7f75b30000000011fa CertificateTemplate : ESC1 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.10657968.9897558) RequestDate : 6/3/2021 5:54:51 PM StartDate : 6/3/2021 5:44:51 PM EndDate : 6/3/2022 5:44:51 PM CA : dc.theshire.local\theshire-DC-CA RequestID : 4603 RequesterName : THESHIRE\cody RequesterMachineName : dev.theshire.local RequesterProcessName : Certify.exe SubjectAltNamesExtension : Administrator SubjectAltNamesAttrib : SerialNumber : 55000011fb021b79cf7276c2de0000000011fb CertificateTemplate : ESC1 Template (1.3.6.1.4.1.311.21.8.10395027.10224472.4213181.15714845.1171465.9.10657968.9897558) RequestDate : 6/3/2021 5:55:10 PM StartDate : 6/3/2021 5:45:10 PM EndDate : 6/3/2022 5:45:10 PM ``` `SubjectAltNamesExtension` 属性表示使用 x509 SubjectAlternativeNames 扩展指定了 SAN,这发生在具有 `CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT` 标志的模板中。`SubjectAltNamesAttrib` 属性表示使用了 x509 名称/值对,这发生在设置了 `EDITF_ATTRIBUTESUBJECTALTNAME2` CA 标志时指定 SAN 的情况。 可以使用 PSPKI 的 [Revoke-Certificate](https://www.pkisolutions.com/tools/pspki/Revoke-Certificate/) 函数吊销现有的已颁发证书: `PS C:\> Get-CertificationAuthority | Get-IssuedRequest -RequestID | Revoke-Certificate -Reason "KeyCompromise"` -Reason 的适用值为 “KeyCompromise”、“CACompromise” 和 “Unspecified”。
标签:Active Directory, AD CS, AI合规, AWS 安全, Certified Pre-Owned, IPv6, Libemu, log2timeline, Plaso, PowerShell, PSPKI, Terraform 安全, 提权漏洞, 数字证书, 特权提升, 自动化部署, 证书服务, 误配置预防, 超级时间线, 配置检查, 防御矩阵