aboutsummaryrefslogtreecommitdiff
path: root/examples/persistent_demo
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-05-29 14:35:05 +0200
committerGitHub <noreply@github.com>2020-05-29 14:35:05 +0200
commit710dda522186310a7fb4e3b6a05cae0b28fa619e (patch)
treef96fcfe756fe5e6e0dde11be8df8b3df9f654952 /examples/persistent_demo
parent6892018142cc21ba9a0744c0757d39f21e9b66bc (diff)
parentc3b864d8d4dfaf148158a689df0c5ddf4bcc1f32 (diff)
downloadafl++-710dda522186310a7fb4e3b6a05cae0b28fa619e.tar.gz
Merge pull request #374 from AFLplusplus/dev
Dev
Diffstat (limited to 'examples/persistent_demo')
-rw-r--r--examples/persistent_demo/Makefile6
-rw-r--r--examples/persistent_demo/persistent_demo.c14
-rw-r--r--examples/persistent_demo/persistent_demo_new.c97
3 files changed, 115 insertions, 2 deletions
diff --git a/examples/persistent_demo/Makefile b/examples/persistent_demo/Makefile
new file mode 100644
index 00000000..cbbb7239
--- /dev/null
+++ b/examples/persistent_demo/Makefile
@@ -0,0 +1,6 @@
+all:
+ afl-clang-fast -o persistent_demo persistent_demo.c
+ afl-clang-fast -o persistent_demo_new persistent_demo_new.c
+
+clean:
+ rm -f persistent_demo persistent_demo_new
diff --git a/examples/persistent_demo/persistent_demo.c b/examples/persistent_demo/persistent_demo.c
index 36f12850..2da49bb0 100644
--- a/examples/persistent_demo/persistent_demo.c
+++ b/examples/persistent_demo/persistent_demo.c
@@ -63,7 +63,7 @@ int main(int argc, char **argv) {
We just have some trivial inline code that faults on 'foo!'. */
/* do we have enough data? */
- if (len < 4) return 0;
+ if (len < 8) continue;
if (buf[0] == 'f') {
@@ -77,7 +77,17 @@ int main(int argc, char **argv) {
if (buf[3] == '!') {
printf("four\n");
- abort();
+ if (buf[4] == '!') {
+
+ printf("five\n");
+ if (buf[5] == '!') {
+
+ printf("six\n");
+ abort();
+
+ }
+
+ }
}
diff --git a/examples/persistent_demo/persistent_demo_new.c b/examples/persistent_demo/persistent_demo_new.c
new file mode 100644
index 00000000..36411e13
--- /dev/null
+++ b/examples/persistent_demo/persistent_demo_new.c
@@ -0,0 +1,97 @@
+/*
+ american fuzzy lop++ - persistent mode example
+ --------------------------------------------
+
+ Originally written by Michal Zalewski
+
+ Copyright 2015 Google Inc. All rights reserved.
+
+ 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
+
+ This file demonstrates the high-performance "persistent mode" that may be
+ suitable for fuzzing certain fast and well-behaved libraries, provided that
+ they are stateless or that their internal state can be easily reset
+ across runs.
+
+ To make this work, the library and this shim need to be compiled in LLVM
+ mode using afl-clang-fast (other compiler wrappers will *not* work).
+
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+
+__AFL_FUZZ_INIT();
+
+/* Main entry point. */
+
+int main(int argc, char **argv) {
+
+ ssize_t len; /* how much input did we read? */
+ unsigned char *buf; /* test case buffer pointer */
+
+ /* The number passed to __AFL_LOOP() controls the maximum number of
+ iterations before the loop exits and the program is allowed to
+ terminate normally. This limits the impact of accidental memory leaks
+ and similar hiccups. */
+
+ buf = __AFL_FUZZ_TESTCASE_BUF;
+
+ while (__AFL_LOOP(1000)) {
+
+ len = __AFL_FUZZ_TESTCASE_LEN;
+
+ /* do we have enough data? */
+ if (len < 8) continue;
+
+ if (buf[0] == 'f') {
+
+ printf("one\n");
+ if (buf[1] == 'o') {
+
+ printf("two\n");
+ if (buf[2] == 'o') {
+
+ printf("three\n");
+ if (buf[3] == '!') {
+
+ printf("four\n");
+ if (buf[4] == '!') {
+
+ printf("five\n");
+ if (buf[6] == '!') {
+
+ printf("six\n");
+ abort();
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ /*** END PLACEHOLDER CODE ***/
+
+ }
+
+ /* Once the loop is exited, terminate normally - AFL will restart the process
+ when this happens, with a clean slate when it comes to allocated memory,
+ leftover file descriptors, etc. */
+
+ return 0;
+
+}
+