NtRemoveProcessDebug
Desengancha un DebugObject de un proceso — la cara kernel de DebugActiveProcessStop.
Prototipo
NTSTATUS NtRemoveProcessDebug( HANDLE ProcessHandle, HANDLE DebugObjectHandle );
Argumentos
| Name | Type | Dir | Description |
|---|---|---|---|
| ProcessHandle | HANDLE | in | Handle al proceso actualmente enganchado a DebugObjectHandle. |
| DebugObjectHandle | HANDLE | in | Handle al DebugObject a retirar. Debe coincidir con el que reside en EPROCESS.DebugPort. |
IDs de syscalls por versión de Windows
| Versión de Windows | ID de syscall | Build |
|---|---|---|
| Win10 1507 | 0x157 | win10-1507 |
| Win10 1607 | 0x15E | win10-1607 |
| Win10 1703 | 0x164 | win10-1703 |
| Win10 1709 | 0x167 | win10-1709 |
| Win10 1803 | 0x169 | win10-1803 |
| Win10 1809 | 0x16A | win10-1809 |
| Win10 1903 | 0x16B | win10-1903 |
| Win10 1909 | 0x16B | win10-1909 |
| Win10 2004 | 0x171 | win10-2004 |
| Win10 20H2 | 0x171 | win10-20h2 |
| Win10 21H1 | 0x171 | win10-21h1 |
| Win10 21H2 | 0x173 | win10-21h2 |
| Win10 22H2 | 0x173 | win10-22h2 |
| Win11 21H2 | 0x17B | win11-21h2 |
| Win11 22H2 | 0x17E | win11-22h2 |
| Win11 23H2 | 0x17E | win11-23h2 |
| Win11 24H2 | 0x180 | win11-24h2 |
| Server 2016 | 0x15E | winserver-2016 |
| Server 2019 | 0x16A | winserver-2019 |
| Server 2022 | 0x179 | winserver-2022 |
| Server 2025 | 0x180 | winserver-2025 |
Módulo del kernel
APIs relacionadas
Stub del syscall
4C 8B D1 mov r10, rcx B8 80 01 00 00 mov eax, 0x180 F6 04 25 08 03 FE 7F 01 test byte ptr [0x7FFE0308], 1 75 03 jne short +3 0F 05 syscall C3 ret CD 2E int 2Eh C3 ret
Notas no documentadas
Llama a DbgkpRemoveProcessDebugObject, que limpia EPROCESS.DebugPort, drena la lista de eventos pendientes del DebugObject y reanuda los hilos congelados. Tras retornar, el proceso vuelve a ser enganchable por un depurador externo — útil cuando el malware quiere *temporalmente* ocupar el puerto de depuración y soltarlo cuando una región sensible termina. Devuelve STATUS_PORT_NOT_SET (0xC000033C) si el proceso no estaba siendo depurado por el DebugObject indicado. A diferencia de NtCreateDebugObject, este SSN cae en el rango alto 0x150-0x180 y se mueve en *cada* actualización mayor — resolución dinámica obligatoria.
Uso común por malware
Dos patrones. (1) Anti-attach con ventana de tiempo: retener el puerto de depuración durante el desempaquetado y soltarlo al alcanzar el bucle C2 de larga vida — minimiza la superficie expuesta al analista mientras el implante está latente. (2) Limpieza antes de fork-and-run o migración: el nuevo proceso hereda EPROCESS.DebugPort si se forkó bajo DEBUG_ONLY_THIS_PROCESS, así que el loader se desengancha explícitamente antes de ceder al hijo. Visto principalmente en runtimes de protectores comerciales (Themida, VMProtect), poco en crypters comunes.
Oportunidades de detección
Mismo proveedor que NtDebugActiveProcess: Microsoft-Windows-Threat-Intelligence emite evento al desengancharse. Mucho menos común en telemetría legítima que el attach: detaches emitidos por algo distinto de windbg.exe / vsjitdebugger.exe / devenv.exe / cdb.exe / un relé kernel-debugger destacan. Correlacione siempre con el attach correspondiente — eventos de detach huérfanos sin attach previo pueden indicar reuso de handle o un depurador que se inyectó vía NtCreateDebugObject directamente sin pasar por DebugActiveProcess.
Ejemplos de syscalls directos
cTime-windowed anti-attach release
// Once the loader has decrypted and resolved imports, release the debug
// port so long-running operations don't have the burden of servicing the
// DebugObject's event loop. Analysts attaching later will succeed — but by
// then the interesting work has already happened.
typedef NTSTATUS(NTAPI* fnNtRemoveProcessDebug)(HANDLE, HANDLE);
void ReleaseSelfDebug(HANDLE hDebugObject) {
HMODULE n = GetModuleHandleA("ntdll.dll");
fnNtRemoveProcessDebug pRemove = (fnNtRemoveProcessDebug)
GetProcAddress(n, "NtRemoveProcessDebug");
pRemove((HANDLE)-1 /* self */, hDebugObject);
CloseHandle(hDebugObject);
}asmx64 direct stub (Win11 24H2 SSN)
; SSN 0x180 on win11-24h2 / winserver-2025. Moves on every channel update.
NtRemoveProcessDebug PROC
mov r10, rcx
mov eax, 180h
syscall
ret
NtRemoveProcessDebug ENDPrustPre-migration cleanup
// Detach our DebugObject before doing a fork-and-run so that the child
// process inherits a clean EPROCESS.DebugPort.
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
type NtRemoveProcessDebug = unsafe extern "system" fn(p: isize, d: isize) -> i32;
pub unsafe fn detach(process: isize, debug_object: isize) -> i32 {
let n = GetModuleHandleA(b"ntdll.dll\0".as_ptr());
let addr = GetProcAddress(n, b"NtRemoveProcessDebug\0".as_ptr()).unwrap();
let f: NtRemoveProcessDebug = std::mem::transmute(addr);
f(process, debug_object)
}Mapeos MITRE ATT&CK
Last verified: 2026-05-20