Fuzzing software: common challenges and potential solutions (Part 1) | GitHub Security Lab
skip to content Resources Open Source Community Enterprise / Security Lab Research Advisories CodeQL Wall of Fame Resources Open Source Community Enterprise Events Get Involved In this two-part blog series, we’ll review some of the challenges we commonly face in our fuzzing workflows and provide ways to address these challenges. We’ll also discuss a variety of fuzzing methodologies and strategies that can improve our results.
The second part of this series will go deeper and cover some additional advanced fuzzing concepts. As a practical example we’ll use vulnerabilities we found in VLC Media Player through our fuzzing efforts with the AFL and AFL++ toolchains. Learn more about the VLC vulnerabilities Fuzzing command-line arguments Often, the project that we’re analyzing supports a variety of configuration options that can be set by command line parameters.
While these arguments can be set as just another static parameter in our fuzzer configuration, we’re generally interested in testing all possible inputs and configurations to broaden our attack surface. Including dynamic command-line arguments in our fuzzing allows us to find bugs that only arise under certain configurations. For example, in the case of VLC, the CVE-2019-14535 vulnerability can only be triggered if the video is forwarded.
One way to accomplish this is to set the command-line option “–start-time” with a value of type float (https://wiki.videolan.org/VLC_command-line_help). This can be implemented into our fuzzing workflow by representing command-line arguments with the type of data they contain (bool, float, string, etc). The following examples illustrate this idea: Boolean arguments can be represented using 1 bit: Playlist These options define the behavior of the playlist.
Some of them can be overridden in the playlist dialog box. -Z, --random, --no-random Play files randomly forever (default disabled) VLC will randomly play files in the playlist until interrupted. -L, --loop, --no-loop Repeat all (default disabled) VLC will keep playing the playlist indefinitely. -R, --repeat, --no-repeat Repeat current item (default disabled) VLC will keep playing the current playlist item. --play-and-exit, --no-play-and-exit Play and exit (default disabled) Exit if there are no more items in the playlist. --play-and-stop, --no-play-and-stop Play and stop (default disabled) Stop the playlist after each played playlist item. --play-and-pause, --no-play-and-pause Play and pause (default disabled) Pause each item in the playlist on the last frame. --start-paused, --no-start-paused Start paused (default disabled) Pause each item in the playlist on the first frame. --playlist-autostart, --no-playlist-autostart Auto start (default enabled) Float and integer arguments can be represented using 4/8 bytes: Grain video filter (grain) Adds filtered gaussian noise --grain-variance=<float [0.000000 ..
10.000000]> Variance Variance of the gaussian noise --grain-period-min=<integer [1 .. 64]> Minimal period Minimal period of the noise grain in pixel --grain-period-max=<integer [1 .. 64]> Maximal period Maximal period of the noise grain in pixel Variable-length strings can be represented using a fixed-size array: Scene video filter (scene) Send your video to picture files --scene-format=<string> Image format Format of the output images (png, jpeg, ...).
A straightforward way to configure fuzzing input for the command-line arguments is as follows: First, calculate the total number of bytes required for the new block. For this, take the sum of the length in bytes of each argument data type. In our example, the total is 50 bytes (8x1 bit + 3x4 bytes + 37 bytes). Prepend a zeroed block of 50 bytes to the input file. The content of this block will be progressively mutated by the fuzzer.
Finally, add a code snippet to the code in order to assign each block position an input variable. </img> Figure 1 - Prepending a zeroed block to the beginning of the input file unsigned char arguments[50] = {0}; fread(arguments, 1, 50, inputFile); randomArg = (arguments[0] >> 7) & 1; loopArg = (arguments[0] >> 6) & 1; repeatArg = (arguments[0] >> 5) & 1; playAndExit = (arguments[0] >> 4) & 1; playAndStop = (arguments[0] >> 3) & 1; playAndPause = (arguments[0] >> 2) & 1; startPaused = (arguments[0] >> 1) & 1; playlistAutostart = (arguments[0] >> 0) & 1; memcpy(&grain-variance, arguments[1], 4); memcpy(&grain-period-min, arguments[5], 4); memcpy(&grain-period-max, arguments[9], 4); memcpy(scene-format, arguments[13], 50-13); //File content starts at inputFile[50] Example of code snippet for command-line arguments assignment This process allows us to test input file data and command-line arguments at the same time.
In other words, we can now dynamically fuzz the various configurations of the target program. For an input corpus containing several files, we can automate this process by creating a script that prepends the required length to the original input files. And you can speed up the fuzzing process considerably by using multiple valid configuration combinations as your seed data instead of filling the files with zeroes. Specific dictionary entries can also be added to the current fuzzing session, which we’ll cover in the section about providing a custom dictionary.
Note that this approach is equally valid for cases where settings are read from configuration files. Splitting up comparisons In many cases, subsequent iterations of coverage-guided fuzzers are capable of discovering amazing code patterns. However, there are often cases where the fuzzer will remain constrained in its coverage. An example of this can be seen in the following code snippet: </img> Figure 2 - Code snippet in VLC file demux/ogg.c When using a fuzzer such as AFL, which introduces random mutations in the OGG file, a pass through this conditional statement requires a concrete 0x05589f80 value at a particular position in the current in-memory file.
Since it’s a 32-bit value, it would be relatively unlikely for the fuzzer to chance upon this exact value. However, if we’re able to split this comparison statement across multiple single-byte comparisons and each of them was instrumented, once the fuzzer guesses the first byte correctly it will execute the first nested-if condition and therefore discover a new path. This will signal AFL that the current input should be used again in further fuzzing attempts and, recursively, it will allow the fuzzer to discover these new paths and pass through this conditional statement.
This is exactly what the Laf-intel AFL plugin does. This plugin “deoptimizes” code generated by LLVM to increase AFL code coverage. The following example shows it more clearly: </img> Figure 3 - Split-compare-pass example Laf-intel implements three different LLVM passes: Split-compare-pass : explained in the last paragraph. Compare-transform-pass : rewrites the code in order to discover string variables. Note: This works with strcmp and memcmp calls.
Split-switches-pass : rewrites the switch - case statement to an if - else - if construct. Note that this patch is not included by default in AFL, and you must manually apply the patch to the AFL source code. However, an AFL fork called AFL++ (AFLplusplus) was recently released. AFL++ includes a variety of popular community patches, as well as many other improvements. It’s maintained by Marc “van Hauser” Heuse , Heiko “hexcoder-“ Eißfeldt and Andrea Fioraldi .
You can find more information from their repository . AFL++ laf-intel module can also split floating-point comparisons using AFL_LLVM_LAF_SPLIT_FLOATS (thanks to Andrea Fioraldi for the insight). We’ve made use of AFL++ during our fuzzing research due to its useful add-ons such as Laf-intel. To enable it, we need to compile the target program using afl-clang-fast (LLVM), to enable the split passes you just set the following environment variables before compiling the target project: export AFL_LLVM_LAF_SPLIT_SW
The rest of this page is on the live site.