text
stringlengths
4
429
As per MSDN documentation7, METHOD_NEITHER is a special transfer type when Input/Output Request Packet (IRP) supplies the
user-mode virtual addresses of the input and output buffers, without validating or mapping them.
http://www.codeproject.com/Articles/28318/Bypassing-PatchGuard-3
http://uninformed.org/index.cgi?v=3&a=3&p=17
http://www.coresecurity.com/content/virtualbox-privilege-escalation-vulnerability
http://msdn.microsoft.com/en-us/library/windows/hardware/ff543023(v=vs.85).aspx
BAE Systems Applied Intelligence: Snake Rootkit Report 2014 22
It is the responsibility of the driver to validate the addresses sent from user mode in order to make sure those addresses are valid
usermode addresses.
The source code of the vulnerable driver (shown below) demonstrates how the integer value of the rc variable is first derived from
the input parameters pDevObj (device object) and pIrp (request packet). Next, that integer value is written into the UserBuffer - an
arbitrary address, pointed by the input parameter pIrp (request packet). As there are no validations made for the UserBuffer an
attacker can craft such input parameters that will define address within kernel memory to patch and the data to patch it with:
01 /**
02 * Device I/O Control entry point.
03 *
04 * @param pDevObj Device object.
05 * @param pIrp Request packet.
06 */
07 NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
08 {
09 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
10 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
11 PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
12
13 ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
14
15 if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
16 || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
17 || ulCmd == SUP_IOCTL_FAST_DO_NOP)
18 {
19 int rc;
20
...
21 rc = supdrvIOCtlFast(ulCmd, pDevExt, pSession);
22
23
// supdrvIOCtlFast() function itself will return:
24
// pDevExt->pfnVMMR0EntryFast(pSession->pVM, SUP_VMMR0_DO_NOP);
25
// the function depends pDevExt and pSession, which in turn
26
// are derived from the input parameters pDevObj and pIrp
27 // therefore, rc value can be manipulated
28 __try
29 {
30 // save the manipulated rc value back into
31 *(int *)pIrp->UserBuffer = rc; // the input parameter (the address to patch)
32 }
33 __except(EXCEPTION_EXECUTE_HANDLER)
34 {
35 ...
36 }
37 }
38 }
Now that the vulnerable driver can be used as a weapon to patch kernel memory, all the malware needs to do is to patch the content
of the variable nt!g_CiEnabled, a boolean variable
Code Integrity Enabled
that marks whether the system was booted in
WinPE mode.
When running in WinPE mode there is no Code Integrity control, therefore by enabling this mode by patching only one bit,
Code Integrity verification is disabled so that the unsigned 64-bit driver can be loaded.
This variable is used within the function SepInitializeCodeIntegrity(), implemented within CI.dll
s function
CiInitialize() and imported by the NT core (ntoskrnl.exe). In order to find the variable in kernel memory, the Snake
dropper loads a copy of the NT core image (ntoskrnl.exe), locates the import of CI.dll
s function CiInitialize(), and then
SepInitializeCodeIntegrity() within it. Then it parses the function
s code to locate the offset of the variable.
Once located, the content of the variable nt!g_CiEnabled is patched in kernel memory and the 64-bit unsigned driver is loaded.
This explains why Snake dropper registers itself as a service to start each time Windows starts: in order to install the vulnerable
VBox driver first, then pass it a malformed structure to disable Code Integrity control with a DeviceIoControl() API call, and
finally, load the driver.
In order to be able to perform the steps above, the dropper must first obtain Administrator privileges. It attempts to do this by
running MS09-025 and MS10-015 exploits on the target system. These exploits are bundled within the dropper in its resource
section as executable files. Other resources embedded within the dropper are the 32-bit and 64-bit builds of its driver, a tool for
creating NTFS file systems, and the initial message queue file which is written into the virtual volume. The message queue file
contains configuration data and the libraries that will be injected into usermode processes.
BAE Systems Applied Intelligence: Snake Rootkit Report 2014 23
USERMODE DLLS
The usermode DLLs injected by the kernel-mode driver into the userland system process (e.g. explorer.exe) are:
32-bit Windows OS:
rkctl_Win32.dll
inj_snake_Win32.dll
64-bit Windows OS:
rkctl_x64.dll
inj_snake_x64.dll
The rkctl_Win32.dll/rkctl_x64.dll module uses the following hard-coded named pipe for communications:
\\.\pipe\services_control
The remote commands it receives appear to be designed to control other components of Snake:
tc_cancel
tc_free_data
config_read_uint32
tc_get_reply
tr_free