Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESC4 detection to ldap_esc_vulnerable_cert_finder module #19816

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jheysel-r7
Copy link
Contributor

@jheysel-r7 jheysel-r7 commented Jan 20, 2025

This adds support for ESC4 to the ldap_esc_vulnerable_cert_finder module. Certificates vulnerable to ESC4 are certs where the user enumerating can edit them. The idea being that if the user has edit permissions they can modify the cert to be vulnerable to ESC1 then exploit it to get domain admin on the DC.

This addition works by first running an LDAP query to determine what user we are authenticating with and what security groups they are a part of. The module then gets a list of all certificate templates and determines whether the user has the ability to edit any of them.

Verification Steps

First deploy a vulnerable template with ad_cs_cert_template

  • Do use admin/ldap/ad_cs_cert_template
  • Do set TEMPLATE_FILE data/auxiliary/admin/ldap/ad_cs_cert_template/esc4_template.yaml
  • Do set CERT_TEMPLATE VulnToEsc4
  • Do set action CREATE
  • Input domain admin credentials:DOMAIN PASSWORD RHOSTS USERNAME
  • Go in to the certsrv on the domain controller, right click Certificate Templates -> New -> Certificate Template to Issue and select VulnToEsc4

Ensure ldap_esc_vulnerable_cert_finder finds the vulnerable certificate

  • Do use gather/ldap_esc_vulnerable_cert_finder
  • Run the module with a low privilege user: run domain=kerberos.issue password=N0tpassword! rhost=172.16.199.200 username=msfuser
  • Verify VulnToEsc4 appears vulnerable to ESC4.

Note if you run the vulnerable cert finder with a domain admin as you might expect, almost all templates should be reported as vulnerable to ESC4.

Testing

msf6 auxiliary(admin/ldap/ad_cs_cert_template) > set CERT_TEMPLATE VulnToEsc4
CERT_TEMPLATE => VulnToEsc4
msf6 auxiliary(admin/ldap/ad_cs_cert_template) > set TEMPLATE_FILE /Users/jheysel/rapid7/metasploit-framework/data/auxiliary/admin/ldap/ad_cs_cert_template/esc4_template.yaml
TEMPLATE_FILE => /Users/jheysel/rapid7/metasploit-framework/data/auxiliary/admin/ldap/ad_cs_cert_template/esc4_template.yaml
msf6 auxiliary(admin/ldap/ad_cs_cert_template) > set domain kerberos.issue
domain => kerberos.issue
msf6 auxiliary(admin/ldap/ad_cs_cert_template) > set password N0tpassword!
password => N0tpassword!
msf6 auxiliary(admin/ldap/ad_cs_cert_template) > set rhost 172.16.199.200
rhost => 172.16.199.200
smsf6 auxiliary(admin/ldap/ad_cs_cert_template) > set username Administrator
username => Administrator
msf6 auxiliary(admin/ldap/ad_cs_cert_template) > run
[*] Running module against 172.16.199.200
[*] Discovering base DN automatically
[*] Creating: CN=VulnToEsc4,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[+] The operation completed successfully!
[*] Auxiliary module execution completed
msf6 auxiliary(gather/ldap_esc_vulnerable_cert_finder) > run domain=kerberos.issue rhost=172.16.199.200 username=msfuser password=Derpderp69!
[*] Running module against 172.16.199.200
[*] Discovering base DN automatically
[!] Couldn't find any vulnerable ESC13 templates!
[+] Template: Copy of Web Server
[*]   Distinguished Name: CN=Copy of Web Server,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures: 0
[+]   Vulnerable to: ESC1, ESC2
[*]   Notes:
[*]     * ESC1: Request can specify a subjectAltName (msPKI-Certificate-Name-Flag) and EKUs permit authentication
[*]     * ESC2: Template defines the Any Purpose OID or no EKUs (PkiExtendedKeyUsage)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-11 (Authenticated Users)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[+] Template: WebServer
[*]   Distinguished Name: CN=WebServer,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures: 
[+]   Vulnerable to: ESC4, ESC15
[*]   Notes:
[*]     * ESC4: The user msfuser is a part of the following groups: (Authenticated Users) which have edit permissions over the template WebServer making it vulnerable to ESC4
[*]     * ESC15: Request can specify a subjectAltName (msPKI-Certificate-Name-Flag) and EKUs can be altered (msPKI-Template-Schema-Version)
[*]   Users or Groups SIDs with Certificate Template write access:
[*]     * S-1-5-11 (Authenticated Users)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[+] Template: ExchangeUserSignature
[*]   Distinguished Name: CN=ExchangeUserSignature,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures: 
[+]   Vulnerable to: ESC4, ESC15
[*]   Notes:
[*]     * ESC4: The user msfuser is a part of the following groups: (Authenticated Users) which have edit permissions over the template ExchangeUserSignature making it vulnerable to ESC4
[*]     * ESC15: Request can specify a subjectAltName (msPKI-Certificate-Name-Flag) and EKUs can be altered (msPKI-Template-Schema-Version)
[*]   Users or Groups SIDs with Certificate Template write access:
[*]     * S-1-5-11 (Authenticated Users)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[+] Template: CAExchange
[*]   Distinguished Name: CN=CAExchange,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures: 
[+]   Vulnerable to: ESC4
[*]   Notes: ESC4: The user msfuser is a part of the following groups: (Authenticated Users) which have edit permissions over the template CAExchange making it vulnerable to ESC4
[*]   Users or Groups SIDs with Certificate Template write access:
[*]     * S-1-5-11 (Authenticated Users)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[+] Template: Copy 2 of Web Server
[*]   Distinguished Name: CN=Copy 2 of Web Server,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures: 
[+]   Vulnerable to: ESC4
[*]   Notes:
[*]     * ESC4: The user msfuser has edit permissions over the template Copy 2 of Web Server making it vulnerable to ESC4
[*]     * ESC4: The user msfuser is a part of the following groups: (Authenticated Users) which have edit permissions over the template Copy 2 of Web Server making it vulnerable to ESC4
[*]   Users or Groups SIDs with Certificate Template write access:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-1000 (msfuser)
[*]     * S-1-5-11 (Authenticated Users)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-1000 (msfuser)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*] Auxiliary module execution completed

@rapid7 rapid7 deleted a comment from Theivaraj1211 Jan 20, 2025
@smcintyre-r7 smcintyre-r7 self-assigned this Jan 21, 2025
@smcintyre-r7 smcintyre-r7 added the rn-modules release notes for new or majorly enhanced modules label Jan 21, 2025
@jheysel-r7 jheysel-r7 marked this pull request as ready for review January 22, 2025 05:15
user_groups << group_sid
end

user_groups << Rex::Proto::Secauthz::WellKnownSids::SECURITY_AUTHENTICATED_USER_SID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to this, I think we'll want to figure out if the account we're using is a User or a Computer. Once we know, we'll want to add the SID for Domain Users or Domain Computers as applicable. That means you'll also have to get the Domain SID though too.

Once you have the Users or Computers group, we'll want to look up it's DN and add it to the filter_with_users using the logical OR operator. With this in place, we should be able to identify cases where one of these groups has inherited permissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module now differentiates between users and computer accounts and adds the necessary SIDs to the user_groups where applicable.

New relevant testing output:

[+] Template: Copy 2 of Web Server
[*]   Distinguished Name: CN=Copy 2 of Web Server,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=kerberos,DC=issue
[*]   Manager Approval: Disabled
[*]   Required Signatures:
[+]   Vulnerable to: ESC4
[*]   Notes: ESC4: The computer DC2$ is a part of the following groups: (Domain Computers) which have edit permissions over the template Copy 2 of Web Server making it vulnerable to ESC4
[*]   Users or Groups SIDs with Certificate Template write access:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-515 (Domain Computers)
[*]   Certificate Template Enrollment SIDs:
[*]     * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-515 (Domain Computers)
[*]     * S-1-5-21-2324486357-3075865580-3606784161-1000 (msfuser)
[*]     * S-1-5-11 (Authenticated Users)
[+]   Issuing CA: kerberos-DC2-CA (dc2.kerberos.issue)
[*]     Enrollment SIDs:
[*]       * S-1-5-11 (Authenticated Users)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-519 (Enterprise Admins)
[*]       * S-1-5-21-2324486357-3075865580-3606784161-512 (Domain Admins)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-modules release notes for new or majorly enhanced modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants