My procedure, that locates nt!KeServiceDescriptorTable on x64, by disassembling a code of exported nt!KeAddSystemServiceTable().
Code: Select allPVOID GetKeSDT(void)
{
PVOID Ret = NULL;
#ifdef _X86_
PVOID KernelBase = KernelGetModuleBase("ntoskrnl.exe");
if (KernelBase)
{
ULONG KeSDT_RVA = KernelGetExportAddress(KernelBase, "KeServiceDescriptorTable");
if (KeSDT_RVA > 0)
{
Ret = RVATOVA(KernelBase, KeSDT_RVA);
}
else
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Symbol nt!KeServiceDescriptorTable is not found\n");
}
}
else
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Unable to locate kernel base\n");
}
#elif _AMD64_
#define MAX_INST_LEN 24
PVOID KernelBase = KernelGetModuleBase("ntoskrnl.exe");
if (KernelBase)
{
ULONG Func_RVA = KernelGetExportAddress(KernelBase, "KeAddSystemServiceTable");
if (Func_RVA > 0)
{
// initialize disassembler engine
ud_t ud_obj;
ud_init(&ud_obj);
UCHAR ud_mode = 64;
// set mode, syntax and vendor
ud_set_mode(&ud_obj, ud_mode);
ud_set_syntax(&ud_obj, UD_SYN_INTEL);
ud_set_vendor(&ud_obj, UD_VENDOR_INTEL);
for (ULONG i = 0; i < 0x40;)
{
PUCHAR Inst = (PUCHAR)RVATOVA(KernelBase, Func_RVA + i);
if (!MmIsAddressValid(Inst))
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Invalid memory at "IFMT"\n", Inst);
break;
}
ud_set_input_buffer(&ud_obj, Inst, MAX_INST_LEN);
// get length of the instruction
ULONG InstLen = ud_disassemble(&ud_obj);
if (InstLen == 0)
{
// error while disassembling instruction
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Can't disassemble instruction at "IFMT"\n", Inst);
break;
}
/*
Check for the following code
nt!KeAddSystemServiceTable:
fffff800`012471c0 448b542428 mov r10d,dword ptr [rsp+28h]
fffff800`012471c5 4183fa01 cmp r10d,1
fffff800`012471c9 0f871ab70c00 ja nt!KeAddSystemServiceTable+0x78
fffff800`012471cf 498bc2 mov rax,r10
fffff800`012471d2 4c8d1d278edbff lea r11,0xfffff800`01000000
fffff800`012471d9 48c1e005 shl rax,5
fffff800`012471dd 4a83bc1880bb170000 cmp qword ptr [rax+r11+17BB80h],0
fffff800`012471e6 0f85fdb60c00 jne nt!KeAddSystemServiceTable+0x78
*/
if ((*(PULONG)Inst & 0x00ffffff) == 0x1d8d4c &&
(*(PUSHORT)(Inst + 0x0b) == 0x834b || *(PUSHORT)(Inst + 0x0b) == 0x834a))
{
// clculate nt!KeServiceDescriptorTableAddress
LARGE_INTEGER Addr;
Addr.QuadPart = (ULONGLONG)Inst + InstLen;
Addr.LowPart += *(PULONG)(Inst + 0x03) + *(PULONG)(Inst + 0x0f);
Ret = (PVOID)Addr.QuadPart;
break;
}
i += InstLen;
}
}
else
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Symbol nt!KeServiceDescriptorTable is not found\n");
}
}
else
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"() ERROR: Unable to locate kernel base\n");
}
#endif
if (Ret)
{
DbgMsg(__FILE__, __LINE__, __FUNCTION__"(): nt!KeServiceDescriptorTable is at "IFMT"\n", Ret);
}
return Ret;
}