Using global API hooks to hide processes on Windows 7 systems

Onedaysec
3 min read
0 views
docx image 1770015588827 0 9c6235fa50

0x00 Preface

---

In the previous article 'Powershell tricks::Hide Process by kd.exe', the technique of hiding processes via kd.exe was introduced, with the main drawback being the need to enable Local kernel debugging mode and wait for a system restart to take effect.

This time, another method for hiding processes is introduced—using global API hooks.

The advantage is that it takes effect immediately without waiting for a system restart.

0x01 Introduction

---

This article will refer to Sergey Podobry's work to introduce this method, analyze the details to note in practical testing, and supplement the specific parameter settings for 64-bit systems.

Reference links:

https://www.codeproject.com/articles/49319/easy-way-to-set-up-global-api-hooks?display=print

https://github.com/subTee/AppInitGlobalHooks-Mimikatz

0x02 Principle

---

At the user level, the test DLL is injected into all system processes via global API hooks to achieve the hiding of specified processes.

hook method

modify registry key AppInit_DLLs

location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows

parameter description:

LoadAppInit_DLLs:

(REG_DWORD) Value that globally enables or disables AppInit_DLLs.

  • 0x0 – AppInit_DLLs are disabled.
  • 0x1 – AppInit_DLLs are enabled.

AppInit_DLLs:

(REG_SZ)

Space - or comma -separated list of DLLs to load. The complete path to the DLL should be specified using short file names. C:\PROGRA~1\Test\Test.dll

RequireSignedAppInit_DLLs:

(REG_DWORD) Require code-signed DLLs.

  • 0x0 – Load any DLLs.
  • 0x1 – Load only code-signed DLLs.

Code Implementation

Implement API hooking via Mhook library

Advantages:

  • Open source
  • Supports x86 and x64
  • Easy to use

Reference URL:

http://codefromthe70s.org/mhook22.aspx

0x03 Practical Testing

---

Testing Environment:

Win7x86

1. Set registry key AppInit_DLLs

Reference code:

https://github.com/subTee/AppInitGlobalHooks-Mimikatz/blob/master/AppInit.reg

The .reg file is as follows:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]
"AppInit_DLLs"="C:\\Tools\\AppInitHookx64.dll,C:\\Tools\\AppInitHook.dll"
"LoadAppInit_DLLs"=dword:00000001
"RequireSignedAppInit_DLLs"=dword:00000000

Indicates

  • AppInit_DLLs are enabled
  • Load any DLLs, do not need code-signed DLLs
  • DLL path: C:\\Tools\\AppInitHookx64.dll,C:\\Tools\\AppInitHook.dll

Note:

The set path must not contain spaces, otherwise it will be invalid

2. Compile and generate AppInitHook.dll and place it under C:\Tools

Reference project:

https://github.com/subTee/AppInitGlobalHooks-Mimikatz

3. Run mimikatz.exe

Task Manager process list does not contain mimikatz.exe

Process Explorer does not show mimikatz.exe

Tasklist.exe does not display mimikatz.exe

Note:

The process is not completely hidden here; the process name is set to conhost.exe because mimikatz is a console application

If replaced with a Win32 project like putty.exe or calc.exe, this issue does not exist, and the process can be completely hidden

Using Process Explorer to view the newly created processes, all have loaded AppInitHook.dll, as shown in the figure

3. Run mimikatz.exe — technical illustration 1

Note:

Run Process Explorer with administrator privileges to view DLLs loaded by high-privilege processes

4. Win7x64 Testing

The difference between 64-bit and 32-bit systems is also reflected in the registry

Note:

For details, please refer to the previous article 'Notes on Redirection Issues When Running 32-bit Programs on 64-bit Systems'.

Registry location for 64-bit programs:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\

Registry location for 32-bit programs:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\

Therefore, to hook all processes (both 32-bit and 64-bit) on a 64-bit system, two registry key values need to be modified.

Registry key location for 64-bit:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]

Registry key location for 32-bit:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Windows]

The specific modification code has been uploaded to GitHub at the following address:

An open-source project

After modification, view using Process Explorer as shown in the figure.

4. Win7x64 Testing — technical illustration 2

4. Win7x64 Testing — technical illustration 3

Successfully injected into 32-bit and 64-bit processes

0x04 Supplement

---

This method only supports Windows 7 and Windows Server 2008 R2, and does not support higher versions such as Windows 8 or Server 2012

0x04 Supplement — technical illustration 4

As shown in the figure above, on Windows 8 systems, although AppInitHook.dll is successfully loaded, the process cannot be hidden

Reasons are as follows:

Starting from Windows 8, Microsoft imposed restrictions on AppInit_DLLs: the secure boot enabled by default in the BIOS will disable AppInit_DLLs, rendering it ineffective

For details, refer to:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn280412(v=vs.85).aspx

0x05 Defense

---

Only applicable to Windows 7, Windows Server 2008 R2, and earlier systems

1. Check the registry key value

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Windows]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Windows]

Check AppInit_DLLs for suspicious DLL paths

2. Use Process Explorer to check if processes have loaded suspicious DLLs

0x06 Summary

---

This article introduces the method of hiding processes using global API hooks in Windows 7 systems. Combined with exploitation concepts, it helps everyone better defend against this type of attack.

Of course, global API hooks can be used for much more than this.

Related Questions & Answers

What are some ways to defend against process hiding via global API hooks?

On Windows 7 and earlier systems, check the registry keys `AppInit_DLLs` under both the standard and Wow6432Node paths for any suspicious DLL paths. Also use Process Explorer (with administrator privileges) to inspect loaded DLLs in all processes. Enabling `RequireSignedAppInit_DLLs` can also block unsigned hook DLLs. These defensive measures are outlined in [Using global API hooks to hide processes on Windows 7 systems](/news/using-global-api-hooks-to-hide-processes-on-windows-7-systems).

Does the global API hook method work on Windows 8 or later systems?

No, this method only works on Windows 7 and Windows Server 2008 R2. Starting with Windows 8, Microsoft disables AppInit_DLLs when Secure Boot is enabled, which is the default. Even if the DLL is loaded, the process hiding fails due to these restrictions. The [Using global API hooks to hide processes on Windows 7 systems](/news/using-global-api-hooks-to-hide-processes-on-windows-7-systems) article references the MSDN documentation explaining this limitation.

How does the registry configuration differ when hiding processes on a 64-bit Windows 7 system?

On 64-bit Windows 7, you must configure two registry locations: the standard path for 64-bit processes (`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows`) and the Wow6432Node path for 32-bit processes (`HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Windows`). Without both, your hook DLL won't be injected into all processes. This detail is critical, as emphasized in [Using global API hooks to hide processes on Windows 7 systems](/news/using-global-api-hooks-to-hide-processes-on-windows-7-systems).

What registry keys need to be modified to enable global API hooks for process hiding?

You need to set the `AppInit_DLLs` key under `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows` with the full path to your hook DLL. Also set `LoadAppInit_DLLs` to 1 (enable) and `RequireSignedAppInit_DLLs` to 0 (allow unsigned DLLs). The DLL path must not contain spaces. As noted in [Using global API hooks to hide processes on Windows 7 systems](/news/using-global-api-hooks-to-hide-processes-on-windows-7-systems), these changes take immediate effect.

What is the global API hook method for hiding processes on Windows 7 and how does it work?

The global API hook method uses the AppInit_DLLs registry mechanism to inject a custom DLL into every process that loads user32.dll. This DLL hooks API functions like EnumProcesses to hide a specified process from tools like Task Manager and Process Explorer. Unlike the kd.exe method described in [Using global API hooks to hide processes on Windows 7 systems](/news/using-global-api-hooks-to-hide-processes-on-windows-7-systems), this technique takes effect immediately without needing a system restart.

Continue Reading