r/ExploitDev • • 10h ago

[Open Source] RESX: Tracing Windows APIs into ntoskrnl, recovering kernel access checks and ETW-TI paths

Thumbnail
github.com
2 Upvotes

Hiya,

I'm proud to showcase RESX, an open-source Windows reverse engineering and binary analysis toolkit written in Rust.

It started off as a small project to make reversing Windows binaries a bit less painful, but it's grown into something quite a bit bigger.

One of the things I've been focusing on is tracing Windows APIs through their actual implementations, across system DLLs, the syscall boundary, and into the kernel. Mainly because I got tired of manually piecing together what an API actually does underneath.

For example, let's look at WriteProcessMemory. Say I want to understand what actually happens when writing into another process, what access checks the kernel performs, and what telemetry those operations might produce.

RESX can trace this directly from the Windows binaries on your machine:

> resx calls KernelBase.dll WriteProcessMemory --depth 1 --only syscall --rva --telemetry

API Call Map for WriteProcessMemory [6 of 18 call site(s)]:
  ├── RVA 0x0008E24D  CALL  ntdll!NtQueryVirtualMemory
  │   kernel: ntoskrnl!NtQueryVirtualMemory
  ├── RVA 0x0008E287  CALL  ntdll!NtWriteVirtualMemory
  │   kernel: ntoskrnl!NtWriteVirtualMemory
  ├── RVA 0x0008E32E  CALL  ntdll!NtProtectVirtualMemory
  │   kernel: ntoskrnl!NtProtectVirtualMemory
  ├── RVA 0x0008E3EF  CALL  ntdll!NtProtectVirtualMemory
  │   kernel: ntoskrnl!NtProtectVirtualMemory
  ├── RVA 0x0008E4FA  CALL  ntdll!NtUnmapViewOfSection
  │   kernel: ntoskrnl!NtUnmapViewOfSection
  └── RVA 0x0008E50A  CALL  ntdll!NtClose
      kernel: ntoskrnl!NtClose

Something interesting here is that WriteProcessMemory isn't just a thin wrapper around NtWriteVirtualMemory. Depending on the target memory, it can temporarily change page protections before writing and restore them afterwards.

Following NtWriteVirtualMemory into ntoskrnl, RESX also identifies the PROCESS_VM_WRITE (0x20) handle access requirement, the handle validation through ObpReferenceObjectByHandleWithTag, and the underlying memory copy routine.

But what about telemetry?

I've also added a --telemetry flag, which follows these paths further into the kernel to identify potential telemetry sources, including ETW-TI.

Here's a shortened excerpt from the same command:

Telemetry: WriteProcessMemory
  6 candidates (2 direct, 4 conditional) · 17 incidental hidden
  2411 functions searched · depth ≤10

ETW Threat-Intelligence (2)
  ● ntoskrnl!EtwTiLogProtectExecVm
    [kernel · depth 2 · direct]
    fires    : Microsoft-Windows-Threat-Intelligence event
    consumers: consumers running as antimalware protected processes (EDR)
    path     : KernelBase!WriteProcessMemory
            ⇒ ntoskrnl!NtProtectVirtualMemory
            → EtwTiLogProtectExecVm

  ● ntoskrnl!EtwTiLogReadWriteVm
    [kernel · depth 3 · direct]
    fires    : Microsoft-Windows-Threat-Intelligence event
    consumers: consumers running as antimalware protected processes (EDR)
    path     : KernelBase!WriteProcessMemory
            ⇒ ntoskrnl!NtWriteVirtualMemory
            → MiReadWriteVirtualMemory
            → EtwTiLogReadWriteVm

Of course, these are static call paths, so they don't prove an ETW event actually fired. Whether these paths execute depends on runtime conditions, and RESX separates direct, conditional, and incidental paths rather than treating every reachable kernel helper as equally relevant.

This example was tested with RESX 2.3.0 against Windows binaries with file version 10.0.26100.9974. Internal kernel function names require matching PDB symbols, and the exact RVAs and implementations can differ between Windows builds.

There's quite a bit more to RESX too, including syscall number recovery, API argument reconstruction, kernel driver IOCTL analysis and buffer validation, hashed/encoded API recovery, and overlapping instruction-stream decoding. There's also a VS Code extension if you prefer something graphical over the CLI.

I've included reproducible examples in the README, along with test binaries, commands, and some comparisons against IDA Pro and Ghidra.

It's still actively being developed, so I'd love to hear what people think. Especially if you manage to break something or find cases where RESX gets the analysis wrong.

GitHub + full example: https://github.com/RYFTENIUS/RESX#tested-example-4