etc~ scripts and random things |
| git clone https://github.com/djnnvx/etc.git |
| log | files | refs | archive |
start-fuzzers.sh (3442B)
1 #!/bin/bash 2 # start-fuzzers.sh - launch libnfs fuzzing in tmux (8 instances across 4 harnesses). 3 # Each harness gets a -M master (explore) and a -S secondary driven by its CmpLog 4 # binary. Usage: bash start-fuzzers.sh [--rerun|--status] 5 set -euo pipefail 6 7 SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)" 8 cd "${SCRIPT_DIR}" 9 10 AFL_BIN="${SCRIPT_DIR}/afl-build/usr/local/bin" 11 [[ -d "${AFL_BIN}" ]] && export PATH="${AFL_BIN}:${PATH}" 12 13 SESSION="libnfs-fuzz" 14 OUTPUT="${SCRIPT_DIR}/output" 15 CORPUS="${SCRIPT_DIR}/corpus" 16 DICT="${SCRIPT_DIR}/dictionaries/xdr.dict" 17 18 log() { echo "[*] $*"; } 19 ok() { echo "[+] $*"; } 20 die() { echo "[!] $*" >&2; exit 1; } 21 22 case "${1:-}" in 23 --status) 24 afl-whatsup "${OUTPUT}" 2>/dev/null || echo "Output: ${OUTPUT}" 25 exit 0 ;; 26 --rerun) 27 tmux kill-session -t "${SESSION}" 2>/dev/null || true ;; 28 "") ;; 29 *) die "Unknown option: ${1}" ;; 30 esac 31 32 command -v afl-fuzz > /dev/null 2>&1 || die "afl-fuzz not found. Run setup.sh first." 33 for h in fuzz_nfs3 fuzz_nfs4 fuzz_mount fuzz_pdu; do 34 [[ -f "${h}" ]] || die "${h} not found. Run setup.sh first." 35 [[ -f "${h}.cmplog" ]] || die "${h}.cmplog not found. Run setup.sh first." 36 done 37 tmux list-sessions 2>/dev/null | grep -q "${SESSION}" && \ 38 die "Session '${SESSION}' already running. Use --rerun." 39 40 sudo sysctl -w kernel.core_pattern=core > /dev/null 2>&1 || true 41 echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor > /dev/null 2>&1 || true 42 mkdir -p "${OUTPUT}" 43 44 export AFL_SKIP_CPUFREQ=1 45 export AFL_AUTORESUME=1 46 export AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 47 export AFL_DISABLE_TRIM=1 48 export AFL_KEEP_TIMEOUTS=1 49 export ASAN_OPTIONS="abort_on_error=1:symbolize=0:detect_leaks=0:allocator_may_return_null=1:detect_stack_use_after_scope=1" 50 export UBSAN_OPTIONS="print_stacktrace=0:halt_on_error=1" 51 52 # role: -M/-S flag; kind: master|cmplog|sec; target+corpus subdir; schedule 53 afl_cmd() { 54 local role="$1" kind="$2" target="$3" corpus_sub="$4" sched="${5:-fast}" 55 local cmplog="" 56 [[ "${kind}" == "cmplog" ]] && cmplog="-c ./${target}.cmplog -l 2AT" 57 echo "afl-fuzz ${role} -i '${CORPUS}/${corpus_sub}' -o '${OUTPUT}' -x '${DICT}' -t 1000 -p ${sched} -m none ${cmplog} -- './${target}'" 58 } 59 60 log "Starting session '${SESSION}'..." 61 tmux new-session -d -s "${SESSION}" -n "nfs3+nfs4" -x 220 -y 50 62 tmux split-window -t "${SESSION}:0" -h 63 tmux split-window -t "${SESSION}:0.0" -v 64 tmux split-window -t "${SESSION}:0.2" -v 65 tmux new-window -t "${SESSION}" -n "mount+pdu" 66 tmux split-window -t "${SESSION}:1" -h 67 tmux split-window -t "${SESSION}:1.0" -v 68 tmux split-window -t "${SESSION}:1.2" -v 69 tmux new-window -t "${SESSION}" -n "status" 70 sleep 0.5 71 72 send() { tmux send-keys -t "${SESSION}:${1}.${2}" "${3}" Enter; } 73 74 send 0 0 "$(afl_cmd '-M master_nfs3' master fuzz_nfs3 nfs3 explore)" 75 send 0 1 "$(afl_cmd '-S sec_nfs3' cmplog fuzz_nfs3 nfs3 coe)" 76 send 0 2 "$(afl_cmd '-M master_nfs4' master fuzz_nfs4 nfs4 explore)" 77 send 0 3 "$(afl_cmd '-S sec_nfs4' cmplog fuzz_nfs4 nfs4 rare)" 78 send 1 0 "$(afl_cmd '-M master_mount' master fuzz_mount mount explore)" 79 send 1 1 "$(afl_cmd '-S sec_mount' cmplog fuzz_mount mount coe)" 80 send 1 2 "$(afl_cmd '-M master_pdu' master fuzz_pdu pdu explore)" 81 send 1 3 "$(afl_cmd '-S sec_pdu' cmplog fuzz_pdu pdu lin)" 82 send 2 0 "watch -n 15 'afl-whatsup ${OUTPUT} 2>/dev/null || echo waiting...'" 83 84 ok "Session started. Attach: tmux attach -t ${SESSION}"