Quick post to analyze a particular function where the XC3 Driver manages the different version of Windows and bring support to each of them.
As you may know, on windows the offsets inside of different kernel structure may change from one version to the next one.
Critical kernel structures like EPROCESS, KTHREAD, etc, have a lot of information on their attributes. Anti-Cheats usually access that information to manually check information about processes, system and memory by their own, without the need of using the windows API.
If this Driver is being used by hundreds of thousands of users, they need to properly determine the correct offsets of each attribute they want to access for each version. And this function initialize some variables, than later are used by the rest of the functions.
- Part 1 – Identifying the Driver Entry Point
- Part 2 – Analyzing init functions (fn_InitDispatchMethodArray and fn_ObtainKernelFunctions)
- Part 3 – Analyze Dispatch function (fn_DriverIOCTLDispatcher)
- Part 4.1 – Registering Notify and Callback Routines
What we will go through?
- How Drivers of this kind support multiple version of Window
- How hard-coded offsets used to access kernel structures are maintained.
- To identify the kernel structures being used.
j_fn_ConfigWindowsVersion (0x 140003C38)
Worth mentioning that I will just provide some examples of the offsets they are managing. Identifying each of them is really time consuming and I let you that part as homework 😉 Those which I have identified, have been used on other functions I manually reversed before.
This function it is basically a jump to the real implementation:
If we take a look to sub_14000646C, we will notice that the function is basically obtaining the current version of the operative system. Then based on the Major and minor version, and build number, they initialize a group of global variables.
Based on the documentation, PsGetVersion returns the Major, minor and build version on the first, second and third parameter respectively. What happens later is a series of “if and else”, where they determine the exact version and build number:
A number of 8 global variables are being initialized with function pointers that retrieve some particular offset of different structures.
Let’s focus on one case: qword_14000CDF0 is being initialize with off_140009BA0, which contains a reference to another function:
We can see how the function is taking the value of rcx (first parameter) and adding 0x418:
Here is where things get harder. In order to identify which structure is the one that is being sent via RCX, we need to find a case where qword_14000CDF0 is being used:
To sum up and avoid getting things even more complex, we are going to end with the following case (of course, after renaming and some analysis):
fn_GetObjectTable is our function qword_14000CDF0, and this will be the hint that tell us that the function EPROCESS is the one being sent as parameter. Note that PsLookupProcessByProcessId is being called before and the second parameter is being used to store the EPROCESS structure, as the documentation explains.
The offset 0x418 belongs to the attribute ObjectTable, a pointer to the _HANDLE_TABLE structure inside of the kernel.
ObjectTable is used a lot to manually enumerate and analyze the HANDLEs of a process. ACs usually take this table and access to each existing handle in order to determine if other processes have a HANDLEs to the process of the game; or if the HANDLE from process like lsass.exe or csrss.exe have been manipulated.
- Part 4.3 – Using ObRegisterCallbacks
- Part 4.4 – Analyzing the Notify Routines