McAfee Rootkit Windows
McAfee Rootkit Windows
Rootkits Part 2:
A Technical Primer
by Aditya Kapoor and Ahmed Sallam
www.mcafee.com
Rootkits Part 2: A Technical Primer www.mcafee.com
When a function call is made to the via a special processor facility that
Win32 subsystem, it may, in turn, could be either an interrupt (INT 02E
carry out one of the following for Windows 2000 and older Windows
four activities: NT systems) or the SysEnter/SysExit
instructions (for Windows XP and
• Deal with the request locally, inside Windows Vista).1
the user-mode space and not call
into the kernel. The kernel32.dll is commonly mistaken
• Call into a user-mode service such as the Windows kernel. Kernel32.dll is
as csrss.exe, which is responsible actually a user-mode DLL that simply
for keeping the Win32 subsystem passes on requests for the kernel to
running. This process maintains ntdll.dll, another DLL that operates
the Win32 processes state-related in user mode. Windows kernel
information and returns informa- functions actually reside in ntoskrnl.
tion to the calling APIs. exe. The file win32k.sys is another
• Issue a remote procedure call to kernel-mode component that exists
one of the running Windows within the Win32 subsystem. Other
services that acts as the server subsystems, such as OS/2 and POSIX,
for that specific RPC interface. are included only to provide backward
• Make an API call that requires the compatibility.
services of the kernel. This category
of API call actually calls into the cor- A rootkit must alter the flow of this
responding function in the ntdll.dll. normal execution path to make its
stealth implementation successful. This
Ntdll is a special-purpose DLL that modification can occur via a process
contains internal support functions called system hooking. The Windows
and system-service dispatch stubs to architecture itself supports many
executive functions. Ntdll.dll maps the easily implemented hooking methods
incoming API requests to their cor- to keep itself flexible and extendible.
responding kernel services through a Rootkits normally modify the data
mechanism called system service returned by Windows system function
dispatching. The control from user calls to hide their binary files,
mode to kernel mode is transferred processes, and registry entries.
Other Subsystems,
OS/2, POSIX Advapi32.dll Kernel32.dll User32/GDI23 Login/GINA
Kernel Mode
Executive
Ntoskrnl.exe
Underlying Kernel
Rootkits Part 2: A Technical Primer www.mcafee.com
2. SetWindowsHookEx
3. CreateRemoteThread
4. WriteProcessMemory
Kernel32.dll
Rootkit code
Rootkits Part 2: A Technical Primer www.mcafee.com
user32.dll to also load the rootkit any running process over which the
DLL listed under this same reg- malicious process has access rights.
istry. That rootkit DLL will then One typical technique is to call
have access to the process address CreateRemoteThread while
space and can apply different specifying the address of the
methods of hooking to the process LoadLibrary function and the name
code and data sections. Malware of the attacking DLL. This loads the
attacks Urbin4 and Adware-FCHelp5 attacker’s library inside the victim’s
employed this technique. process address space. Once in that
• Internet Explorer toolbar and space, the malware can monitor and
search extensions, browser helper alter API calls. (This function is also
objects, etc. employed by many legitimate
• Windows Explorer shell extensions applications to create a thread in
• Microsoft Office applets, plug-ins, another running application so that
and controls it shares its resources or queries
heap and process information.)
Injection by Windows Adcliker-BA Trojan uses this
messaging filtering injection vector.
The Windows Messaging System • WriteProcessMemory can write
allows the installation of message code over any existing process
filters to support a wide range of memory to which it has access.
functions. Computer-based training SetThreadContext can then modify
is one example. To install a filter, the thread’s extended instruction
Windows provides an interface that pointer to redirect the execution
can place a given library in each pro- of the thread into the newly
cess address space. written code bytes. The
WriteProcessMemory injection
• SetWindowsHookEx can be called method works in much the same
to hook one or more system way as CreateRemoteThread, except
events. Hooks can be set for any that no new DLL loads, and the
input method or for any Windows malicious, inserted code can exist
message generated for a single only in memory, which makes
application. Applications running detection and cleanup more
on the same desktop as the call- difficult. HackerDefender is the
ing thread are frequent targets. All classic example of a Trojan
hooked events are opportunities for implementing this technique.
the rootkit to alter subsequent API
call results. Injection by application vulnerability
Windows applications have many
Injection by debugging subsystem methods for interprocess communi-
The debugging subsystem provided cations, in addition to other inputs
by Windows allows one application to using network connections and local
debug and influence the execution files shared with other applications.
of another application. Assuming Usually, local applications are not
enough privileges are available to restricted to communicating solely
the user running the debugger, it with other local applications, thus
is possible to create new execution allowing a wide range of possible
threads in a target process, as well attack paths. If an application contains
as read and write from its memory buffer overflow vulnerability, or trusts
address space. a local file that can be modified by
another application, malware can gain
• CreateRemoteThread can run code control of the code executed inside a
remotely into the address space of vulnerable application.
Rootkits Part 2: A Technical Primer www.mcafee.com
Rootkits Part 2: A Technical Primer www.mcafee.com
process calls will hit the rootkit first. use kernel-mode programs to monitor
As with IAT, the rootkit code checks for system-wide changes and to access
to see if the parameters indicate kernel-level permissions to defend
the need to falsify results and then against malicious activity by any file.
responds appropriately. For security products, kernel-mode
execution brings the added advantage
Figure 5 illustrates the differ- that the program cannot be deleted
ences between the two techniques. by most user-mode processes.
Resuming normal execution paths
after hooking requires that the initial A device driver running with kernel
five bytes of the original FindNextFile privileges has full access to all system
function (inside kernel32.dll) be data, and permission to terminate any
replaced at location 0x12345678, running service or process. Rootkit
before jumping back to kernel32.dll technology’s next logical step is to
code. (The initial bytes are saved in operate in kernel mode with system
the Trampoline Function.7) privileges. By operating at the same
User-mode rootkits that use this high privilege level as security tools,
technique include Adclicker-BA,3 rootkits will better avoid detection
AFXrootkit,6 Adware-Elitebar,8 and deletion.
and Backdoor-BAC.9
Rootkits Part 2: A Technical Primer www.mcafee.com
Ntdll.dll
0x77F7595E:
mov edx, …
Int 2E / SYSENTER
NtCreateFile
Index
System Service
Dispatcher
Rootkits Part 2: A Technical Primer www.mcafee.com
Rootkits Part 2: A Technical Primer www.mcafee.com
NtQuerySystemInformation NtQuerySystemInformation
(Original) (Apropos Hook)
Rootkits Part 2: A Technical Primer www.mcafee.com
ntdll!NtCreateFile:
7c90d682 b825000000 mov eax, 25h
7c90d687 ba0003fe7f mov edx, offset SharedUserData!SystemCallStub
7c90d68c ff12 call dword ptr [edx]
7c90d68e c22c00 ret 2Ch
10
Rootkits Part 2: A Technical Primer www.mcafee.com
Linear Address
31 22 21 12 11 0
Directory Table Offset
12 4KB page
11
Rootkits Part 2: A Technical Primer www.mcafee.com
and the fault address are the same. target system. Because software
If they are not, the caller is trying to running on the target system can’t
execute read only and not execute a assess the state of this type of rootkit,
kernel-mode call. Thus, the rootkit can the software fails to even detect it.
modify the results before returning
them by changing the PTE temporarily SubVirt is permanent and has to take
to map to a garbage page and then control during the boot phase—
accessing that page, which results before the operating system starts.
in the processor updating the cor- Therefore, it can be detected only by
responding DTLB entry. When control booting the system in an offline
returns to the processor to execute scanning mode. SubVirt is based on a
the faulting memory read again, the commercial virtual machine monitor,
CPU will do the translation based on which allows for easier detection.
the entry inside its updated DTLB.
Blue Pill:
SubVirt: processor-based virtualization
malware as virtual machines Both Intel and AMD have extended
Conceptually, virtual machine–based their 64-bit processor instruction sets
rootkits (VMBRs)17 install a virtual to support hardware virtualization.
machine monitor beneath an existing Blue Pill18 is a new conceptual root-
operating system and hoist the kit that uses the new virtualization
original operating system into a instructions provided by AMD’s Secure
virtual machine. Virtual machine– Virtual Machine extension. Blue Pill
based rootkits are hard to detect and uses ultrathin hypervisor, and all the
remove because their state cannot be hardware is natively accessible with-
accessed by software out negatively affecting performance.
running in the target system. Further, The key to Blue Pill is its ability to
VMBRs support general-purpose install itself on the fly—without
malicious services by allowing such modifying the BIOS, boot sector, or
services to run in a separate operating system files.
system that is protected from the
Physical Memory
System Bus
(External) Data Cache
L2 Cache L3 Cache†
Unit (L1)
Instruction
TLBs
Bus Interface Unit
Data TLBs
12
Rootkits Part 2: A Technical Primer www.mcafee.com
13
Rootkits Part 2: A Technical Primer www.mcafee.com
Appendix
This table details the prevalence of various user- and kernel-mode techniques
found in rootkits today. Data from McAfee Avert Labs.
Kernel-Mode
Techniques
Techniques
User-Mode
Number of variants
in wild since 2003
to variant count
SYSENTER
Memory
DKOM
Inline
Filter
SSDT
IAT
Malware name
NTillusion X N/A 0
BootRootkit X N/A 0
Vanquish X Low 1
Rootkit-DigitalNames X Low 1
WinKRootkit X Low 1
PWS-Gogo X Low 2
Adware-PigSearch X X Low 5
CommonName X Low 7
ISearch X Low 8
Backdoor-ALI X Low 9
He4hook.sys X Low 9
FURootkit X Moderate 10
CoolWebSearch X Moderate 11
W32/Maddis.worm X Moderate 15
AFXRootkit X Moderate 40
PWS-Progent X X High 48
Spam-Mailbot.c X X High 48
Qoolaid X High 58
Vanti X X High 60
Frequency
of technique
3 10 12 4 1 3 1 1 2595
Table 1
14
Rootkits Part 2: A Technical Primer www.mcafee.com
1 Greg Hoglund and Jamie Butler, “Rootkits: Subverting the Windows Kernel,”
Addison-Wesley Professional.
2 Adware-Qoolaid, http://vil.nai.com/vil/content/v_126149.htm
3 AdClicker-BA, http://vil.mcafeesecurity.com/vil/content/v_128301.htm
4 Urbin, http://vil.nai.com/vil/content/v_125663.htm
5 Adware-FCHelp, http://vil.nai.com/vil/content/v_137814.htm
6 AFXrootkit, http://vil.nai.com/vil/content/v_102335.htm
7 Galen Hunt and Doug Brubacher,
“Detours: Binary Interception of Win32 Functions,”
http://www.usenix.org/publications/library/proceedings/
usenix-nt99/full_papers/hunt/hunt.pdf
8 Adware-EliteBar.dll, http://vil.nai.com/vil/content/v_133782.htm
9 Backdoor-BAC.gen.dr, http://vil.nai.com/vil/content/v_138676.htm
10 FURootkit, http://vil.nai.com/vil/content/v_127131.htm
11 FU rootkit description, http://rootkit.com/project.php?id=12
12 Adware-CommonName, http://vil.nai.com/vil/content/v_100875.htm
13 Spam-Mailbot.c, http://vil.nai.com/vil/content/v_140181.htm
14 PWS-Gogo, http://vil.nai.com/vil/content/v_141447.htm
15 Apropos, http://vil.nai.com/vil/content/v_137345.htm
16 Sherri Sparks and Jamie Butler, “ ‘Shadow Walker,’
Raising the bar for rootkit detection,”
www.blackhat.com/presentations/bh-jp-05/bh-jp-05-sparks-butler.pdf
17 Samuel T. King, Peter M. Chen, Yi-Min Wang, Chad Verbowski, Helen J. Wang,
and Jacob R. Lorch, “SubVirt: Implementing malware with virtual machines,”
http://www.eecs.umich.edu/virtual/papers/king06.pdf
18 Joanna Rutkowska, “Subverting Vista Kernel for Fun and Profit,”
The Symposium on Security for Asia Network.
19 Robert Lemos, “Researchers: Rootkits headed for BIOS,”
http://www.securityfocus.com/news/11372
20 John Heasman, “Implementing and Detecting ACPI BIOS Rootkit,”
Black Hat Europe 2006 conference.
© 2007 McAfee, Inc. No part of this document may be reproduced without the expressed written
permission of McAfee, Inc. The information in this document is provided only for educational
McAfee, Inc. purposes and for the convenience of McAfee’s customers. The information contained herein
3965 Freedom Circle is subject to change without notice, and is provided “as is” without guarantee or warranty
Santa Clara, CA 95054, as to the accuracy or applicability of the information to any specific situation or circumstance.
888.847.8766 McAfee, Avert, and Avert Labs are trademarks or registered trademarks of McAfee, Inc. in the
www.mcafee.com United States and other countries. All other names and brands may be the property of others.
15