Fuzzing

(adapted from The Fuzzing Book by Andreas Zeller et. al.)

Generating random software inputs

def fuzzer(max\_length : int = 100, char\_start : int = 32, char\_range: int = 32) -> str;
Example Randomly Fuzzed Output
Example Randomly Fuzzed Output

A general con of fuzzing

Mutation-based Fuzzing

Example for Mutation Fuzzing
Example for Mutation Fuzzing
AFL Screenshot
AFL Screenshot

Symbolic Analysis

Find an input that crashes this program. Construct a first-order logic formula, and use a “SAT/SMT Solver” to solve for its satisfiability.

int f(int y) {
  z = y * 2;
  assert(z != 12);
  ...
}

Tackle branches using the Weakest Precondition Calculus.

int f(int y) {
  z = y * 2;
  if (z <= 12) {
    x = w + y;
    assert(x > 4);
  }
  ...
}

Avoid exponential-sized first-order logic formulas

int f(int y) {
  z = y;
  if (a) {
    z = f1(z);
  } else {
    z = f2(z);
  }
  if (b) {
    z = f3(z);
  } else {
    z = f4(z);
  }
  if (c) {
    z = f5(z);
  } else {
    z = f6(z);
  }
  if (d) {
    z = f7(z);
  } else {
    z = f8(z);
  }
  assert(z != 0);
}

Tackle loops!

int f(int y, int w) {
  z = y;
  a = w;
  while (a) {
    z = f1(z); //z = z + 1;
    a = f2(a); //a = a - 1;
  }
  assert(z + a != 0);
}

Does there exist an input y, such that the assertion fails? This is undecidable in Turing’s model of computation with an infinite tape.

Example output:

=input.src.llvm-mem
1 : ([ 536870912; 2147483647 ] -> 0, [ 3221225471; 3221225471 ] -> 128, { [ 0; 536870911 ], [ 2147483648; 3221225470 ], [ 3221225472; 4294967295 ], } -> (RAC: m_multiplier -> 49 , m_adder -> 103), ) : ARRAY[BV:32 -> BV:8]
=input.src.llvm-mem.alloc
1 : ([ 0; 536870911 ] -> memlabel-mem--heap, [ 536870912; 650084367 ] -> memlabel-mem--esp, [ 650084368; 650084371 ] -> memlabel-mem--local./*___y___memrchr__x__=L0%0%argnum0=/, [ 650084372; 1769861115 ] -> memlabel-mem--esp, [ 1769861116; 1769861119 ] -> memlabel-mem--local./*___y___memrchr__x__=L0%0%argnum1=/, [ 1769861120; 1992261623 ] -> memlabel-mem--esp, [ 1992261624; 1992261627 ] -> memlabel-mem--local./*___y___memrchr__x__=L0%0%argnum2=/, [ 1992261628; 2147483647 ] -> memlabel-mem--esp, [ 2147483648; 4294959612 ] -> memlabel-mem--heap, [ 4294959613; 4294959615 ] -> memlabel-mem--symbol.1.0, [ 4294959616; 4294963200 ] -> memlabel-mem--heap, [ 4294963201; 4294966877 ] -> memlabel-mem--rodata, [ 4294966878; 4294966878 ] -> memlabel-mem--heap, [ 4294966879; 4294966908 ] -> memlabel-mem--symbol.2.0, [ 4294966909; 4294967295 ] -> memlabel-mem--heap, ) : ARRAY[BV:32 -> MEMLABEL]
=input.src.local./*___y___memrchr__x__=L0%0%argnum1=/
1 : 1769861116 { 0x697deffc +1.98388624e83 } : BV:32
=input.src.llvm-%c
1 : 0 { 0x0 +1.0e129 } : BV:32