aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2019-09-22 11:42:39 +0200
committervan Hauser <vh@thc.org>2019-09-22 11:42:39 +0200
commitf097f780af8bf30a51d2d462dfe303604e4a6a75 (patch)
tree592f9408f937cc58107e0f18f5d3d87b5a741f96 /test
parent99be29472657d074d53f7487198acca44a1f5c82 (diff)
downloadAFLplusplus-f097f780af8bf30a51d2d462dfe303604e4a6a75.tar.gz
final tests
Diffstat (limited to 'test')
-rw-r--r--test/test-compcov.c35
-rwxr-xr-xtest/test.sh76
2 files changed, 74 insertions, 37 deletions
diff --git a/test/test-compcov.c b/test/test-compcov.c
index bbad3aed..978d5551 100644
--- a/test/test-compcov.c
+++ b/test/test-compcov.c
@@ -4,25 +4,26 @@
#include <string.h>
int main(int argc, char** argv) {
+ char *input = argv[1], *buf, buffer[20];
- char *buf;
-
- if (argc > 1) {
-
- if (strcmp(argv[1], "LIBTOKENCAP") == 0)
- printf("your string was libtokencap\n");
- else if (strcmp(argv[1], "BUGMENOT") == 0)
- printf("your string was bugmenot\n");
- else if (strcmp(argv[1], "BUFFEROVERFLOW") == 0) {
- buf = malloc(16);
- strcpy(buf, "TEST");
- strcat(buf, argv[1]);
- printf("This will only crash with libdislocator: %s\n", buf);
- return 0;
- } else
- printf("I do not know your string\n");
-
+ if (argc < 2) {
+ ssize_t ret = read(0, buffer, sizeof(buffer) - 1);
+ buffer[ret] = 0;
+ input = buffer;
}
+
+ if (strcmp(input, "LIBTOKENCAP") == 0)
+ printf("your string was libtokencap\n");
+ else if (strcmp(input, "BUGMENOT") == 0)
+ printf("your string was bugmenot\n");
+ else if (strcmp(input, "BUFFEROVERFLOW") == 0) {
+ buf = malloc(16);
+ strcpy(buf, "TEST");
+ strcat(buf, input);
+ printf("This will only crash with libdislocator: %s\n", buf);
+ return 0;
+ } else
+ printf("I do not know your string\n");
return 0;
diff --git a/test/test.sh b/test/test.sh
index ad1bdc97..5d67588a 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -27,8 +27,13 @@ test -z "$ECHO" && { echo Error: echo command does not support -e option ; exit
export AFL_EXIT_WHEN_DONE=1
export AFL_SKIP_CPUFREQ=1
+unset AFL_DEBUG
+unset AFL_HARDEN
+unset AFL_LLVM_WHITELIST
+unset AFL_LLVM_INSTRIM
GREY="\\x1b[1;90m"
+BLUE="\\x1b[1;94m"
GREEN="\\x1b[0;32m"
RED="\\x1b[0;31m"
YELLOW="\\x1b[1;93m"
@@ -36,6 +41,7 @@ RESET="\\x1b[0m"
$ECHO "${RESET}${GREY}[*] starting afl++ test framework ..."
+$ECHO "$BLUE[*] Testing: afl-gcc, afl-showmap and afl-fuzz"
test -e ../afl-gcc -a -e ../afl-showmap -a -e ../afl-fuzz && {
../afl-gcc -o test-instr.plain ../test-instr.c > /dev/null 2>&1
AFL_HARDEN=1 ../afl-gcc -o test-instr.harden ../test-instr.c > /dev/null 2>&1
@@ -53,27 +59,27 @@ test -e ../afl-gcc -a -e ../afl-showmap -a -e ../afl-fuzz && {
test -e test-instr.harden && {
grep -qa fstack-protector-all test-instr.harden > /dev/null 2>&1 && {
$ECHO "$GREEN[+] afl-gcc hardened mode succeeded and is working"
- } || $ECHO "$RED[!] hardened mode is not hardened"
+ } || $ECHO "$RED[!] afl-gcc hardened mode is not hardened"
rm -f test-instr.harden
} || $ECHO "$RED[!] afl-gcc hardened mode compilation failed"
# now we want to be sure that afl-fuzz is working
test -n "$TIMEOUT" && {
mkdir -p in
echo 0 > in/in
- $ECHO "$GREY[*] running afl-fuzz, this will take approx 10 seconds"
+ $ECHO "$GREY[*] running afl-fuzz for afl-gcc, this will take approx 10 seconds"
{
timeout -s KILL 10 ../afl-fuzz -i in -o out -- ./test-instr.plain > /dev/null 2>&1
} > /dev/null 2>&1
test -n "$( ls out/queue/id:000002* 2> /dev/null )" && {
$ECHO "$GREEN[+] afl-fuzz is working correctly with afl-gcc"
- } || $ECHO "$RED[!] afl-fuzz is not working correctly"
+ } || $ECHO "$RED[!] afl-fuzz is not working correctly with afl-gcc"
rm -rf in out
} || $ECHO "$YELLOW[-] we cannot test afl-fuzz because we are missing the timeout command"
rm -f test-instr.plain
} || $ECHO "$YELLOW[-] afl is not compiled, cannot test"
+$ECHO "$BLUE[*] Testing: llvm_mode"
test -e ../afl-clang-fast && {
-
../afl-clang-fast -o test-instr.plain ../test-instr.c > /dev/null 2>&1
AFL_HARDEN=1 ../afl-clang-fast -o test-compcov.harden test-compcov.c > /dev/null 2>&1
test -e test-instr.plain && {
@@ -90,32 +96,32 @@ test -e ../afl-clang-fast && {
test -e test-compcov.harden && {
grep -Eqa 'stack_chk_fail|fstack-protector-all|fortified' test-compcov.harden > /dev/null 2>&1 && {
$ECHO "$GREEN[+] llvm_mode hardened mode succeeded and is working"
- } || $ECHO "$RED[!] hardened mode is not hardened"
+ } || $ECHO "$RED[!] llvm_mode hardened mode is not hardened"
rm -f test-compcov.harden
} || $ECHO "$RED[!] llvm_mode hardened mode compilation failed"
# now we want to be sure that afl-fuzz is working
test -n "$TIMEOUT" && {
mkdir -p in
echo 0 > in/in
- $ECHO "$GREY[*] running afl-fuzz, this will take approx 10 seconds"
+ $ECHO "$GREY[*] running afl-fuzz for llvm_mode, this will take approx 10 seconds"
{
timeout -s KILL 10 ../afl-fuzz -i in -o out -- ./test-instr.plain > /dev/null 2>&1
} > /dev/null 2>&1
test -n "$( ls out/queue/id:000002* 2> /dev/null )" && {
$ECHO "$GREEN[+] afl-fuzz is working correctly with llvm_mode"
- } || $ECHO "$RED[!] afl-fuzz is not working correctly"
+ } || $ECHO "$RED[!] afl-fuzz is not working correctly with llvm_mode"
rm -rf in out
} || $ECHO "$YELLOW[-] we cannot test afl-fuzz because we are missing the timeout command"
rm -f test-instr.plain
+
# now for the special llvm_mode things
AFL_LLVM_INSTRIM=1 AFL_LLVM_INSTRIM_LOOPHEAD=1 ../afl-clang-fast -o test-compcov.instrim test-compcov.c > /dev/null 2> test.out
test -e test-compcov.instrim && {
- grep -q " 1 location" test.out && {
+ grep -Eq " [1-3] location" test.out && {
$ECHO "$GREEN[+] llvm_mode InsTrim feature works correctly"
} || $ECHO "$RED[!] llvm_mode InsTrim feature failed"
} || $ECHO "$RED[!] llvm_mode InsTrim feature compilation failed"
rm -f test-compcov.instrim test.out
-
AFL_LLVM_LAF_SPLIT_SWITCHES=1 AFL_LLVM_LAF_TRANSFORM_COMPARES=1 AFL_LLVM_LAF_SPLIT_COMPARES=1 ../afl-clang-fast -o test-compcov.compcov test-compcov.c > /dev/null 2> test.out
test -e test-compcov.compcov && {
grep -Eq " [3-9][0-9] location" test.out && {
@@ -123,8 +129,6 @@ test -e ../afl-clang-fast && {
} || $ECHO "$RED[!] llvm_mode laf-intel/compcov feature failed"
} || $ECHO "$RED[!] llvm_mode laf-intel/compcov feature compilation failed"
rm -f test-compcov.compcov test.out
-
-
echo foobar.c > whitelist.txt
AFL_LLVM_WHITELIST=whitelist.txt ../afl-clang-fast -o test-compcov test-compcov.c > test.out 2>&1
test -e test-compcov && {
@@ -133,11 +137,17 @@ test -e ../afl-clang-fast && {
} || $ECHO "$RED[!] llvm_mode whitelist feature failed"
} || $ECHO "$RED[!] llvm_mode whitelist feature compilation failed"
rm -f test-compcov test.out whitelist.txt
-
+ ../afl-clang-fast -o test-persistent ../experimental/persistent_demo/persistent_demo.c > /dev/null 2>&1
+ test -e test-persistent && {
+ echo foo | ../afl-showmap -o /dev/null -q -r ./test-persistent && {
+ $ECHO "$GREEN[+] lvm_mode persistent mode feature works correctly"
+ } || $ECHO "$RED[!] llvm_mode persistent mode feature failed to work"
+ } || $ECHO "$RED[!] llvm_mode persistent mode feature compilation failed"
+ rm -f test-persistent
} || $ECHO "$YELLOW[-] llvm_mode not compiled, cannot test"
+$ECHO "$BLUE[*] Testing: shared library extensions"
gcc -o test-compcov test-compcov.c > /dev/null 2>&1
-
test -e ../libtokencap.so && {
AFL_TOKEN_FILE=token.out LD_PRELOAD=../libtokencap.so ./test-compcov foobar > /dev/null 2>&1
grep -q BUGMENOT token.out > /dev/null 2>&1 && {
@@ -145,7 +155,6 @@ test -e ../libtokencap.so && {
} || $ECHO "$RED[!] libtokencap did not capture tokens"
rm -f token.out
} || $ECHO "$YELLOW[-] libtokencap is not compiled, cannot test"
-
test -e ../libdislocator.so && {
{
ulimit -c 1
@@ -156,17 +165,44 @@ test -e ../libdislocator.so && {
} || $ECHO "$GREEN[+] libdislocator did successfully detect the memory corruption"
rm -f test.out core test-compcov.core core.test-compcov
} || $ECHO "$YELLOW[-] libdislocator is not compiled, cannot test"
+rm -f test-compcov
+$ECHO "$BLUE[*] Testing: qemu_mode"
test -e ../afl-qemu-trace && {
+ gcc -o test-instr ../test-instr.c
+ gcc -o test-compcov test-compcov.c
+ test -e test-instr -a -e test-compcov && {
+ test -n "$TIMEOUT" && {
+ mkdir -p in
+ echo 0 > in/in
+ $ECHO "$GREY[*] running afl-fuzz for qemu_mode, this will take approx 10 seconds"
+ {
+ timeout -s KILL 10 ../afl-fuzz -Q -i in -o out -- ./test-instr > /dev/null 2>&1
+ } > /dev/null 2>&1
+ test -n "$( ls out/queue/id:000002* 2> /dev/null )" && {
+ $ECHO "$GREEN[+] afl-fuzz is working correctly with qemu_mode"
+ } || $ECHO "$RED[!] afl-fuzz is not working correctly with qemu_mode"
+
+ test -e ../libcompcov.so && {
+ $ECHO "$GREY[*] running afl-fuzz for qemu_mode libcompcov, this will take approx 10 seconds"
+ {
+ export AFL_PRELOAD=../libcompcov.so
+ export AFL_COMPCOV_LEVEL=2
+ timeout -s KILL 10 ../afl-fuzz -Q -i in -o out -- ./test-compcov > /dev/null 2>&1
+ } > /dev/null 2>&1
+ test -n "$( ls out/queue/id:000002* 2> /dev/null )" && {
+ $ECHO "$GREEN[+] afl-fuzz is working correctly with qemu_mode libcompcov"
+ } || $ECHO "$RED[!] afl-fuzz is not working correctly with qemu_mode libcompcov"
+ } || $ECHO "$YELLOW[-] we cannot test qemu_mode libcompcov because it is not present"
+ rm -rf in out
+ } || $ECHO "$YELLOW[-] we cannot test afl-fuzz because we are missing the timeout command"
+ } || $ECHO "$RED[-] gcc compilation of test targets failed - what is going on??"
+
+ $ECHO "$YELLOW[?] we need a test case for qemu_mode persistent mode"
- echo todo: qemu_mode
- # we will use test-compcov for testing libcompcov
-
+ rm -f test-instr test-compcov
} || $ECHO "$YELLOW[-] qemu_mode is not compiled, cannot test"
-rm -f test-compcov
-
$ECHO "$GREY[*] all test cases completed.$RESET"
-$ECHO "$RESET"
# unicorn_mode ?