Detecting DCSync with Velociraptor: Hunting Directory Replication Abuse on a Windows DC
1.0 Introduction
Problem statement: DCSync lets an attacker who has never touched a Domain Controller pull every password hash in an Active Directory domain, using a replication call the domain already trusts. Velociraptor has no artifact dedicated to detecting it.
DCSync is quiet for two reasons. The traffic blends in, since it’s the same call real Domain Controllers use with each other. And a detection built around known tools (Mimikatz, Impacket, NetExec) misses any re-tooled variant, while one built around the behaviour, a non-DC account asking to replicate secrets, catches all of them.
This post closes the gap end to end:
- Confirm the gap is real by querying Velociraptor’s own artifact catalogue.
- Write a custom artifact,
Custom.Windows.DC.ADAbuse, to close it. - Deploy it to a live lab Domain Controller.
- Run a real DCSync attack with NetExec, including a genuine debugging detour worth reading if a correct password ever fails mysteriously (Section 5.1).
- Confirm the detection fires against that real attack, not a synthetic test.
- Export the results to CSV and triage them from the command line.
- Write the same detection as KQL, for Sentinel/Defender for Identity.
- Cover how to actually protect a domain against DCSync, not just detect it.
Every finding here comes from a real Windows Server 2016 Domain Controller in an isolated home lab.
1.1 What is DCSync?
DCSync abuses the MS-DRSR DsGetNCChanges call [1], the RPC call real Domain Controllers use to replicate with each other. Any account holding Replicating Directory Changes and Replicating Directory Changes All on the domain object can ask a DC to replicate secrets to it, and the DC has no way to tell a real peer from an attacker using the same call. By default only Domain Admins, Enterprise Admins, and DC machine accounts hold these rights. A misconfigured ACL, a compromised delegated account, or a legitimate sync account (Azure AD Connect’s MSOL_) can hold them too [6].
Tools that perform DCSync: Mimikatz (lsadump::dcsync), Impacket’s secretsdump.py [9], NetExec/CrackMapExec (--ntds drsuapi), DSInternals, and most C2 frameworks. All of them make the same DsGetNCChanges call underneath, which is why detecting the pattern beats detecting the tool [5].
1.2 Lab Topology
| Role | Host | Notes |
|---|---|---|
| Domain Controller | DESKTOP-W3 (192.168.0.30) |
Windows Server 2016 Datacenter, domain daniyell.lab (NetBIOS DANIIYELL) |
| Velociraptor server | macOS (192.168.0.118) |
v0.77.4, server and GUI, isolated lab network |
| Attacker tooling | macOS | NetExec 1.5.1 (pipx install netexec) |
The Velociraptor agent is already enrolled on the DC as client C.d1a4ea923b34b62f; installing the agent itself is covered in an earlier article [4].
2.0 Gap Analysis: What Velociraptor’s Built-in Artifacts Don’t Cover
Before writing VQL, the first question: does Velociraptor already do this?
SELECT name FROM artifact_definitions()
WHERE type='client'
AND (name =~ 'dcsync|4662|1131f6a|replication'
OR description =~ 'dcsync|4662|1131f6a|replication'
OR join(array=sources.query, sep=' ') =~ '(?i)dcsync|4662|1131f6a|replication')
The query returned nothing. No built-in artifact matches event 4662, the replication GUIDs, or the word “DCSync” anywhere. This ran by keyword over names, descriptions, and VQL source, so an artifact doing the same job under an unrelated name could in principle slip past it — a caveat worth keeping, not a reason to distrust the result.
With the gap confirmed, the next step is building the artifact that closes it.
3.0 Building the Detection: Custom.Windows.DC.ADAbuse/DCSync
The artifact ships several sources for different DC attack signals. This post focuses on the two that matter for DCSync: the audit-policy check and the detection itself.
3.1 The AuditPolicy Source
A detection on Security event logs is only as good as the audit policy generating those events. If the subcategory is off, the detection returns zero rows forever, indistinguishable from “nothing happened.” This source makes that failure loud instead of silent.
LET Raw = SELECT Stdout FROM execve(argv=['auditpol.exe', '/get', '/category:*'])
LET Lines = SELECT parse_string_with_regex(string=_value,
regex='^[ ]+(?P<Subcategory>.+?)[ ]{2,}(?P<Setting>No Auditing|Success and Failure|Success|Failure)[[:space:]]*$') AS P
FROM foreach(row=split(string=Raw[0].Stdout, sep='\n'), query={SELECT _value FROM scope()})
LET Needed = dict(`Directory Service Access`='Success', `Directory Service Changes`='Success',
`Security Group Management`='Success', `User Account Management`='Success',
`Computer Account Management`='Success', `Authentication Policy Change`='Success',
`Kerberos Authentication Service`='Success and Failure', `Kerberos Service Ticket Operations`='Success and Failure')
SELECT P.Subcategory AS Subcategory, P.Setting AS Setting,
if(condition=get(item=Needed, member=P.Subcategory),
then=if(condition=P.Setting =~ 'Success', then='ok', else='GAP: detections for this are blind'),
else='') AS Assessment
FROM Lines
WHERE P.Subcategory AND get(item=Needed, member=P.Subcategory)
Annotation:
execve(auditpol.exe)is used instead of a registry read because audit policy is partly stored in a binary file (audit.csl) the registry doesn’t fully reflect.parse_string_with_regexturns auditpol’s fixed-width table into structured rows.- The
Assessmentcolumn is the point: filter on=~ 'GAP'and get an instant list of blind spots.
Running this against the lab DC found a real gap:
{ "Subcategory": "Directory Service Access", "Setting": "Success", "Assessment": "ok" }
{ "Subcategory": "Directory Service Changes", "Setting": "No Auditing", "Assessment": "GAP: detections for this are blind" }
Fig 1: AuditPolicy source output on DESKTOP-W3.
Directory Service Access, the subcategory event 4662 needs, was correctly set. Directory Service Changes auditing was off — a blind spot a measurement-only hunt would miss, since the hunt package itself ran fine.
3.2 The DCSync Source
The core of the artifact: the source that actually detects DCSync.
LET Parse(Log, IDs) = SELECT timestamp(epoch=System.TimeCreated.SystemTime) AS EventTime,
System.EventID.Value AS EventID,
System.Computer AS Computer,
System.Provider.Name AS Provider,
EventData
FROM parse_evtx(filename=Log, accessor='auto')
WHERE System.EventID.Value IN IDs
SELECT EventTime, Computer,
EventData.SubjectUserName AS Account,
EventData.SubjectDomainName AS Domain,
EventData.SubjectLogonId AS LogonId,
EventData.ObjectName AS Object,
EventData.AccessMask AS AccessMask,
EventData.Properties AS Properties,
'Replication rights used (DCSync-like). Legit: DC machine accounts, MSOL_ sync accounts' AS Note
FROM Parse(Log=SecurityLog, IDs=(4662,))
WHERE TRUE AND EventTime > DateAfterTime
AND EventData.Properties =~ '(?i)1131f6aa-9c07-11d1-f79f-00c04fc2dcd2|1131f6ad-9c07-11d1-f79f-00c04fc2dcd2|89e95b76-444d-4c62-991a-0facbeda640c'
AND NOT (ExcludeMachineAccounts AND EventData.SubjectUserName =~ '[$]$')
Annotation:
- Event 4662 (“An operation was performed on an object”) is the only event Windows generates when an account exercises extended rights against a directory object. It fires identically for Mimikatz, Impacket, NetExec, or a bespoke module, since all invoke the same RPC.
- The three GUIDs are the signature.
1131f6aa-...isDS-Replication-Get-Changes,1131f6ad-...isDS-Replication-Get-Changes-All,89e95b76-...isDS-Replication-Get-Changes-In-Filtered-Set. An attacker needs the first two; the third is a bonus indicator. EventData.Propertieson a 4662 event lists every GUID touched as a flat string, so a regex match is enough.ExcludeMachineAccountsdefaults true and filters$-suffixed accounts, DC machine accounts doing real replication. Without it, legitimate multi-DC traffic drowns the one row that matters. It’s also a documented blind spot: an attacker impersonating a machine identity would slip past it — a trade-off against false positives, not an oversight.Parse(Log, IDs)is a reusable function taking the ID list as a parameter, specifically to avoid a bug hit in testing: projectingEventData.*before filtering by Event ID throws"Symbol EventData not found"on events with noEventDatablock. Filtering insideFROM, before the projection, fixes it — this bug sent the first real run toERRORstate.
4.0 Deploying the Hunt Package in Velociraptor
A custom artifact has to be loaded before it can run. Loading it via VQL [2] is scriptable and doubles as a parse check.
SELECT artifact_set(definition=read_file(filename='/path/to/Custom.Windows.DC.ADAbuse.yaml')).name AS loaded
FROM scope()



With the artifact loaded, I ran it as a direct collection:
SELECT collect_client(client_id='C.d1a4ea923b34b62f',
artifacts=['Custom.Windows.DC.ADAbuse'],
timeout=300).flow_id AS flow
FROM scope()
5.0 Executing a Real DCSync Attack with NetExec
A detection is only proven once it has seen the real attack. I installed NetExec [3] with pipx install git+https://github.com/Pennyw0rth/NetExec.
nxc smb 192.168.0.30

Two incidental findings here: SMBv1 is enabled, and null-session authentication is allowed.
5.1 A Detour: Diagnosing a False “Wrong Password”
This stays in the post because the failure mode is real and others will hit it.
Running DCSync with what should have been a correct password returned a failure (password redacted below, never shown in full):
nxc smb 192.168.0.30 -u Administrator -p '<password>' -d DANIIYELL

The investigation is a lesson in not trusting one validation method:
PrincipalContext.ValidateCredentials, run locally on the DC inside an already-authenticated session, returnedTrue.- Win32
LogonUser()withLOGON32_LOGON_NETWORK, also local, alsoTrue. - NetExec over SMB/NTLM, from the external host, returned
STATUS_LOGON_FAILURE. - NetExec with Kerberos (
-k) returnedKDC_ERR_PREAUTH_FAILED. smbclient, a separate codebase, also returnedNT_STATUS_LOGON_FAILURE.
Three independent external tools agreed the credential was wrong. Two local checks, run from a session already authenticated as the account under test, gave a false positive — a known class of issue where Windows SSO/ticket-cache reuse can satisfy a check without re-validating the password. Lesson: validate from a genuinely independent vantage point, never from inside a session already authenticated as the account under test.
The real cause was unrelated: a reset via PowerShell’s Set-ADAccountPassword wasn’t taking effect in this environment. Resetting via the classic net user administrator <password> /domain, then validating externally with smbclient, worked immediately. The Set-ADAccountPassword discrepancy itself was never root-caused (Section 10.0).
With a confirmed credential, the DCSync ran cleanly:
nxc smb 192.168.0.30 -u Administrator -p '<redacted>' -d DANIIYELL --ntds drsuapi --user krbtgt

(Pwn3d!) confirms authentication. The highlighted line is the krbtgt NTDS hash, the credential behind Golden Ticket forgery — why Section 9 leads with rotating it twice.
A second, full run (dropping --user krbtgt) dumped 62 NTDS hashes across 59 accounts.
6.0 The Hunt Fires: Results and Analysis
With the attack executed, I collected the DCSync source again.


383 rows in 19.39 seconds: account Administrator, domain DANIIYELL, AccessMask 0x100, against the domain NC head. The Note field names the finding and its legitimate exceptions — this is the real NetExec run from Section 5, no synthetic data.

A large dump legitimately produces dozens of individual 4662 events, not one — each is a replication-cursor batch, not a single “DCSync happened” event. Section 7 breaks down exactly how many, and when.
7.0 Triaging the Exported CSV from the Command Line
383 rows across two sessions is better triaged as data than eyeballed in the GUI. Velociraptor’s Download Results exports the full set as CSV; the same export works over the API:
SELECT * FROM source(client_id='C.d1a4ea923b34b62f',
flow_id='F.DC5OTP5QVD78C',
artifact='Custom.Windows.DC.ADAbuse/DCSync')
That’s a 383-row, 9-column CSV. No notebook needed for a first pass — wc, cut, sort, uniq are enough. Everything below is the real terminal session, not retyped.

wc -l reports 1,533 lines for 383 rows plus a header — a red flag before any analysis starts. The Properties column spans several physical lines in the raw EVTX, and the CSV export correctly keeps that as one quoted multi-line field. wc -l counts physical lines, not records, so it overcounts ~4x. Check this whenever a line count disagrees with a CSV-aware tool.

The highlighted lines are GUID fragments and a stray MSOL_ sync accounts", leaked into what should be clean account names. cut -d, splits on every comma on every physical line with no concept of a quoted field; the continuation lines of Properties have no commas, so cut -f3 prints them back unchanged. The one correct-looking count, 383 Administrator, is right by coincidence, not correctness — exactly the kind of thing that produces a confidently wrong number in a live incident if nobody double-checks it.
The fix: csvkit [10] (pip install csvkit), whose csvstat summarises every column in one pass.

Clean: 383 rows, one account, one domain, one access mask, one object, and a 256/127 split between the two GUIDs matching the VQL’s own Get-Changes/Get-Changes-All names. The LogonId table adds something the VQL output doesn’t surface at a glance: two sessions produced exactly 186 events each, three smaller ones produced three each.
csvcut, also from csvkit, isolates the one safe-to-split column for the burst pattern:

The two 186-event minutes are the two nxc --ntds drsuapi runs from Section 5.
| Time (UTC) | Count | What it is |
|---|---|---|
| 2026-11-26 12:58 | 1 | Isolated earlier test run |
| 2026-11-26 13:07 | 1 | Same test run, group-change check |
| 2026-11-29 02:23 | 3 | NetExec connection overhead |
| 2026-11-29 02:24 | 3 | Same overhead, continued |
| 2026-11-29 02:25 | 186 | The krbtgt-only DCSync (5.1) |
| 2026-11-29 02:30 | 3 | NetExec reconnecting |
| 2026-11-29 02:31 | 186 | The full 62-account dump |

Every row used the identical AccessMask 0x100 — one technique, not several — and the total is really two discrete sessions, not continuous activity. Alerting logic should group bursts into one incident per window; a single dump would otherwise flood a SOC queue with 186 duplicate alerts for one event.
Broader lesson: a CSV export is never safe to hand to awk/cut by reflex once any column can legitimately hold a comma or newline — event-log property lists and command lines do this routinely. csvstat/csvcut are the correct second move the instant the numbers look suspicious.
8.0 The Same Detection in KQL (Microsoft Sentinel / Defender for Identity)
Teams on Sentinel’s SecurityEvent table can run the direct equivalent: same Event ID, same three GUIDs, same machine-account exclusion.

SecurityEvent
| where EventID == 4662
| where Properties has_any (
"1131f6aa-9c07-11d1-f79f-00c04fc2dcd2", // DS-Replication-Get-Changes
"1131f6ad-9c07-11d1-f79f-00c04fc2dcd2", // DS-Replication-Get-Changes-All
"89e95b76-444d-4c62-991a-0facbeda640c" // DS-Replication-Get-Changes-In-Filtered-Set
)
| where SubjectUserName !endswith "$" // exclude DC machine accounts
| where SubjectUserName !startswith "MSOL_" // exclude Azure AD Connect sync accounts
| extend GuidTag = case(
Properties has "1131f6aa-9c07-11d1-f79f-00c04fc2dcd2", "Get-Changes",
Properties has "1131f6ad-9c07-11d1-f79f-00c04fc2dcd2", "Get-Changes-All",
"Get-Changes-Filtered")
| project TimeGenerated, Computer, SubjectUserName, SubjectDomainName,
ObjectName, AccessMask = EventData.AccessMask, GuidTag
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated)
by bin(TimeGenerated, 5m), SubjectUserName, Computer
| where EventCount > 0
| order by TimeGenerated desc
Annotation:
- The
!endswith "$"/!startswith "MSOL_"filters mirror the VQL’sExcludeMachineAccounts— tune the prefix to your own sync-service naming. bin(TimeGenerated, 5m)mirrors Section 7’s bucketing: it collapses a 186-event burst into one row, the correct alert unit.- Depends on the same prerequisite as
AuditPolicy:Directory Service Accessauditing must beSuccesson every DC in scope, and the connector must actually be ingesting 4662 from them. - Defender for Identity also ships a native, non-KQL DCSync alert (“Suspicious directory services replication request”) [8] built on packet-level DRSUAPI analysis, independent of this event-log method. Running both is stronger than either alone.
9.0 How to Protect Against DCSync
Detecting DCSync after the fact is necessary but not sufficient — the account already has every hash by the time an alert fires.
Prevent the account from having the rights
- Audit who holds
Replicating Directory Changes/...Allbeyond the default (Domain Admins, Enterprise Admins, DCs).dsaclsor a BloodHound collection [11] surface this quickly. - Run a tiered administration model (Tier 0–2) [12]: Domain Admin credentials should never touch a workstation that browses the web. Most DCSync attacks start with a lower-tier compromise, not a direct DC attack.
- Use Privileged Access Workstations [12] and Authentication Policy Silos [13] so privileged credentials can’t authenticate anywhere else.
Reduce the blast radius
- Rotate
krbtgttwice, with a replication cycle between, after any suspected compromise [7] — one rotation leaves the old key valid for ticket decryption. - Enable LAPS [14] so a shared local admin password isn’t also sitting in the dump.
- Unique passwords, no reversible encryption, MFA where supported. DCSync bypasses interactive MFA entirely.
Harden the attack path
- Restrict which hosts can speak DRSUAPI/RPC to a DC via firewall [15] — scoping the endpoint mapper and dynamic ports to known DC ranges blocks DCSync from any non-DC host, valid credentials or not.
Detect faster
- Turn on
Directory Service Accessauditing everywhere (this lab had it on, butDirectory Service Changesoff — verify both; Section 3.1). - Deploy the VQL artifact, the KQL query, or both — redundancy across platforms, not duplicated effort.
- Plant a honeytoken account with the replication right and no legitimate use — any DCSync against it is near-zero-false-positive.
- Monitor for new grants of the replication right (event 5136 on
nTSecurityDescriptor) — catching the grant beats catching the use.
10.0 Limitations and Honest Unknowns
- The
Set-ADAccountPassworddiscrepancy (5.1) was worked around, not root-caused. - The machine-account exclusion filter is a documented blind spot: an attacker impersonating a machine identity bypasses it — a trade-off, not an oversight, and it applies to the KQL version too.
- The keyword-based gap analysis (2.0) could miss an existing artifact under an unrelated name.
- Every source reading
.evtxfiles directly can race Windows’ log-flush timing. Not measured for the DCSync source itself, but observed for a sibling source: a service-install event read ~19s after it existed returned zero rows, a read ~27s later found it. A hunt within ~20–45s of a DCSync attempt could return a false negative.
11.0 Indicators and Detections Summary
| Technique | Event source | Detection |
|---|---|---|
| DCSync (replication rights abuse) | Security 4662 and the replication GUIDs | Custom.Windows.DC.ADAbuse/DCSync (Velociraptor), the KQL query in Section 8.0 (Sentinel) |
| Missing audit coverage (meta-detection) | auditpol.exe |
Custom.Windows.DC.ADAbuse/AuditPolicy |
IOCs validated in this lab (test artifacts, not real threat intelligence):
- Replication-rights GUIDs:
1131f6aa-9c07-11d1-f79f-00c04fc2dcd2,1131f6ad-9c07-11d1-f79f-00c04fc2dcd2,89e95b76-444d-4c62-991a-0facbeda640c
12.0 Conclusion
The sequence that matters: gap analysis, build, deploy, attack for real, verify the hit, triage properly, know how to stop it. This lab surfaced a genuine audit-policy blind spot, a real log-flush race condition, and a credential-validation gotcha — none of which would have surfaced from the VQL alone. A detection without a prevention plan only ever tells you the hashes are already gone.
Custom.Windows.DC.ADAbuse is available as a hunt package for any Velociraptor deployment that wants DCSync coverage beyond the built-in library; the KQL query covers the same signal for Sentinel.
Before trusting either in production, run AuditPolicy against your own DCs first — if Directory Service Access auditing is off anywhere, both detections are blind there until that changes. If you find something, or a case this misses, get in touch through the links at the top of this site.
13.0 References
- Microsoft. [MS-DRSR]: Directory Replication Service (DRS) Remote Protocol. The spec
DsGetNCChangesand this detection are built around. - Velociraptor documentation. VQL Reference. Reference for every VQL function used in Sections 3, 4, and 7.
- Pennyw0rth. NetExec. The tool used for the real DCSync attack in Section 5.
- Daniel Jeremiah. Using Velociraptor to Detect and Hunt for Affected Systems: Unknown Malware Analysis. Covers the agent installation this post assumes.
- MITRE ATT&CK. OS Credential Dumping: DCSync (T1003.006). The canonical technique entry.
- Sean Metcalf. Mimikatz DCSync Usage, Exploitation, and Detection. ADSecurity.org. The original community disclosure.
- Sean Metcalf. Kerberos & KRBTGT: Active Directory’s Domain Kerberos Service Account. ADSecurity.org. Background on the two-reset rotation.
- Microsoft Learn. Security Alerts - Microsoft Defender for Identity. The native, sensor-based DCSync alert.
- Fortra. Impacket. The library behind
secretsdump.py. - csvkit documentation. csvkit.
csvstat/csvcut, used throughout Section 7. - SpecterOps. BloodHound. For auditing who holds replication rights beyond the default.
- Microsoft Learn. Enterprise access model. Tiering and PAWs.
- Microsoft Learn. Authentication Policies and Authentication Policy Silos.
- Microsoft Learn. Windows LAPS overview.
- Microsoft Learn. Restrict Active Directory RPC traffic to a specific port.