> Windows Syscalls
ntoskrnl.exeT1622T1106

NtRemoveProcessDebug

Detaches a DebugObject from a process — the kernel side of DebugActiveProcessStop.

Prototype

NTSTATUS NtRemoveProcessDebug(
  HANDLE ProcessHandle,
  HANDLE DebugObjectHandle
);

Arguments

NameTypeDirDescription
ProcessHandleHANDLEinHandle to the process currently attached to DebugObjectHandle.
DebugObjectHandleHANDLEinHandle to the DebugObject to remove. Must match the one currently on EPROCESS.DebugPort.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
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

Kernel module

ntoskrnl.exeNtRemoveProcessDebug

Related APIs

DebugActiveProcessStopDebugSetProcessKillOnExitNtCreateDebugObjectNtDebugActiveProcessNtDebugContinueNtWaitForDebugEvent

Syscall stub

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

Undocumented notes

Calls DbgkpRemoveProcessDebugObject, which clears EPROCESS.DebugPort, drains the DebugObject's pending-event list and continues any frozen threads. After it returns, the process is once again attachable by an external debugger — this matters when malware wants to *temporarily* hold the debug port and release it once a sensitive code region has finished executing. Returns STATUS_PORT_NOT_SET (0xC000033C) if the process was not actually being debugged by the supplied DebugObject. Unlike NtCreateDebugObject's SSN, this one lives in the high-0x150s/0x180 range and is one of the syscalls that moves *every* feature update — dynamic resolution mandatory.

Common malware usage

Used in two patterns. (1) Time-windowed anti-attach: hold the debug port during unpacking, then release it once execution reaches the long-lived C2 loop — keeps the attack surface for analysts low while the implant is dormant. (2) Self-debug cleanup before a fork-and-run or migrate: the new process inherits an EPROCESS.DebugPort if forked under DEBUG_ONLY_THIS_PROCESS, so loaders explicitly detach before handing off to a clean child. Mostly seen inside commercial protector runtimes (Themida, VMProtect) rather than in commodity crypters.

Detection opportunities

Same provider as NtDebugActiveProcess — Microsoft-Windows-Threat-Intelligence emits an event for debug detach. Far less common in legitimate telemetry than attach: detaches by anything other than windbg.exe / vsjitdebugger.exe / devenv.exe / cdb.exe / a kernel-debugger relay are notable. Always correlate with the matching attach event — orphan detach events with no preceding attach can indicate handle reuse or a debugger that injected via NtCreateDebugObject directly without going through DebugActiveProcess.

Direct syscall examples

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)
}

MITRE ATT&CK mappings

Last verified: 2026-05-20