ADCS
ADCS
Certificate Templates
• Intended Use
• Permissions
• Functionality
EKU (extended key usage) are OIDs (object identifier) that define the functions and usage of the
certificate template.
Certificate Authority
• Name
• Hostname
• Web Enrollment
• Flags
• Permissions
• Access Rights
• Enrollment Agent Restrictions
Certificate Templates
• Domain Object
• CA
• Name
• Enabled
• Extended Key Usage (EKU)
• Permissions
• Enrollment Permissions
• Object Control Permissions
UnPac The Hash Attack
UnPac the Hash
This technique used to obtain the NTLM hash of a domain account from a
certificate. This technique will be used in each of the attacks demonstrated. I
believe it is important to cover the attack even if Certipy automates the process
for us.
This technique revolves around Kerberos authentication using PKINIT. If you are
not familiar with how Kerberos works, this attack may be difficult to understand.
When a TGT is requested with PKINIT the NTLM hash is added in the
PAC_CREDENTIAL_INFO field in case Kerberos authentication is not supported.
The PAC is encrypted with the KRBTGT account’s hash. This means we can’t just
extract the NTLM hash from the ticket.
If we utilize this TGT to request a TGS the same structure is added but is ciphered
with the session key. This session key can be extracted and used to decrypt the
PAC, including the PAC_CREDENTIAL_INFO field. Which allows us to extract the
NTLM hash of the authenticating account.
Privilege Escalation (ESC 1)
ESC 1 - Enumeration (certipy)
This occurs when a template is over permissioned and results in
complete domain compromise.
Requirements:
- Client Authentication set to True (PKINIT EKU)
- The EnroleeSuppliesSubject certificate name flag (subject
alternative name EKU)
- The ability to enroll (any valid domain account)
The certipy tool can be used to remotely request CA and template
information.
$ certipy find –vulnerable –u user –p pass –target domain.corp
ESC 1- Exploitation (certipy)
To exploit this, we first need to request a certificate authenticated as our
current user while specifying the target CA, Template, and target user.
Then using the pfx (certificate) requested, we perform an un-pac the hash
attack to extract the targeted account’s NTLM hash.
Privilege Escalation (ESC 4)
ESC 4 - Enumeration (certipy)
Like ESC 1 this occurs when a template is over permissioned and
results in complete domain compromise.
Requirements:
- Write Permissions over a template
The write permissions allow us to back up the template, modify it
to be vulnerable to ESC 1, exploit ESC 1, and finally revert the
template back to the original configuration.
ESC 4 - Enumeration (certipy)
For ESC 1 the entire domain users can enroll. If that is a must, then making sure that
the template is configured in a way that it either cannot be used by an attacker to
authenticate or to remove the EnrolleeSuppliesSubject configuration. A less common
way to mitigate this is by enabling Certificate Manager Approval before issuing
certificates.
When it comes to situations like these its best to first configure the templates and CA
based on the principal of least privilege. For the case of ESC 4, if that user absolutely
requires the ability to modify the template, it may be best to create a specific domain
account intended for that.
For ESC 8 if its possible to disable web enrollment, that would be the first step to
mitigating the risk. Enabling extended protection for authentication (EPA) is an
additional configuration that can be made. And lastly, disabling NTLM on the DA and
CA could prevent the abuse.
Microsoft does have its own document on security the PKI. Link to it is here.
tylertech.com