POC ring 3 Windows rootkit in C++ (x86 / x64), hide processes, files, registry keys, services and the injected DLL
Basic Rootkit is a proof-of-concept ring 3 Windows rootkit that hides processes, files, registry keys and services from the running system, hides itself from the module list and protects its host process.
It is built as a DLL that patches the Import Address Table (IAT) of the host process, redirecting several Nt* and Win32 functions to filtered versions. Every entry whose name contains a hidden token is unlinked from the returned list, so the target becomes invisible to the tools that enumerate it. The same code base handles x86 and x64 applications.
Hide processes
- Unlink matching processes from
NtQuerySystemInformation(SystemProcessInformation)
Hide files
- Unlink matching files from
NtQueryDirectoryFile(FileIdBothDirectoryInformation)
Hide registry keys and values
- Skip matching keys and values from
NtEnumerateKeyandNtEnumerateValueKey
Hide services
- Remove matching services from
EnumServicesStatusExW
Hide the injected DLL
- Unlink the DLL from the PEB loader lists so it disappears from
EnumProcessModulesand module snapshots
Protect the host process
- Strip
PROCESS_TERMINATEinNtOpenProcessso the host process cannot be terminated from the outside
It has been tested with Task Manager (x64), Explorer (x64) and Process Hacker (x86) on Windows 10.
The identifier used to mark the entries to hide defaults to $pwn. It can be overridden at load time, in this order:
- The
ROOTKIT_TOKENSenvironment variable (several tokens separated by;,,or newlines) - A
rootkit.tokensfile placed next to the DLL (one token per line,#starts a comment) - The
$pwndefault
Hiding can also be toggled at runtime through the exported functions:
void EnableHiding();
void DisableHiding();
BOOL IsHidingEnabled();Demo.Task.Manager.mp4
Demo.Explorer.mp4
This project produces a DLL that can be injected into any application you want to hook. Once loaded, every entry whose name contains a hidden token is removed from the hooks described above, and the DLL itself disappears from the module list.
The hidden token must be part of the name of the process, file, registry key/value or service you want to hide (for example a process whose executable is named payload$pwn.exe).
- Open
Basic Rootkit.slnin Visual Studio. - Build the project in Debug / Release (x86 / x64).
- Output: every configuration is already set up, the produced DLL is named
Basic Rootkit.dll - Architecture: the x86 and x64 builds work on both x86 and x64 applications
You can also easily carry this project to CMake.
Warning
If you have any linking error when compiling make sure you include "Shlwapi.lib" to the project.
This project is provided for educational and research purposes only, to study how user-mode rootkits work. Use it only on systems you own or are explicitly authorized to test.
This project is licensed under the GNU GPLv3.