NTDS.dit

NTDS Database

The NTDS.dit file is the Active Directory database that stores user accounts, group memberships, password hashes, and other critical domain information. As one of the most valuable targets in a Windows domain environment, understanding how to properly extract and analyze the NTDS.dit can be crucial during penetration testing and security assessments.

Overview of NTDS.dit

The NTDS.dit (NT Directory Services Directory Information Tree) file:

  • Is the primary database for Active Directory Domain Services

  • Stores all domain objects including users, groups, and computers

  • Contains password hashes for all domain accounts

  • Is typically located at C:\Windows\NTDS\ntds.dit on domain controllers

  • Is locked while Active Directory services are running

  • Can contain historical password hashes if enabled in the domain

Unlike the SAM database, which only contains local accounts, NTDS.dit contains information for all domain accounts across the entire Active Directory forest.

Obtaining NTDS.dit

Prerequisites

To extract the NTDS.dit file, you typically need:

  • Domain Admin privileges (or equivalent)

  • Access to a Domain Controller

  • Methods to bypass the file lock

Method 1: Using Volume Shadow Copy

One of the most common methods is to create a Volume Shadow Copy (VSS) to bypass the file lock:

Method 2: Using Windows Built-in Backup Utilities

Windows provides native tools for backing up Active Directory, which can be leveraged:

Method 3: Using PowerShell and CrackMapExec

For remote extraction, CrackMapExec provides a streamlined approach:

Extracting and Analyzing Hashes

Using Secretsdump.py (Impacket)

After obtaining the NTDS.dit and SYSTEM files, you can extract the hashes using Impacket's secretsdump.py:

Example output:

Understanding the Output

The output format follows this pattern:

  • username:RID:LM hash:NT hash:::

Where:

  • username is the user account name

  • RID is the Relative Identifier

  • LM hash is the legacy LAN Manager hash (usually the default "no password" value)

  • NT hash is the NTLM hash of the user's password

Additional Hash Types

Secretsdump.py also extracts Kerberos keys and supplementary credentials:

Cracking NTDS Hashes

After extracting hashes, they can be cracked to recover plaintext passwords:

Using Hashcat

Example output:

Using John the Ripper

Leveraging NTDS Hashes for Attacks

Pass-the-Hash Attacks

With obtained NT hashes, you can perform pass-the-hash attacks without cracking:

DCSync Attacks

If you compromise an account with DCSync privileges, you can extract NTDS.dit data remotely without direct access to the domain controller:

Golden Ticket Attacks

The krbtgt account hash is especially valuable as it can be used to create forged Kerberos tickets:

NTDS.dit Structure and Components

The NTDS.dit file consists of several key components:

  1. Data Table (datatable): Contains most Active Directory objects

  2. Link Table: Maintains relationships between objects

  3. Security Descriptor Table: Stores access control information

  4. PEK (Password Encryption Key): Used to encrypt sensitive attributes like password hashes

Encryption in NTDS.dit

Password hashes in NTDS.dit are protected by multiple layers:

  1. Encrypted with the PEK (Password Encryption Key)

  2. The PEK is encrypted with the Boot Key from the SYSTEM registry hive

  3. Modern systems use stronger encryption for newer hash types (e.g., AES keys)

Defending Against NTDS.dit Extraction

Technical Controls

  1. Protected LSASS: Enable LSA Protection and Credential Guard

  2. Enhanced Auditing: Monitor for suspicious activities related to NTDS.dit access

  3. Privileged Access Management: Implement Just-In-Time administration

  4. Regular Backups: Secure backup procedures for Domain Controllers

  5. ESAE (Enhanced Security Admin Environment): Separate administrative forest

  6. Password Policies: Strong passwords reduce the risk of cracked hashes

  7. Least Privilege: Restrict accounts with Domain Admin privileges

Detection Strategies

Monitor for indicators of NTDS.dit extraction attempts:

  1. Creation of Volume Shadow Copies on Domain Controllers

  2. Unexpected system state backups

  3. Use of tools like vssadmin, diskshadow, or ntdsutil

  4. Large data transfers from Domain Controllers

  5. Authentication attempts with extracted credentials

Post-Compromise Cleanup

After security testing activities involving NTDS.dit:

  1. Remove temporary files: Delete any copies of NTDS.dit and related files

  2. Clean up shadow copies: Delete any Volume Shadow Copies created

  3. Document actions: Record all extraction activities for reporting

  4. Report findings: Provide recommendations for securing the environment

Differences Between SAM and NTDS.dit

Feature
SAM Database
NTDS.dit

Scope

Local machine accounts

All domain accounts

Location

%SystemRoot%\System32\config\SAM

%SystemRoot%\NTDS\ntds.dit

Size

Small (KB to MB)

Large (MB to GB)

Protected by

SYSTEM bootkey

PEK + SYSTEM bootkey

Contains

Local user hashes

Domain user hashes, Kerberos keys, group info

Historical data

No

Yes (if enabled)

Replication

No

Yes (to other DCs)

Summary

The NTDS.dit database is a critical component of Active Directory that contains sensitive authentication data for all domain users. Understanding how to extract and analyze this database is essential for comprehensive security assessments, but must be performed with proper authorization and care to avoid disrupting domain operations.

When properly handled, NTDS.dit extraction can provide valuable insights into password policies, account security, and potential vulnerabilities in a Windows domain environment.

Last updated