RegisterUserApiHook - A forgotten undocumented handle-less session-wide DLL injection primitive and its impact on EDR tamper protection

CybersecurityCybershieldAll industries
Expertjulian-horoszkiewicz
Julian Horoszkiewicz

Security Researcher, Author, CVE Contributor, Reverse Engineer

RegisterUserApiHook - A forgotten undocumented handle-less session-wide DLL injection primitive and its impact on EDR tamper protection

 

Introduction

RegisterUserApiHook is an undocumented export from user32.dll that registers a DLL to be automatically loaded into every process in the same session that calls certain instrumented user32.dll exports (window/metrics/theming APIs). It is the mechanism Windows uses internally to inject uxtheme.dll (the theming engine) into GUI processes – ensuring that every window is themed without applications needing to opt in.

This API is a cousin of better-known SetWindowHookEx (opens in a new tab) and SetWinEventHook (opens in a new tab). They all share the following important characteristics:

  • They provide DLL injection primitive into GUI-capable processes on Windows.
  • They do not require the caller to open a handle to target process.


The handle-less characteristic is significant in the context of EDR, especially when evaluating tamper protection. This is because most of the kernel mode tamper protection logic is structured around object handles.

Inspiration - SetWindowHookEx

A couple of years ago I discovered a local privilege escalation vulnerability in an undisclosed EDR product. The attack chain required to operate from a process that was trusted by the product’s tamper protect filter.

There were two challenges:

  • While operating as a regular user with Medium integrity obviously I would not be able to open a writable handle to a process running with System integrity.
  • Standard process injection methods that involve handles obtained with OpenProcess were all blocked by the filter, which is standard behavior and was expected.


But there was one process that allowed me to work around both of those: the tray-embedded GUI component, a very common part of security software solutions.

Those usually run with Medium integrity and are usually also protected from standard process injection by the filter. Knowing that the filter callbacks were structured around handles, I started exploring other process injection primitives and decided to try with SetWindowHookEx. That turned out successful, allowing me to inject into that component, which itself was trusted by the filter, and as a result I was able to take advantage of the process trust relationship to carry out the rest of the attack.

Continuation - RegisterUserApiHook

This year I decided to revisit this subject, and search for more APIs that allow process injection without using a handle.

The outcome were 3 API calls: SetWindowHookEx, SetWinEventHook and RegisterUserApiHook.

Since RegisterUserApiHook is the least known among the three, I decided to explore it deeper.

The only mention of this method in the security context which I was able to find is this presentation from Recon 2012 - Smashing the Atom (opens in a new tab). As a reminder, the term “EDR” was officially coined in 2013 (opens in a new tab).

The offensive potential

I have empirically confirmed this API to be a viable tampering approach alternative to BYOVD, by evaluating this idea against 4 well-known EDR products. For legal and compliance reasons I am not naming any vendors or products.

Contrary to SetWindowHookEx and SetWinEventHook, RegisterUserApiHook requires SYSTEM privileges (which is the same pre-requisite as for BYOVD).

Read the full research (opens in a new tab)