aboutsummaryrefslogtreecommitdiff
path: root/examples/aflpp_driver
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-06-09 19:25:09 +0200
committerGitHub <noreply@github.com>2020-06-09 19:25:09 +0200
commit12bdefe00e38cdc3dd8cb028eeac325ab2e94e16 (patch)
tree0d321d362a19ff19a4a98dcd1b9b72601945695f /examples/aflpp_driver
parent748238d6ab4aeb7f34958d4c37c5ef200ad22463 (diff)
parent81829d132bebcb42c0e289bb5788b8f2b29c1599 (diff)
downloadafl++-12bdefe00e38cdc3dd8cb028eeac325ab2e94e16.tar.gz
Merge pull request #392 from AFLplusplus/dev
Push to master
Diffstat (limited to 'examples/aflpp_driver')
-rw-r--r--examples/aflpp_driver/GNUmakefile24
-rw-r--r--examples/aflpp_driver/aflpp_driver.cpp21
-rw-r--r--examples/aflpp_driver/aflpp_driver_test.cpp20
-rw-r--r--examples/aflpp_driver/aflpp_qemu_driver.c38
-rw-r--r--examples/aflpp_driver/aflpp_qemu_driver_hook.c22
5 files changed, 114 insertions, 11 deletions
diff --git a/examples/aflpp_driver/GNUmakefile b/examples/aflpp_driver/GNUmakefile
index a681d2cf..7ddfc485 100644
--- a/examples/aflpp_driver/GNUmakefile
+++ b/examples/aflpp_driver/GNUmakefile
@@ -9,7 +9,7 @@ endif
FLAGS=-O3 -funroll-loops
-all: libAFLDriver.a
+all: libAFLDriver.a libAFLQemuDriver.a aflpp_qemu_driver_hook.so
aflpp_driver.o: aflpp_driver.cpp
$(LLVM_BINDIR)clang++ $(FLAGS) -stdlib=libc++ -funroll-loops -std=c++11 -c aflpp_driver.cpp
@@ -17,5 +17,25 @@ aflpp_driver.o: aflpp_driver.cpp
libAFLDriver.a: aflpp_driver.o
ar ru libAFLDriver.a aflpp_driver.o
+debug:
+ $(LLVM_BINDIR)clang++ -D_DEBUG=\"1\" $(FLAGS) -stdlib=libc++ -funroll-loops -std=c++11 -c aflpp_driver.cpp
+ ar ru libAFLDriver.a aflpp_driver.o
+
+
+aflpp_qemu_driver.o: aflpp_qemu_driver.c
+ $(LLVM_BINDIR)clang $(FLAGS) -O0 -funroll-loops -c aflpp_qemu_driver.c
+
+libAFLQemuDriver.a: aflpp_qemu_driver.o
+ ar ru libAFLQemuDriver.a aflpp_qemu_driver.o
+
+aflpp_qemu_driver_hook.so: aflpp_qemu_driver_hook.o
+ $(LLVM_BINDIR)clang -shared aflpp_qemu_driver_hook.o -o aflpp_qemu_driver_hook.so
+
+aflpp_qemu_driver_hook.o: aflpp_qemu_driver_hook.c
+ $(LLVM_BINDIR)clang -fPIC $(FLAGS) -funroll-loops -c aflpp_qemu_driver_hook.c
+
+test: libAFLDriver.a aflpp_driver_test.cpp
+ afl-clang-fast++ -Wl,--allow-multiple-definition -stdlib=libc++ -funroll-loops -std=c++11 -o aflpp_driver_test aflpp_driver_test.cpp libAFLDriver.a
+
clean:
- rm -f *.o libAFLDriver*.a *~ core
+ rm -f *.o libAFLDriver*.a libAFLQemuDriver.a aflpp_qemu_driver_hook.so *~ core aflpp_driver_test
diff --git a/examples/aflpp_driver/aflpp_driver.cpp b/examples/aflpp_driver/aflpp_driver.cpp
index 3dcc8c3c..a60eb264 100644
--- a/examples/aflpp_driver/aflpp_driver.cpp
+++ b/examples/aflpp_driver/aflpp_driver.cpp
@@ -90,7 +90,7 @@ If 1, close stdout at startup. If 2 close stderr; if 3 close both.
#endif
int __afl_sharedmem_fuzzing = 1;
-extern unsigned int __afl_fuzz_len;
+extern unsigned int *__afl_fuzz_len;
extern unsigned char *__afl_fuzz_ptr;
// libFuzzer interface is thin, so we don't include any libFuzzer headers.
@@ -246,35 +246,38 @@ int main(int argc, char **argv) {
LLVMFuzzerInitialize(&argc, &argv);
// Do any other expensive one-time initialization here.
- int N = 1000;
+ uint8_t dummy_input[1] = {0};
+ int N = 100000;
if (argc == 2 && argv[1][0] == '-')
N = atoi(argv[1] + 1);
else if(argc == 2 && (N = atoi(argv[1])) > 0)
Printf("WARNING: using the deprecated call style `%s %d`\n", argv[0], N);
else if (argc > 1) {
- if (!getenv("AFL_DRIVER_DONT_DEFER")) {
+// if (!getenv("AFL_DRIVER_DONT_DEFER")) {
__afl_sharedmem_fuzzing = 0;
__afl_manual_init();
- }
+// }
return ExecuteFilesOnyByOne(argc, argv);
exit(0);
}
assert(N > 0);
- if (!getenv("AFL_DRIVER_DONT_DEFER"))
- __afl_manual_init();
+// if (!getenv("AFL_DRIVER_DONT_DEFER"))
+ __afl_manual_init();
// Call LLVMFuzzerTestOneInput here so that coverage caused by initialization
// on the first execution of LLVMFuzzerTestOneInput is ignored.
- uint8_t dummy_input[1] = {0};
LLVMFuzzerTestOneInput(dummy_input, 1);
int num_runs = 0;
while (__afl_persistent_loop(N)) {
- if (__afl_fuzz_len > 0) {
+#ifdef _DEBUG
+ fprintf(stderr, "len: %u\n", *__afl_fuzz_len);
+#endif
+ if (*__afl_fuzz_len) {
num_runs++;
- LLVMFuzzerTestOneInput(__afl_fuzz_ptr, __afl_fuzz_len);
+ LLVMFuzzerTestOneInput(__afl_fuzz_ptr, *__afl_fuzz_len);
}
}
Printf("%s: successfully executed %d input(s)\n", argv[0], num_runs);
diff --git a/examples/aflpp_driver/aflpp_driver_test.cpp b/examples/aflpp_driver/aflpp_driver_test.cpp
new file mode 100644
index 00000000..81aa9db4
--- /dev/null
+++ b/examples/aflpp_driver/aflpp_driver_test.cpp
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+
+ fprintf(stderr, "Received size %lu\n", Size);
+
+ if (Size < 4)
+ return 0;
+
+ if (Data[0] == 'F')
+ if (Data[1] == 'A')
+ if (Data[2] == '$')
+ if (Data[3] == '$')
+ abort();
+
+ return 0;
+
+}
diff --git a/examples/aflpp_driver/aflpp_qemu_driver.c b/examples/aflpp_driver/aflpp_qemu_driver.c
new file mode 100644
index 00000000..4f3e5f71
--- /dev/null
+++ b/examples/aflpp_driver/aflpp_qemu_driver.c
@@ -0,0 +1,38 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+// libFuzzer interface is thin, so we don't include any libFuzzer headers.
+int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
+__attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv);
+
+static const size_t kMaxAflInputSize = 1 * 1024 * 1024;
+static uint8_t AflInputBuf[kMaxAflInputSize];
+
+void __attribute__((noinline)) afl_qemu_driver_stdin_input(void) {
+
+ size_t l = read(0, AflInputBuf, kMaxAflInputSize);
+ LLVMFuzzerTestOneInput(AflInputBuf, l);
+
+}
+
+int main(int argc, char **argv) {
+
+ if (LLVMFuzzerInitialize) LLVMFuzzerInitialize(&argc, &argv);
+ // Do any other expensive one-time initialization here.
+
+ if (getenv("AFL_QEMU_DRIVER_NO_HOOK")) {
+
+ afl_qemu_driver_stdin_input();
+
+ } else {
+
+ uint8_t dummy_input[1024000] = {0};
+ LLVMFuzzerTestOneInput(dummy_input, 1);
+
+ }
+
+ return 0;
+
+}
+
diff --git a/examples/aflpp_driver/aflpp_qemu_driver_hook.c b/examples/aflpp_driver/aflpp_qemu_driver_hook.c
new file mode 100644
index 00000000..823cc42d
--- /dev/null
+++ b/examples/aflpp_driver/aflpp_qemu_driver_hook.c
@@ -0,0 +1,22 @@
+#include <stdint.h>
+#include <string.h>
+
+#define g2h(x) ((void *)((unsigned long)(x) + guest_base))
+
+#define REGS_RDI 7
+#define REGS_RSI 6
+
+void afl_persistent_hook(uint64_t *regs, uint64_t guest_base,
+ uint8_t *input_buf, uint32_t input_len) {
+
+ memcpy(g2h(regs[REGS_RDI]), input_buf, input_len);
+ regs[REGS_RSI] = input_len;
+
+}
+
+int afl_persistent_hook_init(void) {
+
+ return 1;
+
+}
+