positive hack days. Матросов. Мастер-класс: Проведение...

60
Проведение криминалистической экспертизы и анализа руткит- программ на примере Win32/Olmarik (TDL4) Александр Матросов Евгений Родионов

Upload: positive-hack-days

Post on 27-Jun-2015

5.593 views

Category:

Technology


1 download

DESCRIPTION

В рамках мастер-класса будет рассмотрены следующие вопросы: методы внедрения и работы руткита TDL4; инструментарий и методы сбора данных для проведения криминалистической экспертизы зараженной машины; отладка буткит-составляющей на ранней стадии загрузки системы с использованием эмулятора Bochs; анализ зараженной машины при помощи WinDbg; удаление руткита из системы после сбора всех необходимых данных.

TRANSCRIPT

Page 1: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Проведение криминалистической экспертизы и анализа руткит-программ на примере Win32/Olmarik (TDL4)

Александр Матросов

Евгений Родионов

Page 2: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

План мастер-класса

Эволюция современных руткит-программ

Этапы установки на x86/x64 Буткит и обход проверки подписи Отладка буткита на эмуляторе Bochs Хуки в режиме ядра Отладка с использованием WinDbg Файловая система TDL4

TdlFsReader, как инструмент криминалистической экспертизы

Page 4: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Evolution of rootkits

Page 5: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Dropper

Evolution of rootkits functionality

bypass HIPS and AV

x86x64

privilege escalation

install rootkit driver

Rootkit

self-defense

surviving reboot

injecting payload

Rootkit

Rootkit

self-defense

Surviving reboot

injecting payload

bypass signature check

bypass MS PatchGuard

User

mod

e

Kern

el m

od

e

Page 6: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

64-bit OS 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)

Page 7: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 8: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Evolution of TDL rootkits

TDL3/TDL3+ TDL4

Bypassing HIPS AddPrintProcessorAddPrintProvidor

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 9: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Installation x86/x64

Page 10: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ
Page 11: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Installation stages

exploit payload dropper rootkit

Page 12: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Packed usermode dropper

Unpacked usermode dropper

Kernel mode driver

cmd.dll/cmd64.dll

cfg.ini

drv32/drv64

bckfg.tmp

The module to inject into processes

Configuration file

The body of the rootkit

Temporary file

Dropper layouts

Page 13: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 14: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Installation 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 15: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Installation x64

Write FS image,patch MBR and Adjust

SE_SHUTDOWN_PRIVILEGEfail success

Copy itself into%TMP% directory

ExploitationMS10-092success

fail

Createmanifest requesting

admin privilege

CallZwRaiseHardError

to create BSOD

Prepare hidden FS image

Report to C&C

Restart Dropper

CallShellExecute

fail

success

Page 16: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Bootkit and bypassing driver signature check

Page 17: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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

Page 18: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Kernel-mode Code Signing Policy Enforcement

64-bit Windows Vista and later

32-bit Windows Vista and later

Boot-start driver Not boot-start PnP driver

Not boot-start, non-PnP driver

(except stream

protected media drivers)

Page 19: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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

Boot process of Windows OS

Page 20: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Bootmgr

OS loader

OS kernel

Not boot-start kernel-mode drivers

OS kernel dependencies

Boot-startDrivers

Code integrity check

Page 21: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

BCD Object

Inheritable

Application

Firmware boot manager

Windows boot manager

Windows boot loader

Windows memory tester

Windows resume app

Ntldr

Boot sector

Device

BCD Element

Library

Application

Device

Boot Configuration Data (BCD)

Page 22: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

BCD

BCD Object1

BCD Element1

BCD Element2

BCD Object2

BCD Element3

BCD Example

Page 23: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

BCD Elements controlling 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: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Subverting KMCSP

o Abusing vulnerable signed legitimate kernel-

mode driver

o Switch off kernel-mode code signing checks

by altering BCD data:

abuse WinPe Mode

disable signing check

patch Bootmgr and OS loader

Page 25: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Abusing Win PE mode: TDL4 modules

Module name Descriptionmbr (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: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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

VPB 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 KdDebufferInitialize1

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: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

MS Patch (KB2506014)

o BcdOsLoaderBoolean_WinPEMode no longer

influence kernel-mode

o Size of the export directory of kdcom.dllhas

been changed

Page 28: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Bypassing KMCSP: another attempt

Patch bootmgr and OS loader (winload.exe) to

disable KMCSP

Page 29: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Bypassing KMCSP: Result

Bootmgr fails to verify OS loader’s integrity

MS10-015kill TDL3

Page 30: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Debugging bootkit with Bochs

Page 31: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Bochs support starting from IDA 5.5

Page 32: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

•DEMO

Page 33: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Kernel-mode hooks

Page 34: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 35: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 36: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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/writtern

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 37: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Debugging bootkit with WinDbg

Page 38: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

WinDbgKDCOM.DLLNTOSKRNL

KD_RECV_CODE_OK

Data packet

Data Packet

KdDebuggerInitialize

KdSendPacket

KdReceivePacket

RETURN_STATUS

WinDbg and kdcom.dll

RETURN_CONTROL

Page 39: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

original call

fake call

TDL4 and kdcom.dll

Page 40: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TDL4 and kdcom.dll

original export table fake export table

Page 41: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

•DEMO

Page 42: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

kd> !object \Device\Harddisk0 Object: e1022d10 Type: (8a5e54f0) Directory ObjectHeader: e1022cf8 (old version) HandleCount: 1 PointerCount: 8 Directory Object: e10116f0 Name: Harddisk0 Hash Address Type Name ---- ------- ---- ---- 21 8a5c9ab8 Device DR0 24 8a5c8c68 Device DP(1)0x7e00-0xffea9600+1 33 e101abe8 SymbolicLink Partition0 8a5c88a0 Device DP(2)0x1748a3fc00-0x1bf0797a00+2 34 e1011258 SymbolicLink Partition1 35 e101a078 SymbolicLink Partition2

Page 43: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

kd> !devobj \Device\Harddisk0\DR0 Device object (8a5c9ab8) is for: DR0 \Driver\Disk DriverObject 8a5cd730 Current Irp 00000000 RefCount 0 Type 00000007 Flags 00000050 Vpb 8a5dafa8 Dacl e101723c DevExt 8a5c9b70 DevObjExt 8a5c9fd0 Dope 8a59ff98 ExtensionFlags (0000000000) AttachedDevice (Upper) 8a5c9890 \Driver\PartMgr AttachedTo (Lower) 89fd902889fd9028: is not a device object

Page 44: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

kd> !devstack 8a5c9ab8 !DevObj !DrvObj !DevExt ObjectName 8a5c9890 \Driver\PartMgr 8a5c9948 > 8a5c9ab8 \Driver\Disk 8a5c9b70 DR0 Invalid type for DeviceObject 0x89fd9028

Page 45: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

kd> dt _DEVICE_OBJECT 0x89fd9028 ntdll!_DEVICE_OBJECT +0x000 Type : 0n0 +0x002 Size : 0xfb8 +0x004 ReferenceCount : 0n0 +0x008 DriverObject : 0x899574f0 _DRIVER_OBJECT +0x00c NextDevice : 0x8a5ca028 _DEVICE_OBJECT +0x010 AttachedDevice : 0x8a5c9ab8 _DEVICE_OBJECT +0x014 CurrentIrp : (null) +0x018 Timer : (null) +0x01c Flags : 0x5050 +0x020 Characteristics : 0x100 +0x024 Vpb : (null) +0x028 DeviceExtension : 0x89fd90e0 Void +0x02c DeviceType : 7

Page 46: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

kd> !drvobj 0x899574f0 Driver object (899574f0) is for: 899574f0: is not a driver object

Page 47: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TDL hidden file system

Page 48: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 49: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 50: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 51: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TDL4 Hidden FS

Growth direction

Disk partitions

One sector

One sectorVariable length Not more than 8 Mb

Infe

cted

MBR

TDL4 File System Layout

Page 52: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TdlFsReader, how forensic tool

Page 53: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TdlFsReader, how forensic tool

Page 54: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TdlFileReader

User mode

Kernel mode

TdlFsRecognizer

TdlFsDecryptor

TdlSelfDefenceDisabler

LowLevelHddReader

TdlFsReader architecture

Page 55: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

TdlFsRecognizer

FsCheckVersion

FsStructureParser

TdlFsDecryptor

TdlCheckVersion

TdlDecryptor

TdlSelfDefenceDisabler

TdlUnHooker

HddBlockReader

TdlFsReader architecture

Page 56: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

•DEMO

Page 57: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

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 Bloghttp://blog.eset.com

Page 58: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Questions

Page 59: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Thank you for your attention ;)

Aleksandr [email protected]@matrosov

Eugene [email protected]@vxradius

Page 60: Positive Hack Days. Матросов. Мастер-класс: Проведение криминалистической экспертизы и анализа руткит-программ

Конкурс «Лучший реверсер» уже начался !

Нужно зарегистрироваться на стенде

конкурса

Скачать crackme phd.esetnod32.ru

Прислать ключи и краткое описание

процесса прохождения на email:

[email protected]

Получить призы:

1. Amazon Kindle DX

2. Amazon Kindle 3 Wi-Fi

3. ESET Smart Security (3 года)