American F Lop

Fuzzing can be fun

Posted by NSEcho on 2021-02-05 19:04:36


Recently, I have started fuzzing with AFL (American Fuzzy Lop) to try to find some vulnerabilities. For the target, I have chosen shell from prakhar1989 on the prakhar1989/shell repo.

AFL is very versatile fuzzer which basically works like this: * Instrument binary * Prepare input * Start fuzzing and wait

Let’s go through all of these three steps in this post and in another post I will write how to analyze crashes.


This is basically small shell, written probably for learning purposes with limited functionality. Clone it from github repo, run make on it and start exploring w4118_sh binary a bit.

# git clone
# cd shell
# make
# ./w4118_sh
$ /bin/ls
Makefile	demo_run.txt	shell.h	shell.c		w4118_sh 

Instrumenting the binary

Let’s now instrument our binary to use AFL C compiler, called afl-clang-fast. Inside Makefile we need to substitute gcc with ${CC} so we can pass our own CC variable to make process.

It should look like this:

$ cat Makefile

all: shell

shell: shell.c
	${CC} -g -o $(EXECUTABLE) shell.c -Wall -W


Now for the compilation part we simply need to pass our own CC variable and instrumentaion is done. Two more steps to go.

We also need to pass AFL_HARDEN=1 variable which per AFL documentation means:

Setting AFL_HARDEN automatically adds code hardening options when invoking the downstream compiler. This currently includes -D_FORTIFY_SOURCE=2 and -fstack-protector-all. The setting is useful for catching non-crashing memory bugs at the expense of a very slight (sub-5%) performance loss.

$ CC=afl-clang-fast AFL_HARDEN=1 make`
afl-clang-fast -g -o w4118_sh shell.c -Wall -W
afl-cc ++3.01a by Michal Zalewski, Laszlo Szekeres, Marc Heuse - mode: LLVM-PCGUARD
shell.c:398:4: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
                        ^~~~ ~~~~~~~~~~
[+] Instrumented 148 locations with no collisions (hardened mode).
1 warning generated.

Prepare input

AFL expects us to provide input directory which will contain our input string, or binary depending on our case. This does not apply in all fuzzing cases, but for this one, this will work. Sample input should be something simple that would generally work inside our target like /bin/ls which we saw that works inside our shell binary.

On the business now.

$ mkdir in
$ echo '/bin/ls' > in/a


When we are done with previous two steps, it is now time to fuzz and the process is incredibly simple.

$ afl-fuzz -i in/ -o out ./w4118_sh
[+] afl++ is open source, get it at
[+] NOTE: This is v3.x which changes defaults and behaviours - see
[+] No -M/-S set, autoconfiguring for "-S default"
[*] Getting to work...
[+] Using exponential power schedule (FAST)
[+] Enabled testcache with 50 MB
[*] Checking core_pattern...
[+] You have 1 CPU core and 4 runnable tasks (utilization: 400%).
[*] Setting up output directories...
[+] Output directory exists but deemed OK to reuse.
[*] Deleting old session data...
[+] Output dir cleanup successful.
[*] Scanning 'in/'...
[+] Loaded a total of 1 seeds.
[*] No auto-generated dictionary tokens to reuse.
[*] Creating hard links for all input files...
[*] Validating target binary...
[*] Attempting dry run with 'id:000000,time:0,orig:a'...
[*] Spinning up the fork server...
[+] All right - fork server is up.
[*] Target map size: 160
    len = 8, map size = 26, exec speed = 1030 us
[+] All test cases processed.
[+] Here are some useful stats:

    Test case count : 1 favored, 0 variable, 0 ignored, 1 total
       Bitmap range : 26 to 26 bits (average: 26.00 bits)
        Exec timing : 1030 to 1030 us (average: 1030 us)

[*] No -t option specified, so I'll use exec timeout of 20 ms.
[+] All set and ready to roll!

Then you should screen like this:

AFL running

Generally, you should wait minmum of one cycle to end your fuzzing.

Confirming crash

After running for one minute, we already saw that we have created 18 unique crashes. Let’s take on of those crash strings and run it on our binary to see that we really crashed it.

Crashes are inside your out/ directory which you passed to afl-fuzz using -o flag.

$ ls out/default/crashes
$ ./w4118_sh < out/default/crashes/'id:000008,sig:11,src:000038,time:14634,op:havoc,rep:16'
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
error: No such file or directory
Segmentation fault (core dumped)

There you have it, we have really crashed our binary and in the second post I will analyze what exactly this vulnerability is and if it is really exploitable.