46
Protecting the irreplaceable | f-secure.com Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware Today Copyright F-Secure 2010. All rights reserved.

Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

  • Upload
    others

  • View
    39

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Protecting the irreplaceable | f-secure.com

Malware Analysis and Antivirus Technologies:Kernel Malware & A Look at Malware Today

Copyright F-Secure 2010. All rights reserved.

Page 2: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

© F-Secure Confidential06 April, 20112

Page 3: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Brain

• Brain is the first known PC virus

• Discovered in 1986

• Boot sector virus

• First versions only infected 360k floppies

• Stealth features

• Hides infected boot sector by hooking sector read interrupt• Hides infected boot sector by hooking sector read interrupt

• Marks sectors in FAT bad

• … but after all hiding efforts, some variants change floppy label to “© Brain”

© F-Secure06 April, 20113

Page 4: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Brain: Boot Sector Before Infection

© F-Secure06 April, 20114

Page 5: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Brain: Infected Boot Sector

© F-Secure06 April, 20115

Page 6: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Demo: Brain

PUBLIC

Page 7: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

© F-Secure Confidential06 April, 20117

Page 8: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

© F-Secure Confidential06 April, 20118

Page 9: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

© F-Secure Confidential06 April, 20119

Page 10: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Definition

“Kernel malware is malicious software that runs fully or partially at the most privileged execution level, ring 0, having full access to memory, all CPU instructions, and all hardware.”

• Can be divided into two subcategories

• Full-Kernel malware

• Semi-Kernel malware

Copyright F-Secure 2010. All rights reserved.

Page 11: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

History

• Kernel malware is not new – it has just been rare

• WinNT/Infis

• Discovered in November 1999

• Full-Kernel malware

• Payload – PE EXE file infector

• Virus.Win32.Chatter• Virus.Win32.Chatter

• Discovered in January 2003

• Semi-Kernel malware

• Payload – PE SYS file infector

• Mostly proof of concepts

Copyright F-Secure 2010. All rights reserved.

Page 12: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

32000

37000

Unique malicious drivers

Increase of Kernel-Mode Malware

2800

15500

2006 2007 2008 2009

No. samples

Copyright F-Secure 2010. All rights reserved.

Page 13: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Key Techniques

• Majority of existing kernel malware is semi-kernel malware where their function is to hide and protect the main payload that executes in user mode

• Implementing a full-kernel malware can vary from hard to impossible depending on its features

• Basic downloader does following tasks when it executes:

• Allocates memory for storing temporary data

• Accesses internet to download the new payload

• Stores the file on the file system

• Modifies the registry to add a launch point

• Executes the new payload

Copyright F-Secure 2010. All rights reserved.

Page 14: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Executing Code in Ring 0

• The only documented way to execute third party KM code is to load a kernel-mode driver

• They are loaded at boot time if they have an entry in HKLM\System\CurrentControlSet\Services

• Type = SERVICE_KERNEL_DRIVER (0x1) or SERVICE_FILE_SYSTEM_DRIVER (0x2)

• Start = SERVICE_BOOT_START (0x0) or SERVICE_SYSTEM_START • Start = SERVICE_BOOT_START (0x0) or SERVICE_SYSTEM_START (0x1) or SERVICE_AUTO_START (0x2)

• They can also be installed and loaded at run time

• CreateService + StartService Windows APIs

• There is also an undocumented way to do this

• ntdll!ZwSetSystemInformation

Copyright F-Secure 2010. All rights reserved.

Page 15: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Executing Code in Ring 0

• There are other undocumented ways of executing third party code in Ring 0

• Code injection into system address space

• Exploits

• Call gates

• Both ways require write access to system address space from Ring 3

• \Device\PhysicalMemory• \Device\PhysicalMemory

• ntdll!ZwSystemDebugControl

• Microsoft fixed this problem in Windows Server 2003 SP1 and later operating systems versions [2]

2. Ionescu, Alex. (2006). Subverting Windows 2003 SP1 Kernel Integrity Protection

Copyright F-Secure 2010. All rights reserved.

Page 16: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Kernel-Mode Support Routines

• Windows kernel provides an API for kernel-mode drivers to do basic tasks

• ExAllocatePoolWithTag / ExFreePoolWithTag

• ZwCreateFile / ZwWriteFile / ZwClose

• ZwCreateKey / ZwSetValueKey / ZwClose

• Only a subset of Native API functions exported by ntdll.dll are available for driversdrivers

• The solution - use ntdll.dll to get correct index to nt!KiServiceTable and fetch the pointer

• Read index from ntdll.dll in user mode and pass it to the driver

• Driver loads the ntdll.dll file into kernel memory and reads index from it

PUBLIC

Page 17: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Kernel-Mode Support Routines

PUBLIC

Page 18: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Executing Code in Ring 3 from Ring 0

• Sometimes it is not feasible for kernel malware to execute all code in Ring 0

• Launching of new processes

• Complex libraries

• Information stealing and encryption

• Two different approaches

• Injecting payload into target process context• Injecting payload into target process context

• Queuing an user-mode Asynchronous Procedure Call

Copyright F-Secure 2010. All rights reserved.

Page 19: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Executing Code in Ring 3 from Ring 0

pMdl = IoAllocateMdl(pPayloadBuf, dwBufSize, FALSE, FALSE, NULL);

// Lock the pages in memory

__try {

MmProbeAndLockPages(pMdl, KernelMode, IoWriteAccess);

}

__except (EXCEPTION_EXECUTE_HANDLER){}

// Map the pages into the specified process

KeStackAttachProcess(pTargetProcess, &ApcState);KeStackAttachProcess(pTargetProcess, &ApcState);

MappedAddress = MmMapLockedPagesSpecifyCache(pMdl,

• UserMode, MmCached, NULL, FALSE, NormalPagePriority);

KeUnstackDetachProcess(&ApcState);

// Initialize APC

KeInitializeEvent(pEvent, NotificationEvent, FALSE);

KeInitializeApc(pApc, pTargetThread, OriginalApcEnvironment,

&MyKernelRoutine, NULL, MappedAddress, UserMode, (PVOID)NULL);

// Schedule APC

KeInsertQueueApc(pApc, pEvent, NULL, 0)

Copyright F-Secure 2010. All rights reserved.

Page 20: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Rootkit techniques:hooking the handler table

Copyright F-Secure 2010. All rights reserved.

Page 21: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Rootkit techniques:inline hooking

Copyright F-Secure 2010. All rights reserved.

Page 22: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Rootkit techniques: in-memory data structure manipulation

Copyright F-Secure 2010. All rights reserved.

Page 23: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Demo: Hiding processes

PUBLIC

Page 24: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Evolution – The Average Joe

• A simple piece of code whose purpose is to perform a specific task on behalf of the main malware component

• No code obfuscation or packing

• Usually a rootkit that hides

• Files/Directories

• Registry keys/values• Registry keys/values

• Network connections

• Uses System Service Table and IRP handler hooks

• Easy to find and remove by modern AV solutions

Copyright F-Secure 2010. All rights reserved.

Page 25: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Evolution – Haxdoor

• Backdoor with rootkit and spying capabilities

• August 2003: First variant found

• 2005 – 2006: Active distribution through spam

• Has three components – EXE (installer), DLL (payload), SYS (rootkit)

• Uses the driver to make its detection and removal more difficult

• Hides its process and files• Hides its process and files

• Protects its own threads and processes against termination

• Protects its own files against any access

• Injects the main payload into newly created processes

• First widely utilized kernel-mode malware

• Sold as a package including Trojan generator & management console, prices ranging from $250 to $2500

Copyright F-Secure 2010. All rights reserved.

Page 26: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Demo: Haxdoor

PUBLIC

Page 27: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Evolution – Rustock

• Spambot and backdoor with rootkit capabilities

• Rustock.A was found in 27th May 2006

• Rustock.B was found in 3rd July 2006

• Rustock.C becomes publicly known 6th May 2008

• Consists of a single kernel-mode driver

• EXE file loads the driver and deletes itself• EXE file loads the driver and deletes itself

• SYS file carries the main payload inside an encrypted user-mode DLL

• The driver loads the main payload and acts as a rootkit to complicate its detection/removal and to bypass personal firewalls

• The most powerful and stealthiest rootkit seen by that time

Copyright F-Secure 2010. All rights reserved.

Page 28: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Rustock – Details

• Rustock introduced new techniques to the stealth malware scene

• Consists of a single driver which starts early during the boot process

• Obvious traces of the loaded driver are removed from the memory

• Driver is stored in a “hidden” and protected NTFS Alternate Data Stream

• Driver uses obfuscation and a polymorphic packer

• Hooks INT 0x2E and SYSENTER handler functions to control system calls• Hooks INT 0x2E and SYSENTER handler functions to control system calls

• System Service Table hooks are present only when needed

• Has an advanced rootkit anti-detection engine

• Bypasses filter drivers by communicating directly to the lowest level device

• Bypasses NDIS hooks by getting original pointers from ndis.sys file

• Uses APC mechanism to execute the DLL in user mode

• Tunnels network traffic from the DLL directly to the NDIS layer

Copyright F-Secure 2010. All rights reserved.

Page 29: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

System Service Dispatching

PUBLIC

Page 30: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Rustock – System Call Hooking

System Service Dispatcher

Int 0x2e / Sysenter

Service Descriptor Table

Service Table

NtOpenKey()

_KTHREAD…

Service Descriptor Table

Service Table

NtOpenKeyHook()

Copyright F-Secure 2010. All rights reserved.

Page 31: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Demo: Rustock

PUBLIC

Page 32: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Mebroot• The first complex MBR rootkit with malicious payload

• First variant found in November 2007

• MBR technique based on “BootRoot” project (BlackHat USA 2005)

• Consists of a custom MBR (loader) and a custom kernel-mode driver

• EXE file replaces the MBR and writes the driver to raw disk sectors located in unpartitioned slack space at the end of the disk

• The most advanced and stealthiest malware seen so far!• The most advanced and stealthiest malware seen so far!

• Uses MBR as its launch point

• All non-volatile data is stored in physical sectors outside of the file system

• Driver uses polymorphic packer and advanced code obfuscation

• Uses NDIS hooks and private TCP/IP stack to send/receive packets

• Utilizes “code pullout” technique to bypass memory hooks

• Active Anti-Removal protection

• Totally generic and open malware platform (MAOS)

© F-Secure06 April, 201132

Page 33: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Mebroot – Architecture

Mebroot

Bootkit

Update Module

Torpig/Sinowal/Anserin

Password Stealer

Banking TrojanMebroot

C&CTCP/IP Stack

MBR

Malware Operating System (MAOS)

Module

API

Banking Trojan

System Fingerprinting

C&C Stack

Adapted from Andreas Greulich, MELANI/GovCERT.ch

Page 34: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Mebroot: End of Disk Before Infection

© F-Secure06 April, 201134

Page 35: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Mebroot: End of Disk After Infection

© F-Secure06 April, 201135

Page 36: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

16-b

it

BIOS

Mebroot MBR

ldr16

MBR

Boot sector

INT13

Mebroot: Boot Sequence

Infected MBR loads and runs “ldr16” which hooks INT13. Original MBR is then called.

INT13 hook patches the real mode Ntldr to disable its code integrity checks and to hook itsprotected mode part.

16-b

it

BIOS

MBR

Boot sector

32-b

it

INT13

Ntldr

Ntldr

ldr32

Ntoskrnl.exe

ldrdrv

Mebroot Driver

© F-Secure06 April, 201136

”ldr32” patches nt!Phase1Initialization functionfrom ntoskrnl.exe to hook nt!IoInitSystem call.

”ldrdrv” loads Mebroot driver from raw sectorsand executes it.32

-bit

Ntldr

Ntldr

Ntoskrnl.exe

Page 37: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Demo: Mebroot

PUBLIC

Page 38: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

TDL (Alureon)

• TDL is the latest advanced rootkit seen in the wild

• TDL3 started spreading late 2009

• TDL4 was found during summer 2010

• Kernel-mode backdoor

• User-mode payload hijacks search engine results

• Interesting features in TDL4• Interesting features in TDL4

• Hidden, private file system in disk slack space

• MBR infection

• 64-bit support

© F-Secure06 April, 201138 Copyright F-Secure 2010. All rights reserved.

Page 39: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Windows 7 MBR vs. TDL MBR

© F-Secure Confidential06 April, 201139

Page 40: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

TDL: End of Disk Before Infection

© F-Secure06 April, 201140 Copyright F-Secure 2010. All rights reserved.

Page 41: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

TDL: End of Disk After Infection

© F-Secure06 April, 201141 Copyright F-Secure 2010. All rights reserved.

Page 42: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

TDL: End of Disk Decrypted

© F-Secure06 April, 201142

Encryption is done in 0x200 blocks with RC4, key is the sector as a DWORD.

Copyright F-Secure 2010. All rights reserved.

Page 43: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

16-b

it

BIOS

TDL MBR

ldr16

MBR

Boot sector

Bootmgr

TDL: Boot Sequence

Infected MBR decrypts and runs “ldr16” which hooks INT13. Original MBR is then called.

INT13 hook tricks boot into Windows PE mode by modifying BCD (BcdLibraryBoolean_EmsEnabled �

BcdOSLoaderBoolean_WinPEMode)

64-b

it

Bootmgr

INT13

Winload

INT13

ntoskrnl

ldr64

drv64

© F-Secure06 April, 201143

BcdOSLoaderBoolean_WinPEMode) and patching winload.exe (“/MININT” � “IN/MINT”)

INT13 hook replaces kdcom.dll with “ldr64”

“ldr64” decrypts and runs “drv64”

Copyright F-Secure 2010. All rights reserved.

Page 44: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Conclusions

• Kernel malware is a threat that has to be taken seriously

• Wide distribution – Srizbi and Pandex spam runs, Mebroot drive-by-downloads from high volume web sites in Italy and other parts of Europe

• Today’s kernel-mode malware is robust and effective

• Biggest spam botnets are kernel-mode malware

• Rustock, Mebroot and TDL are written by professional developers• Rustock, Mebroot and TDL are written by professional developers

• Detection and removal is becoming very challenging

• How do you fight against someone who does not follow common software development practices and rules?

• Enforcing digital signatures for drivers helps but how about stolen private keys (think about Stuxnet)

Copyright F-Secure 2010. All rights reserved.

Page 45: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Additional Information

• Kasslin, K. (2006). Kernel malware: The attack from within.

• http://www.f-secure.com/weblog/archives/kasslin_AVAR2006_KernelMalware_paper.pdf

• Florio, E.; Pathak P. (2006). Raising the bar: Rustock and advances in rootkits

• http://www.virusbtn.com/virusbulletin/archive/2006/09/vb200609-rustock

• Kasslin, K.; Florio E. (2007). Spam from the kernel.

• http://www.virusbtn.com/virusbulletin/archive/2007/11/vb200711-srizbi

• Kasslin, K.; Florio E. (2008). Your computer is now stoned (…again!).• Kasslin, K.; Florio E. (2008). Your computer is now stoned (…again!).

• http://www.virusbtn.com/virusbulletin/archive/2008/04/vb200804-MBR-rootkit

• Kasslin, K.; Florio E. (2008). Your computer is now stoned (…again!). The rise of MBR rootkits.

• http://www.f-secure.com/weblog/archives/Kasslin-Florio-VB2008.pdf

Copyright F-Secure 2010. All rights reserved.

Page 46: Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware … · 2011-08-16 · Malware Analysis and Antivirus Technologies: Kernel Malware & A Look at Malware

Copyright F-Secure 2010. All rights reserved.