rotate-exclamationDcSync

DCSync Attack: A Deep Technical Dive into Active Directory Credential Theft

Note: This article provides an in-depth technical analysis of the DCSync attack technique, including detailed API function breakdowns, network protocol analysis, and practical exploitation methods. Intended for security researchers, penetration testers, and defensive security professionals.


Introduction

DCSync is one of the most powerful post-exploitation techniques in Active Directory environments. Introduced by Benjamin Delpy and Vincent Le Toux in Mimikatz (August 2015), DCSync allows an attacker to impersonate a Domain Controller and request password data from legitimate DCs without requiring code execution on the target server.

Unlike traditional credential dumping methods that require physical or remote access to extract the NTDS.dit database, DCSync operates entirely over the network using legitimate Windows replication protocols. This makes it particularly stealthy and difficult to prevent once an attacker has obtained the necessary permissions.

Why DCSync is Critical

  • No Code Execution Required: Works remotely over the network

  • Leverages Legitimate Protocols: Uses Microsoft's Directory Replication Service (DRS)

  • Minimal Forensic Footprint: Harder to detect than traditional memory dumping

  • Extracts All Credentials: Retrieves NTLM hashes, password history, and Kerberos keys

  • Persistence Friendly: Can be used repeatedly without touching disk


What is DCSync?

DCSync is a credential dumping technique that abuses the MS-DRSR (Directory Replication Service Remote Protocol) to replicate password data from a Domain Controller. It essentially tricks the DC into thinking the attacker's machine is another DC requesting legitimate replication data.

The Core Concept

Normal DC Replication: When you have multiple Domain Controllers in an Active Directory environment, they need to stay synchronized. Domain Controllers replicate data between each other using Microsoft's replication protocols. This is completely normal and expected behavior.

The DCSync Attack: An attacker with the right permissions tells the Domain Controller: "Hey, I'm another DC, please replicate user password data to me." The DC validates the requester has replication permissions, and if yes, it sends back the password hashes.

Key Point: DCSync doesn't exploit a vulnerability—it abuses a legitimate feature. If you have the right permissions, the DC will happily give you the data because it thinks you're another DC requesting normal replication.

Key Characteristics

Aspect
Details

Protocol Used

MS-DRSR (Directory Replication Service Remote Protocol)

Transport

RPC over TCP (Port 135 + Dynamic Ports)

Interface UUID

e3514235-4b06-11d1-ab04-00c04fc2dcd2 (DRSUAPI)

Core Function

IDL_DRSGetNCChanges

Authentication

Kerberos or NTLM

Required Rights

Replication permissions on domain object

What Makes DCSync Different?

Traditional Methods
DCSync

Requires DC access

Works remotely

Reads NTDS.dit file

Uses replication protocol

Memory dumping (LSASS)

Network-based

Needs local admin on DC

Needs replication rights

High detection risk

Blends with legitimate traffic


Required Permissions

To successfully execute DCSync, an attacker needs specific Extended Rights on the domain object. These permissions control who can replicate directory data.

The Three Critical Rights

1. Replicating Directory Changes (DS-Replication-Get-Changes)

  • GUID: 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2

  • Purpose: Allows replication of non-secret domain data

  • Scope: Changes replicated to Global Catalog

2. Replicating Directory Changes All (DS-Replication-Get-Changes-All)

  • GUID: 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2

  • Purpose: Allows replication of secret domain data (passwords)

  • Scope: All data including password hashes

3. Replicating Directory Changes In Filtered Set

  • GUID: 89e95b76-444d-4c62-991a-0facbeda640c

  • Purpose: Required in some environments with RODCs

  • Scope: Filtered attribute sets

Default Privileged Groups

The following groups have these rights by default:

  • Domain Admins

  • Enterprise Admins

  • Administrators

  • Domain Controller computer accounts

Why These Permissions Exist

These permissions are necessary for legitimate DC replication. When you promote a new Domain Controller, it needs these rights to synchronize the entire Active Directory database from existing DCs. Without these permissions, replication would fail.

Checking Who Has DCSync Permissions

To find who has DCSync rights in your domain, you can use PowerView:


Under the Hood: Understanding the Functions

Before we see how everything works together, let's understand each function that DCSync uses. Most articles skip this part, but understanding these functions is crucial for both attacking and defending.

Function 1: DsBind() and DsBindWithCred()

These are Windows API functions that create an authenticated connection to a Domain Controller's Directory Service.

What is DsBind?

DsBind() establishes an RPC (Remote Procedure Call) connection to a Domain Controller and authenticates the user. Think of it like opening a database connection before running queries, or logging into SSH before executing commands.

Function Signature:

What it does:

  1. Establishes an RPC connection to the specified Domain Controller

  2. Authenticates using the current user's credentials (Kerberos ticket or NTLM hash)

  3. Returns a handle (phDS) that represents this connection

  4. This handle is used for all subsequent directory service operations

Example:

DsBindWithCred - The Offensive Version:

Difference: DsBindWithCred() allows you to specify explicit credentials instead of using the current user. This is useful when you've compromised credentials and want to authenticate as a different user.

Example with stolen creds:

What Happens Under the Hood:

When you call DsBind():

  1. RPC Endpoint Resolution: Client connects to DC port 135 (RPC Endpoint Mapper) and asks "Where is the Directory Service?"

  2. Response: DC responds "Directory Service is on port 49XXX" (dynamic port)

  3. New Connection: Client connects to the dynamic port

  4. Authentication: Client authenticates using Kerberos or NTLM

  5. DRSUAPI Binding: Client binds to the DRSUAPI interface (UUID: e3514235-4b06-11d1-ab04-00c04fc2dcd2)

  6. Handle Returned: A DRS_HANDLE is returned for subsequent operations

Why This Matters for DCSync:

Without DsBind(), you cannot make any DRSUAPI calls. It's the authentication gateway. Once you have the handle from DsBind(), you can call the actual DCSync function IDL_DRSGetNCChanges().


Function 2: DsCrackNames()

This function converts usernames between different formats.

Function Signature:

What it does:

Converts username formats. For example:

  • Input: DOMAIN\krbtgt (NT4 account name format)

  • Output: CN=krbtgt,CN=Users,DC=domain,DC=local (Distinguished Name format)

Why This is Needed:

The replication protocol works with Distinguished Names (DNs), not SAM account names. When you want to DCSync a specific user, you typically know their username like "krbtgt" or "Administrator", but the replication function needs the full DN path.

Example:

Common Name Formats:

Format Constant
Example

DS_NT4_ACCOUNT_NAME

LOCAL\krbtgt

DS_FQDN_1779_NAME

CN=krbtgt,CN=Users,DC=local,DC=htb

DS_USER_PRINCIPAL_NAME

krbtgt@loacl.htb

DS_CANONICAL_NAME

loacl.htb/Users/krbtgt


Function 3: IDL_DRSGetNCChanges() THE ACTUAL DCSYNC FUNCTION

This is the core function that performs DCSync. This is NOT in the standard Windows API list it's part of the DRSUAPI RPC interface.

Function Signature:

Critical Details:

  • Protocol: MS-DRSR (Directory Replication Service Remote Protocol)

  • Interface UUID: e3514235-4b06-11d1-ab04-00c04fc2dcd2

  • Operation Number (opnum): 3

Why it's not in the Win32 API list:

This function is part of the DRSUAPI RPC interface, not the Win32 API. It's accessed through:

  • Direct RPC calls (Mimikatz)

  • Impacket library (Python)

  • DSInternals PowerShell module

What This Function Does:

IDL_DRSGetNCChanges() is the function Domain Controllers use to replicate directory data between each other. When you call this function with the right permissions:

  1. You send a replication request specifying which object you want

  2. The DC validates you have replication permissions

  3. If yes, DC sends back the object's attributes, including password hashes

  4. The hashes are encrypted during transmission but Mimikatz/Impacket decrypt them


The Input Structure: DRS_MSG_GETCHGREQ

This is what you send TO the Domain Controller:

Important Fields Explained:

pNC (Naming Context): This is the Distinguished Name of the object you want to replicate. For example:

  • CN=krbtgt,CN=Users,DC=local,DC=htb - To get krbtgt's password

  • CN=Administrator,CN=Users,DC=local,DC=htb - To get Administrator's password

ulFlags (Replication Flags): These flags tell the DC how to perform replication. Common flags:

Typical DCSync Flag Combination:

This tells the DC: "I'm a writable Domain Controller doing initial synchronization, please give me the data."

cMaxObjects: How many objects to return. For DCSync of a single user, set to 1.

cMaxBytes: Maximum response size. Usually set to something like 0x00a00000 (10 MB).


The Output Structure: DRS_MSG_GETCHGREPLY

This is what the Domain Controller sends BACK to you:

The Magic Field: pObjects

This is where the actual password data lives. It's a linked list of objects:

Password Attributes in the Response:

Attribute Name
Attribute ID (OID)
Contains

unicodePwd

1.2.840.113556.1.4.90 (ATT_UNICODE_PWD)

Current NTLM hash

ntPwdHistory

1.2.840.113556.1.4.94 (ATT_NT_PWD_HISTORY)

Password history (NTLM hashes)

supplementalCredentials

1.2.840.113556.1.4.125 (ATT_SUPPLEMENTAL_CREDENTIALS)

Kerberos keys (AES256, AES128, DES)

lmPwdHistory

1.2.840.113556.1.4.160 (ATT_LM_PWD_HISTORY)

LM hash history (if enabled)

How Password Data is Stored:

The password hashes are:

  1. Encrypted with the DC's boot key (also called SysKey)

  2. Encrypted again for RPC transmission using the session key

  3. Mimikatz/Impacket automatically decrypt both layers to give you the plaintext NTLM hash


Function 4: DsUnBind()

This function closes the connection.

Function Signature:

What it does:

  • Closes the RPC connection to the Domain Controller

  • Frees associated resources

  • Should ALWAYS be called after operations complete


How DCSync Works: The Complete Process

Now that you understand all the functions, let's see how they work together in phases.

Phase 1: Connection Establishment

Objective: Create an authenticated connection to the Domain Controller.

The Process:

The attacker machine first needs to establish an RPC connection to the Domain Controller. This happens in several steps:

  1. DNS Resolution: Resolve the DC name to an IP address

  2. RPC Endpoint Mapper Connection: Connect to port 135 on the DC

  3. DRSUAPI Discovery: Ask the endpoint mapper where DRSUAPI is listening

  4. Dynamic Port Connection: Connect to the DRSUAPI service on the dynamic port

  5. Authentication: Authenticate using Kerberos or NTLM

  6. Bind to DRSUAPI: Establish the DRSUAPI context

Code:

What You've Accomplished: You now have an authenticated connection handle (hDS) to the Domain Controller that can be used for replication requests.


Phase 2: Name Resolution

Objective: Convert the target username to a Distinguished Name.

Why This is Needed:

The replication protocol doesn't understand usernames like "krbtgt" or "Administrator". It needs the full LDAP path (Distinguished Name). So if you want to DCSync the krbtgt account, you need to convert "LOCAL\krbtgt" into "CN=krbtgt,CN=Users,DC=local,DC=htb".

Code:

What You've Accomplished: You now have the full Distinguished Name that the replication function requires.


Phase 3: Build Replication Request

Objective: Prepare the replication request structure.

The Request Structure:

You need to build a DRS_MSG_GETCHGREQ_V8 structure that tells the DC exactly what you want to replicate.

Code:

What You've Accomplished: The replication request is ready to send to the DC.


Phase 4: Execute DCSync (The Attack)

Objective: Send the replication request and receive password hashes.

The Core Attack:

This is where the actual DCSync happens. You call IDL_DRSGetNCChanges() with your prepared request.

Code:

What Happened:

The Domain Controller:

  1. Received your replication request

  2. Validated that your account has replication permissions

  3. Retrieved the password data for the krbtgt account

  4. Encrypted the data for transmission

  5. Sent it back in the reply structure

What You've Accomplished: The password data is now in the reply.pObjects structure, ready to be extracted!


Phase 5: Parse Password Data

Objective: Extract the NTLM hash and Kerberos keys from the response.

Understanding the Response Structure:

The reply.pObjects is a linked list. Each node contains an object (in our case, just one: krbtgt). Each object has an AttrBlock containing all its attributes, including the password hashes.

Code:

What You've Accomplished: You've extracted all the password data! You now have:

  • Current NTLM hash

  • Password history (previous NTLM hashes)

  • Kerberos keys (AES256, AES128, DES)


Phase 6: Cleanup

Objective: Close the connection and free resources.

Code:

What You've Accomplished: Clean exit with no resource leaks.


Code Implementation Analysis

Now let's look at how real tools implement DCSync.

Mimikatz Implementation

Mimikatz is written in C and directly calls the Windows APIs and DRSUAPI functions.

Main File: mimikatz/modules/kuhl_m_lsadump.c

Entry Point Function: kuhl_m_lsadump_dcsync()

The Core DCSync Implementation:

Password Decryption Function:


Impacket Implementation (secretsdump.py)

Impacket is a Python library that reimplements Windows protocols. The DCSync functionality is in secretsdump.py.

Main Class: DRSUAPIDumpSecrets

File: impacket/examples/secretsdump.py


Practical Exploitation

Now that you understand how it works under the hood, let's see how to actually exploit DCSync in the real world.

Method 1: Mimikatz (Windows)

Mimikatz is the original and most popular DCSync tool.

Basic DCSync (krbtgt account):

DCSync specific user:

DCSync all users in the domain:

Specify target DC explicitly:

Using explicit credentials:

Example Output:


Method 2: Impacket secretsdump.py (Linux/Cross-Platform)

Impacket works from Linux, macOS, or Windows.

Install Impacket:

Basic usage with password:

Just domain credentials (skip SAM/SYSTEM dump):

DCSync specific user only:

Using NTLM hash instead of password (Pass-the-Hash):

Using Kerberos authentication:

Output hashes to file:

Example Output:


Method 3: DSInternals PowerShell Module (Windows)

DSInternals is a PowerShell module specifically for Active Directory security research.

Install DSInternals:

Get single account with credentials:

Get all accounts:

Save to Hashcat format:

Get password history:


Method 4: SharpKatz (C# - Good for Offensive Security Engagements)

SharpKatz is a C# implementation that can be run in-memory or from disk.

Compile from source:

Execute:

From Cobalt Strike beacon:


Network Traffic Analysis

Understanding network traffic helps both red and blue teams.

Wireshark Display Filters

See all DRSUAPI traffic:

See only DCSync (DRSGetNCChanges):

See DCSync from non-DC IP addresses (potential attack):

Replace 10.0.0.10 and 10.0.0.11 with your actual DC IP addresses.

See single-object replication (unusual for legitimate DC replication):


References

Official Microsoft Documentation

  1. MS-DRSR: Directory Replication Service (DRS) Remote Protocol https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-drsr/f977faaa-673e-4f66-b9bf-48c640241d47

  2. IDL_DRSGetNCChanges Method https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-drsr/b63730ac-614c-431c-9501-28d6aca91894

  3. DsBind Function https://learn.microsoft.com/en-us/windows/win32/api/ntdsapi/nf-ntdsapi-dsbinda

  4. DsCrackNames Function https://learn.microsoft.com/en-us/windows/win32/api/ntdsapi/nf-ntdsapi-dscracknamesa

  5. Samba Wiki - DRSUAPI https://wiki.samba.org/index.php/DRSUAPI

Security Research & Blog Posts

  1. ADSecurity.org - Mimikatz DCSync Usage, Exploitation, and Detection https://adsecurity.org/?p=1729

  2. harmj0y - Mimikatz and DCSync and ExtraSids, Oh My https://blog.harmj0y.net/redteaming/mimikatz-and-dcsync-and-extrasids-oh-my/

  3. ired.team - DCSync: Dump Password Hashes from Domain Controller https://www.ired.team/offensive-security-experiments/active-directory-kerberos-abuse/dump-password-hashes-from-domain-controller-with-dcsync

  4. Haboob Team - DCSync Attack Whitepaper (PDF) https://dl.packetstormsecurity.net/papers/general/ad-dcsync.pdf

Tools & Source Code

  1. Mimikatz https://github.com/gentilkiwi/mimikatz

  2. Impacket https://github.com/fortra/impacket

  3. DSInternals https://github.com/MichaelGrafnetter/DSInternals


Conclusion

DCSync represents a critical post-exploitation technique that every security professional should understand deeply. By leveraging the MS-DRSR protocol and the IDL_DRSGetNCChanges function, attackers can extract credentials remotely without requiring code execution on Domain Controllers.

Key Takeaways

  1. DCSync uses four main functions: DsBind(), DsCrackNames(), IDL_DRSGetNCChanges(), and DsUnBind()

  2. The core is IDL_DRSGetNCChanges() - a DRSUAPI RPC function

  3. Password data is in the pObjects->Entinf.AttrBlock.pAttr structure

  4. Network-based detection is most effective

Last updated