> Windows Syscalls
ntoskrnl.exeT1622T1106

NtRemoveProcessDebug

Desengancha un DebugObject de un proceso — la cara kernel de DebugActiveProcessStop.

Prototipo

NTSTATUS NtRemoveProcessDebug(
  HANDLE ProcessHandle,
  HANDLE DebugObjectHandle
);

Argumentos

NameTypeDirDescription
ProcessHandleHANDLEinHandle al proceso actualmente enganchado a DebugObjectHandle.
DebugObjectHandleHANDLEinHandle al DebugObject a retirar. Debe coincidir con el que reside en EPROCESS.DebugPort.

IDs de syscalls por versión de Windows

Versión de WindowsID de syscallBuild
Win10 15070x157win10-1507
Win10 16070x15Ewin10-1607
Win10 17030x164win10-1703
Win10 17090x167win10-1709
Win10 18030x169win10-1803
Win10 18090x16Awin10-1809
Win10 19030x16Bwin10-1903
Win10 19090x16Bwin10-1909
Win10 20040x171win10-2004
Win10 20H20x171win10-20h2
Win10 21H10x171win10-21h1
Win10 21H20x173win10-21h2
Win10 22H20x173win10-22h2
Win11 21H20x17Bwin11-21h2
Win11 22H20x17Ewin11-22h2
Win11 23H20x17Ewin11-23h2
Win11 24H20x180win11-24h2
Server 20160x15Ewinserver-2016
Server 20190x16Awinserver-2019
Server 20220x179winserver-2022
Server 20250x180winserver-2025

Módulo del kernel

ntoskrnl.exeNtRemoveProcessDebug

APIs relacionadas

DebugActiveProcessStopDebugSetProcessKillOnExitNtCreateDebugObjectNtDebugActiveProcessNtDebugContinueNtWaitForDebugEvent

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 ENDP

rustPre-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