############################################################################### # https://en.wikipedia.org/wiki/American_fuzzy_lop_(fuzzer) # lottery.c from https://events.static.linuxfound.org/sites/events/files/slides/AFL%20filesystem%20fuzzing%2C%20Vault%202016_0.pdf ############################################################################### .ONESHELL: EXE = $(basename $(SRC)) IN = $(EXE:=.in) OUT = $(EXE:=.out) PAT = core_pattern PTH = /proc/sys/kernel/$(PAT) PKG = american-fuzzy-lop SRC = $(wildcard *.c *.cc) CC = afl-gcc CXX = afl-g++ CFLAGS = -fanalyzer -fsanitize={address,pointer-compare,pointer-subtract,undefined} -Wall CXXFLAGS = $(CFLAGS) FUZ = AFL_BENCH_UNTIL_CRASH=1 AFL_SKIP_CPUFREQ=1 afl-fuzz all: $(OUT) clean: core_off -rm -frv $(EXE) $(IN) $(OUT) $(PAT) core.* *~ # default: "|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" core_off: $(PAT) @cat $< | sudo tee $(PTH) &> /dev/null core_on: $(PAT) @echo core | sudo tee $(PTH) &> /dev/null $(PAT): @cat $(PTH) > $@ exe: $(EXE) pkg: sudo dnf -y install $(PKG) %.in: % mkdir -p $@ case '$*' in integer) echo {0..9} | tr ' ' '\n';; # digits # * ) printf "%b" $$(printf '\\x%x' {0..255});; # every char * ) printf "%b" $$(printf '\\x%x' {30..127});; # printable chars esac | sort | uniq > ./$@/samples.txt %.out: %.in -make -s core_on -case '$*' in writeme) $(FUZ) -D -i ./$< -o ./$@ -T $* -- ./$* @@;; # file * ) $(FUZ) -D -i ./$< -o ./$@ -T $* -- ./$* ;; # stdio esac -make -s core_off .PRECIOUS: $(IN) $(OUT) $(PAT) .PHONY: all clean core_off core_on exe pkg