Page cover

Certified

SUMMARY

This is a Windows 2019 Server running as a domain controller with several overly permissive misconfigurations, that we enumerate with the new BloodHound CE tool, and a vulnerable AD CS template. First we upgrade our rig: we install the new Bloodhound CE and update our data collector tool so it is compatible with the new BloodHound version. Once all is running, we enumerate the Active Directory and discover overly permissive ACEs that enable a shadow credentials attack on one account. As a result of the attack we obtain an NT hash and gain the user flag.

Regarding escalation, we enumerate AD CS templates and find one vulnerable to ESC9. This is abused to generate an administrator certificate and obtain the administrator NT hash.

KEYWORDS

BloodHound CE, BloodHound-CE-Python, Impacket, owneredit.py, dacledit.py, shadow credentials attack, pyWhisker, bloodyAD, Active Directory Certificate Services (AD CS), ESC9.

REFERENCES

https://github.com/SpecterOps/BloodHound

https://support.bloodhoundenterprise.io/hc/en-us/articles/17468450058267-Install-BloodHound-Community-Edition-with-Docker-Compose

https://m4lwhere.medium.com/the-ultimate-guide-for-bloodhound-community-edition-bhce-80b574595acf

https://github.com/dirkjanm/BloodHound.py

https://github.com/CravateRouge/bloodyAD

https://i-tracing.com/blog/dacl-shadow-credentials/

https://github.com/ShutdownRepo/pywhisker

https://github.com/dirkjanm/PKINITtools

https://www.thehacker.recipes/ad/movement/dacl/forcechangepassword

https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf

https://docs.metasploit.com/docs/pentesting/active-directory/ad-certificates/attacking-ad-cs-esc-vulnerabilities.html

https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7

ENUMERATION

Port scan.

We have also credentials for judith.mader:judith09. We can use them to enumerate the SMB service.

And bruteforce the RID to get a list of usernames.

This looks like an excellent opportunity to test BloodHound CE, the new version of the legendary graphical Active Directory enumeration tool Bloodhound. It seems the original release is now called BloodHound Legacy, and there is another BloodHound Enterprise version.

Let's follow instructions to install BloodHound CE. The process can be done with Docker Compose, and looks simplified with regards how was done in the classic release.

Download the composer file and run it.

When finished, access BHCE GUI via http://localhost:8080/ui/login. Username is admin, and the password is provided in the Docker Compose output. Take note of it as it needs to be reset during first login.

Once inside the tool, we are presented an empty database.

We need a collector to gather data to ingest. We do not have a shell in the host so we cannot use SharpHound.exe. We will have to collect the data remotely with BloodHound.py. However, it seems collectors for BloodHound Legacy do not work anymore with BHCE, so we will have to update our toolbox.

In the BloodHound.py GitHub repository we see there is a new package called bloodhound-ce specifically designed for BHCE.

Install with pip

The binary is installed in /home/kali/.local/bin/bloodhound-ce-python and is designed to run under Python3.

Just take the JSON files and ingest the data in BHCE. Click on Settings → Administration → Upload Files.

Now we can start exploring the domain. The built-in queries are available in Explore → Cypher → Open. For example, let's list all domain admins.

To enumerate judith.mader, click on "Search" and type the username, the user icon is displayed. Then click on "Outbound Object Control" to list which objects the user judith.mader can control or manipulate.

We see she has WriteOwner rights over the management@certified.htb group, meaning she has permissions to change the owner of this group.

USER

By clicking on the WriteOwner edge, the application itself suggests an exploitation path.

Basically, the abuse path is:

  1. Leverage the WriteOwner right to set judith.mader as the group owner.

  2. Grant judith.mader permission to add any user to the group.

  3. Add judith.mader to the group.

Let's start by enumerating the management@certified.htb group with ldapsearch

Next, change the group owner with Impacket's owneredit.py. Version 0.12 is needed for this, so you may need to upgrade your packages.

owneredit.py allows to work with either sAMAccountName or distinguishedName to identify the target and new owner accounts. We can take any of these from BHCE.

Next step would be to edit the group DACL adding a new ACE that grants judith.mader permission to add new members. It is done with Impacket's dacledit.py

Now judith.mader has permission to add herself to the group. For this we use bloodyAD.

We have taken ownership of management@certified.htb group and added ourselves as a member. We mark this as "Owned" in BHCE and continue enumerating from there.

The group has another member, the user management_svc, over which we have GenericWrite permissions as group owners. Again, by clicking on the edge, the tool suggests possible ways to abuse this.

We see the possibility of launching a shadow credentials attack with pyWhisker.

In summary, in a shadow credentials attack, the attacker populates the msDS-KeyCredentialLink attribute on the targeted account, for which GenericAll or GenericWrite is needed. Then the attacker requests a PFX certificate for this target user, that is used to authenticate and request either a TGT or the target's NT hash. Both of them allow to get a shell under the context of the target account.

Let's start by populating the attribute with pywhisker.py. First we check current status of the attribute.

It seems the attribute is empty, let's populate it.

The tool generates a PFX file containing a certificate and a private, and suggests we can use with PKINITtools.

The procedure explaining how to request a TGT ticket with gettgtpkinit.py and a PEM certificate is explained at pyWhisker GitHub repository. In our case we have a PFX certificate, but only a minor modification to the command is needed.

Before using the tool PKINITtools, it is needed to manually install a dependency Minikerberos.

Now let's request a TGT ticket for managemenet_svc using the PFX certificate and gettgtpkinit.py. As always when requesting TGT tickets, remember to synchronize clock to avoid skew errors.

Ticket has been saved. Export it for use.

And use it to retrieve management_svc NT hash.

The only thing that's left is to open a shell as management_svc

And collect the user flag.

SYSTEM

Start from the management_svc shell and take the opportunity to enumerate the system.

Enumerate the user in BHCE, we see it has GenericAll over another user ca_operator. Clicking over the edge the application suggest an abuse path, including a force password change.

We can do a shadow credentials attack again, or force a password change with bloodyAD.

The new credential does not work for Evil-WinRM, but we can check the password has been successfully changed via SMB.

The username ca_operator strongly suggests AD CS is running on the machine. Since we cannot have a local shell as ca_operator we cannot enumerate templates with certify.exe, but we can do it remotely with Certipy as we did in Authority.

Which reports there is a template CertifiedAuthentication vulnerable to ESC9.

These ESC codes are given following the terminology used in the original AD CS abuse whitepaper that initially described 8 different domain escalation attacks, and were later expanded by subsequent researches.

Let's abuse ESC9 following the researcher's step-by-step. We comply with the requirements for this attack since management_svc has has GenericWrite over ca_operator, who in turn is allowed to enroll in the certificate template ESC9, that contains the CT_FLAG_NO_SECURITY_EXTENSION flag in the msPKI-Enrollment-Flag value.

Following the guide, first we change ca_operator UPN to "Administrator", using management_svc credentials (in this case management_svc hash is used for authentication).

Now, we request the vulnerable certificate template ESC9 as ca_operator

Next, modify again the ca_operator UPN so there is no mismatch errors in the next step.

Finally, we try to authenticate with the certificate so we receive the NT hash of the Administrator. You will need to add domain since there is no domain specified in the certificate.

Also, we have to deal with skew errors, stopping the timedatectl auto synchronization, and synchronizing manually with rdate

Now, we can run certipy to request a TGT and retrieve the Administrator NT hash.

An use it to open a shell.

You are root.

Last updated