[Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

46
FUZZING UNDERESTIMATED METHOD OF FINDING HIDDEN BUGS by Pawel Rzepa

Transcript of [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

Page 1: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

FUZZING UNDERESTIMATED METHOD OF FINDING

HIDDEN BUGS

by Pawel Rzepa

Page 2: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

AGENDA

• What fuzzing really is?

• Mutation based (dumb) fuzzing

• Instrumented fuzzing

• Generation based (smart) fuzzing

• Fuzzing in Software Development Life Cycle

• Fuzzing web application

Page 3: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

— “Fuzzing: Brute Force Vulnerability Discovery”

FUZZING IS A METHOD FOR DISCOVERING FAULTS IN SOFTWARE BY PROVIDING

UNEXPECTED INPUT AND MONITORING FOR EXCEPTIONS.

“WHAT FUZZING REALLY IS?

Page 4: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

IN OTHER WORDS…

A child noticed unwatched dad’s phone…

A child has found a chain of instructions to crash a phone.

Page 5: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

HISTORY OF FUZZINGIn 1988 a professor Barton Miller from University of Winsconsin observed that when he was logged to a modem during a storm, there was a lot of line noise generating junk characters and those characters caused programs to crash.

Page 6: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

THE MOST BASIC FUZZER (RANDOM TESTING)

…but what is missing?• information about what exactly causes a crash (how to reproduce it?)• information about the program state (how do we know that an input caused any crash?)

$> while true;\ > do [tested_program] `head -c 100 /dev/urandom;\ > done

• in most cases such random input will be ignored

Page 7: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

WHY IT’S WORTH FUZZING?

• High return on investment - machine time is cheap and human time is expensive• Human role is just to customize a fuzzer to your needs and… profit!

Page 8: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

WHAT YOU CAN FUZZ?• Literally - every piece of software which accepts user input

• All kinds of apps (mobile, desktop, web, etc.)• OS -> https://vimeo.com/129701495

• Online games -> http://bit.ly/2e0w2YO

• Bluetooth -> http://bit.ly/2dQfPqM

• HDMI -> http://bit.ly/2e0ynmA

• Fonts -> http://bit.ly/293DKE0• Virtualization systems -> http://bit.ly/2ernSfs…and much more!

Page 9: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

WHAT FUZZERS CAN FIND?

• Buffer overruns (remote code execution),

• Deadlocks, thread hangs, unhandled exceptions (denial-of-service),

• Memory leaks (Heartbleed)

“(…) yeah it sometimes happen. Just restart

and don’t give a f@%k about it.”

Page 10: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

MUTATION /

BRUTEFORCE/

DUMB FUZZING

sample data fuzzed

data

- bitflipping - byteflipping - chunkspew -…

program input

Page 11: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

MUTATION IN PRACTICE

Page 12: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LET’S FUZZ - DUMB FUZZING (1)Testing robustness of Android AV to APK bombs

Target: Android AV winner at av-test.org (July 2016)

Page 13: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

CREATING SAMPLE DATA• Create fuzzed data from sample:

$> radamsa -o fuzz_sample_%n.apk -n 3000 com.appsec.appuse.apk

• Move fuzzed data to SD card

$> for i in {1..3000}; do adb push fuzz_sample_$i.apk /sdcard/Download; done

• Capture logs

$> adb logcat -v long > logs.txt

Page 14: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

DUMB FUZZING - V3 AV

Page 15: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

DUMB FUZZING - WHY NOT PERFECT?

IF (VERY_RARE_CONDITION) { //VULNERABLE CODE

}ELSE { …

}

Page 16: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

DUMB FUZZING - TCPDUMP$> radamsa -o fuzz_sample_%n.pcap -n 3000 small_capture.pcap

$> for i in {1..3000}; do tcpdump -nr fuzz_sample_%i.pcap >> radamsa_pcap.logs; done

Page 17: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LET’S FUZZ - INSTRUMENTED FUZZING

• Generates samples, which cover subsets of all code paths

• Requires a dedicated compiler, which detects possible code paths

• Much more effective

Page 18: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING - PREPARATIONS

• Compile sources with afl-gcc/afl-clang

$> CC=/path_to_AFL/afl-gcc ./configure $> make

• Prepare valid sample (the best if <100 KB)

• Create folders for input, output and (optionally) garbage

Page 19: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING IN PRACTICE

$> /path_to_AFL/afl-fuzz -i ./fuzz-input/ -o \ >./fuzz-output/ tcpdump-4.6.2/tcpdump -nr @@

Page 20: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING IN PRACTICE

Page 21: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING IN PRACTICE

Page 22: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING IN PRACTICE

Page 23: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

INSTRUMENTED FUZZING IN PRACTICE

Page 24: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

COOL STORY BRO, BUT MY PROGRAM ISN’T WRITTEN IN C…

• AFL is so good that the community has created many implementations of AFL supporting other languages/environments. Just check it out here:

https://github.com/mirrorer/afl/blob/master/docs/sister_projects.txt

• Still doesn’t suit your needs?

Then write your own fuzzer!

Page 25: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

HOW TO FUZZ NETWORK PROTOCOLS?

- Will it work???

$> while true;\ $> do cat /dev/urandom | nc -vv ftp.hq.nasa.gov 21;\ $> done

FAIL

Page 26: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LIMITATIONS OF DUMB FUZZING (1)

• Not compliant types

Page 27: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LIMITATIONS OF DUMB FUZZING (2)

• Not compliant fixups (checksum, length etc.)

Page 28: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LIMITATIONS OF DUMB FUZZING (3)

• Not supported relationships

Page 29: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

LIMITATIONS OF DUMB FUZZING (4)

• Not supported program states

Page 30: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

GENERATION BASED FUZZING - CREATING A MODEL

• Fuzzing frameworks like Peach or Sulley require modelling each portion of data

Page 31: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• With DataModels, you can create different states

Page 32: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• You can also define a monitor for tested process

• Finally, put all defined parts in a Test

Page 33: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

SMART FUZZING WITH PEACH

$> sudo mono Peach.exe —debug ./samples/ftp.xml

Page 34: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

SMART FUZZING WITH PEACH

Page 35: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

HOMEWORK• Fuzz a “Vulnserver”. Download from: http://sites.google.com/site/lupingreycorner/vulnserver.zip

• Write a Peach model. Refer to this tutorial: http://resources.infosecinstitute.com/fuzzing-vulnserver-with-peach-part-2/

Page 36: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

FUZZING WEB APPLICATION

• Locate an input you want fuzz

Page 37: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• Intercept request (e.g. Burp Suite/OWASP Zap)

Page 38: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• Define which parameter should be fuzzed

Page 39: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• Select a dictionary with invalid input

More sample dictionaries: https://github.com/fuzzdb-

project/fuzzdb

Page 40: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

• Find errors!

Page 41: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

ANALYSING THE CRASH• Every crash can be treated as a pure DoS attack • Not every crash can be exploited :(• Depending on OS, use different tools to analyse a crash:

- Microsoft !exploitable Crash Analyser (Windows)

- CERT GDB exploitable plugin (Linux)

- Apple Crash Wrangler Monitor (OSX)

Page 42: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

WHAT’S NEXT? IMPLEMENT FUZZING IN SDLC

Page 43: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

FUZZING AND OTHER TESTING METHODS

• Fuzzing can find some type of bugs, but not all of them

• That means, fuzzing should be treated as ADDITIONAL method to your security tests

You still need static analysis, vulnerability assessment and

penetration tests!!!

Page 44: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

SUMMARY

• Fuzzer should contain: input generator, history of generated input and process monitor

• Fuzzing discovers bugs by providing invalid input

• There are 2 main types of fuzzers:

• Fuzzing should be a part of SDLC process as additional method of security tests

- generation based (requires sample definition) - mutation based (mutates a valid sample)

Page 45: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

QUESTIONS???

Page 46: [Wroclaw #4] Fuzzing - underestimated method of finding hidden bugs

THANK YOU!

Contact me: [email protected]