Saltar al contenido ForoHackers

Why coverage-guided fuzzing finds what random input never will

FuzzingFormación en seguridadPruebas
#995 · hexdump_hermit · · Denunciar

A toy target to show the idea:

int parse(const uint8_t *buf, size_t len) {
    if (len >= 4 && buf[0] == 'F' && buf[1] == 'U' &&
        buf[2] == 'Z' && buf[3] == 'Z') {
        crash_here();   /* the bug */
    }
    return 0;
}

A blind fuzzer that throws random bytes needs to guess four specific bytes at once: one chance in 2^32 per try, around four billion tries.

A coverage-guided fuzzer instruments the binary and records which branches each input reaches. When a random input happens to start with F, it takes a branch that no input took before, so it is kept in the corpus. The next mutations start from there. Each correct byte is a new branch, so the fuzzer climbs one byte at a time: roughly 256 tries per byte, about a thousand in total. Four billion became a thousand.

The harness is tiny too. With libFuzzer it is just:

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    parse(data, size);
    return 0;
}

Build with a sanitizer (-fsanitize=fuzzer,address) so that memory errors turn into crashes right away instead of silent corruption.

That is the whole trick: feedback turns a search through a huge space into a ladder of small steps. The rest (dictionaries, structure-aware mutators, parallel workers) is engineering around that idea.

#1369 · heap_spray_and_pray · · Denunciar

The ladder picture is exactly right. Two practical notes from my own lab: a good seed corpus (a few small valid files) saves hours, and checksums are the enemy. If the format has a CRC, a mutated input is rejected at the door and the fuzzer never reaches the interesting code. Build a variant of the parser that skips the check, in the fuzz build only.

#1370 · rubber_duck_supervisor · · Denunciar

Beginner question: how does it know which branches it reached? Does the compiler add code?

#1371 · hexdump_hermit · · Denunciar

Yes. The compiler inserts a small counter update at each branch (or edge between basic blocks). After the run, the fuzzer reads the counters. Different edges hit equals "new behaviour".

#1372 · off_by_two · · Denunciar

This is hill climbing with a very clever fitness function: "did anything new happen?". Nice framing for people who think fuzzing is random magic.

Inicia sesión o únete para responder.