Definition
Mutation-based fuzzing is a kind of fuzzing §10.9, the automated testing of a program on very many inputs, in which each new input is made by changing an existing input, called a seed, with small random edits: flipping bits, replacing, inserting or deleting bytes, or splicing two inputs together. A valid seed already has the right structure, so most of its mutants, the inputs made from it, keep that structure and reach code that random bytes would not. Unlike generation-based fuzzing §10.11, mutation-based fuzzing needs no model of the input format.
The idea
Random bytes almost never form a valid input. A file format typically opens with a fixed signature of several bytes, then has length fields that must match the data, and ends with a check value computed over the data. A random input fails the first check, and the fuzzer spends its time in the same few lines of rejection code. A real file, by contrast, passes every check. Changing one byte of it produces an input that is still almost valid and that reaches the code behind the checks, where the interesting behavior is. Mutation-based fuzzing explores the neighborhood of known good inputs.
The weakness comes from the same structure. Nested checks reject most mutants at the first check that a mutation breaks. A checksum §4.32 or CRC (cyclic redundancy check), a short value computed from the data that the receiver recomputes and compares, is a typical such check: a CRC-32 detects every change confined to 32 consecutive bits, so every single-byte mutation of the data it covers is rejected. Length fields, fixed signatures and syntax rules act the same way. Getting past them takes either help for the fuzzer or a mutant whose dependent fields have been repaired.
How it works
A mutation-based fuzzer repeats one loop.
Select an input from the corpus, the current set of inputs worth mutating; at the start this is the seed corpus §10.14.
Mutate it with one or several edits chosen at random: flip a bit; replace a byte with a random value or a boundary value such as
0x00,0x7f,0x80or0xff; insert or delete bytes; copy a block within the input; insert a token from an input dictionary §10.16, a list of byte strings that matter to the format, such as keywords and signatures; or splice two corpus inputs together.Run the target on the mutant through the fuzz harness §10.13, the code that hands one input to the target, and apply the test oracle §10.5, the check that decides whether the run failed.
Keep the mutant in the corpus if the feedback says it is new, for example because it reached code that no earlier input reached.
Four techniques get mutants past nested checks.
Seeds that cover the format. Each optional part of the format that appears in some seed is a small edit away; a part that appears in no seed must arise by chance.
Dictionaries and comparison feedback. A fuzzer can record the values that the target compares its input against and insert those values into new mutants. AFL++ §10.27, the maintained successor of the fuzzer American Fuzzy Lop (AFL), does this in its CmpLog mode, and libFuzzer §10.26 uses comparison tracing that the compiler adds to the target. Checks for exact values, such as signatures, then stop being a barrier.
Repairing mutators. A structure-aware mutation §10.17, made by a mutator that knows the format, edits the content and then recomputes the dependent fields: lengths, counts and checksums. Both libFuzzer and AFL++ accept a custom mutator written by the tester.
Checks disabled in a fuzzing build. The target is compiled with the checksum comparison turned off, by convention under the macro
FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. Every finding must then be confirmed on an input with a correct checksum, and the fuzzing build must never ship.
An authentication §1.6 tag is not a checksum. Anyone can recompute a checksum; a message authentication code §5.7 (MAC), a tag computed with a secret key, can be recomputed only by a holder of the key. No mutation produces a valid MAC by chance: a random 128-bit tag is right with probability . To fuzz the parser behind a MAC check, the harness either holds a test key and computes the correct tag for every mutant, or calls the parser directly, below the check. Either way, the campaign tests how the parser handles authenticated input, which matters if a key holder sends bad data or a key leaks. It does not show that an attacker without the key can reach the parser, and it does not test the MAC check itself. A separate campaign sends mutants with wrong tags and requires that every one is rejected with no change of state.
Worked example
A toy format has three parts: a 1-byte length , then payload bytes, then a 1-byte checksum equal to the sum of all earlier bytes modulo 256. The parser rejects an input whose total size is not bytes or whose checksum does not match. The seed carries the payload 0x10 0x20 0x30 0x40, so . Its checksum is , which is 0xa4. The seed is the 6 bytes 04 10 20 30 40 a4, written in hexadecimal.
Consider every single-byte mutation of the seed: 6 positions, each with 255 other values, mutants.
Changing the length byte makes , so the length check rejects the mutant.
Changing the checksum byte makes the checksum wrong, so the checksum check rejects the mutant.
Changing a payload byte by , where is a whole number from to 255 other than 0, changes the sum by . Modulo 256 that change is never 0, because no such is a multiple of 256, so the checksum check rejects the mutant.
All 1530 mutants stop at the two checks, and the payload parser never sees a changed payload.
A repairing mutator changes a payload byte and then recomputes the checksum. Changing 0x20 to 0x21 raises the sum by 1, to 165, so the repaired checksum is 0xa5. All payload mutants now pass both checks and reach the payload parser. The fuzzer also keeps a second stream of unrepaired mutants, and of length mutants such as with only 4 payload bytes, so that the rejection paths stay tested. If the format ended with a 16-byte MAC instead of the checksum, the repair would need the key, as described above.
Stated precisely
Model the target as a chain of checks that an input must pass, followed by the code behind them. For each check, a mutation strategy either preserves it (the check’s condition stays true, by repair or by the choice of edits), violates it on purpose, or ignores it.
A campaign that preserves all of to gives evidence about only for inputs that satisfy all of them.
A campaign that disables check in the build gives evidence about under the assumption that holds, and none about itself.
Evidence about check comes only from inputs that violate , compared with the required outcome: rejection with no change of state.
For a check value of bits that anyone can compute, a mutant that changes the covered bytes at random without repairing the check value passes with probability about ; a small change that the check is built to detect, such as any single changed byte under a CRC-32, never passes; a repaired mutant always passes. A MAC of bits differs in one point: without the key no repair is possible, and each guessed tag passes with probability about .
Limits and common mistakes
Over-repair hides bugs. A mutator that always repairs lengths and checksums never sends the inconsistent inputs that the parser must reject. Keep unrepaired and deliberately inconsistent mutants as well.
Mutants stay near their seeds. A message type, an option or a nesting depth that appears in no seed is reached rarely or never. Review the seed corpus against the format specification, or combine mutation with generation-based fuzzing.
A finding from a build with checks disabled may be unreachable in the real program. Reproduce it with every check enabled and a correct checksum before reporting it; a campaign behind a test key is reported as testing of the parser under the assumption that the input was authenticated.
Mutation-based fuzzing is not mutation testing §10.45. Mutation testing changes the program, not the input, to measure whether a test suite notices the change.
The limits of fuzzing in general apply: an input that reaches new code shows where the search went, not that the result there was correct, and the oracle sees only the failures it checks for.
Questions answered
Can mutations get past nested checksums and syntax constraints?
Random byte-level mutations alone mostly cannot get past nested checksums and syntax constraints, but mutations combined with repair, feedback and good seeds can. In mutation-based fuzzing, each new test input is made by editing an existing valid input, called a seed. Every check in the target, such as a length field that must match the data, a fixed signature, a syntax rule, or a checksum (a value computed from the data that the target recomputes and compares), rejects the edits that break it, and each later check sees only what the earlier checks let through. A checksum is a hard case for blind edits: under a CRC-32 (32-bit cyclic redundancy check), every single-byte change of the covered data is rejected.
Four techniques get past such checks.
Seeds that contain every part of the format, so that deep structures are a small edit away.
Dictionaries of the format’s keywords and signatures, and comparison feedback, in which the fuzzer copies the values that the target compares against into new inputs.
Structure-aware mutators that edit the content and then recompute lengths, counts and checksums.
A fuzzing build that disables a checksum comparison, with every finding confirmed afterwards on an input with a correct checksum.
The campaign must still send unrepaired and inconsistent mutants, because the rejection paths are code that must be tested too.
A cryptographic authentication tag, a message authentication code (MAC) computed with a secret key, cannot be passed by mutation, because nobody without the key can compute it. A harness that holds a test key, or that calls the code below the tag check directly, tests the parser behind the check; it does not show that an attacker can get past the check.
Related entries: Structure-aware mutation (§10.17), Seed corpus (§10.14), Message authentication code (MAC) (§5.7), Checksum versus CRC (§4.32), Input dictionary (§10.16), Mutation testing (§10.45), Generation-based fuzzing (§10.11). Further reading: [24, 107].