Fuzzing
In fuzzing, or fuzz testing, a program is fed large numbers of unexpected, malformed or partly malformed inputs by another program, the fuzzer, which records every input that makes it crash, hang or fail a check.1 Some of the bugs it turns up are a vulnerability: a crash in a parser can become a denial of service, and a memory error in C code can expose the contents of memory. Like Dynamic application security testing, fuzzing runs the code; like a unit test, it is often aimed at a single function inside it.
History
The method comes from the University of Wisconsin-Madison, where Barton Miller set it as a project in his graduate operating systems class in the autumn of 1988, and the resulting report, "An Empirical Study of the Reliability of UNIX Utilities", appeared in Communications of the ACM in December 1990.2 The group has repeated the study four times since, most recently in 2020. In its classic form the test pipes streams of random characters into command-line programs with no model of how they ought to behave, and a program fails only by crashing or hanging.2
How a fuzzer works
A fuzzer has two parts: a generator that produces inputs, and a way to notice failure. The simplest generators produce random bytes. Others draw on lists of known-dangerous values, called fuzz vectors: zero, negative and very large numbers for integer fields, and characters that a parser interprets, such as quotes in SQL, for text fields.1 A field meant to hold 0, 1 or 2 gets 3 or 255, and a program with no safe default case for those values may crash.1
Most fuzzers know the format of their target, because a program rejects input that is not structured enough to pass its first checks. A web server answers only to known methods such as GET, so a fuzzer that keeps GET fixed and varies the rest reaches deeper code faster. The cost is that the closer a fuzzer sticks to the protocol, the fewer odd errors it turns up.1 Grouped by target, there is application fuzzing (the user interface, command-line options, and for web applications URLs, forms and API requests), protocol fuzzing (forged network packets, or a proxy that changes requests and replays them) and file format fuzzing (malformed files opened one after another).1
Coverage-guided fuzzing
Coverage-guided fuzzers measure code coverage while they run. libFuzzer, part of the LLVM compiler project, calls a target function in the same process, records which parts of the code each input reached, and changes (mutates) the inputs in its corpus to reach as much code as possible. An input that reaches a path no earlier input reached is saved to the corpus and becomes a parent for further mutations.3 The corpus is best seeded with a mix of valid and invalid samples; libFuzzer runs without seeds but is slower on structured formats.3 For C and C++, libFuzzer is usually combined with a sanitizer such as AddressSanitizer, and a sanitizer failure is reported in the same way as a crash.3
Go has had coverage-guided fuzzing in its standard toolchain since Go 1.18. The command go test -fuzz=FuzzName runs until it finds a failure or is stopped, and -fuzztime sets a limit. Go counts as a failure a panic, a failed check in the test, an exit or stack overflow, and any single run longer than one second.4
Reading the results
When a run fails, Go shrinks the failing input to the smallest and most readable value that still fails. Go then writes it to testdata/fuzz/<name>/, where every later go test run replays it, so the input becomes a regression test once the bug is fixed.4 In Go's tutorial, a fuzz test found that a function reversing a string byte by byte turns some text into invalid UTF-8, a case the hand-written tests missed.5
Fuzzing web application code
For JavaScript, Jazzer.js is a coverage-guided fuzzer for Node.js based on libFuzzer. A fuzz target is a function that receives a buffer of fuzzer data:6
npm install --save-dev @jazzer.js/core
// FuzzTarget.js
module.exports.fuzz = function (data /*: Buffer */) {
const fuzzerData = data.toString();
myAwesomeCode(fuzzerData);
};
npx jazzer FuzzTargetJazzer.js also runs fuzz tests inside Jest. For Python, Google's Atheris works the same way and reports a failure when the code under test raises an uncaught exception.7 Against a running site, the ZAP fuzzer replaces a highlighted part of any request with values from built-in payload lists, add-ons or scripts.8
Limits
A fuzzer detects what its pass rule can see: crashes, hangs, exceptions and sanitizer reports. A query that returns another user's rows, as in Insecure direct object reference, raises no error and passes. The bugs fuzzers find tend to be simple ones, and on a closed system the impact of a crash is hard to judge without a debugger.1 Go leaves the length of a run to the tester, since a run that finds no failure can continue indefinitely.4
OSS-Fuzz and Heartbleed
Heartbleed, CVE-2014-0160, was a flaw in OpenSSL's handling of the TLS heartbeat extension that let a client read up to 64 kilobytes of server memory per request, and repeat the request. It was found independently by engineers at Codenomicon, while working on the company's security testing tools, and by Neel Mehta of Google, and became public on 7 April 2014.9 Google describes it as a simple buffer overflow that fuzzing could have found, and launched OSS-Fuzz in 2016 in response: a free service that runs fuzzers on open source projects and reports bugs to their maintainers in private.10 OSS-Fuzz supports C and C++, Rust, Go, Python, Java, JavaScript and Lua, and by August 2023 had helped fix over 10,000 vulnerabilities and 36,000 other bugs in 1,000 projects.10
Related methods
Fuzzing runs the code, where Static application security testing reads the source without running it. A Dynamic application security testing tool also sends input to running code, but its input is a list of known attack strings and it looks for specific responses. Software composition analysis checks dependencies for flaws that are already published, such as Heartbleed's CVE record.
See also
- Static application security testing
- Dynamic application security testing
- Penetration testing
- Vulnerability scanning
- Input validation
- Denial-of-service attack
- Category: Testing and standards
References
- a b c d e f OWASP Foundation. "Fuzzing". OWASP Community.
- a b Miller, Barton P. (updated 1 August 2023). "Fuzz Testing of Application Reliability". University of Wisconsin-Madison.
- a b c LLVM Project. "libFuzzer, a library for coverage-guided fuzz testing". LLVM documentation.
- a b c The Go Project. "Go Fuzzing". go.dev.
- back The Go Project. "Tutorial: Getting started with fuzzing". go.dev.
- back Code Intelligence. "Jazzer.js". GitHub.
- back Google. "Atheris: A Coverage-Guided, Native Python Fuzzer". GitHub.
- back ZAP. "Fuzzing". ZAP documentation.
- back Codenomicon (2014). "The Heartbleed Bug". heartbleed.com.
- a b Google. "OSS-Fuzz". OSS-Fuzz documentation.
External links
- Tutorial: Getting started with fuzzing, go.dev
- OSS-Fuzz documentation, Google