Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Exploit development and reversing

Lab · Hard · 3 hoursFree account

Introduction to Binary Fuzzing

AFL++, libFuzzer, and coverage-guided fuzzing to discover binary vulnerabilities.

  • fuzzing
  • afl
  • libfuzzer
  • coverage-guided
On this page 9 sections
  1. ·Lab Setup
  2. 1Write a vulnerable target
  3. 2Compile with AFL++ instrumentation
  4. Locked: Run AFL++ and read the status screen
  5. Locked: Triage and minimise the crash
  6. Locked: Write a libFuzzer harness
  7. Locked: Assess exploitability
  8. Locked: Defence and Detection
  9. Locked: Check Your Work

Before you start

Fuzzing finds bugs by feeding malformed input to a program until it crashes, and a coverage-guided fuzzer steers that input toward new code paths. Many high-impact CVEs in parsers, codecs, and file formats have been found through coverage-guided fuzzing. The work here builds a vulnerable target, runs AFL++ and libFuzzer against it, and triages the crashes down to the smallest reproducer.

What You'll Learn

  • Build a fuzzing harness for a vulnerable C target
  • Run AFL++ with coverage-guided feedback and read its status screen
  • Write a libFuzzer harness and compare the two approaches
  • Triage crashes and minimise them to the smallest reproducer
  • Assess whether a crash is exploitable using AddressSanitizer and GDB
  • Choose compiler flags that make fuzzing find bugs faster

Lab Setup

You compile and fuzz your own vulnerable program. No network targets are involved.

ItemRequirement
Lab VMKali Linux or Ubuntu 22.04+, 64-bit, at least 2 CPU cores and 4 GB RAM
CompilerGCC 12+ and Clang 14+ (for libFuzzer)
AFL++Version 4.x. Install from the package manager or build from source
Toolsafl-fuzz, afl-gcc, afl-clang-lto, afl-tmin, gdb with pwndbg
ASanBuilt into GCC and Clang — no separate install

Install AFL++ if it is not present:

sudo apt update && sudo apt install -y afl++ clang gcc gdb

Authorised scope only. Isolated lab network. Never on production.

Step 1: Write a vulnerable target

1

You need a program with a real bug. Writing it yourself means you know exactly where the flaw is, so you can verify that the fuzzer finds it.

Create a file called parsebuf.c. It reads input from stdin, copies it into a fixed buffer and branches on specific byte values. The branches give the fuzzer something to discover.

/* parsebuf.c — a deliberately vulnerable parser */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void parse(const char *data, size_t len) {
    char buf[64];
    if (len < 4) return;
    if (data[0] == 'F' && data[1] == 'U' &&
        data[2] == 'Z' && data[3] == 'Z') {
        /* the bug: copies the full input into a 64-byte buffer */
        memcpy(buf, data, len);
    }
}

int main(void) {
    char input[1024];
    size_t n = fread(input, 1, sizeof(input), stdin);
    parse(input, n);
    return 0;
}

The overflow only triggers when the first four bytes are FUZZ. Without coverage feedback, a dumb fuzzer almost never guesses that prefix. Coverage-guided fuzzing discovers it branch by branch.

Step 2: Compile with AFL++ instrumentation

2

AFL++ rewrites the binary at compile time so it reports which code paths each input reaches. Without instrumentation, the fuzzer runs blind.

mkdir -p ~/fuzz/afl && cd ~/fuzz/afl
afl-clang-lto -g -O1 -fno-omit-frame-pointer -fsanitize=address \
  -o parsebuf_afl parsebuf.c
afl-cc++4.21a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode: LTO
[+] Instrumented 6 locations (non-hardened mode).

The 6 locations count is the number of branch points AFL++ found. -fsanitize=address adds AddressSanitizer, which turns a silent overwrite into an immediate, detailed crash report. -O1 keeps the binary fast without removing code the fuzzer needs.

Create a seed corpus. AFL++ needs at least one input file to start from.

mkdir -p corpus
echo -n "AAAA" > corpus/seed1.txt

The seed does not need to trigger the bug. It only needs to be valid input. AFL++ mutates it.

Sign in to continue

6 more sections are for signed-in members. It is free: sign in with Google.

Related