Top Banner
Yet Another Heapspray Detector Danny Kovach Raytheon SI
31
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: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Yet Another Heapspray Detector

Danny KovachRaytheon SI

Page 2: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Introduction

• Our main purpose is to detect malware.

Page 3: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Introduction

• Currently we monitor an application in a VM for such behavior as:– Loading drivers– Creating executable files– Network activity

• Heap sprays are very hard to detect.

Page 4: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

What is a heapspray?

• Technique used to put executable code onto the heap.

• Consists of– NOP sled– Shellcode

• Goal: direct execution flow to the NOP sled; shellcode.

Page 5: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

How to detect a heapspray?

• Nozzle [1]

• BuBBle [3]

• Entropy

Page 6: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Idea!

• Treat byte values on the heap as a random variable and do math!

Page 7: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Assumptions

• Bytes on a normal heap should be randomly distributed (white noise)

• Fourier transform of white noise has constant magnitude.

Page 8: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(normal program operation)

256 512 768

50 000

100 000

150 000

Page 9: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(normal program operation)

256 512 768 1024

50 000

100 000

150 000

Page 10: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(normal program operation)

256 512 768 1024 1280 1536 1792 2048

50 000

100 000

150 000

Page 11: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(normal program operation)

200 400 600

500 000

1 .0 106

1 .5 106

2 .0 106

2 .5 106

3 .0 106

Page 12: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(normal program operation)

200 400 600 800 1000

500 000

1 .0 106

1 .5 106

2 .0 106

2 .5 106

3 .0 106

3 .5 106

Page 13: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(normal program operation)

500 1000 1500 2000

1 106

2 106

3 106

4 106

Page 14: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(heap spray)

256 512 768

20 000

40 000

60 000

80 000

100 000

120 000

Page 15: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(heap spray)

256 512 768 1024

20 000

40 000

60 000

80 000

100 000

120 000

140 000

Page 16: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Visualizing the Heap(heap spray)

256 512 768 1024 1280 1536 1792 2048

20 000

40 000

60 000

80 000

100 000

Page 17: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(heap spray)

200 400 600

1 106

2 106

3 106

4 106

5 106

Page 18: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(heap spray)

500 1000 1500 2000

1 106

2 106

3 106

4 106

Page 19: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Fourier Transforms of the Heap(heap spray)

200 400 600 800 1000

2 106

3 106

4 106

Page 20: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Problem:

Page 21: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Low hanging fruit?

Page 22: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

More Analysis

• Used the open source tool RapidMiner

• Started by making a decision tree

Page 23: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Results

Page 24: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Results

• 100% accurate for all our test cases.

• Rushed into production (without further testing).

• FAIL!

Page 25: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Next attempt: Statistics

• Assume that distribution of bytes is Gaussian

Page 26: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Statistics for normal heap

• About 40 counts > 1 standard deviation

• Actual measurement: 20 – 30

Page 27: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Statistics for Heapspray

• NOP slide altered distribution

• Typically 2 – 8 > 1 standard deviation

Page 28: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Advantages of a Statistical Approach

• Easy to code

• Friendly to system resources

• More general than hard coded approach

• Theoretically sound

Page 29: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

Results

• Out of over 500 files tested, we had 100% success.

• 0 false positives

• 0 false negatives

Page 30: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

How to defeat

• Write shellcode so as to minimally alter normal distribution.

• Most likely will leave some signature.

• Invites cat and mouse game.

Page 31: Yet Another Heapspray Detector Danny Kovach Raytheon SI.

References

1. http://research.microsoft.com/en-us/projects/nozzle/

2. http://en.wikipedia.org/wiki/Heap_spraying

3. https://lirias.kuleuven.be/bitstream/123456789/265421/1/fulltext.pdf

4. http://www.mathnstuff.com/math/spoken/here/2class/90/normal.htm