Skip to content

updated afl releases #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Written and maintained by Michal Zalewski <[email protected]>
#
# Copyright 2013, 2014, 2015, 2016 Google Inc. All rights reserved.
# Copyright 2013, 2014, 2015, 2016, 2017 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,8 +111,8 @@ all_done: test_build
.NOTPARALLEL: clean

clean:
rm -f $(PROGS) afl-as as afl-g++ afl-clang afl-clang++ *.o *~ a.out core core.[1-9][0-9]* *.stackdump test .test test-instr .test-instr0 .test-instr1 qemu_mode/qemu-2.3.0.tar.bz2 afl-qemu-trace
rm -rf out_dir qemu_mode/qemu-2.3.0
rm -f $(PROGS) afl-as as afl-g++ afl-clang afl-clang++ *.o *~ a.out core core.[1-9][0-9]* *.stackdump test .test test-instr .test-instr0 .test-instr1 qemu_mode/qemu-2.10.0.tar.bz2 afl-qemu-trace
rm -rf out_dir qemu_mode/qemu-2.10.0
$(MAKE) -C llvm_mode clean
$(MAKE) -C libdislocator clean
$(MAKE) -C libtokencap clean
Expand All @@ -123,7 +123,11 @@ install: all
install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH)
rm -f $${DESTDIR}$(BIN_PATH)/afl-as
if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi
ifndef AFL_TRACE_PC
if [ -f afl-clang-fast -a -f afl-llvm-pass.so -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-pass.so afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi
else
if [ -f afl-clang-fast -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi
endif
if [ -f afl-llvm-rt-32.o ]; then set -e; install -m 755 afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH); fi
if [ -f afl-llvm-rt-64.o ]; then set -e; install -m 755 afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH); fi
set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $${DESTDIR}$(BIN_PATH)/$$i; done
Expand Down
28 changes: 21 additions & 7 deletions afl-analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Written and maintained by Michal Zalewski <[email protected]>

Copyright 2016 Google Inc. All rights reserved.
Copyright 2016, 2017 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,6 +68,7 @@ static s32 shm_id, /* ID of the SHM region */
dev_null_fd = -1; /* FD to /dev/null */

static u8 edges_only, /* Ignore hit counts? */
use_hex_offsets, /* Show hex offsets? */
use_stdin = 1; /* Use stdin for program input? */

static volatile u8
Expand Down Expand Up @@ -486,9 +487,13 @@ static void dump_hex(u8* buf, u32 len, u8* b_data) {
/* Every 16 digits, display offset. */

if (!((i + off) % 16)) {

if (off) SAYF(cRST cLCY ">");
SAYF(cRST cGRA "%s[%06u] " cRST, (i + off) ? "\n" : "", i + off);

if (use_hex_offsets)
SAYF(cRST cGRA "%s[%06x] " cRST, (i + off) ? "\n" : "", i + off);
else
SAYF(cRST cGRA "%s[%06u] " cRST, (i + off) ? "\n" : "", i + off);

}

Expand All @@ -512,7 +517,10 @@ static void dump_hex(u8* buf, u32 len, u8* b_data) {

#else

SAYF(" Offset %u, length %u: ", i, rlen);
if (use_hex_offsets)
SAYF(" Offset %x, length %u: ", i, rlen);
else
SAYF(" Offset %u, length %u: ", i, rlen);

switch (rtype) {

Expand Down Expand Up @@ -658,15 +666,15 @@ static void set_up_environment(void) {

u8* use_dir = ".";

if (!access(use_dir, R_OK | W_OK | X_OK)) {
if (access(use_dir, R_OK | W_OK | X_OK)) {

use_dir = getenv("TMPDIR");
if (!use_dir) use_dir = "/tmp";

prog_in = alloc_printf("%s/.afl-tmin-temp-%u", use_dir, getpid());

}

prog_in = alloc_printf("%s/.afl-analyze-temp-%u", use_dir, getpid());

}

/* Set sane defaults... */
Expand Down Expand Up @@ -874,6 +882,10 @@ static char** get_qemu_argv(u8* own_loc, char** argv, int argc) {
char** new_argv = ck_alloc(sizeof(char*) * (argc + 4));
u8 *tmp, *cp, *rsl, *own_copy;

/* Workaround for a QEMU stability glitch. */

setenv("QEMU_LOG", "nochain", 1);

memcpy(new_argv + 3, argv + 1, sizeof(char*) * argc);

/* Now we need to actually find qemu for argv[0]. */
Expand Down Expand Up @@ -1026,6 +1038,8 @@ int main(int argc, char** argv) {

if (optind == argc || !in_file) usage(argv[0]);

use_hex_offsets = !!getenv("AFL_ANALYZE_HEX");

setup_shm();
setup_signal_handlers();

Expand Down
11 changes: 8 additions & 3 deletions afl-as.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static u8* modified_file; /* Instrumented file for the real 'as' */
static u8 be_quiet, /* Quiet mode (no stderr output) */
clang_mode, /* Running in clang mode? */
pass_thru, /* Just pass data through? */
just_version; /* Just show version? */
just_version, /* Just show version? */
sanitizer; /* Using ASAN / MSAN */

static u32 inst_ratio = 100, /* Instrumentation probability (%) */
as_par_cnt = 1; /* Number of params to 'as' */
Expand Down Expand Up @@ -454,7 +455,8 @@ static void add_instrumentation(void) {
pass_thru ? " (pass-thru mode)" : "");
else OKF("Instrumented %u locations (%s-bit, %s mode, ratio %u%%).",
ins_lines, use_64bit ? "64" : "32",
getenv("AFL_HARDEN") ? "hardened" : "non-hardened",
getenv("AFL_HARDEN") ? "hardened" :
(sanitizer ? "ASAN/MSAN" : "non-hardened"),
inst_ratio);

}
Expand Down Expand Up @@ -521,7 +523,10 @@ int main(int argc, char** argv) {
ASAN-specific branches. But we can probabilistically compensate for
that... */

if (getenv("AFL_USE_ASAN") || getenv("AFL_USE_MSAN")) inst_ratio /= 3;
if (getenv("AFL_USE_ASAN") || getenv("AFL_USE_MSAN")) {
sanitizer = 1;
inst_ratio /= 3;
}

if (!just_version) add_instrumentation();

Expand Down
44 changes: 29 additions & 15 deletions afl-cmin
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,28 @@ fi
# Do a sanity check to discourage the use of /tmp, since we can't really
# handle this safely from a shell script.

echo "$IN_DIR" | grep -qE '^(/var)?/tmp/'
T1="$?"
if [ "$AFL_ALLOW_TMP" = "" ]; then

echo "$TARGET_BIN" | grep -qE '^(/var)?/tmp/'
T2="$?"
echo "$IN_DIR" | grep -qE '^(/var)?/tmp/'
T1="$?"

echo "$OUT_DIR" | grep -qE '^(/var)?/tmp/'
T3="$?"
echo "$TARGET_BIN" | grep -qE '^(/var)?/tmp/'
T2="$?"

echo "$STDIN_FILE" | grep -qE '^(/var)?/tmp/'
T4="$?"
echo "$OUT_DIR" | grep -qE '^(/var)?/tmp/'
T3="$?"

echo "$PWD" | grep -qE '^(/var)?/tmp/'
T5="$?"
echo "$STDIN_FILE" | grep -qE '^(/var)?/tmp/'
T4="$?"

echo "$PWD" | grep -qE '^(/var)?/tmp/'
T5="$?"

if [ "$T1" = "0" -o "$T2" = "0" -o "$T3" = "0" -o "$T4" = "0" -o "$T5" = "0" ]; then
echo "[-] Error: do not use this script in /tmp or /var/tmp." 1>&2
exit 1
fi

if [ "$T1" = "0" -o "$T2" = "0" -o "$T3" = "0" -o "$T4" = "0" -o "$T5" = "0" ]; then
echo "[-] Error: do not use this script in /tmp or /var/tmp." 1>&2
exit 1
fi

# If @@ is specified, but there's no -f, let's come up with a temporary input
Expand Down Expand Up @@ -240,13 +244,23 @@ fi
IN_COUNT=$((`ls -- "$IN_DIR" 2>/dev/null | wc -l`))

if [ "$IN_COUNT" = "0" ]; then
echo "No inputs in the target directory - nothing to be done."
echo "[+] Hmm, no inputs in the target directory. Nothing to be done."
rm -rf "$TRACE_DIR"
exit 1
fi

FIRST_FILE=`ls "$IN_DIR" | head -1`

# Make sure that we're not dealing with a directory.

if [ -d "$IN_DIR/$FIRST_FILE" ]; then
echo "[-] Error: The target directory contains subdirectories - please fix." 1>&2
rm -rf "$TRACE_DIR"
exit 1
fi

# Check for the more efficient way to copy files...

if ln "$IN_DIR/$FIRST_FILE" "$TRACE_DIR/.link_test" 2>/dev/null; then
CP_TOOL=ln
else
Expand Down Expand Up @@ -384,7 +398,7 @@ sort -k1,1 -s -u "$TRACE_DIR/.candidate_list" | \
sed 's/^/BEST_FILE[/;s/ /]="/;s/$/"/' >"$TRACE_DIR/.candidate_script"

if [ ! -s "$TRACE_DIR/.candidate_script" ]; then
echo "[-] Error: no traces obtained from test cases, check syntax!"
echo "[-] Error: no traces obtained from test cases, check syntax!" 1>&2
test "$AFL_KEEP_TRACES" = "" && rm -rf "$TRACE_DIR"
exit 1
fi
Expand Down
Loading