06.08.2015 Views

Fuzzing the Media Framework in Android

9bUpku

9bUpku

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> <strong>Media</strong> <strong>Framework</strong> <strong>in</strong> <strong>Android</strong>Alexandru BlandaOTC Security QA1


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data Generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright <strong>Framework</strong>Logg<strong>in</strong>g & Triage Mechanisms2


Introduction<strong>Fuzz<strong>in</strong>g</strong>• Form of black-box test<strong>in</strong>g• Involves send<strong>in</strong>g corrupt <strong>in</strong>put to a software system andmonitor<strong>in</strong>g for crashes• Purpose: f<strong>in</strong>d security-related problems or any o<strong>the</strong>r criticaldefects that could lead to an undesirable behaviour of <strong>the</strong> system3


Introduction<strong>Fuzz<strong>in</strong>g</strong>Possible targets:‣ <strong>Media</strong> Players‣ Document Viewers‣ Web Browsers‣ Antivirus products‣ B<strong>in</strong>ary (ELF)4


IntroductionAudio and video as attack vectors• B<strong>in</strong>ary streams conta<strong>in</strong><strong>in</strong>g complex data• Large variety of audio and video players and associated mediacodecs• User perception that media files are harmless• <strong>Media</strong> playback doesn’t require special permissions5


IntroductionWhat to expect• Crashes (SIGSEGV, SIGFPE, SIGABRT, SIGILL)• Process hangs (synchronization issues, memory leaks, <strong>in</strong>f<strong>in</strong>iteloops)• Denial of Service situations (device reboots, application crashes)• Buffer overflows, null-po<strong>in</strong>ter dereference, <strong>in</strong>teger overflows6


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data Generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright <strong>Framework</strong>Logg<strong>in</strong>g & Triage Mechanisms7


<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Overview• Create corrupt but structurally valid media files• Direct <strong>the</strong>m to <strong>the</strong> appropriate decoders <strong>in</strong> <strong>Android</strong>• Monitor <strong>the</strong> system for potential issues• Pass <strong>the</strong> issues through a triage mechanism8


<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Steps <strong>in</strong> a fuzz<strong>in</strong>g campaign1. Identify type of <strong>in</strong>put2. Identify entry po<strong>in</strong>t <strong>in</strong> <strong>the</strong> system3. Data generation4. Execution phase (actual fuzz<strong>in</strong>g process)5. Monitor results (logg<strong>in</strong>g process)6. Triage phase9


<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Steps <strong>in</strong> a fuzz<strong>in</strong>g campaign1. Identify type of <strong>in</strong>put - corrupt media files2. Identify entry po<strong>in</strong>t <strong>in</strong> <strong>the</strong> system - Stagefright framework3. Data generation - various fuzz<strong>in</strong>g tools4. Execution phase - Stagefright CLI5. Monitor results - log buffer <strong>in</strong> <strong>Android</strong>6. Triage phase - /data/tombstones10


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkLogg<strong>in</strong>g & Triage mechanisms11


Data generationTools• Basic <strong>Fuzz<strong>in</strong>g</strong> <strong>Framework</strong> (BFF)• FuzzBox• Radamsa• American Fuzzy Lop (AFL)• Seed ga<strong>the</strong>r<strong>in</strong>g12


Data generationBasic <strong>Fuzz<strong>in</strong>g</strong> <strong>Framework</strong> (BFF)• Mutational fuzz<strong>in</strong>g on software that consumes file <strong>in</strong>put• Automatically generated GDB and Valgr<strong>in</strong>d traces• Crash classification based on bug severity/exploitabilitydegree• Automated test case m<strong>in</strong>imization, for <strong>in</strong>puts that produce acrash• Based on a modified version of zzuf13


Data generationBFF for <strong>Android</strong> fuzz<strong>in</strong>g• Generate test files on a temporary location <strong>the</strong> disk (ra<strong>the</strong>rthan directly <strong>in</strong> memory)• External script to save <strong>the</strong> files from <strong>the</strong> temporary location• Retrace generated test cases to <strong>the</strong>ir <strong>in</strong>itial seed files14


Data generationFuzzBox• Multi-codec media fuzz<strong>in</strong>g tool, written <strong>in</strong> Python• Creates corrupt but structurally valid media files and launches<strong>the</strong>m <strong>in</strong> a player, while ga<strong>the</strong>r<strong>in</strong>g GDB backtraces• More targeted than BFF (targets specific stream formats)• Supported filetypes: Ogg, FLAC, ASF(WMV, WMA), MP3,MP4, Speex, WAV, AIFF15


Data generationFuzzBox for <strong>Android</strong> fuzz<strong>in</strong>g• Several changes from <strong>the</strong> standard tool:• Only use <strong>the</strong> data generation functionality of <strong>the</strong> tool• Retrace all generated test files to <strong>the</strong>ir <strong>in</strong>itial seed files• Automated tool usage• Much faster than BFF !16


Data generationRadamsa• General purpose fuzzer• Random, determ<strong>in</strong>istic, model-based fuzzer• Collection of ~15 smaller model-based fuzzers• Control over mutation patterns and data generation sources• Ma<strong>in</strong>ly used only for generat<strong>in</strong>g test cases• Can be easily ported to run directly on <strong>Android</strong> (advantages?)17


Data generationSeed ga<strong>the</strong>r<strong>in</strong>g• Python mass downloader us<strong>in</strong>gGoogle and B<strong>in</strong>g search eng<strong>in</strong>es• The LibAv samples collection:more than 50 GB of valid andcorrupt media fileshttp://samples.mplayerhq.hu/• -<strong>in</strong>url:htm -<strong>in</strong>url:html <strong>in</strong>title:”<strong>in</strong>dex of” .mp3 + wget18


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkLogg<strong>in</strong>g & Triage mechanisms19


<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkThe fuzz<strong>in</strong>g <strong>in</strong>frastructure20


<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkOverview of <strong>the</strong> test<strong>in</strong>g process• Corrupted media <strong>in</strong>put is created on a server us<strong>in</strong>g <strong>the</strong> datageneration tools• The server sends large sets of test cases to <strong>the</strong> local host• Each set of test files is automatically divided <strong>in</strong>to separatebatches• Each device receives a batch of test<strong>in</strong>g files <strong>in</strong> a distributedmanner and logs <strong>the</strong> results separately21


<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkStagefright command l<strong>in</strong>e <strong>in</strong>terfaceroot@android:/ # stagefright -husage: stagefright-h(elp)-a(udio)-n repetitions-l(ist) components-m max-number-of-frames-to-decode <strong>in</strong> each pass-p(rofiles) dump decoder profiles supported-t(humbnail) extract video thumbnail or album art-s(oftware) prefer software codec-r(hardware) force to use hardware codec-o playback audio-w(rite) filename (write to .mp4 file)-x display a histogram of decod<strong>in</strong>g times/fps (video only)-S allocate buffers from a surface-T allocate buffers from a surface texture-d(ump) filename (raw stream data to a file)-D(ump) filename (decoded PCM data to a file)22


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkLogg<strong>in</strong>g & Triage mechanisms23


Logg<strong>in</strong>g and Triage MechanismsLogg<strong>in</strong>g process• Log every test case executed with Fatal priority"adb shell log -p F -t sp_stagefright *** Filename:" + test_files[i]• Save filtered logcat buffer for each campaign, for all devices24


Logg<strong>in</strong>g and Triage MechanismsInitial results160000140000120000100000800006000040000200000Number of filesTotal: ~1 million25


Logg<strong>in</strong>g and Triage MechanismsInitial results300025002000Size of files15001000Total: ~11.5 TB500026


Logg<strong>in</strong>g and Triage MechanismsInitial results450004000035000300002500020000150001000050000Number of crashesTotal: ~185000crashes27


Logg<strong>in</strong>g and Triage MechanismsTriage phase• Problem: Automated fuzz<strong>in</strong>g campaigns generat<strong>in</strong>g largenumber of crashes (issues)› Manual sort<strong>in</strong>g is not an option• Suitable test<strong>in</strong>g scenarios: <strong>in</strong>volve execut<strong>in</strong>g various testcases on devices and monitor<strong>in</strong>g for crashes28


Logg<strong>in</strong>g and Triage MechanismsTest<strong>in</strong>g scenario2 separate phases:• First run test<strong>in</strong>g phase› Test cases are executed on <strong>the</strong> device› Logs are created dur<strong>in</strong>g each test run• Triage phase› Generated logs are parsed to identify crash<strong>in</strong>g test cases› Crash<strong>in</strong>g test cases are resent to <strong>the</strong> device› Previously unseen crashes get stored <strong>in</strong> <strong>the</strong> unique issues pool29


Logg<strong>in</strong>g and Triage MechanismsTriage phase - implementation• Each test case that produces a crash generates an entry <strong>in</strong>data/tombstones and data/system/dropbox30


Logg<strong>in</strong>g and Triage MechanismsTriage phase - implementation1. Parse <strong>the</strong> logs and identify <strong>the</strong> test cases that caused a crash2. Resend <strong>the</strong> files to <strong>the</strong> test<strong>in</strong>g <strong>in</strong>frastructure3. For each test file sent:a. Grab <strong>the</strong> generated tombstoneb. Parse <strong>the</strong> tombstone and get <strong>the</strong> PC valuec. Check if <strong>the</strong> PC value has been previously encounteredd. Save <strong>the</strong> tombstone and <strong>the</strong> test case if <strong>the</strong> issue is new31


Logg<strong>in</strong>g and Triage MechanismsTriage phase - implementation• Diff between <strong>the</strong> folder that conta<strong>in</strong>s <strong>the</strong> unique issues, beforeand after <strong>the</strong> triage process:Common subdirectories: ./0015ae9f and old_issues/0015ae9fCommon subdirectories: ./00163774 and old_issues/00163774Only <strong>in</strong> .: 001639cfOnly <strong>in</strong> .: 00167d90Common subdirectories: ./00168304 and old_issues/00168304Common subdirectories: ./00169d0f and old_issues/00169d0fCommon subdirectories: ./0016c8a7 and old_issues/0016c8a7Only <strong>in</strong> .: 001a9211Common subdirectories: ./00235a99 and old_issues/00235a9932


Logg<strong>in</strong>g and Triage MechanismsResults after triage876543210Number of issuesTotal: 35 issues33


Logg<strong>in</strong>g and Triage MechanismsResults after triage• Majority of issues reproduced <strong>in</strong> AOSP – reporteddirectly to Google• 7 issues considered security vulnerabilities, 3 <strong>in</strong>cluded <strong>in</strong><strong>Android</strong> Security Bullet<strong>in</strong> from September 2014• Integer overflows <strong>in</strong> libstagefright:› CVE-2014-7915, CVE-2014-7916, CVE-2014-791734


AgendaIntroduction<strong>Fuzz<strong>in</strong>g</strong> <strong>Media</strong> Content <strong>in</strong> <strong>Android</strong>Data generation<strong>Fuzz<strong>in</strong>g</strong> <strong>the</strong> Stagefright frameworkLogg<strong>in</strong>g & Triage mechanisms<strong>Fuzz<strong>in</strong>g</strong> Stagefright with AFL35


<strong>Fuzz<strong>in</strong>g</strong> Stagefright with AFLThe American Fuzzy Lop fuzz<strong>in</strong>g tool• Instrumentation based fuzz<strong>in</strong>g tool• Targeted b<strong>in</strong>aries need to be compiled with afl-gcc (wrapperover gcc)• Two fuzz<strong>in</strong>g modes: dumb-mode, <strong>in</strong>strumented-mode• Instrumented mode detects changes to program control flowto f<strong>in</strong>d new code paths• Detects both crashes and hangs and sorts out <strong>the</strong> uniqueissues36


<strong>Fuzz<strong>in</strong>g</strong> Stagefright with AFLAFL on <strong>Android</strong>• Build <strong>in</strong>strumented b<strong>in</strong>ary like a regular <strong>Android</strong> module• Use environment variables (afl-gcc built as wrapper overgcc toolcha<strong>in</strong> from <strong>Android</strong>)37


https://github.com/fuzz<strong>in</strong>g/MFFAioan-alexandru.blanda@<strong>in</strong>tel.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!