> Windows Syscalls
ntoskrnl.exeT1027.011T1106

NtCancelTimer2

Cancels a previously armed Timer2 object and reports whether it was still pending.

Prototype

NTSTATUS NtCancelTimer2(
  HANDLE                  TimerHandle,
  PT2_CANCEL_PARAMETERS   Parameters
);

Arguments

NameTypeDirDescription
TimerHandleHANDLEinHandle to a Timer2 object previously armed with NtSetTimer2.
ParametersPT2_CANCEL_PARAMETERSin/outOptional structure: in carries Version, out reports whether the timer was still pending.

Syscall IDs by Windows version

Windows versionSyscall IDBuild
Win10 15070x8Fwin10-1507
Win10 16070x8Fwin10-1607
Win10 17030x90win10-1703
Win10 17090x91win10-1709
Win10 18030x92win10-1803
Win10 18090x92win10-1809
Win10 19030x92win10-1903
Win10 19090x92win10-1909
Win10 20040x94win10-2004
Win10 20H20x94win10-20h2
Win10 21H10x94win10-21h1
Win10 21H20x94win10-21h2
Win10 22H20x94win10-22h2
Win11 21H20x94win11-21h2
Win11 22H20x94win11-22h2
Win11 23H20x94win11-23h2
Win11 24H20x96win11-24h2
Server 20160x8Fwinserver-2016
Server 20190x92winserver-2019
Server 20220x94winserver-2022
Server 20250x96winserver-2025

Kernel module

ntoskrnl.exeNtCancelTimer2

Related APIs

SetThreadpoolTimerWaitForThreadpoolTimerCallbacksCloseThreadpoolTimerNtCancelTimerNtSetTimer2NtCreateTimer2

Syscall stub

4C 8B D1            mov r10, rcx
B8 96 00 00 00      mov eax, 0x96
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

Counterpart to `NtSetTimer2`. Internally `ExpCancelTimer2` removes the `EX_TIMER` from the per-PRCB second-generation queue via `KeCancelTimer2`. If the timer was still pending the kernel returns `STATUS_SUCCESS` and sets `Parameters` to reflect the prior state; if it had already expired and the callback either ran or is in flight, you get `STATUS_TIMER_RESUME_IGNORED`-style semantics — the call cannot un-deliver an APC that is already queued to a thread. Note that `NtCancelTimer2` is remarkably stable across builds (`0x8F` on 1507 → `0x96` on Win11 24H2): the original 1507 SSN survived all the way until the Win11 24H2 syscall-table reshuffle, because the row index reflects sorted alphabetical position relative to insertions/removals — and very little was inserted *before* `Cancel*` for years.

Common malware usage

Used as the symmetric teardown for Timer2-based sleep masks (Cronos, Zilean): right before the implant exits, or when it tears down a temporary mask cycle, `NtCancelTimer2` disarms the timer so the alertable wait completes cleanly. Some kits also use it defensively — if an EDR has begun walking thread-pool timer lists, cancelling the timer early *removes the object from the list* before the scan can correlate the callback pointer with private RWX. Low malware signal on its own.

Detection opportunities

There is no Sysmon event for Timer2 cancellation, and on its own the call is benign. Investigations only consider it as part of a *sequence*: `NtCreateTimer2(HIGH_RESOLUTION) → NtSetTimer2(period ≈ 50 ms, callback in RWX) → NtWaitForSingleObjectEx(Alertable=TRUE) → NtCancelTimer2` repeated tightly is the canonical Timer2 sleep-mask fingerprint. EDR vendors with kernel components (CrowdStrike Falcon, Defender for Endpoint via MAPS) inspect `EX_TIMER` lists directly rather than relying on syscall hooks for this one.

Direct syscall examples

asmx64 direct stub (Win11 24H2)

; Direct syscall stub for NtCancelTimer2 (SSN 0x96 on Win11 24H2 / Server 2025)
NtCancelTimer2 PROC
    mov  r10, rcx          ; syscall convention
    mov  eax, 96h          ; SSN — drifts; resolve dynamically for portability
    syscall
    ret
NtCancelTimer2 ENDP

cSleep-mask teardown

// Sleep-mask cycle teardown: disarm the timer and close the handle.
typedef struct _T2_CANCEL_PARAMETERS {
    ULONG Version;
    ULONG Reserved;
} T2_CANCEL_PARAMETERS, *PT2_CANCEL_PARAMETERS;

T2_CANCEL_PARAMETERS cp = { 0 };
NTSTATUS st = NtCancelTimer2(hTimer, &cp);
// If st == STATUS_SUCCESS the timer was still armed; otherwise the APC already fired.
NtClose(hTimer);

MITRE ATT&CK mappings

Last verified: 2026-05-20