|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +source ./test-pre.sh |
| 4 | + |
| 5 | +$ECHO "$BLUE[*] Testing: ${AFL_GCC}, afl-showmap, afl-fuzz, afl-cmin and afl-tmin" |
| 6 | +test "$SYS" = "i686" -o "$SYS" = "x86_64" -o "$SYS" = "amd64" -o "$SYS" = "i86pc" -o "$SYS" = "i386" && { |
| 7 | + test -e ../${AFL_GCC} -a -e ../afl-showmap -a -e ../afl-fuzz && { |
| 8 | + ../${AFL_GCC} -o test-instr.plain ../test-instr.c > /dev/null 2>&1 |
| 9 | + AFL_HARDEN=1 ../${AFL_GCC} -o test-compcov.harden test-compcov.c > /dev/null 2>&1 |
| 10 | + test -e test-instr.plain && { |
| 11 | + $ECHO "$GREEN[+] ${AFL_GCC} compilation succeeded" |
| 12 | + echo 0 | ../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.0 -r -- ./test-instr.plain > /dev/null 2>&1 |
| 13 | + ../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.1 -r -- ./test-instr.plain < /dev/null > /dev/null 2>&1 |
| 14 | + test -e test-instr.plain.0 -a -e test-instr.plain.1 && { |
| 15 | + diff test-instr.plain.0 test-instr.plain.1 > /dev/null 2>&1 && { |
| 16 | + $ECHO "$RED[!] ${AFL_GCC} instrumentation should be different on different input but is not" |
| 17 | + CODE=1 |
| 18 | + } || { |
| 19 | + $ECHO "$GREEN[+] ${AFL_GCC} instrumentation present and working correctly" |
| 20 | + } |
| 21 | + } || { |
| 22 | + $ECHO "$RED[!] ${AFL_GCC} instrumentation failed" |
| 23 | + CODE=1 |
| 24 | + } |
| 25 | + rm -f test-instr.plain.0 test-instr.plain.1 |
| 26 | + TUPLES=`echo 0|../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- ./test-instr.plain 2>&1 | grep Captur | awk '{print$3}'` |
| 27 | + test "$TUPLES" -gt 3 -a "$TUPLES" -lt 11 && { |
| 28 | + $ECHO "$GREEN[+] ${AFL_GCC} run reported $TUPLES instrumented locations which is fine" |
| 29 | + } || { |
| 30 | + $ECHO "$RED[!] ${AFL_GCC} instrumentation produces weird numbers: $TUPLES" |
| 31 | + CODE=1 |
| 32 | + } |
| 33 | + } || { |
| 34 | + $ECHO "$RED[!] ${AFL_GCC} failed" |
| 35 | + echo CUT------------------------------------------------------------------CUT |
| 36 | + uname -a |
| 37 | + ../${AFL_GCC} -o test-instr.plain ../test-instr.c |
| 38 | + echo CUT------------------------------------------------------------------CUT |
| 39 | + CODE=1 |
| 40 | + } |
| 41 | + test -e test-compcov.harden && { |
| 42 | + grep -Eq$GREPAOPTION 'stack_chk_fail|fstack-protector-all|fortified' test-compcov.harden > /dev/null 2>&1 && { |
| 43 | + $ECHO "$GREEN[+] ${AFL_GCC} hardened mode succeeded and is working" |
| 44 | + } || { |
| 45 | + $ECHO "$RED[!] ${AFL_GCC} hardened mode is not hardened" |
| 46 | + CODE=1 |
| 47 | + } |
| 48 | + rm -f test-compcov.harden |
| 49 | + } || { |
| 50 | + $ECHO "$RED[!] ${AFL_GCC} hardened mode compilation failed" |
| 51 | + CODE=1 |
| 52 | + } |
| 53 | + # now we want to be sure that afl-fuzz is working |
| 54 | + # make sure core_pattern is set to core on linux |
| 55 | + (test "$(uname -s)" = "Linux" && test "$(sysctl kernel.core_pattern)" != "kernel.core_pattern = core" && { |
| 56 | + $ECHO "$YELLOW[-] we should not run afl-fuzz with enabled core dumps. Run 'sudo sh afl-system-config'.$RESET" |
| 57 | + true |
| 58 | + }) || |
| 59 | + # make sure crash reporter is disabled on Mac OS X |
| 60 | + (test "$(uname -s)" = "Darwin" && test $(launchctl list 2>/dev/null | grep -q '\.ReportCrash$') && { |
| 61 | + $ECHO "$RED[!] we cannot run afl-fuzz with enabled crash reporter. Run 'sudo sh afl-system-config'.$RESET" |
| 62 | + true |
| 63 | + }) || { |
| 64 | + mkdir -p in |
| 65 | + echo 0 > in/in |
| 66 | + $ECHO "$GREY[*] running afl-fuzz for ${AFL_GCC}, this will take approx 10 seconds" |
| 67 | + { |
| 68 | + ../afl-fuzz -V10 -m ${MEM_LIMIT} -i in -o out -- ./test-instr.plain >>errors 2>&1 |
| 69 | + } >>errors 2>&1 |
| 70 | + test -n "$( ls out/queue/id:000002* 2>/dev/null )" && { |
| 71 | + $ECHO "$GREEN[+] afl-fuzz is working correctly with ${AFL_GCC}" |
| 72 | + } || { |
| 73 | + echo CUT------------------------------------------------------------------CUT |
| 74 | + cat errors |
| 75 | + echo CUT------------------------------------------------------------------CUT |
| 76 | + $ECHO "$RED[!] afl-fuzz is not working correctly with ${AFL_GCC}" |
| 77 | + CODE=1 |
| 78 | + } |
| 79 | + echo 000000000000000000000000 > in/in2 |
| 80 | + echo 111 > in/in3 |
| 81 | + mkdir -p in2 |
| 82 | + ../afl-cmin -m ${MEM_LIMIT} -i in -o in2 -- ./test-instr.plain >/dev/null 2>&1 # why is afl-forkserver writing to stderr? |
| 83 | + CNT=`ls in2/* 2>/dev/null | wc -l` |
| 84 | + case "$CNT" in |
| 85 | + *2) $ECHO "$GREEN[+] afl-cmin correctly minimized the number of testcases" ;; |
| 86 | + *) $ECHO "$RED[!] afl-cmin did not correctly minimize the number of testcases ($CNT)" |
| 87 | + CODE=1 |
| 88 | + ;; |
| 89 | + esac |
| 90 | + rm -f in2/in* |
| 91 | + export AFL_QUIET=1 |
| 92 | + if command -v bash >/dev/null ; then { |
| 93 | + ../afl-cmin.bash -m ${MEM_LIMIT} -i in -o in2 -- ./test-instr.plain >/dev/null |
| 94 | + CNT=`ls in2/* 2>/dev/null | wc -l` |
| 95 | + case "$CNT" in |
| 96 | + *2) $ECHO "$GREEN[+] afl-cmin.bash correctly minimized the number of testcases" ;; |
| 97 | + *) $ECHO "$RED[!] afl-cmin.bash did not correctly minimize the number of testcases ($CNT)" |
| 98 | + CODE=1 |
| 99 | + ;; |
| 100 | + esac |
| 101 | + } else { |
| 102 | + $ECHO "$YELLOW[-] no bash available, cannot test afl-cmin.bash" |
| 103 | + INCOMPLETE=1 |
| 104 | + } |
| 105 | + fi |
| 106 | + ../afl-tmin -m ${MEM_LIMIT} -i in/in2 -o in2/in2 -- ./test-instr.plain > /dev/null 2>&1 |
| 107 | + SIZE=`ls -l in2/in2 2>/dev/null | awk '{print$5}'` |
| 108 | + test "$SIZE" = 1 && $ECHO "$GREEN[+] afl-tmin correctly minimized the testcase" |
| 109 | + test "$SIZE" = 1 || { |
| 110 | + $ECHO "$RED[!] afl-tmin did incorrectly minimize the testcase to $SIZE" |
| 111 | + CODE=1 |
| 112 | + } |
| 113 | + rm -rf in out errors in2 |
| 114 | + unset AFL_QUIET |
| 115 | + } |
| 116 | + rm -f test-instr.plain |
| 117 | + } || { |
| 118 | + $ECHO "$YELLOW[-] afl is not compiled, cannot test" |
| 119 | + INCOMPLETE=1 |
| 120 | + } |
| 121 | +} || { |
| 122 | + $ECHO "$YELLOW[-] not an intel platform, cannot test afl-gcc" |
| 123 | +} |
| 124 | + |
| 125 | +source ./test-post.sh |
0 commit comments