text
stringlengths
4
429
09 }
TDI FILTER DRIVER
In addition to WFP, Snake also hooks the Transport Driver Interface (TDI) network routines by setting itself up as a TDI filter driver.
TDI is considered deprecated and will be removed in future versions of Microsoft Windows, but it
s still supported on Windows 7.
Being registered as a TDI driver on the device stack, Snake hooks TCP calls. This way it intercepts all requests along with their
parameters via IRP (IO request package) hooks.
sniffing
all the requests, it can now inspect the traffic, looking for and then parsing GET/POST HTTP requests and also SMTP
communications, in order to distinguish commands addressed to itself.
If the rootkit detects that the OS version is pre-Vista (e.g. Windows XP) or Windows Server 2008 (e.g. Windows Server 2003), it will
invoke FwpsStreamInjectAsync0() API in order to generate outbound requests.
Whenever the client establishes connections, the TDI driver will also
pulse
the \BaseNamedObjects\wininet_activate
event, just like the WPF driver
s component of it, in order to notify the userland service about the event.
The data that the driver intercepts, along with the important notifications, is passed to the userland DLL to be processed. If the
data contains commands from C&C, the DLL module is expected to execute them and report results back to the driver to be
delivered back to C&C.
NDIS HOOKING
For NDIS versions 5.X, Snake rootkit contains code that installs NDIS filter intermediate driver.
This driver is set up above a miniport driver (a driver that communicates with the physical device) and below a protocol driver (a
driver that implements a protocol, e.g. TCP/IP).
The driver is registered with NdisIMRegisterLayeredMiniport() API.
After that, the drivers hooks the following exports within ndis.sys:
NdisIMRegisterLayeredMiniport
NdisTerminateWrapper
The rootkit contains code that installs NDIS filter driver for NDIS 6.0 and above:
Unique name: {c06b1a3b-3d16-4181-8c8d-7015bfc5b972}
User-readable description: filter_c06b1a3b
NDIS filter driver configuration is stored in the registry entry:
HKLM\SYSTEM\CurrentControlSet\Control\Network\{4d36e974-e325-11ce-bfc1-08002be10318}
The driver is registered with NdisFRegisterFilterDriver() API.
BAE Systems Applied Intelligence: Snake Rootkit Report 2014 16
After that, the drivers hooks the following exports within ndis.sys (for NDIS 6.0):
NdisFRegisterFilterDriver
NdisFDeregisterFilterDriver
NdisSetOptionalHandlers
NdisFSetAttributes
Another set of exports it attempts to hook in ndis.sys (for NDIS 6.0) is:
NdisMRegisterMiniportDriver
NdisMDeregisterMiniportDriver
NdisMIndicateReceiveNetBufferLists
NdisMRestartComplete
NdisMPauseComplete
With the hooks installed, whenever the network adapter driver attempts to register to NDIS, or whenever there is an attempt to
install NDIS intermediate driver or NDIS filter driver, the hook handlers will register Snake
s own MiniportXxx functions with the NDIS
library.
With its own miniport handler functions, it can send/receive data by using a private TCP/IP stack, bypassing all firewall hooks, and
making its open ports invisible to scanners.
NDIS PROTOCOL DRIVER
The Snake rootkit registers itself as Network Driver Interface Specification (NDIS) protocol driver.
Intercepting Network Data Whenever the underlying miniport driver
receives data from the network, it calls NDIS
by invoking a data receive indication function
NdisMIndicateReceiveNetBufferLists()
NdisMIndicateReceiveNetBufferLists().
NDIS Protocol Miniport
NDIS When that happens, NDIS invokes Snake
s hook function
Driver Driver
(ProtocolReceiveNetBufferLists) to process the
ProtocolReceiveNetBufferLists() received data.
Sending Network Data To send the data back, the protocol driver defines the data
in a list of NET_BUFFER_LIST structures, and then passes
MiniportSendNetBufferLists()
them to NDIS by calling NdisSendNetBufferLists().
NDIS Protocol Miniport
NDIS NDIS, in turn, calls the miniport driver
Driver Driver
MiniportSendNetBufferLists() function to forward
NdisSendNetBufferLists() the data to an underlying miniport driver.
Being able to fully manipulate traffic at 3 different levels (NDIS protocol driver, TDI Driver, and WPF callout driver), Snake is able to
inject
the traffic into existing communications to reach out to external components, and at the same time parse all incoming traffic
to detect traffic addressed to itself:
Infected User Injected
Traffic Interception Application Module
0xDEADBEAF/0xC001BA5E
Checks
WFP TDI NDIS
Internet Memory
pipes
Traffic
Injection
Snake
s Kernel Mode Driver