Post Exploitation - ntds.dit dumping
Through code execution on a Domain Controller
If code execution could be achieved on a Domain Controller
, with sufficient privileges to access the ntds.dit
database (file: %WINDIR%\Windows\NTDS\ ntds.dit
), multiples Windows utilities can be used to export the ntds.dit
.
On a standard Domain Controller
installation, the NT AUTHORITY\SYSTEM
built-in Windows Account and the Administrators
domain group have full control
access on the file. Additionally, yet again in a standard configuration, members of the Backup Operators
(SID: S-1-5-32-551
) domain group have the necessary privileges to open an interactive (and remote) session on the Domain Controllers
(SeInteractiveLogonRight
) and can make use of the SeBackupPrivilege
privilege to open files with the FILE_FLAG_BACKUP_SEMANTICS
flag in order to bypass the file access permissions.
As the ntds.dit
file is being continuously accessed, the file cannot be directly copied ("The action can't be completed because the file is open in another program"). The copy must be done through the Windows shadow copy
mechanism, which leverage a temporary freezing of the I/O requests on the file. The freezing is requested by the Volume Shadow Copy Service (VSS)
Windows built-in service, which orchestrate the creation of the shadow copy
.
The sensitive information in the ntds.dit
file is encrypted using the system Boot Key
(also known as the System Key
, or SysKey
). This key is located in the HKEY_LOCAL_MACHINE\SYSTEM
registry hive (C:\Windows\system32\config\ SYSTEM
file) and is unique to each Domain Controller
. The SYSTEM
registry hive (or the Boot Key
directly) must thus be exported from the Domain Controller
the ntds.dit
was copied from. The Windows built-in reg
command line utility can be used to do so:
ntdsutil
The Windows Active Directory Ntdsutil
administration utility can be used as a wrapper around vssadmin
to dump the ntds.dit
database file.
Ntdsutil
will additionally automatically export the SECURITY
and SYSTEM
registry hives and conduct a defragmentation of the database file (wrapping around the esentutl
utility).
Note that the ntdsutil
utility requires elevated privileges that are not attributed to members of the Backup Operators
domain group (error: error 0x2(The system cannot find the file specified.)
).
vssadmin
The Windows built-in Volume Shadow Copy Service administrative (vssadmin)
command line utility can be used to create a shadow copy
of the Windows install volume in order to make a shadow copy
of the ntds.dit
database file.
While still available by default, the vssadmin
utility has been superseded by the diskshadow
utility on Windows Server 2008
, and later.
Note that the vssadmin
utility requires elevated privileges that are not attributed to members of the Backup Operators
domain group (error: Error: You don't have the correct permissions to run this command.
).
diskshadow
Similarly to the vssadmin
utility, the Windows diskshadow
utility directly interact with the Windows VSS
service.
By default, the diskshadow
utility uses an interactive command interpreter but also includes the possibility to execute diskshadow
commands directly from a script file.
Note that the diskshadow
utility can be used by members of the Backup Operators
domain group to create a shadow volume.
The following diskshadow
commands can be executed, either through an interactive diskshadow
commands interpreter or from a script file by starting diskshadow.exe -s <SCRIPT_FILE>
, to create a shadow volume and directly copy the ntds.dit
file. In order to make use of the diskshadow.exe
's exec "cmd.exe" [...]
command, diskshadow.exe
must be started in the C:\Windows\System32
directory, otherwise the command execution will fail. If doing so is not a possibility, the copy may also be done outside of diskshadow
, after the shadow volume creation.
WMI win32_shadowcopy
The Windows Management Instrumentation (WMI)
class win32_shadowcopy
can be used to create a shadow copy
as well:
Remotely over the network
Remote Volume Shadow Copy
The vssadmin
utility can be executed remotely, over the SMB
, WMI
or DCOM
protocols, in order to export the ntds.dit
. As implemented in impacket
's secretsdump.py
Python script, the ntds.dit
database file is exported in a temporary folder and parsed remotely. CrackMapExec
wraps around the methods from secretsdump.py
.
DCSync (DRSUAPI)
The DCSync
attack consists in leveraging the Active Directory DRSUAPI
replication functions (part of the Directory Replication Service (DRS)
protocol) to remotely retrieve the specified Active Directory objects' sensible information. The DRSUAPI
functions are normally used by the Domain Controllers
to replicate the modifications made to AD objects and keep the AD objects consistent across all the Domain Controllers
of the forest. The DRSUAPI
replication functions are exposed on the network by the Microsoft Remote Procedure Call (MSRPC)
DRSUAPI
interface on each Domain Controller
. Thus, contrary to the others methods explicated so far, no local code execution on a Domain Controller
is required to retrieve information from the ntds.dit
database.
While multiples DRSUAPI
intermediate functions are used in the replication process, the DSGetNCChanges
function implements the replication request.
The following privileges on the domain root object
are necessary to make replication requests through the DRSUAPI
:
Replicating Directory Changes (
Ds-Replication-Get-Changes
,ACE GUID: 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2
)Replicating Directory Changes All (
Ds-Replication-Get-Changes-All
,ACE GUID: 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2
)
Those privileges are, in a default Active Directory configuration, granted to the Domain Controllers
, ENTERPRISE DOMAIN CONTROLLERS
, Domain Admins
, Enterprise Admins
and Administrators
domain groups. For more information on how to retrieve, and potentially exploit, the privileges configured on the domain root object
, refer to the [ActiveDirectory] ACL exploiting
note.
Note that whenever a replication request is made by any security principals that is not a machine account member of the Domain Controllers
/ ENTERPRISE DOMAIN CONTROLLERS
domain groups, Windows Security
events Event 4662: An operation was performed on an object
are generated. The generated events will have, in the Property
attribute, the 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2
and 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2
GUID
, and can thus be effectively used to detect DCSync
attacks. In order to avoid the generation of such events, the identity of a Domain Controller
can be usurped, either after the compromise of a Domain Controller
machine account NTLM
hash or the compromise of any of the krbtgt
account secret.
Indeed, with knowledge of a secret of the targeted domain's krbtgt
account, a golden ticket
impersonating a Domain Controller can be generated to conduct replication operations without raising Windows Security
events (Event 4662: An operation was performed on an object
). The golden ticket
can be crafted using mimikatz
kerberos::golden
module or impacket
's ticketer.py
. For more information on golden tickets
, refer to the [ActiveDirectory] Golden Tickets
note.
For more information on how to impersonate a Domain Controller after the initial compromise of its machine account NTLM
hash refer to the [ActiveDirectory] Silver Tickets
note.
ntds.dit credentials information extraction
The impacket
's secretsdump
Python script and PowerShell cmdlets of the DSInternals
module can be used to extract account(s) credentials information from a specified ntds.dit
file.
If the exported ntds.dit
database file appears to be corrupted, the Windows Extensible Storage Engine Utilities (esentutl)
utility may be used in order to check the integrity and attempt a repair of the database file. esentutl
must be run on a Domain Controller to satisfy external dependencies, such as the ntdsai.dll
DLL, needed to interact with a ntds.dit
database.
References
https://docs.microsoft.com/fr-fr/windows-server/storage/file-server/volume-shadow-copy-service https://github.com/giuliano108/SeBackupPrivilege/blob/master/README.md https://pure.security/dumping-windows-credentials/ https://cqureacademy.com/cqure-labs/cqlabs-dsinternals-powershell-module https://www.dsinternals.com/en/dumping-ntds-dit-files-using-powershell/ https://wiki.samba.org/index.php/DRSUAPI https://adsecurity.org/?p=1729 https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-drsr/58f33216-d9f1-43bf-a183-87e3c899c410 https://blog.stealthbits.com/what-is-dcsync-an-introduction/
Last updated