Top Banner
Fourteenforty Research Institute, Inc. http://www.fourteenforty.jp “egg” - A Stealth fine grained code analyzer Yuji Ukai - Chief Executive Officer Satoshi Tanda Senior Engineer
32

“egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

May 15, 2019

Download

Documents

vongoc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc. http://www.fourteenforty.jp

“egg” - A Stealth fine grained code analyzer

Yuji Ukai - Chief Executive Officer

Satoshi Tanda – Senior Engineer

Page 2: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Agenda

• Background and problems

• Introduce “egg” – Demonstration its basic functions

• Implementation (Taint tracing approach in ring-0) – Demonstration of the taint tracing behavior

• Discuss a limitation of “egg”

• Conclusion

2

Page 3: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Too many malwares!

• We can’t manually analyze each malware.

• Automatic approaches have become more important.

3

0

10

20

30

40

50

60

70

80

90

100

2001 yr 2003 yr 2005 yr 2007 yr

The percentage of packed malwares

80% of malwares ware

packed in 2007

Source:

2001-2005 : McAfee Sage vol.1 issue 1

2007 : Panda Research (http://research.pandasecurity.com/malwareformation-statistics/)

Page 4: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Problems of traditional dynamic analyzers

• We can’t get useful information for more intensive analysis.

• We can’t analyze a kernel mode code.

• It’s difficult to analyze a spreading malware over the process.

4

Page 5: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Innovative analyzers (based on VM environments)

• Innovative analyzers have already resolved the above problems

– Anubis

– Ether

• It’s able to analyze a kernel mode code and perform an instruction level analysis.

– BitBlaze and Renovo

• Also these analyze a spreading malware automatically with approach called “taint tracing”.

• However these systems are detected by VM detection techniques

5

Page 6: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Summary table of problems

Type of system Traditional Innovative

(Based on virtual

environments)

Getting useful information Insufficient Good

Analyzing a kernel mode code Insufficient Good

Analyzing a spreading malware. Insufficient Good

Not affected by VM detection techniques Good Insufficient

6

• I developed “egg” to try and resolve these problems.

Page 7: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What is egg?

• “egg” is a dynamic analyzer based on a Windows device driver.

• egg has following capabilities:

1. It can obtain more detailed information.

2. It can analyze a kernel mode code.

3. It can automatically trace a spreading malware.

• Of course, It’s not affected by VM detection techniques.

• Also most common anti-debug tech can’t detect “egg”.

7

Page 8: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

1. API arguments for IN, OUT (,INOUT), and return value

8

BOOL WINAPI ReadFile( __in HANDLE hFile, __out LPVOID lpBuffer, __in DWORD nNumberOfBytesToRead, __out_opt LPDWORD lpNumberOfBytesRead, __inout_opt LPOVERLAPPED lpOverlapped );

Page 9: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

1. API arguments for IN, OUT (,INOUT), and return value

9

BOOL WINAPI ReadFile( __in HANDLE hFile, __out LPVOID lpBuffer, __in DWORD nNumberOfBytesToRead, __out_opt LPDWORD lpNumberOfBytesRead, __inout_opt LPOVERLAPPED lpOverlapped );

call to kernel32.dll!ReadFile( Arg 1 : 00000064 = File : ¥Device¥HarddiskVolume1¥WINDOWS¥(...) , Arg 3 : 00000800(2048) )

Page 10: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

1. API arguments for IN, OUT (,INOUT), and return value

10

BOOL WINAPI ReadFile( __in HANDLE hFile, __out LPVOID lpBuffer, __in DWORD nNumberOfBytesToRead, __out_opt LPDWORD lpNumberOfBytesRead, __inout_opt LPOVERLAPPED lpOverlapped );

call to kernel32.dll!ReadFile( Arg 1 : 00000064 = File : ¥Device¥HarddiskVolume1¥WINDOWS¥(...) , Arg 3 : 00000800(2048) )

returned from kernel32.dll!ReadFile( Arg 2 : 0012F184 - 0012F983 is dumped as ¥(...)¥(...)ReadFile_Arg02.bin ) => 00000001(1)

Page 11: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

2. Callgraph

3. Branch information

11

Callgraph (made with Graphviz)

Branch Info (with IDA Pro)

Page 12: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

2. Callgraph

3. Branch information

12

Callgraph (made with Graphviz)

Branch Info (with IDA Pro)

Page 13: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

2. Callgraph

3. Branch information

13

Callgraph (made with Graphviz)

Branch Info (with IDA Pro)

Page 14: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What kind of information does ”egg” collect?

2. Callgraph

3. Branch information

14

Callgraph (made with Graphviz)

Branch Info (with IDA Pro)

Page 15: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Demonstration of basic functions(movie)

• Analyzing sample.exe.

• Sample.exe overwrites original beep driver (beep.sys).

• Then restarts beep service to install this driver in the kernel.

• “egg” analyzes sample.exe and the modified beep driver.

15

Page 16: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of the fine-grained code analysis

• Based on the page protection and the trap flag.

• Published by the paper “Stealth Breakpoints”.

• We can run analysis codes for each instruction execution.

• It can applies to both a kernel and user modes, and even works transparently in the user mode code.

16

Stealth Breakpoints

http://www.acsac.org/2005/abstracts/72.html

Page 17: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

What is taint tracing?

• It can automatically trace suspicious elements.

• A suspicious element is marked as tainted.

• A taint automatically influences new elements that used tainted elements.

17

NEW

Tainted

NOT

Tainted

Tainted Some suspicious sources

Page 18: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

An overview of taint tracing approach of “egg”

18

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

• egg takes a novel approach to implement the taint tracing.

• In case of egg, “Elements” are Files, Virtual memory and Threads.

Page 19: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

An overview of taint tracing approach of “egg”

19

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

• egg takes a novel approach to implement the taint tracing.

• In case of egg, “Elements” are Files, Virtual memory and Threads.

Page 20: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

20

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

Using API

PsSetLoadImageNotifyRoutine

Page 21: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

21

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

Using the page protection

(eXecute Disable bit)

Page 22: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

22

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

Using the File system filter driver

Page 23: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

23

Taint

File Taint

Memory

Thread

Taint

Thread

Taint

Memory Taint

File

1. Specify 2. Map in Mem 3. Execute

4. Write to Mem 4. Write to File

Using the page protection

(Write/Read bit)

Page 24: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

• For thread safety, egg hooks thread switching function (called SwapContext).

• Therefore egg can notice a thread switching.

24

Process

Memory

Thread

(not tainted)

Thread

(tainted)

Thread

(not tainted)

Waiting Waiting Running on processor

Process memory has not been modified yet.

Page 25: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

• When taint thread becomes active, egg changes every process memory to read-only.

25

Process

Memory

Thread

(tainted)

Thread

(not tainted)

Thread

(not tainted)

Waiting Waiting Running on processor

Currently, process memory is read-only.

If a thread tries to write somewhere,

the processor causes an exception.

egg catches this exception as taint event.

Page 26: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Implementation of taint tracing in ring-0

• When taint thread becomes inactive, egg restores every page protection.

26

Process

Memory

Thread

(not tainted)

Thread

(not tainted)

Thread

(not tainted)

Waiting Waiting Running on processor

Process memory protection is restored.

Page 27: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Tracking the cross-process memory operation

• To trace cross-process memory operation, egg hooks context switching function (called KiSwapProcess).

• Therefore egg can notice cross-process memory operation.

27

malware.exe

Process

Memory

Thread

(tainted)

Running on processor

CR3

explorer.exe

Process

Memory

Read-only Have not been changed

Page 28: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Tracking the cross-process memory operation

• When taint thread is running on other process memory, its process memory will be changed to read-only.

28

malware.exe

Process

Memory

Thread

(tainted)

Running on processor

CR3

explorer.exe

Process

Memory

egg can trace cross-process

memory operation.

(e.g. WriteProcessMemory)

Restored Read-only

Page 29: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Demonstration of the taint tracing function(movie)

• The sample is the thread injection code.

• Sample malware called “injector.exe” injects to notepad.exe with VirtualAllocEx, WriteProcessMemory and CreateRemoteThread.

• Injected thread calls AllocConsole and WriteConsole in infinite loop.

• egg will trace the injected thread.

29

Page 30: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Problem of same privilege

• egg has limitation against kernel mode code. – egg is visible and breakable from kernel mode malware.

• This limitation is result of trade off for avoiding detection by the VM detection.

30

Page 31: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

Fourteenforty Research Institute, Inc.

Conclusion

• We can save time by using egg.

• In the future, I will try to improve its stability and usability.

31

Type of system egg Traditional Innovative

Getting useful information Good Insufficient Good

Analyzing a kernel mode code Better Insufficient Good

Analyzing a spreading malware. Good Insufficient Good

Not affected by VM detection techniques Good Good Insufficient

Page 32: “egg” - A Stealth fine grained code analyzer - HITCONhitcon.org/2012/download/0721C3_Yuji.Ukai_FFRI_Egg.pdf · • Innovative analyzers have already resolved the above problems

32

ありがとうございました

Fourteenforty Research Institute, Inc.

株式会社 フォティーンフォティ技術研究所 http://www.fourteenforty.jp

発表者肩書き 発表者氏名

発表者メールアドレス

Thank you!