GhostPack/Certify

GitHub: GhostPack/Certify

用于枚举和滥用 Active Directory 证书服务错误配置的 C# 安全工具。

Stars: 1919 | Forks: 273

# 认证 Certify 是一个 C# 工具,用于枚举和滥用 Active Directory 证书服务 (AD CS) 中的错误配置。 [@harmj0y](https://twitter.com/harmj0y) 和 [@tifkin_](https://twitter.com/tifkin_) 是 Certify 及相关 AD CS 研究([blog](https://posts.specterops.io/certified-pre-owned-d95910965cd2) 和 [whitepaper](https://specterops.io/assets/resources/Certified_Pre-Owned.pdf))的主要作者。 ## 目录 - [Certify](#certify) - [Usage](#usage) - [Defensive Considerations](#defensive-considerations) - [Compile Instructions](#compile-instructions) - [Sidenote: Running Certify Through PowerShell](#sidenote-running-certify-through-powershell) - [Sidenote Sidenote: Running Certify Over PSRemoting](#sidenote-sidenote-running-certify-over-psremoting) - [Reflections](#reflections) - [Acknowledgments](#acknowledgments) ## 用法 命令概览和详细使用说明可以在 [wiki](https://github.com/GhostPack/Certify/wiki) 上找到。 ## 防御考量 Certify 是在 Black Hat 2021 上随我们的 ["Certified Pre-Owned: Abusing Active Directory Certificate Services"](https://www.blackhat.com/us-21/briefings/schedule/#certified-pre-owned-abusing-active-directory-certificate-services-23168) 演讲一同发布的。 有关预防和检测指导,请参阅我们的 [whitepaper](https://specterops.io/assets/resources/Certified_Pre-Owned.pdf)。 ## 编译说明 我们不打算发布 Certify 的二进制文件,因此您必须自行编译 :) Certify 是基于 .NET 4.7.2 构建的,并且与 [Visual Studio 2022 Community Edition](https://visualstudio.microsoft.com/vs/community/) 兼容。只需打开项目 .sln 文件,选择“Release”,然后构建即可。 ### 附注:通过 PowerShell 运行 Certify 如果您想通过 PowerShell 包装器在内存中运行 Certify,首先编译 Certify 并对生成的程序集进行 base64 编码: ``` [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\Temp\Certify.exe")) | Out-File -Encoding ASCII C:\Temp\Certify.txt ``` 然后可以使用以下命令将 Certify 加载到 PowerShell 脚本中(其中“aa...”替换为 base64 编码的 Certify 程序集字符串): ``` $CertifyAssembly = [System.Reflection.Assembly]::Load([Convert]::FromBase64String("aa...")) ``` 然后可以按如下方式调用 Main() 方法和任何参数: ``` [Certify.Program]::Main("enum-templates --filter-enabled --filter-vulnerable".Split()) ``` #### 附注的附注:通过 PSRemoting 运行 Certify 由于 PSRemoting 处理输出的方式,我们需要将 stdout 重定向到字符串并返回该字符串。幸运的是,Certify 有一个函数可以帮助解决这个问题。 如果您按照 [Sidenote: Running Certify Through PowerShell](#sidenote-running-Certify-through-powershell) 中的说明创建了 Certify.ps1,请在脚本中追加如下内容: ``` [Certify.Program]::MainString("enum-templates --filter-enabled --filter-vulnerable") ``` 然后,您应该能够通过 PSRemoting 运行 Certify,如下所示: ``` $s = New-PSSession dc.theshire.local Invoke-Command -Session $s -FilePath C:\Temp\Certify.ps1 ``` 或者,Certify 的 `/outfile:C:\FILE.txt` 参数会将所有输出流重定向到指定文件。 ## 反思 关于公开披露的话题,我们在发布 [whitepaper](https://specterops.io/assets/resources/Certified_Pre-Owned.pdf) 后,对攻击性工具(Certify 以及 [ForgeCert](https://github.com/GhostPack/ForgeCert))的发布进行了约 45 天的自我禁令,以便各组织有机会掌握 Active Directory 证书服务相关的问题。我们还预先为两个项目发布了一些 Yara 规则/IOC,并随白皮书发布了专注于防御的 [PSPKIAudit](https://github.com/GhostPack/PSPKIAudit) PowerShell 项目。然而,我们发现,从历史上看,在有人通过概念验证证明某些事情是可能的之前,组织和供应商往往不会修复问题或为“理论上的”攻击构建检测机制。 ## 致谢 Certify 使用了一些在线资源作为参考和灵感: * [This post](https://web.archive.org/web/20200131060008/http://geekswithblogs.net/shaunxu/archive/2012/01/13/working-with-active-directory-certificate-service-via-c.aspx) 关于从 C# 请求证书。 * [This gist](https://gist.github.com/jimmyca15/8f737f5f0bcf347450bd6d6bf34f4f7e#file-certificate-cs-L86-L101) 关于 SAN 规范。 * [This StackOverflow post](https://stackoverflow.com/a/23739932) 关于导出私钥。 * [This PKISolutions post](https://www.sysadmins.lv/blog-en/how-to-convert-pkiexirationperiod-and-pkioverlapperiod-active-directory-attributes.aspx) 关于转换 pkiExpirationPeriod。 * [This section of MS-CSRA](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-csra/b497b1e1-a84c-40c8-9379-524193176fad) 描述注册代理安全 DACL。 AD CS 的工作建立在许多其他人的工作之上。[whitepaper](https://specterops.io/assets/resources/Certified_Pre-Owned.pdf) 进行了完整的论述,但总结如下: * [Benjamin Delpy](https://twitter.com/gentilkiwi/) 因其关于使用 Mimikatz 和 Kekeo 进行智能卡/证书操作的 [extensive work](https://github.com/gentilkiwi/mimikatz/wiki/howto-~-decrypt-EFS-files)。 * PKI Solutions 因其 [excellent posts on PKI in Active Directory](https://www.pkisolutions.com/thepkiblog/) 以及我们的审计工具包所基于的 [PSPKI PowerShell module](https://github.com/PKISolutions/PSPKI)。 * Brian Komar 编写的“[Windows Server 2008 – PKI and Certificate Security](https://www.microsoftpressstore.com/store/windows-server-2008-pki-and-certificate-security-9780735640788)”一书。 * Microsoft 提供的以下开放技术规范: * [MS-CERSOD]: Certificate Services Protocols Overview * [MS-CRTD]: Certificate Templates Structure * [MS-CSRA]: Certificate Services Remote Administration Protocol * [MS-ICPR]: ICertPassage Remote Protocol * [MS-WCCE]: Windows Client Certificate Enrollment Protocol * [Christoph Falta's GitHub repo](https://github.com/cfalta/PoshADCS) 涵盖了有关攻击证书模板的一些细节,包括虚拟智能卡以及一些基于 ACL 滥用的想法。 * CQURE 的“[The tale of Enhanced Key (mis)Usage](https://cqureacademy.com/blog/enhanced-key-usage)”文章涵盖了一些使用者可选名称 (SAN) 的滥用。 * Keyfactor 2016 年的文章“[Hidden Dangers: Certificate Subject Alternative Names (SANs)](https://www.keyfactor.com/blog/hidden-dangers-certificate-subject-alternative-names-sans/)” * [@Elkement](https://twitter.com/elkement) 的文章“[Sizzle @ hackthebox – Unintended: Getting a Logon Smartcard for the Domain Admin!](https://elkement.blog/2019/06/01/sizzle-hackthebox-unintended-getting-a-logon-smartcard-for-the-domain-admin-2/)”和“[Impersonating a Windows Enterprise Admin with a Certificate: Kerberos PKINIT from Linux](https://elkement.wordpress.com/2020/06/21/impersonating-a-windows-enterprise-admin-with-a-certificate-kerberos-pkinit-from-linux/)”详细介绍了证书模板的错误配置。 * Carl Sörqvist 写了一篇详细且合理的场景文章,描述了其中一些错误配置是如何发生的,标题为“[Supply in the Request Shenanigans](https://blog.qdsecurity.se/2020/09/04/supply-in-the-request-shenanigans/)”。 * [Ceri Coburn](https://twitter.com/_ethicalchaos_) 在 2020 年发布了一篇关于“[Attacking Smart Card Based Active Directory Networks](https://ethicalchaos.dev/2020/10/04/attacking-smart-card-based-active-directory-networks/)”的优秀文章,详细介绍了一些智能卡滥用和 Certify 的新增功能。 * Brad Hill 发表了一份题为“[Weaknesses and Best Practices of Public Key Kerberos with Smart Cards](https://research.nccgroup.com/wp-content/uploads/2020/07/weaknesses_and_best_practices_of_public_key_kerberos_with_smart_cards.pdf)”的白皮书,其中从安全角度提供了有关 Kerberos/PKINIT 的一些良好背景知识。
标签:Active Directory, AD CS, AI合规, AWS 安全, Cloudformation, log2timeline, OpenCanary, Plaso, Terraform 安全, URL发现, 内网安全, 内网安全, 协议分析, 域渗透, 多协议支持, 安全检测, 安全防御, 攻击预警, 服务器监控, 权限提升, 电子数据取证, 网络欺骗, 黑客追踪