Chapter 64

Credential Storage

SAM database, NTDS.dit, DPAPI architecture, LSA Secrets, and the paths attackers take to extract stored credentials — with detection telemetry for each.

Scenario

A domain controller compromise is discovered. The attacker ran ntdsutil snapshot to create a VSS snapshot of the DC, then copied NTDS.dit and SYSTEM from the snapshot. These two files together contain every domain account's NT hash. Offline, they ran secretsdump.py and cracked or passed every hash in the domain. The only log entry: a new shadow copy created at 02:14 UTC, and robocopy running against \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3\. This chapter explains what NTDS.dit is, how it's protected, and how to detect its extraction.

SAM Database

The Security Account Manager (SAM) database stores local account credentials. Location: C:\Windows\System32\config\SAM (registry hive). The SAM hive is locked by the OS while running — cannot be directly copied while Windows is live.


  SAM Hash Storage (per local account)
  ══════════════════════════════════════════════════════════════════

  SAM key: HKLM\SAM\SAM\Domains\Account\Users\000001F4 (RID)

  ┌──────────────────────────────────────────────────────┐
  │  V value (binary blob):                              │
  │  Offset 0x38: LM hash (if stored, legacy)            │
  │  Offset 0x9C: NT hash (MD4(password))                │
  │                                                      │
  │  Both hashes are encrypted with:                     │
  │  SYSKEY (128-bit boot key from SYSTEM hive)          │
  │  + RID (Relative Identifier) of the account          │
  └──────────────────────────────────────────────────────┘

  Extraction requires:
  1. SAM hive binary (or live API access as SYSTEM)
  2. SYSTEM hive (to derive SYSKEY / Boot Key)
  3. Offline decryption (secretsdump.py, pwdump, Mimikatz lsadump::sam)

    

VSS bypass for live extraction:

PowerShell
# Create shadow copy
$shadow = (Get-WmiObject -List Win32_ShadowCopy).Create("C:\","ClientAccessible")
$path = (Get-WmiObject Win32_ShadowCopy | Select-Object -Last 1).DeviceObject + "\"
# Copy locked files
cmd /c "robocopy `"$path\Windows\System32\config`" C:\loot SAM SYSTEM /b"

NTDS.dit — Domain Credential Database

Active Directory stores all domain account credentials in C:\Windows\NTDS\NTDS.dit on every Domain Controller. This is an ESE (Extensible Storage Engine / JET Blue) database.

Table in NTDS.ditContents
datatableAll AD objects: users, computers, groups — and their attributes including unicodePwd (NT hash, encrypted)
link_tableGroup memberships, object relationships
hiddentableEncryption key material

The NT hashes are stored encrypted with the PEK (Password Encryption Key), which is itself encrypted with the SYSKEY. Extraction requires NTDS.dit + SYSTEM hive (for SYSKEY).

Why NTDS.dit compromise = full domain compromise

NTDS.dit contains the NT hash of every domain account — including all privileged service accounts, admin accounts, and the KRBTGT account. With the KRBTGT hash, an attacker can forge Kerberos tickets (Golden Ticket attack) for any user, with any privileges, for up to 10 years. The hashes don't need to be cracked — they can be used directly in pass-the-hash or pass-the-ticket attacks. NTDS.dit extraction is the endgame of a domain compromise.

DPAPI — Data Protection API

DPAPI is Windows's mechanism for encrypting secrets tied to a user account or machine. Used by: Chrome/Edge (saved passwords), Windows Credential Manager, certificate private keys, IE saved passwords, RDP client credentials.


  DPAPI Encryption Hierarchy
  ══════════════════════════════════════════════════════════════════

  User password
       │ PBKDF2
       ▼
  User Master Key (MK) ──────────────────────────────────────────►
  Stored: %APPDATA%\Microsoft\Protect\{SID}\{GUID}               │
  (encrypted with user's password-derived key)                    │
                                                                  ▼
  Secret (e.g., Chrome password)                        ┌──────────────────┐
       │ CryptProtectData()                              │  Master Key File │
       ▼                                                 │  Decrypts secret │
  DPAPI Blob (.dat file, registry value, etc.)           └──────────────────┘
  Contains: GUID of master key used + encrypted secret

  Decryption path:
  1. DPAPI blob → find referenced MK GUID
  2. Decrypt master key file (using user password or domain backup)
  3. Decrypt blob with master key → plaintext secret

    

Domain backup keys: DPAPI has a domain backup mechanism. The DC holds a DPAPI domain backup key (LSA Secret). Any domain admin can use this to decrypt any domain user's DPAPI secrets — even without knowing the user's password. Attackers extract this with Mimikatz lsadump::backupkeys.

LSA Secrets

LSA Secrets are service account passwords, DPAPI backup keys, and other secrets stored by the OS in the registry under HKLM\SECURITY\Policy\Secrets — a key readable only by SYSTEM. Contents include:

PowerShellMimikatz equivalent
# Mimikatz commands for credential extraction
# (shown here for defensive understanding)

# Dump SAM (requires SYSTEM)
lsadump::sam

# Dump LSA Secrets
lsadump::secrets

# Dump domain creds from NTDS.dit (on DC)
lsadump::dcsync /domain:corp.local /all /csv

# DPAPI domain backup key
lsadump::backupkeys /system:DC01.corp.local /export

DCSync Attack

DCSync doesn't touch NTDS.dit on disk. It impersonates a DC and requests AD replication using the MS-DRSR (Directory Replication Service Remote Protocol), specifically the IDL_DRSGetNCChanges function. AD hands over credential attributes as part of "replication." Requires: Domain Admin, Replicating Directory Changes, and Replicating Directory Changes All permissions.

Detection: Event 4662 on the DC — object access audit for replication. Source IP is not a real DC. Sysmon-like SIEM rules on MS-DRSR RPC calls from non-DC machines.

Detection Summary

TechniqueKey Events / Artifacts
SAM via VSSSysmon Event 8/10 on vssvc.exe; robocopy/xcopy accessing shadow path; new shadow copy creation
NTDS.dit via ntdsutilntdsutil.exe process (Event 4688); snapshot creation; file copy from shadow path
DCSyncEvent 4662 with access rights 0x100 (Control Access) on domain NC object from non-DC source
LSA Secrets (live)Sysmon Event 10: TargetImage lsass.exe with high access rights; Event 4656 on SECURITY hive if audit configured
DPAPI master key theftFile access to %APPDATA%\Microsoft\Protect\; Mimikatz leaves Event 4624 SYSTEM logon + 4656 on SECURITY hive

Q & A

Q: A DCSync alert fires showing source IP 10.0.1.45 — but the alert rule fires on any replication request. How do you determine if this is malicious?

Compare the source IP against the domain controller IP list (from IPAM, DHCP, or AD Sites and Services). If 10.0.1.45 is not a registered DC, the replication request is unauthorized — this is DCSync. If it is a DC, it could be legitimate replication or a compromised DC. Confirm: check if the source machine is in the Domain Controllers OU in AD. Look at Event 4662's SubjectUserName — for legitimate replication it's a DC computer account (ending in $); for DCSync it's a user account or compromised admin account. Also: legitimate DCs replicate on a schedule; a one-time replication request at 3am from a workstation IP is a strong indicator.

Q: Why does NTDS.dit extraction require the SYSTEM hive in addition to NTDS.dit?

NTDS.dit stores NT hashes encrypted with the PEK (Password Encryption Key). The PEK itself is encrypted with the Boot Key (SYSKEY), which is derived from four registry values scattered across the SYSTEM hive (JD, Skew1, GBG, Data subkeys of HKLM\SYSTEM\CurrentControlSet\Control\Lsa). Without the SYSTEM hive, you cannot decrypt the PEK, and therefore cannot decrypt any password hash in NTDS.dit. This is the same SYSKEY that protects SAM — both databases use the same boot key. Tools like secretsdump.py accept --ntds and --system arguments for exactly this reason.