NtDebugActiveProcess
Attaches an existing DebugObject to a running process — the kernel side of DebugActiveProcess.
Prototype
NTSTATUS NtDebugActiveProcess( HANDLE ProcessHandle, HANDLE DebugObjectHandle );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| ProcessHandle | HANDLE | in | Handle to the target process. Requires PROCESS_SUSPEND_RESUME | PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE. |
| DebugObjectHandle | HANDLE | in | Handle to a DebugObject previously created with NtCreateDebugObject (needs DEBUG_PROCESS_ASSIGN). |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0xBF | win10-1507 |
| Win10 1607 | 0xC2 | win10-1607 |
| Win10 1703 | 0xC5 | win10-1703 |
| Win10 1709 | 0xC6 | win10-1709 |
| Win10 1803 | 0xC7 | win10-1803 |
| Win10 1809 | 0xC8 | win10-1809 |
| Win10 1903 | 0xC9 | win10-1903 |
| Win10 1909 | 0xC9 | win10-1909 |
| Win10 2004 | 0xCD | win10-2004 |
| Win10 20H2 | 0xCD | win10-20h2 |
| Win10 21H1 | 0xCD | win10-21h1 |
| Win10 21H2 | 0xCE | win10-21h2 |
| Win10 22H2 | 0xCE | win10-22h2 |
| Win11 21H2 | 0xD3 | win11-21h2 |
| Win11 22H2 | 0xD4 | win11-22h2 |
| Win11 23H2 | 0xD4 | win11-23h2 |
| Win11 24H2 | 0xD6 | win11-24h2 |
| Server 2016 | 0xC2 | winserver-2016 |
| Server 2019 | 0xC8 | winserver-2019 |
| Server 2022 | 0xD2 | winserver-2022 |
| Server 2025 | 0xD6 | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 D6 00 00 00 mov eax, 0xD6 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
Internally calls DbgkpSetProcessDebugObject, which walks the EPROCESS, checks that DebugPort is NULL, and atomically stores the DebugObject pointer. The NULL-check is the source of the single-debugger limitation: if a process is already being debugged (DebugPort != NULL) the call returns STATUS_PORT_ALREADY_SET (0xC0000048). Sending a NULL DebugObjectHandle (or one without DEBUG_PROCESS_ASSIGN) gives STATUS_INVALID_HANDLE / STATUS_ACCESS_DENIED. After attach, every primary action in the target (image load, thread create/exit, exception, breakpoint) is funneled through DbgkSendApiMessage into the DebugObject's event queue for the owning debugger to consume.
Common malware usage
Pair with NtCreateDebugObject for the classic self-debug anti-attach: the loader attaches its own PID to a DebugObject it owns, occupying the single allowed debug port. Sometimes the inverse is used: malware attaches an EDR or analyst-spawned debugger process to a fake DebugObject (very rare, requires PROCESS_ALL_ACCESS to the EDR — only seen in PoCs). Some loaders also attach a freshly spawned suspended child to a DebugObject so they can intercept exceptions raised by the child's unpacking stub — effectively a userland debugger driving their own protection scheme.
Detection opportunities
Microsoft-Windows-Threat-Intelligence ETW provider raises an event when a process is attached for debugging — EtwTiLogDebugActiveProcess. Defender for Endpoint, Elastic Endpoint Security and CrowdStrike Falcon all subscribe. The high-fidelity pivot is `parent_pid == child_pid` (self-debug) or `actor_image` not in a small allowlist of legitimate debuggers. Sysmon does not currently log this directly, but Sysmon ProcessAccess Event 10 with `GrantedAccess` containing PROCESS_SUSPEND_RESUME|PROCESS_CREATE_THREAD by a non-debugger image is a reasonable proxy when ETW is unavailable.
Direct syscall examples
cAnti-attach via self-debug
// Plug-in to InstallSelfDebug() — see NtCreateDebugObject example.
// External DebugActiveProcess() against us now returns 0xC0000048.
typedef NTSTATUS(NTAPI* fnNtDebugActiveProcess)(HANDLE, HANDLE);
BOOL OccupyDebugPort(HANDLE hDebugObject) {
HMODULE n = GetModuleHandleA("ntdll.dll");
fnNtDebugActiveProcess pAttach = (fnNtDebugActiveProcess)
GetProcAddress(n, "NtDebugActiveProcess");
NTSTATUS s = pAttach((HANDLE)-1 /* current process */, hDebugObject);
return s == 0; // anything else (incl. 0xC0000048) means a debugger beat us to it
}asmx64 direct stub (Win11 24H2 SSN)
; SSN 0xD6 on win11-24h2 / winserver-2025.
NtDebugActiveProcess PROC
mov r10, rcx
mov eax, 0D6h
syscall
ret
NtDebugActiveProcess ENDPrustDetect a pre-existing attached debugger
// If NtDebugActiveProcess returns STATUS_PORT_ALREADY_SET (0xC0000048),
// something is already debugging us — anti-debug check.
use std::ffi::c_void;
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
type NtDebugActiveProcess = unsafe extern "system" fn(p: isize, d: isize) -> i32;
pub unsafe fn already_debugged(self_handle: isize, dbg: isize) -> bool {
let n = GetModuleHandleA(b"ntdll.dll\0".as_ptr());
let addr = GetProcAddress(n, b"NtDebugActiveProcess\0".as_ptr()).unwrap();
let f: NtDebugActiveProcess = std::mem::transmute(addr);
f(self_handle, dbg) as u32 == 0xC000_0048
}
fn _unused(_: *mut c_void) {}MITRE ATT&CK mappings
Last verified: 2026-05-20