Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows display driver hooking, 64 bit

Once I've written a sort of a driver for Windows, which had to intercept the interaction of the native display driver with the OS. The native display driver consists of a miniport driver and a DLL loaded by win32k.sys into the session space. My goal was to meddle between the win32k.sys and that DLL. Moreover, the system might have several display drivers, I had to hook them all.

I created a standard WDM driver, which was configured to load at system boot (i.e. before win32k). During its initialization it hooked the ZwSetSystemInformation, by patching the SSDT. This function is called by the OS whenever it loads/unloads a DLL into the session space, which is exactly what I need.

When ZwSetSystemInformation is invoked with SystemLoadImage parameter - one of its parameters is the pointer to a SYSTEM_LOAD_IMAGE structure, and its ModuleBase is the module base mapping address. Then I analyze the mapped image, patch its entry point with my function, and the rest is straightforward.

Now I need to port this driver to a 64-bit Windows. Needless to say it's not a trivial task at all. So far I found the following obstacles:

  • All drivers must be signed
  • PatchGuard
  • SSDT is not directly exported.

If I understand correctly, PatchGuard and driver signing verification may be turned off, the driver should be installed on a dedicated machine, and we may torture it the way we want.

There're tricks to locate the SSDT as well, according to online sources.

However recently I've discovered there exists a function called PsSetLoadImageNotifyRoutine. It may simplify the task considerably, and help avoid dirty tricks.

My question are:

  • If I use PsSetLoadImageNotifyRoutine, will I receive notifications about DLLs loaded into the session space? The official documentation talks about "system space or user space", but does "system space" also includes the session space?
  • Do I need to disable the PatchGuard if I'm going to patch the mapped DLL image after it was mapped?
  • Are there any more potential problems I didn't think about?
  • Are there any other ways to achieve what I want?

Thanks in advance.

like image 232
valdo Avatar asked Nov 04 '22 03:11

valdo


1 Answers

Do I need to disable the PatchGuard if I'm going to patch the mapped DLL image after it was mapped?

To load any driver on x64 it must be signed. With admin rights you can disabled PatchGuard and I personally recommend using DSEO, a GUI application made for this. Or you can bypass PatchGuard by overwriting the MBR (or BIOS), although this is typically considered a bootkit - malware.

like image 171
caker Avatar answered Nov 10 '22 21:11

caker