ADCS PrivEsc: Certificate Templates
Privilege escalation with Active Directory Certificate Services
Enumeration
Enumerating the ADCS from localhost
Enumerating the ADCS from LDAP
It is also possible to enumerate the Active Directory Certificate Services (ADCS) from Linux or any platform that supports LDAP connectivity
Enumerating certificate templates
When rights like Allow Full Control
or Allow Write
are granted for a user under your control, this will enable you to edit the specific certificate template. If the certificate template has Allow Enroll
for your user(group) or you already obtain a certificate for another User Principal Name (UPN) it might be possible to escalate privileges or perform lateral movement.
Allow Full Control also grants Allow Enroll rights
Enumerating existing certificates
Listing
Extracting a certificate
Extracting the private key from a certificate
The extracted private key also can be used with Rubeus (see here)
Enumerating the CA servers local policy
If you find that EDITF_ATTRIBUTESUBJECTALTNAME2
is set as a flag this allows anyone to set a User Principal Name (UPN) for any certificate template in the active directory (you still might need to modify the template, if you are not able to request/enroll one).
Exploitation / Modification
Abusing write access on a certificate template
Modifying the certificate template and setting the necessary properties
Information about the Properties
mspki-certificate-name-flag
-> specifies the subject name flags1
-> instructs the client to supply subject information in the certificate request
pkiextendedkeyusage
-> list of OIDs that represent the extended key usages1.3.6.1.4.1.311.20.2.2
-> Microsoft Smart Card Logon1.3.6.1.5.5.7.3.2
-> Client Authentication
msPKI-Certificate-Application-Policy
-> application policy OID added to the certificate application policy extensionhas to be the same as
pkiextendedkeyusage
flags = 0
-> general enrollment flags0
-> no flags (clear flags)
mspki-enrollment-flag
-> enrollment flags0
-> no flags (clear flags)
mspki-private-key-flag
256
-> instructs client to process themsPKI-RA-Application-Policies
attribute+16
-> instructs client to allow other applications to copy the private key to a.pfx
file at a later time
pKIDefaultKeySpec
1
-> Keys used to encrypt/decrypt session keys
pKIDefaultCSPs
-> cryptographic service providers (CSP) used to create private and public key1,Microsoft RSA SChannel Cryptographic Provider
integer,
-> priority for the CSPstring
-> CSP to use
Properties like
pkiextendedkeyusage
andmsPKI-Certificate-Application-Policy
should be set as needed depending on the services configured on the CA. However either Client Authentication, Microsoft Smartcard Logon, Key Purpose Client Auth or Any Purpose have to be set, in order to escalate privileges. The corresponding OIDs are publicly available.
Privilege escalation
Using a certificate to authenticate as a privileged principal with PKINIT. There are two ways to achieve this.
The certificate
is configured on the target object as an alternative security identity (Whatever that means; Not covered here)
includes the User Principal Name (UPN) of the target principal in the Subject Alternative Name extension
Using the Subject Alternative Name
when escalating privileges with the UPN, we need (to enroll) a certificate with the subject alternative name
set to our target.
Setting the subject alternative name and enrolling a certificate
Powershell
this already should be configured to abuse
EDITF_ATTRIBUTESUBJECTALTNAME2
you need to modify$IAN.InitializeFromString(0xB,"Administrator")
(Not tested)
CertReq
request.inf (template)
to abuse
EDITF_ATTRIBUTESUBJECTALTNAME2
you need to modifySAN="upn=Administrator"
commands
create a
-new
certificate request from given policy file-Submit
the generatedrequest.pem
to the certificate authority-Accept
and install the response of the certificate authority
Using an existing certificate
If you already have a certificate for another user you might be able to obtain a TGT for this user. However you need to manually check if the certificate fulfills the requirements from the exploitation step.
The subject alternative name
can be extracted for a certificate from the current users store
or using openssl
when parsing certificates (.cer) with openssl you might need to inform openssl about the certificate format e.g. (DER | PEM)
Using Rubeues to escalate privileges with the certificate
Obtain a Ticket Granting Ticket (TGT) for the User Principal Name (UPN)
Obtain a Ticket Granting Service (TGS) for the obtained Ticket Granting Ticket (TGT)
Further things to do (get creative)
*exec with the obtained TGS (e.g.
psexec
)crack the TGS (because the NT hash of the user is included in this ticket)
convert the kirbi ticket to a ccache ticket (e.g. when working on Linux)
use the service you obtained it for :---)
References
Last updated