Back to Articles

AFL++: Breaking Down the Attack

Updated: 8 min read

What is Fuzzing?

Fuzzing is a software testing technique that generates a large number of unexpected inputs and observes what happens. Instead of manually searching for errors, fuzzing automatically feeds a program with various inputs and checks how it behaves.

If a program crashes, hangs, or behaves unexpectedly, the fuzzer flags it as a potential vulnerability. Fuzzing automates this process and can test software significantly faster than a human.

Seed Generation

How does it work in practice?

You select a target — a program, library, or network service — and provide it with input data that the fuzzer will randomly modify (generate random values). Fuzzing does not mean simply entering random data — this is one approach, but there are others based on correct input structures and sequences.

Modern fuzzers often use mutation or generation strategies that allow them to track execution paths and predict inputs that are likely to reach new or interesting parts of the program. They may also combine fuzzing with other techniques, such as symbolic execution or sanitizers (for example, ASan), to identify memory-related errors and other vulnerabilities.

Fuzzing Objectives:

  • Vulnerabilities and security issues (buffer overflows, SQL injection, memory corruption).
  • Failures (software crashes, hangs, or unhandled exceptions).
  • Unexpected behavior (data corruption, infinite loops, incorrect results).

Types of Fuzzing

  • Web Application Fuzzing often involves automatically discovering directories or parameters. The fuzzer repeatedly tests a website using a large number of crafted or malformed URLs and request templates to identify hidden endpoints, control panels, or forgotten resources. In practice, this can lead to discovering endpoints that should only be accessible after authentication, or identifying incorrect configurations that expose confidential functionality. What starts as a seemingly harmless search can quickly reveal the application's attack surface and point to missing access controls.

  • File Format Fuzzing targets parsers and decoders — programs that accept files as input. A typical scenario involves feeding PDF readers malformed or deliberately corrupted PDF files. Because parsers generally make assumptions about the structure and length of the input, a malformed file can cause crashes, memory corruption, or other undefined behavior. These issues are particularly important because they often indicate bugs that could potentially be exploited. An attacker could use such vulnerabilities to send a victim a malicious document.

  • Network Protocol Fuzzing focuses on the data a server receives over a network. In this case, the fuzzer generates unexpected or incorrectly formatted packets and sends them to services that implement a specific protocol. Servers that do not properly validate incoming packets may crash, hang, or behave unpredictably when confronted with unusual input. Such behavior can indicate buffer overflows or logical flaws in protocol handling — vulnerabilities that attackers may potentially exploit remotely.

Across all three cases, the principle is the same: automated input generation systematically reveals assumptions that software may never verify during normal operation. In practice, the results can range from discovering misconfigured web endpoints and identifying flaws in software components to uncovering remotely exploitable vulnerabilities in network services. This is why fuzzing is an important tool for security professionals, and why integrating fuzzing into development and security testing processes can significantly improve software resilience.

Fuzzing Categories

  • Mutation-Based Fuzzing starts with existing valid inputs and introduces small modifications, such as flipping bits, inserting additional bytes, or reordering fields. It relies on existing data and is fast and straightforward, making it useful for identifying errors triggered by unexpected edge cases.

  • Generation-Based Fuzzing takes a different approach by creating new data from scratch using a model or grammar. This makes it particularly effective for complex file formats or protocols where structure matters and random modifications are unlikely to produce meaningful inputs.

  • Feedback-Guided Fuzzing adds another layer of intelligence by observing how a program executes and prioritizing inputs that explore new or previously untested code paths. By learning from execution results, these techniques become increasingly effective at discovering vulnerabilities. In practice, they are often combined with other approaches to balance input quality, execution speed, and exploration depth, ultimately increasing the chances of uncovering serious vulnerabilities.

Fuzzing with AFL++

Installing AFL++

There are several ways to install AFL++, but I recommend using the source code from GitHub without Docker or any virtualization.

sudo apt-get update
sudo apt-get install -y build-essential python3-dev automake cmake git flex bison libglib2.0-dev libpixman-1-dev python3-setuptools cargo libgtk-3-dev
# try to install llvm 14 and install the distro default if that fails
sudo apt-get install -y lld-14 llvm-14 llvm-14-dev clang-14 || sudo apt-get install -y lld llvm llvm-dev clang
sudo apt-get install -y gcc-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-plugin-dev libstdc++-$(gcc --version|head -n1|sed 's/\..*//'|sed 's/.* //')-dev
sudo apt-get install -y ninja-build # for QEMU mode
sudo apt-get install -y cpio libcapstone-dev # for Nyx mode
sudo apt-get install -y wget curl # for Frida mode
sudo apt-get install -y python3-pip # for Unicorn mode
git clone https://github.com/AFLplusplus/AFLplusplus
cd AFLplusplus
make distrib
sudo make install

make distrib also builds the FRIDA, QEMU, and Unicorn modes, among others. If you only need a basic AFL++, run make 1.

Let's move on to an example provided by Alex Maleno:

https://github.com/alex-maleno/Fuzzing-Module.git

The first step is to clone the repository into the target directory:

git clone https://github.com/alex-maleno/Fuzzing-Module.git

The next step is to navigate to the exercise1 folder and add the AFL++ tooling command to the build:

cd exercise1
mkdir build; cd build
CC=$YOUR_PATH/AFLplusplus/afl-clang-fast CXX=$YOUR_PATH/AFLplusplus/afl-clang-fast++ cmake ..

We set the CC and CXX environment variables to afl-clang-fast and afl-clang-fast++, respectively.

These environment variables tell the build system to use the modified Clang compilers provided by AFL++ instead of the standard compilers for C and C++.

cmake .. is used to configure the build system. It tells CMake, running from the build directory, to generate project files for the source code in the parent directory. You can use the generated Makefiles or Ninja build files, which will compile and link the project.

The above AFL++ environment variables, set during compilation, insert lightweight hooks that enable the fuzzer to monitor the execution path.

Compilation and Build

Once CMake has generated the build files, run make to compile the project. Since the toolchain uses afl-clang-fast / afl-clang-fast++, the resulting binary will be built with AFL++ instrumentation.

For this example, the build process creates an executable named simple_crash, as specified in CMakeLists.txt (add_executable(simple_crash simple_crash.cpp)). Once the build is complete, running ./simple_crash will launch the compiled, instrumented target, which is now ready to be controlled by AFL++ for fuzzing.

Seed

In AFL++, a seed is any initial input file placed in the input directory. The fuzzer uses these files as starting points for generating test cases.

Good seeds are small, valid examples that exercise meaningful code paths — ideally, a minimal valid file accompanied by several diverse real-world examples. They give the fuzzer useful structure for mutations and help it reach deeper parts of the program.

Avoid large, unrelated files or purely random fragments.

Tip: Keep a collection of compact, diverse seeds and add a dictionary of important tokens if the format uses recognizable keywords. This can speed up the discovery of interesting vulnerabilities.

mkdir seeds; cd seeds
for i in {0..4}; do dd if=/dev/urandom of=seed_$i bs=64 count=10; done

This command creates seed files for our exercise1 program.

Fuzzing Objectives

To start fuzzing, first run AFL-Fuzz with the required input and output directories. For example:

$YOUR_PATH/AFLplusplus/afl-fuzz -i /build/seeds/ -o out -m none -- /build/simple_crash

AFL++ results for build/simple_crash

Triage

AFL++ instrumentation adds additional instructions to the target program, allowing it to track code coverage and detect crashes during execution. This is useful for identifying potentially vulnerable behavior and understanding which inputs trigger unexpected conditions.

App NameMyID
Package Namecom.vzlavcggac.vslaxgtkgppikawamgmasftqmpjgg...
File Size2.73 MB (2865636 bytes)
Threat CategoryTrojan, Banker
Malware FamilyAjina, SMS Spy
MD5sume0ec4d40158b30564d737feec068572c

After saving the configuration, open simple_crash.cpp and run the application. Press F5 or choose Run → Start Debugging. If the application stops at the breakpoint, press Continue to proceed with execution and analyze the generated crash.

Share:

Ready to Assess Your Organization’s Cybersecurity Readiness?

ONESEC helps organizations assess risks, evaluate their information security posture, and develop a roadmap for further action.

Read Also

View All Articles
ONESEC