etc~ scripts and random things |
| git clone https://github.com/djnnvx/etc.git |
| log | files | refs | archive |
setup.sh (2773B)
1 #!/bin/bash 2 # setup.sh — bootstrap libusb fuzzing environment. 3 # Usage: bash setup.sh [--skip-deps] [--skip-afl] 4 5 set -euo pipefail 6 7 SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)" 8 cd "${SCRIPT_DIR}" 9 10 AFL_REPO="https://github.com/AFLplusplus/AFLplusplus.git" 11 LIBUSB_TAG="v1.0.29" 12 LIBUSB_REPO="https://github.com/libusb/libusb.git" 13 AFL_BIN="${SCRIPT_DIR}/afl-build/usr/local/bin" 14 15 SKIP_DEPS=0 16 SKIP_AFL=0 17 for arg in "$@"; do 18 [[ "$arg" == "--skip-deps" ]] && SKIP_DEPS=1 19 [[ "$arg" == "--skip-afl" ]] && SKIP_AFL=1 20 done 21 22 log() { echo "[*] $*"; } 23 ok() { echo "[+] $*"; } 24 die() { echo "[!] $*" >&2; exit 1; } 25 26 # deps 27 if [[ "${SKIP_DEPS}" -eq 0 ]]; then 28 log "Installing dependencies..." 29 sudo apt-get update -qq 30 sudo apt-get install -y \ 31 build-essential git tmux python3 \ 32 clang llvm lld pkg-config gdb 33 ok "Dependencies installed." 34 fi 35 36 # AFL++ 37 if [[ "${SKIP_AFL}" -eq 1 ]]; then 38 command -v afl-clang-fast > /dev/null 2>&1 || die "afl-clang-fast not found." 39 elif [[ -x "${AFL_BIN}/afl-clang-fast" ]]; then 40 ok "AFL++ already built." 41 export PATH="${AFL_BIN}:${PATH}" 42 else 43 log "Building AFL++..." 44 [[ -d "AFLplusplus" ]] || git clone --depth=1 "${AFL_REPO}" AFLplusplus 45 cd AFLplusplus 46 make source-only -j"$(nproc)" 47 make install PREFIX="${SCRIPT_DIR}/afl-build/usr/local" 48 cd "${SCRIPT_DIR}" 49 export PATH="${AFL_BIN}:${PATH}" 50 ok "AFL++ built." 51 fi 52 53 # libusb source 54 if [[ -d "libusb-src/.git" ]]; then 55 ok "libusb-src present." 56 else 57 log "Cloning libusb ${LIBUSB_TAG}..." 58 git clone --depth=1 --branch "${LIBUSB_TAG}" "${LIBUSB_REPO}" libusb-src 59 ok "libusb-src cloned." 60 fi 61 62 # build harnesses 63 log "Building harnesses..." 64 CC="afl-clang-fast" 65 SRC="libusb-src/libusb" 66 CFLAGS="-fsanitize=address,undefined,signed-integer-overflow -g -O0 -fno-omit-frame-pointer" 67 CFLAGS+=" -I fuzz-include -I ${SRC} -DFUZZ_BUILD" 68 CFLAGS+=" -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Wno-unused-function -Wno-unused-variable" 69 70 build() { 71 local name="$1" extra_src="${2:-}" extra_flags="${3:-}" 72 log " ${name}..." 73 AFL_LLVM_LAF_ALL=1 AFL_LLVM_INSTRUMENT=CLASSIC ${CC} ${CFLAGS} ${extra_flags} "${name}.c" fuzz_stubs.c ${extra_src} -o "${name}" -lpthread 74 AFL_LLVM_LAF_ALL=1 AFL_LLVM_INSTRUMENT=CLASSIC AFL_LLVM_CMPLOG=1 ${CC} ${CFLAGS} ${extra_flags} "${name}.c" fuzz_stubs.c ${extra_src} -o "${name}.cmplog" -lpthread 75 } 76 77 build fuzz_descriptor 78 build fuzz_bos 79 build fuzz_iad 80 build fuzz_usbfs "fuzz_usbfs_shim.c" "-I ${SRC}/os" 81 build fuzz_extra 82 ok "Harnesses built." 83 84 # corpus 85 if [[ -d "corpus/descriptor" && "$(ls corpus/descriptor | wc -l)" -gt 5 ]]; then 86 ok "Corpus present." 87 else 88 log "Generating corpus..." 89 python3 gen_corpus.py 90 fi 91 92 ok "Done. Run: bash run-all.sh"