ADCS + PetitPotam NTLM Relay: Obtaining krbtgt Hash with Domain Controller Machine Certificate
This is a quick lab to familiarize with an Active Directory Certificate Services (ADCS) + PetitPotam + NLTM Relay technique that allows attackers, given ADCS is misconfigured (which it is by default), to effectively escalate privileges from a low privileged domain user to Domain Admin.
The ADCS vulnerabilities were researched by Will Schroeder and Lee Christensen in Certified Pre-Owned, PetitPotam was researched by Gilles Lionel @topotam77, ADCS attack implemented in impacket by ExAndroidDev.
Conditions
Below are some of the conditions making an AD environment vulnerable to ADCS + NTLM relay attack:
ADCS is configured to allow NTLM authentication;
NTLM authentication is not protected by EPA or SMB signing;
ADCS is running either of these services:
Certificate Authority Web Enrollment
Certificate Enrollment Web Service
Overview
Below provides a high level overview of how the attack works:
Get a foothold in an AD network with a misconfigured ADCS instance;
Setup an NTLM relay listener on a box you control, so that incoming authentications are relayed to the misconfigured ADCS;
Force the target DC to authenticate (using PetitPotam or PrintSpooler trick) to the box running your NTLM relay;
Target DC attempts to authenticate to your NTLM relay;
NTLM relay receives the DC$ machine account authentication and relays it to the ADCS;
ADCS provides a certificate for the target DC$ computer account;
Use the target DC's computer account certificate to request its Kerberos TGT;
Use target DC's computer account TGT to perform DCSync and pull the NTLM hash of
krbtgt;Use
krbtgtNTLM hash to create Golden Tickets that allow you to impersonate any domain user, including Domain Admin.
Below graphic visualizes the concept:

Domain Takeover
Lab Setup
This part of the lab is setup with the following computers and servers:
10.0.0.5 - Kali box with NTLM relay;
10.0.0.6 - target Domain Controller
DC01. This is the target DC that we will coerce to authenticate to our NTLM relay on 10.0.0.5;10.0.0.10 - Certificate Authority (
CA01). This is where our NTLM relay 10.0.0.5 will forwardDC01authentication to;10.0.0.7 - Windows worksation (
WS01). This is the initial foothold in the network and this is the machine that will force theDC01to authenticate to our NTLM relay on 10.0.0.5;
Installing Tools
Let's pull the version of impacket that has ADCS attack implemented and checkout the right branch:

Configuring Virtual Environment
Prepare a python virtual environment for impacket. Start by installing the virtual environment package:

Create and activate a new virtual python environment called impacket:

Let's install all impacket dependencies:

Finding Certificate Authority
On WS01, we can use a Windows LOLBIN certutil.exe, to find ADCS servers in the domain:

We confirm that in our domain, CA01 is our Certificate Authority that we will be relaying DC01$ authentication to.
Setting up NTLM Relay
On Kali box at 10.0.0.5, let's setup our NTLM relay to forward incoming authentications from DC01$ to the CA01, or more specifically to one of its HTTP endpoints for certificate enrollment http://ca01/certsrv/certfnsh.asp like so:

Forcing DC01 to Authenticate to NTLM Relay
From WS01, let's force the DC01 to authenticate to our NTLM relay at 10.0.0.5 by executing PetitPotam:

Above shows how:
DC01was forced to authenticate to 10.0.0.5;10.0.0.5 relayed the
DC01$authentication toCA01;CA01issued a certificate for theDC01$computer account.
Requesting DC01$ TGT
On WS01, we can now use rubeus to request a Kerberos TGT for the DC01$ computer account like so:

klist confirms we now have a TGT for DC01$ in the current logon session:

We can now perform DCSync and pull the NTLM hash for the user offsense\krbtgt:

Having the NTLM hash for krbtgt allows us to create Kerberos Golden Tickets.
Remember
It's worth remembering that in some AD environments there will be highly privileged accounts connecting to workstations to perform some administrative tasks and if you have local administrator rights on a compromised Windows box, you can perform ADCS + NTLM relay attack to request a certificate for that service account.
To do so, you'd need the following:
Reminder Consider your OPSEC.
Stop the SMB service on the compromised box. This requires local admin privileges on the box and a reboot to stop the machine from listening on TCP 445;
Spin up the NTLM relay on TCP 445;
Wait for the service account to connect to your machine;
Incoming service account authentication is relayed to the ADCS, which spits out the service account certificate;
Use service account's certificate to request its Kerberos TGT;
You've now gained administrative privileges on machines the compromised service account can access.
RBCD: Remote Computer Takeover
It's also possible to gain administrative privileges over any remote computer given we have network access to that computer, as pointed out by Lee Christensen:
Lab Setup
This part of the lab is setup with the following computers and servers:
10.0.0.5 - Kali box with NTLM relay;
10.0.0.7 - Windows worksation (
WS01). This is the box we will coerce to authenticate our Kali box, which will relay the authentication toDC01and setup the computerWS01for a remote takeover;10.0.0.6 - Domain Controller
DC01;10.0.0.10 - Certificate Authority (
CA01). This is the box from which we will coerceWS01to authenticate toDC01;
Setting up NTLM Relay
Let's set up our NTLM relay on the Kali box to relay authentications to DC01 via LDAP and specify the --delegate-access flag, which will automate the Resource Based Constrained Delegation (RBCD) attack steps:
Notes about RBCD takeover:
Kerberos Resource-based Constrained Delegation: Computer Object TakeoverForcing WS01 to Authenticate to NTLM Relay
On computer CA01, let's invoke PetitPotam and coerce WS01 (10.0.0.7) to authenticate to our Kali box (10.0.0.5) where our NTLM relay is setup:

On our Kali box, we can see the the incoming authentication from WS01$ was relayed to ldaps://dc01 and that a new computer quaiivve$ account (that WS01 now trusts and allows to impersonate any domain user), was created:

Below screenshot shows that the QUAIIVEE computer account has been indeed created and WS01$ has some privileges to it:

Additionally, we can see that the attribute msDS-AllowedToActOnBehalfOfOtherIdentity on computer object WS01 contains some binary value, which is empty by default on computer objects:

From Kerberos Resource-based Constrained Delegation: Computer Object Takeover, we know that the msDS-AllowedToActOnBehalfOfOtherIdentity attribute, after we've successfully performed the LDAP relay attack, effectively encodes the following: computer WS01 trusts the computer account QUAIIVVE$ and allows it to impersonate any domain user, including Domain Admins and grant them administrative access to WS01.
Calculating Hash
On computer CA01, let's calculate the RC4 hash for the newly created computer account's QUAIIVVE$: password:

Impersonating Domain Admin on WS01
Time to impersonate a Domain Admin.
While on CA01, we can use rubeus s4u command, which will:
Retrieve a TGT for
offense.local\QUAIIVVE$;Perform
S4U2Self, which is a Kerberos extension that allows a service to obtain a TGS to itself on another user's behalf. So in our case, theCA01will request a TGS for[email protected]as[email protected];Perform
S4U2Proxy, which is a Kerberos extension that enables services to request TGS tickets to other services on behalf of a given user. In this instance, a TGS will be requested forcifs/ws01.offense.local, which will allowCA01to accessWS01computer's file system (i.e.,c$share) on behalf of the Domain Admin[email protected]:

We can now try to access WS01 c$ share from CA01 to confirm if we've gained administrative access over WS01:

WebClient Service
For the above attack to work, the target system WS01 has to have the WebClient service running:

WebClient service is not running on computers by default and normally you'd need admin rights to start it, however it's possible to force the service to start using the below code:
Below shows WebClient service is not running on WS01 and we cannot start it, however, executing the above code (webclient.cpp compiled as webclient.exe) kicks off the WebClient service for us:

RBCD: Local Computer TakeOver / Local Privilege Escalation
It's also possible to leverage the ADCS NTLM relay + Resource Based Constrained Delegation (RBCD) to escalate privileges on a local computer, if regular domain users can create new machine/computer accounts in AD, which they are by default, as specified in the domain root object's attribute ms-DS-MachineAccountQuota: 10, as seen below:

Lab Setup
This part of the lab is setup with the following computers and servers:
10.0.0.5 - Kali box with NTLM relay;
10.0.0.7 - Windows worksation
WS01. This is the box we will coerce to authenticate our Kali box, which will relay the authentication toDC01and setup the computerWS01for RBCD attack;10.0.0.6 - Domain Controller
DC01;
Calculating Hash
Building on the previous successful NTLM relay, where we forced the WS01$ to authenticate to our Kali box (where our NTLM relay was listening), we got a new machine account QUAIIVVE$ created with a password K_-Jzsb&uK!`TIH. Let's re-calculate the password's hash:

Impersonating Domain Admin on WS01
We can now perform the S4U against WS01, where we currently have low privileged access, but want to elevate to administrator:
Above and below shows how a TGS for [email protected] is granted access to cifs/ws01.offense.local:

Decoding TGS to .kirbi
On a Kali box, let's base64 decode the TGS we got for [email protected] to cifs/ws01.offense.local and save it as admin.kirbi:

Converting .kirbi Ticket to .ccache
Use impacket's tool ticketConverter to convert the .kirbi file to .ccache file like so:

Exporting KRB5CCNAME
Now we need to export the KRB5CCNAME variable and point it to our admin.ccache file:

Executing Code as Domain Admin on WS01
We can now use impacket's wmiexec to execute commands on WS01 as administrator:

Privileged code execution on WS01 can also be achieved using impacket's psexec:

Note to self: what a beautiful attack vector this is.
PetitPotam blocked?
You can now also use:
References
Last updated