diff options
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/argv_fuzzing/Makefile | 48 | ||||
-rw-r--r-- | experimental/argv_fuzzing/README.md | 16 | ||||
-rw-r--r-- | experimental/argv_fuzzing/argvfuzz.c | 49 |
3 files changed, 113 insertions, 0 deletions
diff --git a/experimental/argv_fuzzing/Makefile b/experimental/argv_fuzzing/Makefile new file mode 100644 index 00000000..da0eaed6 --- /dev/null +++ b/experimental/argv_fuzzing/Makefile @@ -0,0 +1,48 @@ +# +# american fuzzy lop - argvfuzz +# -------------------------------- +# +# Copyright 2019 Kjell Braden <afflux@pentabarf.de> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# + +.PHONY: all install clean + +ifndef AFL_NO_X86 +PREFIX ?= /usr/local +BIN_PATH = $(PREFIX)/bin +HELPER_PATH = $(PREFIX)/lib/afl + +CFLAGS = -fPIC -Wall -Wextra +LDFLAGS = -shared -ldl + +all: argvfuzz32.so argvfuzz64.so + +argvfuzz32.so: argvfuzz.c + $(CC) -m32 $(CFLAGS) $^ $(LDFLAGS) -o $@ || echo "argvfuzz32 build failure (that's fine)" + +argvfuzz64.so: argvfuzz.c + $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ + +install: argvfuzz32.so argvfuzz64.so + if [ -f argvfuzz32.so ]; then set -e; install -m 755 argvfuzz32.so $(DESTDIR)$(HELPER_PATH)/; fi + install -m 755 argvfuzz64.so $(DESTDIR)$(HELPER_PATH)/ + +clean: + rm -f argvfuzz32.so argvfuzz64.so + +else + +all: + @echo "[!] Note: skipping compilation of argvfuzz (AFL_NO_X86 set)." + +install: + +clean: + +endif diff --git a/experimental/argv_fuzzing/README.md b/experimental/argv_fuzzing/README.md new file mode 100644 index 00000000..fa8cad80 --- /dev/null +++ b/experimental/argv_fuzzing/README.md @@ -0,0 +1,16 @@ +# argvfuzz + +afl supports fuzzing file inputs or stdin. When source is available, +`argv-fuzz-inl.h` can be used to change `main()` to build argv from stdin. + +`argvfuzz` tries to provide the same functionality for binaries. When loaded +using `LD_PRELOAD`, it will hook the call to `__libc_start_main` and replace +argv using the same logic of `argv-fuzz-inl.h`. + +A few conditions need to be fulfilled for this mechanism to work correctly: + +1. As it relies on hooking the loader, it cannot work on static binaries. +2. If the target binary does not use the default libc's `_start` implementation + (crt1.o), the hook may not run. +3. The hook will replace argv with pointers to `.data` of `argvfuzz.so`. If the + target binary expects argv to be living on the stack, things may go wrong. diff --git a/experimental/argv_fuzzing/argvfuzz.c b/experimental/argv_fuzzing/argvfuzz.c new file mode 100644 index 00000000..65fb5e13 --- /dev/null +++ b/experimental/argv_fuzzing/argvfuzz.c @@ -0,0 +1,49 @@ +/* + american fuzzy lop - LD_PRELOAD for fuzzing argv in binaries + ------------------------------------------------------------ + + Copyright 2019 Kjell Braden <afflux@pentabarf.de> + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at: + + http://www.apache.org/licenses/LICENSE-2.0 + + */ + +#define _GNU_SOURCE /* for RTLD_NEXT */ +#include <dlfcn.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include "argv-fuzz-inl.h" + +int __libc_start_main(int (*main)(int, char **, char **), int argc, char **argv, + void (*init)(void), void (*fini)(void), + void (*rtld_fini)(void), void *stack_end) { + + int (*orig)(int (*main)(int, char **, char **), int argc, char **argv, + void (*init)(void), void (*fini)(void), void (*rtld_fini)(void), + void *stack_end); + int sub_argc; + char **sub_argv; + + (void)argc; + (void)argv; + + orig = dlsym(RTLD_NEXT, __func__); + + if (!orig) { + + fprintf(stderr, "hook did not find original %s: %s\n", __func__, dlerror()); + exit(EXIT_FAILURE); + + } + + sub_argv = afl_init_argv(&sub_argc); + + return orig(main, sub_argc, sub_argv, init, fini, rtld_fini, stack_end); + +} + |