Awesome Open Source
Awesome Open Source

kAFL: HW-assisted Feedback Fuzzing for x86 Kernels

This is a fork of the kAFL kernel fuzzer. It can be used for targets that execute efficiently as Qemu/KVM guests, including BIOS, custom kernels and full-blown Linux VMs.

How is it different?

  • kAFL uses Qemu/KVM and Intel PT to provide fast execution and coverage feedback. This allows to run many x86 FW and OS kernels with any desired toolchain and without major modifications.

  • kAFL uses a modular design, using a (homebrew) python fuzzer that can talk to multiple Qemu instances via SHM and pipes. It is designed for parallel and persistent mode fuzzing but also easy to adapt to special cases, such as observing non-determinism and resetting on demand.

  • Redqueen and Grimoire are new generic fuzzer extensions implemented on top of kAFL. Redqueen uses VM introspection to extract runtime inputs to conditional instructions, overcoming typical magic byte and other input checks. Grimoire attempts to identify keywords and syntax from fuzz inputs in order to generate more clever large-scale mutations.

Getting Started

Installation requires multiple components, some of which can depend on Internet connectivity and defaults of your distribution / version. It is recommended to install step by step and manually investigate any reported errors:

$ git clone $this_repo ~/kafl

$ cd ~/kafl
$ ./ deps     # check platform and install dependencies
$ ./ perms    # allow current user to control KVM (/dev/kvm)
$ ./ qemu     # download, patch and build Qemu
$ ./ linux    # download, patch and build Linux

It is safe to re-execute any of these commands after failure, for example if not all dependencies could have been downloaded.

The final step does not automatically install the new Linux kernel but only gives some default instructions. Install according to your preference/distribution defaults, or simply follow the suggested steps:

$ ./ note

After reboot, make sure the new kernel is booted and PT support is detected by KVM:

$ sudo reboot
$ dmesg|grep VMX
 [VMX-PT] Info:   CPU is supported!

Lauch kAFL-Fuzzer/ to verify all python dependencies are met. You should be able to get a help message with the detailed list of parameters:

$ python3 ~/kafl/kAFL-Fuzzer/ -h

You may have to hunt down some python dependencies that did not install correctly (try the corresponding package provided by your distribution!), or set the correct path to the Qemu binary in kAFL-Fuzzer/kafl.ini.

Available Sample Targets

Once the above setup is working, you may try one of the available samples to get started. For this purpose, please consider the supplied helper scripts and READMEs as your hands-on "getting started" guides:

  - targets/uefi_ovmf_64/{,}    - fuzz UEFI/OVMF and EFI apps
  - targets/zephyr_x86_32/{README.rst,}  - fuzz Zephyr (ELF images)
  - targets/{linux,windows,macOS}\*                - fuzz full VMs (snapshots)
  - tests/user_bench/{,,}   - fuzz binutils (user apps)

Note that these scripts and notes were confirmed to work at some point, but we are not in a position to provide fully tested "stable" releases. For samples 3 and 4, you may also refer to kAFL ReadMe and Redqueen Readme.

Visibility / Debug

The application is not meant to execute interactively and does not provide much output beyond major errors. Instead, the status and statistics are logged directly to the workding directory where they can be inspected with separate tools:

  - corpus/       - corpus of inputs, sorted by execution result
  - metadata/     - metadata associated with each input
  - stats         - overall fuzzer status
  - slave_stats_N - individual status of each slave
  - debug.log     - detailed logging (activate with -v)

Most of the status/state files are stored as msgpack. You can use kAFL-Fuzzer/tools/ to dump their content.

A more intuitive user interface can be started like this:

$ python3 ~/kafl/kAFL-Fuzzer/ $workdir

Or use the plot tool to watch as the corpus grows:

$ python3 ~/kafl/kAFL-Fuzzer/ $workdir
$ python3 ~/kafl/kAFL-Fuzzer/ $workdir ~/
$ xdot ~/

kAFL also records some basic stats to plot progress over time:

$ gnuplot -c ~/kafl/tools/stats.plot $workdir/stats.csv

To obtain detailed coverage analysis, you can post-process a given workdir using kAFL-Fuzzer/ This also creates a CSV file to plot discovered edges over time. An example usage can be is provided for the UEFI target:

$ ./targets/uefi_ovmf_64/ cov $workdir

To replay a specific payload or trace its execution in GDB, take a look at kAFL-Fuzzer/


kAFL, Redqueen & Grimoire were originally developed by:

Sergej Schumilo         <[email protected]>
Cornelius Aschermann    <[email protected]>
Robert Gawlik           <[email protected]>
Tim Blazytko            <[email protected]>

This project merges the respective released prototypes and adds various changes in the hope that they are useful. Contributions are welcome.

Current developer(s):

Steffen Schulz <[email protected]>

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (54,388
security (1,908
validation (320
kernel (250
research (203
firmware (159
fuzzing (147
qemu (78
intel (66
kvm (61