Skip to content

Commit 0a9de81

Browse files
authored
Merge pull request #70 from trailofbits/libafl-section
Add LibAFL section
2 parents 4af612d + e2e94fa commit 0a9de81

File tree

31 files changed

+7109
-7
lines changed

31 files changed

+7109
-7
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ node_modules/*
88
resources/
99

1010
.direnv/
11-
materials/fuzzing/aflpp/out
11+
materials/fuzzing/aflpp/out
12+
13+
target/

content/docs/fuzzing/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ main.rs (Rust): Example code with a bug that causes an abort. The `check_buf` fu
179179
{{< tabs "harness" >}}
180180
{{< tab "C/C++" >}}
181181
```C++
182+
#include <stddef.h>
182183
#include <stdint.h>
183184
#include <stdlib.h>
184185

content/docs/fuzzing/c-cpp/10-libfuzzer/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ If the LLVM version provided by your distribution is outdated, you can install a
3030

3131
## Compile a fuzz test {#compile-a-fuzz-test}
3232

33-
Creating a binary that fuzzes the SUT is straightforward. The resulting binary will use the harness and the libFuzzer runtime. If using the Clang compiler, the following command produces a binary, called `fuzz`, in the current working directory:
33+
Creating a binary that fuzzes the SUT is straightforward. We are reusing the `harness.cc` and `main.cc` from the [introduction]({{% relref "fuzzing#introduction-to-fuzzers" %}}). The resulting binary will use the harness and the libFuzzer runtime. If using the Clang compiler, the following command produces a binary, called `fuzz`, in the current working directory:
3434

3535
{{< tooltipHighlight shell
3636
"Compiler for C++"

content/docs/fuzzing/c-cpp/11-aflpp/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ weight: 2
1010
The [AFL++](https://github.com/AFLplusplus/AFLplusplus) fuzzer is a fork from the [AFL](https://github.com/google/AFL) fuzzer. It offers better fuzzing performance and more advanced features while still being a very stable alternative to libFuzzer. A major benefit over libFuzzer is that AFL++ has stable support for running fuzzing campaigns on multiple cores (see [Multi-core fuzzing](#multi-core-fuzzing)).
1111

1212
{{< fuzzing/intro-os >}}
13-
AFL++ supports different environments like [macOS](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/INSTALL.md#macos-x-on-x86-and-arm64-m1), but there are caveats. If you only have a macOS computer, we recommend fuzzing on a local x64_64 VM or renting one on DigitalOcean, AWS, Hetzner, etc to simplify the setup.
13+
AFL++ supports different environments like [macOS](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/INSTALL.md#macos-x-on-x86-and-arm64-m1), but there are caveats. If you only have a macOS computer, we recommend fuzzing on a local x86_64 VM or renting one on DigitalOcean, AWS, Hetzner, etc to simplify the setup.
1414

1515

1616
## Installation {#installation}
@@ -217,7 +217,7 @@ The AFL++ fuzzer offers multiple compilation modes, including [LTO](https://gith
217217

218218
Depending on the mode you choose, use a different compilation command: `afl-clang-lto`, `afl-clang-fast`, `afl-gcc`, or `afl-clang`, respectively. The C++ versions are also available by appending `++`, which gives, e.g., `afl-clang-lto++`. The LTO mode is recommended because it features a better and faster instrumentation of the SUT. However, this depends on your project whether LTO mode works. Give it a try and fall back to the other modes if compilation fails.
219219

220-
If you use the Clang compiler and want to use the LLVM mode, then the following command produces a binary `fuzzer`. Essentially, we are replacing the call to `clang++` with `afl-clang-fast++`.
220+
If you use the Clang compiler and want to use the LLVM mode, then the following command produces a binary `fuzzer`. Essentially, we are replacing the call to `clang++` with `afl-clang-fast++`. We are reusing the `harness.cc` and `main.cc` from the [introduction]({{% relref "fuzzing#introduction-to-fuzzers" %}})
221221

222222

223223
{{< tooltipHighlight shell
@@ -841,7 +841,7 @@ When running the fuzzer, the above heap-buffer overflow will be discovered by th
841841
If you are fuzzing C projects that produce static libraries, you can follow this recipe:
842842

843843
1. Read the `INSTALL` file in the project's codebase (or other appropriate documentation) and find out how to create a static library.
844-
2. Set the compiler to Clang, and pass additional flags to the compiler during compilation.
844+
2. Set the compiler to AFL++'s comiler wrapper (e.g. `afl-clang-fast++`), and pass required flags to the compiler during compilation.
845845
3. Build the static library, set the environment variable `AFL_USE_ASAN=1`, and pass the flag `-fsanitize=fuzzer-no-link `to the C compiler, which enables fuzzing-related instrumentations, without linking in the fuzzing engine. The runtime, which includes the `main` symbol, is linked later when using the `-fsanitize=fuzzer` flag. The build step will create a static library, which we will refer to as `$static_library`. The environment variable enables ASan to detect memory corruption.
846846
4. Find the compiled static library from step 3 and call: `./afl++ <host/docker> AFL_USE_ASAN=1 afl-clang-fast++ -fsanitize=fuzzer $static_library harness.cc -o fuzz`.
847847
5. You can start fuzzing by calling `./afl++ <host/docker> afl-fuzz -i seeds -o out -- ./fuzz`.

0 commit comments

Comments
 (0)