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.diton domain controllersIs 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:
usernameis the user account nameRIDis the Relative IdentifierLM hashis the legacy LAN Manager hash (usually the default "no password" value)NT hashis 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:
Data Table (datatable): Contains most Active Directory objects
Link Table: Maintains relationships between objects
Security Descriptor Table: Stores access control information
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:
Encrypted with the PEK (Password Encryption Key)
The PEK is encrypted with the Boot Key from the SYSTEM registry hive
Modern systems use stronger encryption for newer hash types (e.g., AES keys)
Defending Against NTDS.dit Extraction
Technical Controls
Protected LSASS: Enable LSA Protection and Credential Guard
Enhanced Auditing: Monitor for suspicious activities related to NTDS.dit access
Privileged Access Management: Implement Just-In-Time administration
Regular Backups: Secure backup procedures for Domain Controllers
ESAE (Enhanced Security Admin Environment): Separate administrative forest
Password Policies: Strong passwords reduce the risk of cracked hashes
Least Privilege: Restrict accounts with Domain Admin privileges
Detection Strategies
Monitor for indicators of NTDS.dit extraction attempts:
Creation of Volume Shadow Copies on Domain Controllers
Unexpected system state backups
Use of tools like vssadmin, diskshadow, or ntdsutil
Large data transfers from Domain Controllers
Authentication attempts with extracted credentials
Post-Compromise Cleanup
After security testing activities involving NTDS.dit:
Remove temporary files: Delete any copies of NTDS.dit and related files
Clean up shadow copies: Delete any Volume Shadow Copies created
Document actions: Record all extraction activities for reporting
Report findings: Provide recommendations for securing the environment
Differences Between SAM and 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