Top Banner
Fuzzing Suman Jana *Acknowledgements: Dawn Song, Kostya Serebryany, Peter Collingbourne
28

Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Apr 01, 2018

Download

Documents

vothuan
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: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Fuzzing

SumanJana

*Acknowledgements:DawnSong,KostyaSerebryany,PeterCollingbourne

Page 2: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Techniquesforbugfinding

Automa'ctestcasegenera'on

LowercoverageLowerfalseposi0vesHigherfalsenega0ves

Fuzzing DynamicsymbolicexecuFon

StaFcanalysis ProgramverificaFon

HighercoverageHigherfalseposi0vesLowerfalsenega0ves

Page 3: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Blackboxfuzzing

Testprogram

Randominput

Milleretal.‘89

Page 4: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Blackboxfuzzing

•  Givenaprogramsimplyfeedrandominputsandseewhetheritexhibitsincorrectbehavior(e.g.,crashes)

•  Advantage:easy,lowprogrammercost•  Disadvantage:inefficient

–  InputsoUenrequirestructures,randominputsarelikelytobemalformed

–  InputsthattriggeranincorrectbehaviorisaaverysmallfracFon,probablyofgeVngluckyisverylow

Page 5: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Fuzzing

•  AutomaFcallygeneratetestcases•  Manyslightlyanomaloustestcasesareinputintoatarget

•  ApplicaFonismonitoredforerrors•  Inputsaregenerallyeitherfilebased(.pdf,.png,.wav,etc.)ornetworkbased(hWp,SNMP,etc.)

Inputgenerator

Monitor

TestapplicaFon

Page 6: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

ProblemdetecFon

•  Seeifprogramcrashed–  Typeofcrashcantellalot(SEGVvs.assertfail)

•  Runprogramunderdynamicmemoryerrordetector(valgrind/purify/AddressSaniFzer)–  Catchmorebugs,butmoreexpensiveperrun.

•  Seeifprogramlocksup•  Rollyourowndynamiccheckere.g.valgrindskins

Page 7: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Regressionvs.FuzzingRegrssion Fuzzing

DefiniFon Runprogramonmanynormalinputs,lookforbadness

Runprogramonmanyabnormalinputs,lookforbadness

Goals Preventnormalusersfromencounteringerrors(e.g.,asserFonfailuresarebad)

PreventaWackersfromencounteringexploitableerrors(e.g.,asserFonfailuresareoUenok)

Page 8: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Enhancement1:MutaFon-Basedfuzzing

•  Takeawell-formedinput,randomlyperturb(flippingbit,etc.)

•  LiWleornoknowledgeofthestructureoftheinputsisassumed

•  AnomaliesareaddedtoexisFngvalidinputs– AnomaliesmaybecompletelyrandomorfollowsomeheurisFcs(e.g.,removeNULL,shiUcharacterforward)

•  Examples:ZZUF,Taof,GPF,ProxyFuzz,FileFuzz,Filep,etc.

Seedinput Mutatedinput Runtestprogram

?

Page 9: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Example:fuzzingaPDFviewer

•  Googlefor.pdf(about1billionresults)•  Crawlpagestobuildacorpus•  Usefuzzingtool(orscript)

–  CollectseedPDFfiles–  Mutatethatfile–  Feedittotheprogram–  Recordifitcrashed(andinputthatcrashedit)

Page 10: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

MutaFon-basedfuzzing

•  Supereasytosetupandautomate•  LiWleornofileformatknowledgeisrequired•  LimitedbyiniFalcorpus•  Mayfailforprotocolswithchecksums,thosewhichdependonchallenge

Page 11: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

EnhancementII:GeneraFon-BasedFuzzing

•  TestcasesaregeneratedfromsomedescripFonoftheinputformat:RFC,documentaFon,etc.–Usingspecifiedprotocols/fileformatinfo–E.g.,SPIKEbyImmunity

•  Anomaliesareaddedtoeachpossiblespotintheinputs

•  KnowledgeofprotocolshouldgivebeWerresultsthanrandomfuzzing

Inputspec Generatedinputs Runtestprogram

?RFC

Page 12: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

EnhancementII:GeneraFon-BasedFuzzing

SamplePNGspec

Page 13: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

MutaFon-basedvs.GeneraFon-based

•  MutaFon-basedfuzzer– Pros:Easytosetupandautomate,liWletonoknowledgeofinputformatrequired

– Cons:LimitedbyiniFalcorpus,mayfallforprotocolswithchecksumsandotherhardchecks

•  GeneraFon-basedfuzzers– Pros:Completeness,candealwithcomplexdependncies(e.g,checksum)

– Cons:wriFnggeneratorsishard,performancedependsonthequalityofthespec

Page 14: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Howmuchfuzzingisenough?

•  MutaFon-based-fuzzersmaygenerateaninfinitenumberoftestcases.Whenhasthefuzzerrunlongenough?

•  GeneraFon-basedfuzzersmaygenerateafinitenumberoftestcases.Whathappenswhenthey’reallrunandnobugsarefound?

Page 15: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Codecoverage

•  SomeoftheanswerstothesequesFonslieincodecoverage

•  Codecoverageisametricthatcanbeusedtodeterminehowmuchcodehasbeenexecuted.

•  Datacanbeobtainedusingavarietyofprofilingtools.e.g.gcov,lcov

Page 16: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Linecoverage

•  Line/blockcoverage:Measureshowmanylinesofsourcecodehavebeenexecuted.

•  Forthecodeontheright,howmanytestcases(valuesofpair(a,b))neededforfull(100%)linecoverage?

if( a > 2 ) a = 2; if( b >2 ) b = 2;

Page 17: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Branchcoverage

•  Branchcoverage:Measureshowmanybranchesincodehavebeentaken(condiFonaljmps)

•  Forthecodeontheright,howmanytestcasesneededforfullbranchcoverage?

if( a > 2 ) a = 2; if( b >2 ) b = 2;

Page 18: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Pathcoverage

•  Pathcoverage:Measureshowmanypathshavebeentaken

•  Forthecodeontheright,howmanytestcasesneededforfullpathcoverage?

if( a > 2 ) a = 2; if( b >2 ) b = 2;

Page 19: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

BenefitsofCodecoverage

•  CananswerthefollowingquesFons–HowgoodisaniniFalfile?–AmIgeVngstucksomewhere? if (packet[0x10] < 7) { //hot path� } else { //cold path } – HowgoodisfuzzerXvs.fuzzerY– AmIgeVngbenefitsbyrunningmulFplefuzzers?

Page 20: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Problemsofcodecoverage

•  For:mySafeCopy(char *dst, char* src) { if(dst && src) strcpy(dst, src); }

•  Doesfulllinecoverageguaranteefindingthebug?

•  Doesfullbranchcoverageguaranteefindingthebug?

Page 21: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

EnhancementIII:Coverage-guidedgray-boxfuzzing

•  SpecialtypeofmutaFon-basedfuzzing–  Runmutatedinputsoninstrumentedprogramandmeasurecodecoverage

– Searchformutantsthatresultincoverageincrease

– OUenusegeneFcalgorithms,i.e.,tryrandommutaFonsontestcorpusandonlyaddmutantstothecorpusifcoverageincreases

– Examples:AFL,libfuzzer

Page 22: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

AmericanFuzzyLop(AFL)

Inputqueue

Seedinputs

Nextinput

MutaFon

Executeagainst

instrumentedtarget

branch/edge

coverageincreased?

Addmutanttothequeue

Periodicallycullsthequeuewithout

affecFngtotalcoverage

Page 23: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

AFL

•  Instrumentthebinaryatcompile-Fme•  Regularmode:instrumentassembly•  RecentaddiFon:LLVMcompilerinstrumentaFonmode•  Provide64KcountersrepresenFngalledgesintheapp•  Hashtablekeepstrackof#ofexecuFonofedges

–  8bitsperedge(#ofexecuFons:1,2,3,4-7,8-15,16-31,32-127,128+)

–  Imprecise(edgesmaycollide)butveryefficient•  AFL-fuzzisthedriverprocess,thetargetapprunsas

separateprocess(es)

Page 24: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Data-flow-guidedfuzzing

•  Interceptthedataflow,analyzetheinputsofcomparisons–  Incursextraoverhead

•  Modifythetestinputs,observetheeffectoncomparisons

•  PrototypeimplementaFonsinlibFuzzerandgo-fuzz

Page 25: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Fuzzingchallenges

•  Howtoseedafuzzer?– Seedinputsmustcoverdifferentbranches– Removeduplicateseedscoveringthesamebranches

– SmallseedsarebeWer(Why?)

•  Somebranchesmightbeveryhardtogetpastasthe#ofinputsstaFsfyingthecondiFonsareverysmall– Manually/automaFcallytransform/removethosebranches

Page 26: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Hardtofuzzcode

void test (int n) { if (n==0x12345678) crash(); }

needs2^32or4billionaWemptsIntheworstcase

Page 27: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Makeiteasiertofuzz

void test (int n) { int dummy = 0; char *p = (char *)&n; if (p[3]==0x12) dummy++; if (p[2]==0x34) dummy++; if (p[1]==0x56) dummy++; if (p[0]==0x56) dummy++; if (dummy==4) crash(); }

needsaround2^10aWempts

Page 28: Fuzzing - Columbia Universitysuman/secure_sw_devel/fuzzing.pdf · Blackbox fuzzing • Given a program simply feed random inputs and see whether it exhibits incorrect behavior (e.g.,

Fuzzingrulesofthumb•  Input-formatknowledgeisveryhelpful•  GeneraFonaltendstobeatrandom,beWerspecsmakebeWerfuzzers

•  EachimplementaFonwillvary,differentfuzzersfinddifferentbugs– MorefuzzingwithisbeWer

•  Thelongeryourun,themorebugsyoumayfind–  ButitreachesaplateauandsaturatesaUerawhile

•  Bestresultscomefromguidingtheprocess•  NoFcewhereyouaregeVngstuck,useprofiling(gcov,lcov)!