Fixed how NTDS parses read-only objects #2105
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
In Impacket v0.13.0 and v0.14.0, the
secretsdump.pyscript fails to extract user hashes when performing a parse of an NTDS.dit file from a Read-Only Domain Controller (RODC). The script successfully finds and decrypts the PEK (Password Encryption Key) but outputs no user credentials, exiting silently. This is a regression from v0.12.0, which parses the same RODC file correctly.Root Cause
The bug is located in the
NTDSHashesclass's main record-processing loop (thewhile True:loop using__ESEDB.getNextRow()). A filtering condition incorrectly excludes all relevant user records from an RODC database.The condition in question was:
The check
record[self.NAME_TO_INTERNAL['instanceType']] & 4evaluates whether theinstanceTypeattribute has bit 4 (0x4) set. According to Microsoft documentation, this bit indicates "The object is writable on this directory."This condition is valid for objects on a writable Domain Controller. However, on an RODC, all replicated objects are read-only. Therefore, this bit is not set for user account records within an RODC's NTDS.dit. Consequently, the
ifstatement evaluates toFalsefor every RODC user record, causing the loop to silently skip them and produce no output.Proposed Fix
Remove the
instanceType & 4check from the filtering condition for the offline NTDS.dit parsing path. The check forsAMAccountTypeis sufficient to identify user and computer accounts.Change from:
Change to:
Testing performed
With Impacket v0.14.0 (happens the same with v0.13.0):
Sensitive information has been replaced with
<...>. As you can notice, the NTDS.dit dump reports nothing.With Impacket v0.12.0:
After modifying latest Impacket (same modification is made in v0.13.0 and v0.14.0) you get the same output as in v0.12.0:
Local dumping makes the same issue to occur.
With impacket v0.12.0 (same files of
ntds.ditandSYSTEM:Fixed v0.14.0 and 0.13.0