Top Banner
MICHALIS POLYCHRONAKIS(COLUMBIA UNIVERSITY,USA), KOSTAS G. ANAGNOSTAKIS(NIOMETRICS, SINGAPORE), EVANGELOS P. MARKATOS(FORTH-ICS, GREECE) ACSAC,2010 Comprehensive Shellcode Detection using Runtime Heuristics
37

Comprehensive Shellcode Detection using Runtime Heuristics

Jan 02, 2016

Download

Documents

malcolm-kirby

Comprehensive Shellcode Detection using Runtime Heuristics. Michalis Polychronakis (Columbia University,USA ), Kostas G. Anagnostakis ( Niometrics , Singapore), Evangelos P. Markatos (FORTH-ICS, Greece) ACSAC,2010. Outline. Introduction Architecture Runtime Heuristics Implementation - PowerPoint PPT Presentation
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: Comprehensive  Shellcode  Detection using Runtime Heuristics

MICHALIS POLYCHRONAKIS(COLUMBIA UNIVERSITY,USA) , KOSTAS G. ANAGNOSTAKIS(NIOMETRICS, SINGAPORE) , EVANGELOS P. MARKATOS(FORTH-ICS, GREECE)ACSAC,2010

Comprehensive Shellcode Detection using Runtime

Heuristics

Page 2: Comprehensive  Shellcode  Detection using Runtime Heuristics

2

IntroductionArchitectureRuntime HeuristicsImplementationExperimental EvaluationConclusion

Outline

Page 3: Comprehensive  Shellcode  Detection using Runtime Heuristics

3

The injected code, known as shellcode, carries out the first stage of the attack, which usually involves the download and execution of a malware binary on the compromised host.

Introduction

Page 4: Comprehensive  Shellcode  Detection using Runtime Heuristics

4

Identify the presence of shellcode in network inputs using static code analysis- advanced obfuscation- self-modifications

Dynamic code analysis using emulation- quite effective

Introduction

Page 5: Comprehensive  Shellcode  Detection using Runtime Heuristics

5

But these are confined to the detection of a particular class of polymorphic shellcode that exhibits self-decrypting behavior

Metamorphism

Introduction

Page 6: Comprehensive  Shellcode  Detection using Runtime Heuristics

6

In this paper, present a comprehensive shellcode detection technique based on payload execution

Detection method relies on several runtime heuristics tailored to the identification of different shellcode types

Gene, a network level detector based on passive network monitoring

Introduction

Page 7: Comprehensive  Shellcode  Detection using Runtime Heuristics

7

Architecture

Page 8: Comprehensive  Shellcode  Detection using Runtime Heuristics

8

Shellcode is meant to be injected into a running process and it usually accesses certain parts of the process' address space

Gene is equipped with a fully blown virtual memory subsystem that handles all user-level memory accesses

Architecture

Page 9: Comprehensive  Shellcode  Detection using Runtime Heuristics

9

Runtime Heuristics

Page 10: Comprehensive  Shellcode  Detection using Runtime Heuristics

10

Windows API is divided into several dynamic load libraries (DLLs)

In order to call an API function, the shellcode must first find its absolute address in the address space of the process

Searching for the Relative Virtual Addresses (RVAs) of the function in the Export Directory Table (EDT) of the DLL- LoadLibrary- GetProcAddress

Runtime Heuristics - Resolving kernel32.dll

Page 11: Comprehensive  Shellcode  Detection using Runtime Heuristics

11

No matter which method is used, a common fundamental operation in all methods is that the shellcode has to first locate the base address of kernel32.dll

Runtime Heuristics - Resolving kernel32.dll

Page 12: Comprehensive  Shellcode  Detection using Runtime Heuristics

12

Process Environment Block [PEB]- a user-level structure that holds extensive process specific information

Runtime Heuristics - Process Environment Block

Page 13: Comprehensive  Shellcode  Detection using Runtime Heuristics

13

Condition P1.

(i) the linear address of FS:[0x30]is read

(ii) the current or any previous instruction involved the FS register, then this input may correspond to a shellcode that resolves kernel32.dll through the PEB

Runtime Heuristics - Process Environment Block

Page 14: Comprehensive  Shellcode  Detection using Runtime Heuristics

14

Condition P2.PEB_LDR_DATA structure

- holds the list of loaded modules(P2): the linear address of PEB.LoaderDatais

read.

Runtime Heuristics - Process Environment Block

Page 15: Comprehensive  Shellcode  Detection using Runtime Heuristics

15

Condition P3.Walk through the loaded modules list and

locate the second entry (kernel32.dll)(P3): the linear address of any of the Flink or

Blink pointers in the one of the three list records of the PEB_LDR_DATA structure is read.

Runtime Heuristics - Process Environment Block

Page 16: Comprehensive  Shellcode  Detection using Runtime Heuristics

16

Structured Exception Handling (SEH) - provides a unified way of handling hardware and software exceptions

Runtime Heuristics - Backwards Searching

Page 17: Comprehensive  Shellcode  Detection using Runtime Heuristics

17

Runtime Heuristics - Backwards Searching

Page 18: Comprehensive  Shellcode  Detection using Runtime Heuristics

18

Condition B1.

(i) any of the linear address between FS:[0]–FS:[0x8] is read

(ii) the current or any previous instruction involved the FS register.

Runtime Heuristics - Backwards Searching

Page 19: Comprehensive  Shellcode  Detection using Runtime Heuristics

19

Condition B2.

(B2): the linear address of the Handlerfield of the default SEH handler is read.

Runtime Heuristics - Backwards Searching

Page 20: Comprehensive  Shellcode  Detection using Runtime Heuristics

20

Condition B3.(B3): at least one memory read form the

address space of kernel32.dll

Runtime Heuristics - Backwards Searching

Page 21: Comprehensive  Shellcode  Detection using Runtime Heuristics

21

Egg-hunt shellcode

Runtime Heuristics – Process Memory Scanning

Page 22: Comprehensive  Shellcode  Detection using Runtime Heuristics

22

Installing a custom exception handler that is invoked in case of a memory access violation

Create a new SEH frame and adjust the current SEH frame pointer of the TIB to point to it

Directly modify the Handler pointer of the current SEH frame to point to the attacker's handler routine

Process Memory Scanning - SEH

Page 23: Comprehensive  Shellcode  Detection using Runtime Heuristics

23

Condition S1.

(i) the linear address of FS:[0]is read or written

(ii) the current or any previous instruction involved the FS register.

Process Memory Scanning - SEH

Page 24: Comprehensive  Shellcode  Detection using Runtime Heuristics

24

Condition S2.

(S2): the linear address of the Handler field in the custom SEH frame is or has been written

Process Memory Scanning - SEH

Page 25: Comprehensive  Shellcode  Detection using Runtime Heuristics

25

Condition S3.

(S3): starting from FS:[0], all SEH frames should reside on the stack, and the Handler field of the last frame should be set to 0xFFFFFFFF

Process Memory Scanning - SEH

Page 26: Comprehensive  Shellcode  Detection using Runtime Heuristics

26

Another way to safely scanning the process address space is to check whether a page is mapped—before actually accessing it—using a system call

Some Windows system calls accept as an argument a pointer to an input parameter. If the supplied pointer is invalid, the system call returns with a return value of STATUS_ACCESS_VIOLATION.

Process Memory Scanning – System Call

Page 27: Comprehensive  Shellcode  Detection using Runtime Heuristics

27

Process Memory Scanning – System Call

Page 28: Comprehensive  Shellcode  Detection using Runtime Heuristics

28

Condition C1.

(C1): the execution of an int 0x2e instruction with the eax register set to one of the following values: NtAccessCheckAndAuditAlarm(0x2), NtAddAtom (0x8), NtDisplayString(0x39 in Windows 2000, 0x43 in XP, 0x46 in 2003 Server, and 0x7F in Vista)

Process Memory Scanning – System Call

Page 29: Comprehensive  Shellcode  Detection using Runtime Heuristics

29

Condition C2.

(C2): (C{N}): C1 holds true N times

Process Memory Scanning – System Call

Page 30: Comprehensive  Shellcode  Detection using Runtime Heuristics

30

The most widely used types of GetPC code for this purpose rely on some instruction from the call or fstenv instruction groups

The shellcode can register a custom exception handler, trigger an exception

Runtime Heuristics – SHE-based GetPC Code

Page 31: Comprehensive  Shellcode  Detection using Runtime Heuristics

31

Gene, a network-level attack detector that uses a custom IA-32 emulator to identify the presence of shellcode in network streams

Scan the client-initiated part of each TCP connection using the runtime heuristics

The virtual memory of the emulator is initialized with an image of the complete address space of a typical Windows XP process taken from a real system

Implementation

Page 32: Comprehensive  Shellcode  Detection using Runtime Heuristics

32

Experimental Evaluation – Detection Effectiveness

Page 33: Comprehensive  Shellcode  Detection using Runtime Heuristics

33

False Positives Evaluation- using a large and diverse set of benign inputs to test

Heuristic Analysis

Experimental Evaluation – Heuristic Robustness

Page 34: Comprehensive  Shellcode  Detection using Runtime Heuristics

34

Running on a system with a Xeon 1.86GHz processor and 2GB of RAM

Experimental Evaluation – Runtime Performance

Page 35: Comprehensive  Shellcode  Detection using Runtime Heuristics

35

Deployed Gene in two University networks, where it has been operational since 25 November 2009.

As of 17 April 2010, Gene has detected 116,513 code injection attacks against internal and external hosts in these two networks

Experimental Evaluation – Real-world Deployment

Page 36: Comprehensive  Shellcode  Detection using Runtime Heuristics

36

Present a comprehensive shellcode detection method based on code emulation

Expands the range of malicious code types that can be detected

Detection of plain and metamorphic shellcodeWithout any false positives

Conclusion

Page 37: Comprehensive  Shellcode  Detection using Runtime Heuristics

37

TIB and Thread Stack