Dumping Domain Password Hashes: NTDS.dit, Shadow Copies and DCSync

7 min read188 courses on OnlySecurity

Every account in an Active Directory domain has a password hash stored on its domain controllers, so anyone who can read that store can recover or reuse the secrets of the whole domain. This article covers where it lives, the two routes to it (copying the database, or DCSync), extraction in a lab, and detection and defence. Test only networks and systems you own or are authorised to assess.

What NTDS.dit holds

The domain database is the file Ntds.dit, which MITRE records at %SystemRoot%\NTDS\Ntds.dit on a domain controller by default (T1003.003). It holds the domain’s users, devices and access rights, and secretsdump.py extracts NTLM hashes and Kerberos keys from it. The secrets are encrypted: the boot key from the SYSTEM registry hive unlocks the password encryption key stored in the database, which unlocks the hashes, so a copy of Ntds.dit is useless without the hive.

Route one: copying the database file

With administrative control of a domain controller, an attacker can copy the file. Windows keeps the live database open, so the usual routes have Windows copy it.

  1. ntdsutil creates install-from-media (IFM) media, which Microsoft documents for building an additional domain controller. Its archived reference says full media includes the registry, so the SYSTEM hive comes too; media for a read-only domain controller has cached secrets removed.
  2. Volume Shadow Copy snapshots the volume. vssadmin create shadow, diskshadow (which needs local Administrators or equivalent) and the WMI Win32_ShadowCopy class can each make one, and the snapshot’s copy of the file is not in use.

Microsoft’s IFM guidance) says members of Backup Operators and Server Operators have the rights to create this media by default, so treat them as domain controller administrators.

Extracting the hashes from a copy

Once you hold Ntds.dit and the SYSTEM hive, impacket’s secretsdump.py parses them offline with LOCAL as the target. Against a live domain controller, -use-vss runs vssadmin create shadow through a remote execution method, copies the file to the Windows temp folder, parses it and deletes the shadow copy it made.

Route two: DCSync

DCSync copies no file. The mimikatz documentation describes lsadump::dcsync as using the DRSR protocol, the one domain controllers replicate with, to ask a domain controller to synchronise an entry. Benjamin Delpy and Vincent Le Toux co-wrote the function in Delpy’s mimikatz, as the mimikatz README credits, and MITRE tracks it as T1003.006.

In Microsoft’s MS-DRSR access check, IsGetNCChangesPermissionGranted, a replication request first needs the DS-Replication-Get-Changes right (display name Replicating Directory Changes, GUID 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2) on the naming context root. A request that reveals secrets also needs DS-Replication-Get-Changes-All (Replicating Directory Changes All, 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2), which Microsoft describes as allowing replication of secret domain data. DS-Replication-Get-Changes-In-Filtered-Set (Replicating Directory Changes In Filtered Set, 89e95b76-444d-4c62-991a-0facbeda640c) covers attributes in the filtered set and is accepted in place of the second for those. MITRE notes that Administrators, Domain Admins, Enterprise Admins and domain controller accounts can run DCSync, as can any account granted the first two rights on the domain root.

NetExec offers both remote routes. Its --ntds option takes drsuapi (the default when no value is given) or vss, and --user limits the dump to one account. The NetExec article covers the tool.

Handle the output as engagement data

A dump is the most sensitive file in an assessment: it can authenticate as anyone in the domain. Keep it in an encrypted engagement folder, off shared drives and chat, report counts and weak passwords rather than hashes, and delete it under the engagement terms. NetExec also saves its dump, by default under ~/.nxc/logs/ntds/, and adds the NTLM hashes to its credential database, so clear both. Service account hashes in it are the material for forged service tickets, covered in the Kerberos silver tickets article. The Advanced Techniques in Active Directory Credential Dumping course covers credential dumping in Active Directory.

Commands on a lab domain controller

Checked against impacket 0.13.1 (tag impacket_0_13_1) and NetExec 1.5.1 (tag v1.5.1). Run secretsdump.py -h on your copy.

secretsdump.py -just-dc -outputfile lab-dump corp.lab.example/[email protected]
secretsdump.py -just-dc-user krbtgt corp.lab.example/[email protected]
secretsdump.py -use-vss -outputfile lab-vss corp.lab.example/[email protected]
secretsdump.py -ntds Ntds.dit -system SYSTEM -outputfile lab-offline LOCAL
nxc smb 192.0.2.10 -u lab-admin -p 'LabPassw0rd!' --ntds
nxc smb 192.0.2.10 -u lab-admin -p 'LabPassw0rd!' --ntds vss
nxc smb 192.0.2.10 -u lab-admin -p 'LabPassw0rd!' --ntds --user krbtgt
  1. -just-dc extracts only domain database data (NTLM hashes and Kerberos keys). -just-dc-user extracts one user, implies -just-dc and is not supported with -use-vss.
  2. Without -use-vss, secretsdump.py uses DRSUAPI replication (DCSync); with it, -exec-method picks smbexec (the default), wmiexec or mmcexec.
  3. LOCAL as the target parses files you already hold, and needs -system or -bootkey. -outputfile names the output files.
  4. In NetExec, --kerberos-keys adds Kerberos keys to the NTLM hashes dumped by default, and --history and --enabled are mutually exclusive. All three need --ntds.

Detection and defence

For DCSync, Microsoft’s event 4662 is written only when an auditing entry (SACL) on the domain object matches, under the Audit Directory Service Access subcategory (Advanced Audit Policy Configuration, DS Access). Microsoft’s Audit Directory Service Access page recommends only Failure auditing there on domain controllers, so turn on Success too. Microsoft’s Sentinel rule Non Domain Controller Active Directory Replication matches 4662 events from non-machine accounts whose Properties field holds any of the three replication right GUIDs above, and joins each to the network logon (4624, logon type 3) with the same logon ID to find the source address. MITRE’s DET0594 adds network capture of DRSUAPI RPC traffic, since replication should come only from domain controllers. That rule excludes every machine account, so a computer account that has been granted replication rights would not trigger it; exclude only your named domain controllers instead. Alert on any other account using those rights, and on DRSUAPI calls from any address that is not a domain controller. Event 4662 appears only if the domain root carries an auditing entry for Success on the three replication rights, so check that it does, then run DCSync once in the lab and confirm a 4662 with those GUIDs arrives.

For the file routes, MITRE’s DET0586 names process creation (4688), Sysmon file events (2 and 11) and shadow copy creation as signals, correlating access to Ntds.dit within minutes of a new shadow copy and excluding backup software. Event 4688 needs Audit Process Creation and Include command line in process creation events to show arguments such as ifm. A shadow copy made over WMI starts no vssadmin process, so alert on shadow copy creation itself. Treat any unplanned shadow copy or ntdsutil run on a domain controller as an incident.

Settings that limit it:

  1. Review the access control list on each domain root for Replicating Directory Changes and Replicating Directory Changes All, by name or GUID (MITRE M1015). Remove any grant that is not a domain controller or a documented sync account; Microsoft Entra Connect needs both for password hash sync.
  2. Limit privileged account use across administrative tiers (MITRE M1026), and follow Microsoft’s securing domain controllers guidance: privileged access workstations, and RDP only from jump servers.
  3. Hardening for the aftermath rather than a block on this technique: add privileged users to Protected Users, testing first. Microsoft says the group stops hosts caching their credentials and blocks their NTLM authentication, warns that untested additions can lock out Domain Admins or Enterprise Admins, and says never to add service or computer accounts. It does not cover replication rights.
  4. Keep Backup Operators and Server Operators empty, as they are by default, and secure domain controller backups (MITRE M1041).

Where to go next

The Advanced Techniques in Active Directory Credential Dumping course is the next step for credential dumping in Active Directory. For the wider workflow from first scan to report, see Penetration Testing Field Notes.

This article replaces the KSEC ARK notes first published in 2019.

More from this author