Cmiller Toorcon2007 Code Coverage With Fuzzing
Cmiller Toorcon2007 Code Coverage With Fuzzing
By Example
Charlie Miller
Independent Security Evaluators
October 20, 2007
▪ Fuzzing 101
▪ Common Fuzzing Problems
▪ Code Coverage
▪ Examples
▪ Improving Code Coverage
▪ Requires
§ 1 test case for line coverage
§ 2 test cases for branch coverage
§ 4 test cases for path coverage
• i.e. (a,b) = {(0,0), (3,0), (0,3), (3,3)}
© 2005, Independent Security Evaluators
www.securityevaluators.com
Path Coverage Issues
▪ Build it:
WebKit/WebKitTools/Scripts/build-webkit -coverage
▪ libpng-1.2.16
▪ Used in Firefox, Safari, and Thunderbird
(and others)
▪ http://www.libpng.org/pub/png/libpng.html
▪ Use script.sh
§ Executes the program 10 at a time
§ Sleeps 5 seconds
§ Kills any processes
§ Repeats
§ Monitors CrashReporter log for crashes
▪ This compares to
§ 0.4% for getting the usage statement
§ 745 of 7399 (10.1%) for opening the good file
• 43 more lines covered by fuzzing...
15.00
11.25
7.50
3.75
0
File 1 File 2 File 3 File 4 File 5
20
15
10
0
File 1 File 2 File 3 File 4 File 5 All
// Header - fixed.
s_binary("89504E470D0A1A0A");
// IHDRChunk
s_binary_block_size_word_bigendian("IHDR"); //size of data field
s_block_start("IHDRcrc");
s_string("IHDR"); // type
s_block_start("IHDR");
// The following becomes s_int_variable for variable stuff
// 1=BINARYBIGENDIAN, 3=ONEBYE
s_push_int(0x1a, 1); // Width
s_push_int(0x14, 1); // Height
s_push_int(0x8, 3); // Bit Depth - should be 1,2,4,8,16, based
on colortype
s_push_int(0x3, 3); // ColorType - should be 0,2,3,4,6
s_binary("00 00"); // Compression || Filter - shall be 00 00
s_push_int(0x0, 3); // Interlace - should be 0,1
s_block_end("IHDR");
s_binary_block_crc_word_littleendian("IHDRcrc"); // crc of type and data
s_block_end("IHDRcrc");
...
30.0
22.5
15.0
7.5
0
File 1 File 2 File 3 File 4 File 5 All Gen
$file = $ENV{'QUERY_STRING'};
$nextfile = $file + 1;
$server = $ENV{'SERVER_NAME'};
$script = $ENV{'SCRIPT_NAME'};
$url = "http://".$server.$script."?".$nextfile;
$pic = sprintf("bad-%d.gif", $nextfile);
$picurl = "http://".$server."/gif/".$pic;
<head>
Fuzz!
";
print " <meta http-equiv=\"refresh\" content=\"2;$url\">";
print " </head><body>";
print"</body>\n";
print "<Script Language=\"JavaScript\">";
print "window.open('$picurl');";
print "</Script>";
▪ f(x) = -x * (x – 10000)
▪ Use “single point crossover” of binary
representation of numbers for
recombination
677 : 00000000000000000000001010100101
9931 : 00000000000000000010011011001011
----------------------------------------------------------------------
651 : 00000000000000000000001010001011
▪ The light blue line indicates the most fit pool of testcases
▪ Code coverage is (slowly) improving
▪ Still experimental
▪ GA’s can get stuck in “local maxima”
▪ GA’s have so many parameters
(population size, initial population,
mutation percentage, etc), hard to
optimize
x : BITVECTOR(32);
QUERY(BVLT(x,0hex0000000a));
x : BITVECTOR(32);
ASSERT(BVLT(x,0hex0000000a));
QUERY(BVGT(x,0hex00000000));
x : BITVECTOR(32);
ASSERT(BVLT(x,0hex0000000a));
QUERY(BVLE(x,0hex00000000));
▪ http://en.wikipedia.org/wiki/Fuzz_testing
▪ Make My Day: Just Run A Web Scanner, Toshinari Kureha, BH-EU-07
▪ How Smart is Intelligent Fuzzing - or - How Stupid is Dumb Fuzzing, Charlie
MIller, DEFCON 2007
▪ Robustness Testing Code Coverage Analysis, Teno Rontti, Masters Thesis
▪ How to Misuse Code Coverage, Brian Marick, http://www.testing.com/
writings/coverage.pdf
▪ ProxyFuzz: http://theartoffuzzing.com/joomla/index.php?
option=com_content&task=view&id=21&Itemid=40
▪ STP: http://theory.stanford.edu/~vganesh/stp.html
▪ SPIKE: http://www.immunitysec.com/downloads/SPIKE2.9.tgz
▪ lcov: http://ltp.sourceforge.net/coverage/lcov.php
▪ GPF and EFS: http://www.vdalabs.com/tools/efs_gpf.html