etc.git


etc

~ scripts and random things
git clone https://github.com/djnnvx/etc.git
log | files | refs | archive

run-all.sh (3555B)

      1 #!/bin/bash
      2 # run-all.sh — launch libusb fuzzing in tmux (8 instances across 4 harnesses).
      3 # Usage: bash run-all.sh [--rerun|--status]
      4 
      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="libusb-fuzz"
     14 OUTPUT="${SCRIPT_DIR}/output"
     15 CORPUS="${SCRIPT_DIR}/corpus"
     16 DICT="${SCRIPT_DIR}/dictionaries/usb.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."
     33 for h in fuzz_descriptor fuzz_bos fuzz_iad fuzz_usbfs fuzz_extra; do
     34     [[ -f "${h}" ]]        || die "${h} not found. Run setup.sh first."
     35     [[ -f "${h}.cmplog" ]] || die "${h}.cmplog not found."
     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 # power_schedule: master=explore (breadth-first), secondaries vary per harness
     53 # -l 2AT on cmplog instances: type-2 transform + auto token insertion
     54 afl_cmd() {
     55     local role="$1" flag="$2" target="$3" corpus_sub="$4" sched="${5:-fast}"
     56     local cmplog=""
     57     [[ "${flag}" == "master" || "${flag}" == "cmplog" ]] && cmplog="-c ./${target}.cmplog -l 2AT"
     58     echo "afl-fuzz ${role} -i '${CORPUS}/${corpus_sub}' -o '${OUTPUT}' -x '${DICT}' -t 500 -p ${sched} -m none ${cmplog} -- './${target}'"
     59 }
     60 
     61 log "Starting session '${SESSION}'..."
     62 tmux new-session  -d -s "${SESSION}" -n "desc+bos" -x 220 -y 50
     63 tmux split-window -t "${SESSION}:0"   -h
     64 tmux split-window -t "${SESSION}:0.0" -v
     65 tmux split-window -t "${SESSION}:0.2" -v
     66 tmux new-window   -t "${SESSION}" -n "iad+usbfs"
     67 tmux split-window -t "${SESSION}:1"   -h
     68 tmux split-window -t "${SESSION}:1.0" -v
     69 tmux split-window -t "${SESSION}:1.2" -v
     70 tmux new-window   -t "${SESSION}" -n "status"
     71 sleep 0.5
     72 
     73 send() { tmux send-keys -t "${SESSION}:${1}.${2}" "${3}" Enter; }
     74 
     75 send 0 0 "$(afl_cmd '-M master_descriptor' master  fuzz_descriptor descriptor explore)"
     76 send 0 1 "$(afl_cmd '-S sec_descriptor'   sec     fuzz_descriptor descriptor rare)"
     77 send 0 2 "$(afl_cmd '-M master_bos'       master  fuzz_bos        bos        explore)"
     78 send 0 3 "$(afl_cmd '-S sec_bos'          cmplog  fuzz_bos        bos        coe)"
     79 send 1 0 "$(afl_cmd '-M master_iad'       master  fuzz_iad        iad        explore)"
     80 send 1 1 "$(afl_cmd '-S sec_iad'          sec     fuzz_iad        iad        lin)"
     81 send 1 2 "$(afl_cmd '-M master_usbfs'     master  fuzz_usbfs      usbfs      explore)"
     82 send 1 3 "$(afl_cmd '-S sec_extra'        sec     fuzz_extra      extra      fast)"
     83 send 2 0 "watch -n 15 'afl-whatsup ${OUTPUT} 2>/dev/null || echo waiting...'"
     84 
     85 ok "Session started. Attach: tmux attach -t ${SESSION}"