65
Defeating x64: The Evolution of the TDL Rootkit Aleksandr Matrosov Eugene Rodionov

Defeating x64: The Evolution of the TDL Rootkit

Embed Size (px)

DESCRIPTION

n this presentation we will be discussing the evolution of the notorious rootkit TDL (classified by ESET as Win32/Olmarik and Win64/Olmarik) which in its latest incarnation is the first widespread rootkit to target 64-bit versions of Microsoft Windows operating systems. The most striking features of the rootkit are its ability to bypass Microsoft Windows Driver Signature Checking in order to load its malicious driver, and its implementation of its own hidden encrypted file system, in which to store its malicious components. Between its first appearance on the malware scene and the present its architecture has been drastically changed several times to adapt to new systems and respond to countermeasures introduced by antivirus and HIPS software. In the presentation we will cover the the following topics: the evolution of the user-mode and kernel-mode components of the rootkit; techniques it has used to bypass HIPS; modifications to the hidden file system; bootkit functionality; tne recently introduced ability to infect x64 operating systems; and, finally, approaches to removing the rootkit from an infected system. In addition, we will present our free forensic tool for dumping the hidden rootkit file system.

Citation preview

Page 1: Defeating x64: The Evolution of the TDL Rootkit

Defeating x64: The Evolution of the TDL Rootkit

Aleksandr Matrosov

Eugene Rodionov

Page 2: Defeating x64: The Evolution of the TDL Rootkit

Who we are?

Malware researchers at ESET

- rootkits analysis

- developing cleaning tools

- tracking new rootkit techniques

- research cybercrime groups

http://www.joineset.com/

Page 3: Defeating x64: The Evolution of the TDL Rootkit

Agenda

Evolution of TDL rootkits

Installation on x86 vs. x64

TDL bootkit or how to bypass driver signature

check

How to debug bootkit with Bochs emulator

Kernel-mode hooks

TDL hidden file system layout

Payload injection

TdlFsReader as a forensic tool

Page 4: Defeating x64: The Evolution of the TDL Rootkit

Evolution of rootkits

Page 5: Defeating x64: The Evolution of the TDL Rootkit

Dropper

Evolution of rootkits features

bypassing HIPS/AV

x86

privilege escalation

installing rootkit

driver

Rootkit

self-defense

surviving reboot

injecting payload

Us

er

mo

de

Ke

rne

l m

od

e

Page 6: Defeating x64: The Evolution of the TDL Rootkit

Dropper

Evolution of rootkits features

bypassing HIPS/AV

x86 x64

privilege escalation

installing rootkit

driver

Rootkit

self-defense

surviving reboot

injecting payload

Rootkit

Rootkit

self-defense

surviving reboot

injecting payload

bypassing signature

check

bypassing

MS PatchGuard

Us

er

mo

de

Ke

rne

l m

od

e

Page 7: Defeating x64: The Evolution of the TDL Rootkit

o Kernel-Mode Code Signing Policy

It is “difficult” to load unsigned kernel-mode

driver

o Kernel-Mode Patch Protection (Patch Guard):

SSDT (System Service Dispatch Table)

IDT (Interrupt Descriptor Table)

GDT ( Global Descriptor Table)

MSRs (Model Specific Registers)

Obstacles for 64-bit rootkits

Page 8: Defeating x64: The Evolution of the TDL Rootkit

TDL3/TDL3+ TDL4

Kernel-mode code

representation

Base independent piece of

code in hidden file system

PE image in the hidden

file system

Surviving after reboot Infecting disk

miniport/random kernel-mode

driver

Infecting MBR of the disk

Self-defense Kernel-mode hooks, registry

monitoring

Kernel-mode hooks, MBR

monitoring

Injecting payload into

processes in the system

tdlcmd.dll cmd.dll/cmd64.dll

x64 support

Complexity

Evolution of TDL rootkits

Page 9: Defeating x64: The Evolution of the TDL Rootkit

Evolution of TDL rootkits

TDL3/TDL3+ TDL4

Bypassing HIPS AddPrintProcessor

AddPrintProvidor

AddPrintProvidor,

ZwConnectPort

Privilege Escalation MS10-092

Installation mechanism by loading kernel-mode driver by loading kernel-mode

driver

overwriting MBR of the

disk

Number of installed

modules

4 10

Page 10: Defeating x64: The Evolution of the TDL Rootkit

Installation on x86 vs. x64

Page 11: Defeating x64: The Evolution of the TDL Rootkit
Page 12: Defeating x64: The Evolution of the TDL Rootkit
Page 13: Defeating x64: The Evolution of the TDL Rootkit

Installation stages

exploit payload dropper rootkit

Page 14: Defeating x64: The Evolution of the TDL Rootkit

Dropped modules Description

mbr original contents of the infected hard drive boot sector

ldr16 16-bit real-mode loader code

ldr32 fake kdcom.dll for x86 systems

ldr64 fake kdcom.dll for x64 systems

drv32 the main bootkit driver for x86 systems

drv64 the main bootkit driver for x64 systems

cmd.dll payload to inject into 32-bit processes

cmd64.dll payload to inject into 64-bit processes

cfg.ini configuration information

bckfg.tmp encrypted list of C&C URLs

Dropped modules

Page 15: Defeating x64: The Evolution of the TDL Rootkit

Installation on x86

AdjustSeLoadDriver

privilegefail success

Copy itself intoPrintProcessor

director

Check OSversion

Copy itself into%TMP% directory

Set IMAGE_FILE_DLLflag in the PE header

CallDeletePrintProvidorW

API

CallAddPrintProvidorW

API

Vista/Win7

ExploitationMS10-092

successfail

Createmanifest requesting

admin privilege

CallShellExecute

Failinstall

WinXP

Page 16: Defeating x64: The Evolution of the TDL Rootkit

Installation on x64

Write FS image,patch MBR and Adjust

SE_SHUTDOWN_PRIVILEGEfail success

Copy itself into%TMP% directory

ExploitationMS10-092

success

fail

Createmanifest requesting

admin privilege

CallZwRaiseHardError

to create BSOD

Prepare hidden FS image

Report to C&C

Restart Dropper

CallShellExecute

fail

success

Page 17: Defeating x64: The Evolution of the TDL Rootkit

TDL bootkit or how to bypass driver

signature check

Page 18: Defeating x64: The Evolution of the TDL Rootkit

Types of integrity checks

o PnP Device Installation Signing Requirements

o Kernel-Mode Code Signing Policy

Enforced on 64-bit version of Windows Vista and later

versions

64-bit Windows Vista and later

32-bit Windows Vista and later

Boot-start driver

Non boot-start PnP driver

Non boot-start, non-PnP driver

(except stream protected media drivers)

Page 19: Defeating x64: The Evolution of the TDL Rootkit

Subverting KMCSP

o Abusing vulnerable signed legitimate kernel-mode

driver

o Switching off kernel-mode code signing checks by

altering BCD data:

abusing WinPe Mode

disabling signing check

patching Bootmgr and OS loader

Page 20: Defeating x64: The Evolution of the TDL Rootkit

Load MBR

Load VBR

Load ntldr

Load kernel and boot

start drivers

real mode

real mode

real mode/protected mode

Load MBR

Load VBR

Load bootmgr

Load winload.exe or winresume.exe

real mode

real mode

real mode/protected mode

Load kernel and boot

start drivers

real mode/protected mode

Boot Process of pre Windows Vista OS

Boot Process of post Windows Vista OS

MBR – Master Boot Record

VBR – Volume Boot Record

Boot process of Windows OS

Page 21: Defeating x64: The Evolution of the TDL Rootkit

Code integrity check

Bootmgr OS loader OS kernel

dependencies

OS kernel

Boot-start drivers

Non boot-start kernel-mode drivers

Page 22: Defeating x64: The Evolution of the TDL Rootkit

BCD

BCD Object1

BCD Element1

BCD Element2

BCD Object2

BCD Element3

Boot Configuration Data (BCD)

BCD Object

Inheritable

Application

Windows boot manager

Windows boot loader

Ntldr Device

Page 23: Defeating x64: The Evolution of the TDL Rootkit

BCD Elements determining KMCSP (before KB2506014)

BCD option Description

BcdLibraryBoolean_DisableIntegrityCheck

(0x16000020)

disables kernel-mode code integrity

checks

BcdOSLoaderBoolean_WinPEMode

(0x26000022)

instructs kernel to be loaded in

preinstallation mode, disabling

kernel-mode code integrity checks

as a byproduct

BcdLibraryBoolean_AllowPrereleaseSignatures

(0x16000049)

enables test signing

Page 24: Defeating x64: The Evolution of the TDL Rootkit

BCD Elements determining KMCSP (before KB2506014)

BCD option Description

BcdLibraryBoolean_DisableIntegrityCheck

(0x16000020)

disables kernel-mode code integrity

checks

BcdOSLoaderBoolean_WinPEMode

(0x26000022)

instructs kernel to be loaded in

preinstallation mode, disabling

kernel-mode code integrity checks

as a byproduct

BcdLibraryBoolean_AllowPrereleaseSignatures

(0x16000049)

enables test signing

Page 25: Defeating x64: The Evolution of the TDL Rootkit

Abusing Win PE mode: TDL4 modules

Module name Description

mbr (infected) infected MBR loads ldr16 module and restores original

MBR in memory

ldr16 hooks 13h interrupt to disable KMCSP and substitute

kdcom.dll with ldr32 or ldr64

ldr32 reads TDL4’s kernel-mode driver from hidden file

system and maps it into kernel-mode address space

ldr64 implementation of ldr32 module functionality for 64-bit

OS

int 13h – service provided by BIOS to communicate to IDE HDD controller

Page 26: Defeating x64: The Evolution of the TDL Rootkit

Load infected MBRInfected mbr is

loadedand executed

Load “ldr16” from hidden file system

Hook BIOS int 13h handler and

restore original MBR

“ldr16” is loaded

and executed

Load VBR

Original mbr isloaded

and executed

Load bootmgr

VBR is loaded and executed

read bcd

Bootmgr is loaded and executed

Load winload.exe

Substitute

EmsEnabled option with WinPe

Load ntoskrnl.exe, hal.dll,kdcom.dll,bootvid.dll ant etc

distrort /MININT option

Call KdDebuggerInitialize1 from loaded kdcom.dll

substitute kdcom.dll

with”ldr32” or “ldr64"

Continue kernel initialization

Load ”drv32” or “drv64"

Load bootmgr

Abusing Win PE mode: workflow

Page 27: Defeating x64: The Evolution of the TDL Rootkit

MS Patch (KB2506014)

o BcdOsLoaderBoolean_WinPEMode option no longer

influences kernel-mode code signing policy

o Size of the export directory of kdcom.dll has been

changed

Page 28: Defeating x64: The Evolution of the TDL Rootkit

MS Patch (KB2506014)

o BcdOsLoaderBoolean_WinPEMode option no longer

influences kernel-mode code signing policy

o Size of the export directory of kdcom.dll has been

changed

Page 29: Defeating x64: The Evolution of the TDL Rootkit

MS Patch (KB2506014)

o BcdOsLoaderBoolean_WinPEMode option no longer

influences kernel-mode code signing policy

o Size of the export directory of kdcom.dll has been

changed

Page 30: Defeating x64: The Evolution of the TDL Rootkit

Bypassing KMCSP: another attempt

Patch Bootmgr and OS loader (winload.exe) to disable

KMCSP:

Page 31: Defeating x64: The Evolution of the TDL Rootkit

Bypassing KMCSP: Result

Bootmgr fails to verify OS loader’s integrity

Page 32: Defeating x64: The Evolution of the TDL Rootkit

Bypassing KMCSP: Result

Bootmgr fails to verify OS loader’s integrity

Page 33: Defeating x64: The Evolution of the TDL Rootkit

Debugging the bootkit with Bochs

Page 34: Defeating x64: The Evolution of the TDL Rootkit

Bochs support starting from IDA 5.5

Page 35: Defeating x64: The Evolution of the TDL Rootkit

•DEMO

Page 36: Defeating x64: The Evolution of the TDL Rootkit

Kernel-mode hooks

Page 37: Defeating x64: The Evolution of the TDL Rootkit

Disk PDO

Disk FDO(Partition 0)

Disk Lower Filter

Disk Upper Filter

Hard drive port/miniport driver object

Hard driveLower Filter driver object

Hard driveUpper Filter driver object

Disk classdriver object

Disk PDO(Partition 1)

Disk PDO(Partition 2)

Storage Device Stack

Page 38: Defeating x64: The Evolution of the TDL Rootkit

Disk FDO(Partition 0)

Disk Lower Filter

Disk Upper Filter

Hard drive port/miniport driver object

Hard driveLower Filter driver object

Hard driveUpper Filter driver object

Disk classdriver object

Disk PDO(Partition 1)

Disk PDO(Partition 1)

FakeDisk PDO

TDL4 driver object

“Real”Disk PDO

Stolen Objects

Before Infection

After Infection

Stealing Miniport Driver Object

Page 39: Defeating x64: The Evolution of the TDL Rootkit

Driver ObjectBootkit driver

DriverObject

Device Object

DeviceObject

Device Object

Device Object

...DriverObject DriverObject

Device Object

DriverObject

NextDevice

NextDevice

Driver ObjectMiniport driver

...

StartIo

...

Device Object

Device Object

Real (Stolen) Device Object

Fake Duplicate Device Object

Stealing Miniport Device Object

Page 40: Defeating x64: The Evolution of the TDL Rootkit

Driver ObjectBootkit driver

DriverObject

Device Object

DeviceObject

Device Object

Device Object

...DriverObject DriverObject

Device Object

DriverObject

NextDevice

NextDevice

Driver ObjectMiniport driver

...

StartIo

...

Device Object

Device Object

Real (Stolen) Device Object

Fake Duplicate Device Object

Stealing Miniport Device Object

Page 41: Defeating x64: The Evolution of the TDL Rootkit

SCSI request

block

Bootkit driver hooks

Bootkit driver:call corresponding miniport’s handler

Bootkit driver:Counterfeit data and

complete request

OtherwiseInfected MBR or hidden file

system is read/written

Filtering Disk Read/Write Requests

o Filtered requests: IOCTL_ATA_PASS_THROUGH_DIRECT

IOCTL_ATA_PASS_THROUGH;

IRP_MJ_INTERNAL_DEVICE_CONTROL

o To protect: Infected MBR;

Hidden file system from being read or overwritten

Page 42: Defeating x64: The Evolution of the TDL Rootkit

TDL hidden file system

Page 43: Defeating x64: The Evolution of the TDL Rootkit

TDL’s hidden storage

o Reserve space in the end of the hard drive (not visible

at file system level analysis)

o Encrypted contents (stream cipher: RC4, XOR-ing)

o Implemented as a hidden volume in the system

o Can be accessed by standard APIs (CreateFile,

ReadFile, WriteFile, SetFilePointer, CloseHandle)

Page 44: Defeating x64: The Evolution of the TDL Rootkit

TDL3 Physical device object

DriverObject

...

TDL3Driver object

XXXXXXXX – random 8-character ASCII string

\\?\globalroot\device\XXXXXXXX\YYYYYYYY\file_name - for user-mode components\device\XXXXXXXX\YYYYYYYY\file_name – for kernel-mode components

\Device\XXXXXXXX

TDL3/TDL3+ Rootkit Device Stack

Page 45: Defeating x64: The Evolution of the TDL Rootkit

TDL4 Volume device object

DriverObject

...

Vpb

...

TDL4 Physical device object

DriverObject

...

\Driver\PnpManagerDriver object

TDL4Driver object

Volume parameter block

DeviceObject

RealDevice

\Device\XXXXXXXX Unnamed

XXXXXXXX – random 32-bit hexadecimal integer

TDL4 Device Stack

Page 46: Defeating x64: The Evolution of the TDL Rootkit

TDL4 Hidden FS

Growth direction

Disk partitions

One sector

One sector

Variable length Not more than 8 MbIn

fect

ed

MB

R

TDL4 File System Layout

Page 47: Defeating x64: The Evolution of the TDL Rootkit

Payload injection

Page 48: Defeating x64: The Evolution of the TDL Rootkit

TDL4 hidden storage

TDL4driver

Process1 Process2 Process3 ProcessN

Payload1 Payload2 Payload3 PayloadN

Payload1 Payload2 Payload3 PayloadN

kernel-mode

user-mode

Injecting payload into target process

Page 49: Defeating x64: The Evolution of the TDL Rootkit

Set ImageLoadNotifyRoutine

Queue special kernel-mode APC

On loading kernel32.dll

Queue work item

Attach to target process

In the context of System process

In the context of the target process

Map image of the payload

In the context of the target process

Queue user-mode APC

Detach from target process

Initialize IAT and call payload’s entry point

Exit from work item

Go back in the context of System process

Allocate user-mode buffer with code and path to the payload

Injecting workflow

Page 50: Defeating x64: The Evolution of the TDL Rootkit

TDL4 cleaning approach

Page 51: Defeating x64: The Evolution of the TDL Rootkit

How to remove TDL

o Defeat self defense:

Disable WORK_ITEM checking infected MBR and

kernel-mode hooks

Remove hooks of storage miniport device object

o Restore original MBR

Page 52: Defeating x64: The Evolution of the TDL Rootkit

Debugging bootkit with WinDbg

Page 53: Defeating x64: The Evolution of the TDL Rootkit

KD_RECV_CODE_OK

Data packet

Data Packet

KdDebuggerInitialize1

KdSendPacket

KdReceivePacket

RETURN_STATUS

WinDbg and kdcom.dll

RETURN_CONTROL

Page 54: Defeating x64: The Evolution of the TDL Rootkit

TDL4 and kdcom.dll

Page 55: Defeating x64: The Evolution of the TDL Rootkit

TDL4 and kdcom.dll

Page 56: Defeating x64: The Evolution of the TDL Rootkit

How to debug TDL4 with WinDbg

o Patch ldr16 to disable kdcom.dll

substitution

o Reboot the system and attach to it with

WinDbg

oManually load drv32/drv64

“TDL4 Analysis Paper: a brief introduction and How to Debug It”, Andrea Allievi

http://www.aall86.altervista.org/TDLRootkit/TDL4_Analysis_Paper.pdf

Page 57: Defeating x64: The Evolution of the TDL Rootkit

TdlFsReader as a forensic tool

Page 58: Defeating x64: The Evolution of the TDL Rootkit

TdlFsReader as a forensic tool

Page 59: Defeating x64: The Evolution of the TDL Rootkit

TdlFileReader

User mode

Kernel mode

TdlFsRecognizer

TdlFsDecryptor

TdlSelfDefenceDisabler

LowLevelHddReader

TdlFsReader architecture

Page 60: Defeating x64: The Evolution of the TDL Rootkit

TdlFsRecognizer

FsCheckVersion

FsStructureParser

TdlFsDecryptor

TdlCheckVersion

TdlDecryptor

TdlSelfDefenceDisabler

TdlUnHooker

HddBlockReader

TdlFsReader architecture

Page 61: Defeating x64: The Evolution of the TDL Rootkit

•DEMO

Page 62: Defeating x64: The Evolution of the TDL Rootkit

Conclusion

o Win64/Olmarik (TDL4) is the first widely spread rootkit

targeting Win x64

o Return to old-school techniques of infecting MBR

o The only possible way of debugging bootkit is to use

emulators (Bochs, QEMU)

o TDL4 is highly resistant to forensic analysis

o TdlFsReader will be shared amongst malware

researchers

Page 63: Defeating x64: The Evolution of the TDL Rootkit

References

“The Evolution of TDL: Conquering x64” http://www.eset.com/us/resources/white-papers/The_Evolution_of_TDL.pdf

“Rooting about in TDSS” http://www.eset.com/us/resources/white-papers/Rooting-about-in-TDSS.pdf

“TDL3: The Rootkit of All Evil?” http://www.eset.com/us/resources/white-papers/TDL3-Analysis.pdf

Follow ESET Threat Blog http://blog.eset.com

Page 64: Defeating x64: The Evolution of the TDL Rootkit

Questions

Page 65: Defeating x64: The Evolution of the TDL Rootkit

Thank you for your attention ;)

Aleksandr Matrosov [email protected]

@matrosov

Eugene Rodionov [email protected]

@vxradius