mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-24 22:53:24 +00:00
Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
5726796936 | |||
bbcb3dd53e | |||
eac53afe7b | |||
55a2362348 | |||
8afb60d2f9 | |||
69a596c089 | |||
ccb952dde8 | |||
7c380a6612 | |||
88e2affe73 | |||
3f26818d97 | |||
bd83eb0f42 | |||
c5acf3f137 | |||
ea42feb06a | |||
a09720665d | |||
6f394842be | |||
02f4f75526 | |||
43f462c91b | |||
77bad3ad23 | |||
835a4b6497 | |||
d1a7b6988c | |||
365129d811 | |||
b840ac91dc | |||
dcd2f9ac77 | |||
37d9afc5cc | |||
62b3a1e800 | |||
9c54be6cf1 | |||
53409530b3 | |||
43014cd465 | |||
e27e3622d4 | |||
b169629dbd | |||
8fbeeb1439 | |||
2a489f844b | |||
a161aac7c1 | |||
a7f928ac31 | |||
50ae95cee4 | |||
f6bfa96a96 | |||
e86dcc9f18 | |||
9d33580aac | |||
77cfd504cf | |||
f7bbd467b5 | |||
8993ba4305 | |||
ba7313b521 | |||
e2d30641be | |||
2248773566 | |||
5f43d0ad42 | |||
af47531745 | |||
e80bd2d30c | |||
ac5815d994 | |||
540d741df0 | |||
ecb5854be0 | |||
25b650f59d | |||
ed6f19d3d8 | |||
aecd157244 | |||
43a98b0ec2 | |||
3b00cee858 | |||
2fbc0aefb1 | |||
2276a2f5c3 | |||
8fcca6fb41 | |||
b8568034f0 | |||
3ebf41ba34 | |||
304e84502d | |||
a6e42d98d9 | |||
de176a10bc | |||
e3183f7cda | |||
b5e0fff6b9 | |||
36db3428ab | |||
e7da8b9d6b | |||
c134df30db | |||
b5e6c2d6e2 | |||
b6f8509234 | |||
d45cd63583 | |||
0c9b460cc4 | |||
dd762726dc | |||
e68d57feec | |||
0c9d8e5929 | |||
75c3fa91dc | |||
a37c7e1246 | |||
392dcd57c6 | |||
1369cf7176 | |||
eccd0985a0 | |||
0617b8898a | |||
fbcdeb8439 | |||
6ed0a2b4aa | |||
8e50c0c103 | |||
f2cd5e1d8e |
@ -34,6 +34,7 @@ file in one the following folders:
|
||||
* [docs/](docs/) (this is where you can find most of our docs content)
|
||||
* [frida_mode/](frida_mode/)
|
||||
* [instrumentation/](instrumentation/)
|
||||
* [nyx_mode/](nyx_mode/)
|
||||
* [qemu_mode/](qemu_mode/)
|
||||
* [unicorn_mode/](unicorn_mode/)
|
||||
|
||||
|
12
GNUmakefile
12
GNUmakefile
@ -441,6 +441,14 @@ test_shm:
|
||||
@echo "[-] shmat seems not to be working, switching to mmap implementation"
|
||||
endif
|
||||
|
||||
ifeq "$(shell echo '$(HASH)include <zlib.h>@int main() {return 0; }' | tr @ '\n' | $(CC) $(CFLAGS) -Werror -x c - -lz -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
|
||||
override SPECIAL_PERFORMANCE += -DHAVE_ZLIB
|
||||
override LDFLAGS += -lz
|
||||
$(info [+] ZLIB detected)
|
||||
else
|
||||
$(info [!] Warning: no ZLIB detected)
|
||||
endif
|
||||
|
||||
.PHONY: test_python
|
||||
ifeq "$(PYTHON_OK)" "1"
|
||||
test_python:
|
||||
@ -471,8 +479,8 @@ src/afl-forkserver.o : $(COMM_HDR) src/afl-forkserver.c include/forkserver.h
|
||||
src/afl-sharedmem.o : $(COMM_HDR) src/afl-sharedmem.c include/sharedmem.h
|
||||
$(CC) $(CFLAGS) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) -c src/afl-sharedmem.c -o src/afl-sharedmem.o
|
||||
|
||||
afl-fuzz: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o src/hashmap.c | test_x86
|
||||
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) -Wno-shift-count-overflow $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o src/hashmap.c -o $@ $(PYFLAGS) $(LDFLAGS) -lm
|
||||
afl-fuzz: $(COMM_HDR) include/afl-fuzz.h $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o | test_x86
|
||||
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) $(AFL_FUZZ_FILES) src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(PYFLAGS) $(LDFLAGS) -lm
|
||||
|
||||
afl-showmap: src/afl-showmap.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o $(COMM_HDR) | test_x86
|
||||
$(CC) $(CFLAGS) $(COMPILE_STATIC) $(CFLAGS_FLTO) $(SPECIAL_PERFORMANCE) src/$@.c src/afl-fuzz-mutators.c src/afl-fuzz-python.c src/afl-common.o src/afl-sharedmem.o src/afl-forkserver.o src/afl-performance.o -o $@ $(PYFLAGS) $(LDFLAGS)
|
||||
|
@ -32,6 +32,9 @@ VERSION = $(shell grep '^$(HASH)define VERSION ' ./config.h | cut -d '"' -f2
|
||||
|
||||
SYS = $(shell uname -s)
|
||||
|
||||
override LLVM_TOO_NEW_DEFAULT := 18
|
||||
override LLVM_TOO_OLD_DEFAULT := 13
|
||||
|
||||
ifeq "$(SYS)" "OpenBSD"
|
||||
LLVM_CONFIG ?= $(BIN_PATH)/llvm-config
|
||||
HAS_OPT = $(shell test -x $(BIN_PATH)/opt && echo 0 || echo 1)
|
||||
@ -39,24 +42,30 @@ ifeq "$(SYS)" "OpenBSD"
|
||||
$(warning llvm_mode needs a complete llvm installation (versions 6.0 up to 13) -> e.g. "pkg_add llvm-7.0.1p9")
|
||||
endif
|
||||
else
|
||||
LLVM_CONFIG ?= llvm-config
|
||||
# Small function to use Bash to detect the latest available clang and clang++ binaries, if using them by that name fails
|
||||
override _CLANG_VERSIONS_TO_TEST := $(patsubst %,-%,$(shell seq $(LLVM_TOO_NEW_DEFAULT) -1 $(LLVM_TOO_OLD_DEFAULT)))
|
||||
detect_newest=$(shell for v in "" $(_CLANG_VERSIONS_TO_TEST); do test -n "$$(command -v -- $1$$v)" && { echo "$1$$v"; break; }; done)
|
||||
LLVM_CONFIG ?= $(call detect_newest,llvm-config)
|
||||
endif
|
||||
|
||||
LLVMVER = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/git//' | sed 's/svn//' )
|
||||
LLVM_MAJOR = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/\..*//' )
|
||||
LLVM_MINOR = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/.*\.//' | sed 's/git//' | sed 's/svn//' | sed 's/ .*//' | sed 's/rc.*//' )
|
||||
LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^[0-2]\.|^3.[0-8]\.' && echo 1 || echo 0 )
|
||||
LLVM_TOO_NEW = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^19|^2[0-9]' && echo 1 || echo 0 )
|
||||
LLVM_TOO_OLD = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^[1-9]\.|^1[012]\.' && echo 1 || echo 0 )
|
||||
LLVM_NEW_API = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[0-9]' && echo 1 || echo 0 )
|
||||
LLVM_NEWER_API = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[6-9]' && echo 1 || echo 0 )
|
||||
LLVM_13_OK = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[3-9]' && echo 1 || echo 0 )
|
||||
LLVM_HAVE_LTO = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[2-9]' && echo 1 || echo 0 )
|
||||
LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir 2>/dev/null)
|
||||
LLVM_LIBDIR = $(shell $(LLVM_CONFIG) --libdir 2>/dev/null)
|
||||
LLVM_STDCXX = gnu++11
|
||||
LLVM_APPLE_XCODE = $(shell $(CC) -v 2>&1 | grep -q Apple && echo 1 || echo 0)
|
||||
LLVM_LTO = 0
|
||||
override LLVM_RAW_VER := $(shell $(LLVM_CONFIG) --version 2>/dev/null)
|
||||
LLVMVER := $(subst svn,,$(subst git,,$(LLVM_RAW_VER)))
|
||||
LLVM_MAJOR := $(firstword $(subst ., ,$(LLVMVER)))
|
||||
LLVM_MINOR := $(firstword $(subst ., ,$(subst $(LLVM_MAJOR).,,$(LLVMVER))))
|
||||
LLVM_TOO_NEW := $(shell test $(LLVM_MAJOR) -gt $(LLVM_TOO_NEW_DEFAULT) && echo 1 || echo 0)
|
||||
LLVM_TOO_OLD := $(shell test $(LLVM_MAJOR) -lt $(LLVM_TOO_OLD_DEFAULT) && echo 1 || echo 0)
|
||||
LLVM_NEW_API := $(shell test $(LLVM_MAJOR) -ge 10 && echo 1 || echo 0)
|
||||
LLVM_NEWER_API := $(shell test $(LLVM_MAJOR) -ge 16 && echo 1 || echo 0)
|
||||
LLVM_13_OK := $(shell test $(LLVM_MAJOR) -ge 13 && echo 1 || echo 0)
|
||||
LLVM_HAVE_LTO := $(shell test $(LLVM_MAJOR) -ge 12 && echo 1 || echo 0)
|
||||
LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir 2>/dev/null)
|
||||
LLVM_LIBDIR := $(shell $(LLVM_CONFIG) --libdir 2>/dev/null)
|
||||
LLVM_STDCXX := gnu++11
|
||||
LLVM_APPLE_XCODE := $(shell $(CC) -v 2>&1 | grep -q Apple && echo 1 || echo 0)
|
||||
LLVM_LTO := 0
|
||||
LLVM_UNSUPPORTED := $(shell echo "$(LLVMVER)" | grep -E -q '^[0-2]\.|^3\.[0-8]\.' && echo 1 || echo 0)
|
||||
# Uncomment to see the values assigned above
|
||||
# $(foreach var,LLVM_CONFIG LLVMVER LLVM_MAJOR LLVM_MINOR LLVM_TOO_NEW LLVM_TOO_OLD LLVM_TOO_NEW_DEFAULT LLVM_TOO_OLD_DEFAULT LLVM_NEW_API LLVM_NEWER_API LLVM_13_OK LLVM_HAVE_LTO LLVM_BINDIR LLVM_LIBDIR LLVM_STDCXX LLVM_APPLE_XCODE LLVM_LTO LLVM_UNSUPPORTED,$(warning $(var) = $($(var))))
|
||||
|
||||
ifeq "$(LLVMVER)" ""
|
||||
$(warning [!] llvm_mode needs llvm-config, which was not found. Set LLVM_CONFIG to its path and retry.)
|
||||
@ -245,7 +254,7 @@ endif
|
||||
|
||||
AFL_CLANG_FUSELD=
|
||||
ifeq "$(LLVM_LTO)" "1"
|
||||
ifeq "$(shell echo 'int main() {return 0; }' | $(CLANG_BIN) -x c - -fuse-ld=`command -v ld` -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
|
||||
ifeq "$(shell echo 'int main() {return 0; }' | $(CLANG_BIN) -x c - -fuse-ld=$$(command -v ld) -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
|
||||
AFL_CLANG_FUSELD=1
|
||||
ifeq "$(shell echo 'int main() {return 0; }' | $(CLANG_BIN) -x c - -fuse-ld=ld.lld --ld-path=$(AFL_REAL_LD) -o .test 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
|
||||
AFL_CLANG_LDPATH=1
|
||||
@ -300,8 +309,8 @@ endif
|
||||
ifneq "$(LLVM_CONFIG)" ""
|
||||
CLANG_CFL += -I$(shell dirname $(LLVM_CONFIG))/../include
|
||||
endif
|
||||
CLANG_CPPFL = `$(LLVM_CONFIG) --cxxflags` -fno-rtti -fno-exceptions -fPIC $(CXXFLAGS) $(CPPFLAGS) -Wno-deprecated-declarations
|
||||
CLANG_LFL = `$(LLVM_CONFIG) --ldflags` $(LDFLAGS)
|
||||
CLANG_CPPFL = $$($(LLVM_CONFIG) --cxxflags) -fno-rtti -fno-exceptions -fPIC $(CXXFLAGS) $(CPPFLAGS) -Wno-deprecated-declarations
|
||||
CLANG_LFL = $$($(LLVM_CONFIG) --ldflags) $(LDFLAGS)
|
||||
|
||||
# wasm fuzzing: disable thread-local storage and unset LLVM debug flag
|
||||
ifdef WAFL_MODE
|
||||
@ -319,7 +328,7 @@ else
|
||||
endif
|
||||
|
||||
ifeq "$(SYS)" "OpenBSD"
|
||||
CLANG_LFL += `$(LLVM_CONFIG) --libdir`/libLLVM.so
|
||||
CLANG_LFL += $$($(LLVM_CONFIG) --libdir)/libLLVM.so
|
||||
CLANG_CPPFL += -mno-retpoline
|
||||
CFLAGS += -mno-retpoline
|
||||
# Needed for unwind symbols
|
||||
@ -417,7 +426,7 @@ endif
|
||||
endif
|
||||
|
||||
instrumentation/afl-llvm-common.o: instrumentation/afl-llvm-common.cc instrumentation/afl-llvm-common.h
|
||||
$(CXX) $(CFLAGS) $(CPPFLAGS) `$(LLVM_CONFIG) --cxxflags` -fno-rtti -fPIC -std=$(LLVM_STDCXX) -c $< -o $@
|
||||
$(CXX) $(CFLAGS) $(CPPFLAGS) $$($(LLVM_CONFIG) --cxxflags) -fno-rtti -fPIC -std=$(LLVM_STDCXX) -c $< -o $@
|
||||
|
||||
./afl-llvm-pass.so: instrumentation/afl-llvm-pass.so.cc instrumentation/afl-llvm-common.o | test_deps
|
||||
ifeq "$(LLVM_MIN_4_0_1)" "0"
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
Release version: [4.21c](https://github.com/AFLplusplus/AFLplusplus/releases)
|
||||
|
||||
GitHub version: 4.21c
|
||||
GitHub version: 4.22a
|
||||
|
||||
Repository:
|
||||
[https://github.com/AFLplusplus/AFLplusplus](https://github.com/AFLplusplus/AFLplusplus)
|
||||
|
2
TODO.md
2
TODO.md
@ -2,7 +2,7 @@
|
||||
|
||||
## Must
|
||||
|
||||
- fast restart of afl-fuzz if cmdline + target hash is the same
|
||||
- ijon support?
|
||||
- check for null ptr for xml/curl/g_ string transform functions
|
||||
- hardened_usercopy=0 page_alloc.shuffle=0
|
||||
- add value_profile but only enable after 15 minutes without finds
|
||||
|
@ -48,7 +48,7 @@ size_t afl_custom_fuzz(my_mutator_t *data, uint8_t *buf, size_t buf_size,
|
||||
|
||||
u8 *ptr = realloc(data->buf, max_size);
|
||||
|
||||
if (ptr) {
|
||||
if (!ptr) {
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -53,7 +53,7 @@ size_t afl_custom_fuzz(my_mutator_t *data, uint8_t *buf, size_t buf_size,
|
||||
|
||||
u8 *ptr = realloc(data->buf, max_size);
|
||||
|
||||
if (ptr) {
|
||||
if (!ptr) {
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -13,7 +13,7 @@ Just type `make` to build `atnwalk.so`.
|
||||
**NOTE:** The commands below just demonstrate an example how running ATNwalk looks like and require a working [testbed](https://github.com/atnwalk/testbed)
|
||||
|
||||
```bash
|
||||
# create the required a random seed first
|
||||
# create the required random seed first
|
||||
mkdir -p ~/campaign/example/seeds
|
||||
cd ~/campaign/example/seeds
|
||||
head -c1 /dev/urandom | ~/atnwalk/build/javascript/bin/decode -wb > seed.decoded 2> seed.encoded
|
||||
|
@ -180,7 +180,8 @@ size_t fail_fatal(int fd_socket, uint8_t **out_buf) {
|
||||
|
||||
if (fd_socket != -1) { close(fd_socket); }
|
||||
*out_buf = NULL;
|
||||
return 0;
|
||||
fprintf(stderr, "atnwalk.socket not found in current directory!\n");
|
||||
exit(-1);
|
||||
|
||||
}
|
||||
|
||||
|
7
custom_mutators/custom_send_tcp/Makefile
Normal file
7
custom_mutators/custom_send_tcp/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
all: custom_send_tcp.so
|
||||
|
||||
custom_send_tcp.so:
|
||||
$(CC) -Wno-unused-result -g -O3 -shared -fPIC -o custom_send_tcp.so -I../../include custom_send_tcp.c
|
||||
|
||||
clean:
|
||||
rm -f custom_send_tcp.so *.o *~ core
|
13
custom_mutators/custom_send_tcp/README.md
Normal file
13
custom_mutators/custom_send_tcp/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Send testcases via TCP custom mutator
|
||||
|
||||
This custom mutator sends the fuzzing testcases via TCP.
|
||||
|
||||
`AFL_CUSTOM_MUTATOR_LATE_SEND` - MUST be set!
|
||||
`CUSTOM_SEND_IP` - the IP address to send to (basically only 127.0.0.1 makes sense)
|
||||
`CUSTOM_SEND_PORT` - the TCP port to send to
|
||||
`CUSTOM_SEND_READ` - if the custom mutator should wait for a reply from the target
|
||||
|
||||
Example:
|
||||
```
|
||||
CUSTOM_SEND_IP=127.0.0.1 CUSTOM_SEND_PORT=8000 CUSTOM_SEND_READ=1 AFL_CUSTOM_MUTATOR_LATE_SEND=1 AFL_CUSTOM_MUTATOR_LIBRARY=custom_send_tcp.so ./afl-fuzz ...
|
||||
```
|
113
custom_mutators/custom_send_tcp/custom_send_tcp.c
Normal file
113
custom_mutators/custom_send_tcp/custom_send_tcp.c
Normal file
@ -0,0 +1,113 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "afl-fuzz.h"
|
||||
|
||||
static int my_debug = 0;
|
||||
static int my_read = 0;
|
||||
|
||||
#define DEBUG(...) if (my_debug) printf(__VA_ARGS__)
|
||||
|
||||
typedef struct tcp_send_mutator {
|
||||
afl_state_t* afl;
|
||||
struct sockaddr_in server_addr;
|
||||
} tcp_send_mutator_t;
|
||||
|
||||
void *afl_custom_init(afl_state_t* afl, uint32_t seed) {
|
||||
const char* ip = getenv("CUSTOM_SEND_IP");
|
||||
const char* port = getenv("CUSTOM_SEND_PORT");
|
||||
|
||||
if (getenv("AFL_DEBUG")) my_debug = 1;
|
||||
if (getenv("CUSTOM_SEND_READ")) my_read = 1;
|
||||
|
||||
if (!ip || !port) {
|
||||
fprintf(stderr, "You forgot to set CUSTOM_SEND_IP and/or CUSTOM_SEND_PORT\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tcp_send_mutator_t* mutator = calloc(1, sizeof(tcp_send_mutator_t));
|
||||
if (!mutator) {
|
||||
fprintf(stderr, "Failed to allocate mutator struct\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mutator->afl = afl;
|
||||
|
||||
bzero(&mutator->server_addr, sizeof(mutator->server_addr));
|
||||
mutator->server_addr.sin_family = AF_INET;
|
||||
if (inet_pton(AF_INET, ip, &mutator->server_addr.sin_addr) <= 0) {
|
||||
fprintf(stderr, "Could not convert target ip address!\n");
|
||||
exit(1);
|
||||
}
|
||||
mutator->server_addr.sin_port = htons(atoi(port));
|
||||
|
||||
printf("[+] Custom tcp send mutator setup ready to go!\n");
|
||||
|
||||
return mutator;
|
||||
}
|
||||
|
||||
int try_connect(tcp_send_mutator_t *mutator, int sock, int max_attempts) {
|
||||
while (max_attempts > 0) {
|
||||
if (connect(sock, (struct sockaddr*)&mutator->server_addr, sizeof(mutator->server_addr)) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Even with AFL_CUSTOM_LATE_SEND=1, there is a race between the
|
||||
// application under test having started to listen for connections and
|
||||
// afl_custom_fuzz_send being called. To address this race, we attempt
|
||||
// to connect N times and sleep a short period of time in between
|
||||
// connection attempts.
|
||||
struct timespec t;
|
||||
t.tv_sec = 0;
|
||||
t.tv_nsec = 100;
|
||||
nanosleep(&t, NULL);
|
||||
--max_attempts;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void afl_custom_fuzz_send(tcp_send_mutator_t *mutator, uint8_t *buf, size_t buf_size) {
|
||||
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
int written = 0;
|
||||
if (sock >= 0 && try_connect(mutator, sock, 10000) == 0) {
|
||||
DEBUG("connected, write()\n");
|
||||
written = write(sock, buf, buf_size);
|
||||
} else {
|
||||
DEBUG("socket() or connect() error: %d\n", errno);
|
||||
}
|
||||
|
||||
if (written < 0) {
|
||||
DEBUG("write() error: %d\n", errno);
|
||||
} else if (my_read) {
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
fd_set set;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(sock, &set);
|
||||
|
||||
int select_res = select(sock + 1, &set, NULL, NULL, &timeout);
|
||||
if (select_res == -1) {
|
||||
DEBUG("select() error: %d\n", errno);
|
||||
} else if (select_res == 0) {
|
||||
DEBUG("read() timeout!\n");
|
||||
} else {
|
||||
uint8_t buf[64];
|
||||
(void)read(sock, buf, sizeof(buf));
|
||||
}
|
||||
}
|
||||
|
||||
close(sock);
|
||||
}
|
||||
|
||||
void afl_custom_deinit(tcp_send_mutator_t* mutator) {
|
||||
free(mutator);
|
||||
}
|
Submodule custom_mutators/gramatron/json-c updated: 11546bfd07...af8dd4a307
@ -1 +1 @@
|
||||
95a6857
|
||||
05d8f53
|
||||
|
Submodule custom_mutators/grammar_mutator/grammar_mutator updated: 95a685773e...05d8f537f8
@ -3707,7 +3707,7 @@ typedef intptr_t wdiff;
|
||||
1024 * 1024 * 8 /* static malloc'd heap size if used as a library */
|
||||
#define FBITS 24 /* bits in fixnum, on the way to 24 and beyond */
|
||||
#define FMAX \
|
||||
((1 << FBITS) - 1) /* maximum fixnum (and most negative fixnum) \
|
||||
((1U << FBITS) - 1) /* maximum fixnum (and most negative fixnum) \
|
||||
*/
|
||||
#define MAXOBJ 0xffff /* max words in tuple including header */
|
||||
#define MAXPAYL \
|
||||
|
5713
dictionaries/ruby.dict
Normal file
5713
dictionaries/ruby.dict
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,32 @@
|
||||
This is the list of all noteworthy changes made in every public
|
||||
release of the tool. See README.md for the general instruction manual.
|
||||
|
||||
### Version ++4.22a (dev)
|
||||
- afl-fuzz:
|
||||
- fastresume feature added. if you abort fuzzing and resume fuzzing
|
||||
with `-i -` or `AFL_AUTORESUME=1` and the target binary has not changed
|
||||
then a dump will be loaded and the calibration phase skipped.
|
||||
to disable this feature set `AFL_NO_FASTRESUME=1`
|
||||
zlib compression is used if zlib is found at compile time
|
||||
- improved seed selection algorithm
|
||||
- added `AFL_CUSTOM_MUTATOR_LATE_SEND=1` to call the custom send()
|
||||
function after the target has been restarted.
|
||||
- frida_mode:
|
||||
- AFL_FRIDA_PERSISTENT_ADDR can now be be any reachable address not just
|
||||
a function entry
|
||||
- AFL_DEBUG is now the same as AFL_FRIDA_VERBOSE
|
||||
- AFL_FRIDA_DEBUG_MAPS now works as expected
|
||||
- qemu_mode:
|
||||
- new hooks supported (optional), see qemu_mode/hooking_bridge - thanks to
|
||||
@CowBoy4mH3LL
|
||||
- custom mutators:
|
||||
- custom_send_tcp custom mutator added, thanks to @dergoegge
|
||||
- afl-cc
|
||||
- new runtime (!) variable: `AFL_OLD_FORKSERVER` to use the old vanilla
|
||||
AFL type forkserver. Useful for symcc/symqemu/nautilus/etc. with
|
||||
AFL_LLVM_INSTRUMENT=CLASSIC
|
||||
|
||||
|
||||
### Version ++4.21c (release)
|
||||
* afl-fuzz
|
||||
- fixed a regression in afl-fuzz that resulted in a 5-10% performace loss
|
||||
@ -42,7 +68,6 @@
|
||||
* Fixed a shmem mmap bug (that rarely came up on MacOS)
|
||||
* libtokencap: script generate_libtoken_dict.sh added by @a-shvedov
|
||||
|
||||
|
||||
### Version ++4.20c (release)
|
||||
! A new forkserver communication model is now introduced. afl-fuzz is
|
||||
backward compatible to old compiled targets if they are not built
|
||||
|
@ -198,6 +198,11 @@ def deinit(): # optional for Python
|
||||
This method can be used if you want to send data to the target yourself,
|
||||
e.g. via IPC. This replaces some usage of utils/afl_proxy but requires
|
||||
that you start the target with afl-fuzz.
|
||||
|
||||
Setting `AFL_CUSTOM_MUTATOR_LATE_SEND` will call the afl_custom_fuzz_send()
|
||||
function after the target has been restarted. (This is needed for e.g. TCP
|
||||
services.)
|
||||
|
||||
Example: [custom_mutators/examples/custom_send.c](../custom_mutators/examples/custom_send.c)
|
||||
|
||||
- `queue_new_entry` (optional):
|
||||
|
@ -331,7 +331,26 @@ mode.
|
||||
the target performs only a few loops, then this will give a small
|
||||
performance boost.
|
||||
|
||||
## 4) Settings for afl-fuzz
|
||||
## 4) Runtime settings
|
||||
|
||||
The following environment variables are for a compiled AFL++ target.
|
||||
|
||||
- Setting `AFL_DUMP_MAP_SIZE` when executing the target directly will
|
||||
dump the map size of the target and exit.
|
||||
|
||||
- Setting `AFL_OLD_FORKSERVER` will use the old AFL vanilla forkserver.
|
||||
This makes only sense when you
|
||||
a) compile in a classic colliding coverage mode (e.g.
|
||||
AFL_LLVM_INSTRUMENT=CLASSIC) or if the map size of the target is
|
||||
below MAP_SIZE (65536 by default), AND
|
||||
b) you want to use this compiled AFL++ target with a different tool
|
||||
that expects vanilla AFL behaviour, e.g. symcc, symqemu, nautilus, etc.
|
||||
You would use this option together with the target fuzzing application.
|
||||
|
||||
- Setting `AFL_DISABLE_LLVM_INSTRUMENTATION` will disable collecting
|
||||
instrumentation. (More of an internal option.)
|
||||
|
||||
## 5) Settings for afl-fuzz
|
||||
|
||||
The main fuzzer binary accepts several options that disable a couple of sanity
|
||||
checks or alter some of the more exotic semantics of the tool:
|
||||
@ -368,6 +387,10 @@ checks or alter some of the more exotic semantics of the tool:
|
||||
XML or other highly flexible structured input. For details, see
|
||||
[custom_mutators.md](custom_mutators.md).
|
||||
|
||||
- Setting `AFL_CUSTOM_MUTATOR_LATE_SEND` will call the afl_custom_fuzz_send()
|
||||
function after the target has been restarted. (This is needed for e.g. TCP
|
||||
services.)
|
||||
|
||||
- Setting `AFL_CYCLE_SCHEDULES` will switch to a different schedule every time
|
||||
a cycle is finished.
|
||||
|
||||
@ -514,6 +537,8 @@ checks or alter some of the more exotic semantics of the tool:
|
||||
- `AFL_NO_SNAPSHOT` will advise afl-fuzz not to use the snapshot feature if
|
||||
the snapshot lkm is loaded.
|
||||
|
||||
- `AFL_NO_FASTRESUME` will not try to read or write a fast resume file.
|
||||
|
||||
- Setting `AFL_NO_UI` inhibits the UI altogether and just periodically prints
|
||||
some basic stats. This behavior is also automatically triggered when the
|
||||
output from afl-fuzz is redirected to a file or to a pipe.
|
||||
@ -636,7 +661,7 @@ checks or alter some of the more exotic semantics of the tool:
|
||||
Note that will not be exact and with slow targets it can take seconds
|
||||
until there is a slice for the time test.
|
||||
|
||||
## 5) Settings for afl-qemu-trace
|
||||
## 6) Settings for afl-qemu-trace
|
||||
|
||||
The QEMU wrapper used to instrument binary-only code supports several settings:
|
||||
|
||||
@ -708,7 +733,7 @@ The QEMU wrapper used to instrument binary-only code supports several settings:
|
||||
crash is found. Setting `AFL_NO_CRASH_README` will prevent this. Useful when
|
||||
counting crashes based on a file count in that directory.
|
||||
|
||||
## 7) Settings for afl-frida-trace
|
||||
## 8) Settings for afl-frida-trace
|
||||
|
||||
The FRIDA wrapper used to instrument binary-only code supports many of the same
|
||||
options as `afl-qemu-trace`, but also has a number of additional advanced
|
||||
@ -798,7 +823,7 @@ support.
|
||||
dump you must set a sufficient timeout (using `-t`) to avoid `afl-fuzz`
|
||||
killing the process whilst it is being dumped.
|
||||
|
||||
## 8) Settings for afl-cmin
|
||||
## 9) Settings for afl-cmin
|
||||
|
||||
The corpus minimization script offers very little customization:
|
||||
|
||||
@ -816,7 +841,7 @@ The corpus minimization script offers very little customization:
|
||||
- `AFL_PRINT_FILENAMES` prints each filename to stdout, as it gets processed.
|
||||
This can help when embedding `afl-cmin` or `afl-showmap` in other scripts.
|
||||
|
||||
## 9) Settings for afl-tmin
|
||||
## 10) Settings for afl-tmin
|
||||
|
||||
Virtually nothing to play with. Well, in QEMU mode (`-Q`), `AFL_PATH` will be
|
||||
searched for afl-qemu-trace. In addition to this, `TMPDIR` may be used if a
|
||||
@ -827,12 +852,12 @@ to match when minimizing crashes. This will make minimization less useful, but
|
||||
may prevent the tool from "jumping" from one crashing condition to another in
|
||||
very buggy software. You probably want to combine it with the `-e` flag.
|
||||
|
||||
## 10) Settings for afl-analyze
|
||||
## 11) Settings for afl-analyze
|
||||
|
||||
You can set `AFL_ANALYZE_HEX` to get file offsets printed as hexadecimal instead
|
||||
of decimal.
|
||||
|
||||
## 11) Settings for libdislocator
|
||||
## 12) Settings for libdislocator
|
||||
|
||||
The library honors these environment variables:
|
||||
|
||||
@ -854,12 +879,12 @@ The library honors these environment variables:
|
||||
- `AFL_LD_VERBOSE` causes the library to output some diagnostic messages that
|
||||
may be useful for pinpointing the cause of any observed issues.
|
||||
|
||||
## 11) Settings for libtokencap
|
||||
## 13) Settings for libtokencap
|
||||
|
||||
This library accepts `AFL_TOKEN_FILE` to indicate the location to which the
|
||||
discovered tokens should be written.
|
||||
|
||||
## 12) Third-party variables set by afl-fuzz & other tools
|
||||
## 14) Third-party variables set by afl-fuzz & other tools
|
||||
|
||||
Several variables are not directly interpreted by afl-fuzz, but are set to
|
||||
optimal values if not already present in the environment:
|
||||
|
@ -214,6 +214,9 @@ all: $(FRIDA_TRACE) $(FRIDA_TRACE_LIB) $(AFLPP_FRIDA_DRIVER_HOOK_OBJ) $(AFLPP_QE
|
||||
arm:
|
||||
CFLAGS="-marm" LDFLAGS="-marm" ARCH="armhf" TARGET_CC=arm-linux-gnueabihf-gcc TARGET_CXX=arm-linux-gnueabihf-g++ make all
|
||||
|
||||
arm64:
|
||||
ARCH="arm64" TARGET_CC=aarch64-linux-gnu-gcc TARGET_CXX=aarch64-linux-gnu-g++ make all
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
|
@ -6,34 +6,39 @@
|
||||
|
||||
#define UNUSED_PARAMETER(x) (void)(x)
|
||||
|
||||
int phdr_callback(struct dl_phdr_info *info, size_t size, void *data)
|
||||
{
|
||||
UNUSED_PARAMETER (size);
|
||||
int phdr_callback(struct dl_phdr_info *info, size_t size, void *data) {
|
||||
|
||||
ElfW(Addr) * base = data;
|
||||
UNUSED_PARAMETER(size);
|
||||
|
||||
ElfW(Addr) *base = data;
|
||||
|
||||
if (info->dlpi_name[0] == 0) { *base = info->dlpi_addr; }
|
||||
return 0;
|
||||
|
||||
if (info->dlpi_name[0] == 0) { *base = info->dlpi_addr; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char** argv, char** envp) {
|
||||
UNUSED_PARAMETER (argc);
|
||||
int main(int argc, char **argv, char **envp) {
|
||||
|
||||
ElfW(Addr) base = 0;
|
||||
UNUSED_PARAMETER(argc);
|
||||
|
||||
int persona = personality(ADDR_NO_RANDOMIZE);
|
||||
if (persona == -1) {
|
||||
ElfW(Addr) base = 0;
|
||||
|
||||
printf("Failed to set ADDR_NO_RANDOMIZE: %d", errno);
|
||||
return 1;
|
||||
}
|
||||
int persona = personality(ADDR_NO_RANDOMIZE);
|
||||
if (persona == -1) {
|
||||
|
||||
if ((persona & ADDR_NO_RANDOMIZE) == 0) { execvpe(argv[0], argv, envp); }
|
||||
printf("Failed to set ADDR_NO_RANDOMIZE: %d", errno);
|
||||
return 1;
|
||||
|
||||
dl_iterate_phdr(phdr_callback, &base);
|
||||
}
|
||||
|
||||
printf("%p\n", (void *)base);
|
||||
if (base == 0) { return 1; }
|
||||
if ((persona & ADDR_NO_RANDOMIZE) == 0) { execvpe(argv[0], argv, envp); }
|
||||
|
||||
dl_iterate_phdr(phdr_callback, &base);
|
||||
|
||||
printf("%p\n", (void *)base);
|
||||
if (base == 0) { return 1; }
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
js_api_set_stdout;
|
||||
js_api_set_traceable;
|
||||
js_api_set_verbose;
|
||||
js_api_ijon_set;
|
||||
|
||||
local:
|
||||
*;
|
||||
|
@ -31,8 +31,8 @@ __attribute__((visibility("default"))) void afl_persistent_hook(
|
||||
// do a length check matching the target!
|
||||
|
||||
void **esp = (void **)regs->esp;
|
||||
void *arg1 = esp[0];
|
||||
void **arg2 = &esp[1];
|
||||
void *arg1 = esp[1];
|
||||
void **arg2 = &esp[2];
|
||||
memcpy(arg1, input_buf, input_buf_len);
|
||||
*arg2 = (void *)input_buf_len;
|
||||
|
||||
|
@ -36,7 +36,7 @@ struct x86_64_regs {
|
||||
void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
|
||||
uint8_t *input_buf, uint32_t input_buf_len) {
|
||||
|
||||
(void)guest_base; /* unused */
|
||||
(void)guest_base; /* unused */
|
||||
memcpy((void *)regs->rdi, input_buf, input_buf_len);
|
||||
regs->rsi = input_buf_len;
|
||||
|
||||
@ -76,14 +76,15 @@ struct x86_regs {
|
||||
void afl_persistent_hook(struct x86_regs *regs, uint64_t guest_base,
|
||||
uint8_t *input_buf, uint32_t input_buf_len) {
|
||||
|
||||
(void)guest_base; /* unused */
|
||||
(void)guest_base; /* unused */
|
||||
void **esp = (void **)regs->esp;
|
||||
void * arg1 = esp[1];
|
||||
void *arg1 = esp[1];
|
||||
void **arg2 = &esp[2];
|
||||
memcpy(arg1, input_buf, input_buf_len);
|
||||
*arg2 = (void *)input_buf_len;
|
||||
|
||||
}
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
struct arm64_regs {
|
||||
@ -177,9 +178,10 @@ struct arm64_regs {
|
||||
void afl_persistent_hook(struct arm64_regs *regs, uint64_t guest_base,
|
||||
uint8_t *input_buf, uint32_t input_buf_len) {
|
||||
|
||||
(void)guest_base; /* unused */
|
||||
(void)guest_base; /* unused */
|
||||
memcpy((void *)regs->x0, input_buf, input_buf_len);
|
||||
regs->x1 = input_buf_len;
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@ -193,3 +195,4 @@ int afl_persistent_hook_init(void) {
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ extern guint64 instrument_fixed_seed;
|
||||
|
||||
extern uint8_t *__afl_area_ptr;
|
||||
extern uint32_t __afl_map_size;
|
||||
extern void __afl_coverage_interesting(uint8_t, uint32_t);
|
||||
|
||||
extern __thread guint64 *instrument_previous_pc_addr;
|
||||
|
||||
@ -72,5 +73,7 @@ void instrument_cache(const cs_insn *instr, GumStalkerOutput *output);
|
||||
void instrument_write_regs(GumCpuContext *cpu_context, gpointer user_data);
|
||||
void instrument_regs_format(int fd, char *format, ...);
|
||||
|
||||
void ijon_set(uint32_t edge);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -449,3 +449,9 @@ void instrument_regs_format(int fd, char *format, ...) {
|
||||
|
||||
}
|
||||
|
||||
void ijon_set(uint32_t edge) {
|
||||
|
||||
__afl_coverage_interesting(1, edge);
|
||||
|
||||
}
|
||||
|
||||
|
@ -326,6 +326,12 @@ class Afl {
|
||||
static jsApiGetSymbol(name) {
|
||||
return Afl.module.getExportByName(name);
|
||||
}
|
||||
|
||||
static IJON = class {
|
||||
static set(addr, val) {
|
||||
Afl.jsApiIjonSet((addr ^ val) & 0xffffffff);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Field containing the `Module` object for `afl-frida-trace.so` (the FRIDA mode
|
||||
@ -377,3 +383,4 @@ Afl.jsApiSetVerbose = Afl.jsApiGetFunction("js_api_set_verbose", "void", []);
|
||||
Afl.jsApiWrite = new NativeFunction(
|
||||
/* tslint:disable-next-line:no-null-keyword */
|
||||
Module.getExportByName(null, "write"), "int", ["int", "pointer", "int"]);
|
||||
Afl.jsApiIjonSet = Afl.jsApiGetFunction("js_api_ijon_set", "void", ["uint32"]);
|
||||
|
@ -316,3 +316,9 @@ __attribute__((visibility("default"))) void js_api_set_verbose(void) {
|
||||
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) void js_api_ijon_set(uint32_t edge) {
|
||||
|
||||
ijon_set(edge);
|
||||
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
// r15 - pc
|
||||
|
||||
static GumCpuContext saved_regs = {0};
|
||||
static gpointer saved_lr = NULL;
|
||||
static gpointer persistent_loop = NULL;
|
||||
|
||||
gboolean persistent_is_supported(void) {
|
||||
|
||||
@ -141,17 +141,10 @@ static void instrument_persitent_restore_regs(GumArmWriter *cw,
|
||||
|
||||
}
|
||||
|
||||
static void instrument_exit(GumArmWriter *cw) {
|
||||
static void instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
gum_arm_writer_put_sub_reg_reg_reg(cw, ARM_REG_R0, ARM_REG_R0, ARM_REG_R0);
|
||||
gum_arm_writer_put_call_address_with_arguments(cw, GUM_ADDRESS(_exit), 1,
|
||||
GUM_ARG_REGISTER, ARM_REG_R0);
|
||||
if (__afl_persistent_loop(persistent_count) == 0) { _exit(0); }
|
||||
|
||||
}
|
||||
|
||||
static int instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
int ret = __afl_persistent_loop(persistent_count);
|
||||
if (instrument_previous_pc_addr == NULL) {
|
||||
|
||||
FATAL("instrument_previous_pc_addr uninitialized");
|
||||
@ -159,7 +152,6 @@ static int instrument_afl_persistent_loop_func(void) {
|
||||
}
|
||||
|
||||
*instrument_previous_pc_addr = instrument_hash_zero;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@ -203,7 +195,8 @@ static void instrument_persitent_save_lr(GumArmWriter *cw) {
|
||||
gum_arm_writer_put_str_reg_reg_offset(cw, ARM_REG_R0, ARM_REG_SP,
|
||||
GUM_RED_ZONE_SIZE);
|
||||
|
||||
gum_arm_writer_put_ldr_reg_address(cw, ARM_REG_R0, GUM_ADDRESS(&saved_lr));
|
||||
gum_arm_writer_put_ldr_reg_address(cw, ARM_REG_R0,
|
||||
GUM_ADDRESS(&persistent_ret));
|
||||
gum_arm_writer_put_str_reg_reg_offset(cw, ARM_REG_LR, ARM_REG_R0, 0);
|
||||
|
||||
gum_arm_writer_put_ldr_reg_reg_offset(cw, ARM_REG_R0, ARM_REG_SP,
|
||||
@ -214,65 +207,35 @@ static void instrument_persitent_save_lr(GumArmWriter *cw) {
|
||||
void persistent_prologue_arch(GumStalkerOutput *output) {
|
||||
|
||||
/*
|
||||
* SAVE RET (Used to write the epilogue if persistent_ret is not set)
|
||||
* SAVE REGS
|
||||
* SAVE RET
|
||||
* POP RET
|
||||
* loop:
|
||||
* loop: (Save address of where the eiplogue should jump back to)
|
||||
* CALL instrument_afl_persistent_loop
|
||||
* TEST EAX, EAX
|
||||
* JZ end:
|
||||
* call hook (optionally)
|
||||
* CALL hook (optionally)
|
||||
* RESTORE REGS
|
||||
* call original
|
||||
* jmp loop:
|
||||
*
|
||||
* end:
|
||||
* JMP SAVED RET
|
||||
*
|
||||
* original:
|
||||
* INSTRUMENTED PERSISTENT FUNC
|
||||
*/
|
||||
|
||||
GumArmWriter *cw = output->writer.arm;
|
||||
|
||||
gconstpointer loop = cw->code + 1;
|
||||
|
||||
FVERBOSE("Persistent loop reached");
|
||||
|
||||
if (persistent_ret == 0) { instrument_persitent_save_lr(cw); }
|
||||
|
||||
/* Save the current context */
|
||||
instrument_persitent_save_regs(cw, &saved_regs);
|
||||
|
||||
/* loop: */
|
||||
gum_arm_writer_put_label(cw, loop);
|
||||
/* Store a pointer to where we should return for our next iteration */
|
||||
persistent_loop = gum_arm_writer_cur(cw);
|
||||
|
||||
/* call instrument_prologue_func */
|
||||
/* call __afl_persistent_loop and _exit if zero. Also reset our previous_pc */
|
||||
instrument_afl_persistent_loop(cw);
|
||||
|
||||
/* jz done */
|
||||
gconstpointer done = cw->code + 1;
|
||||
gum_arm_writer_put_cmp_reg_imm(cw, ARM_REG_R0, 0);
|
||||
gum_arm_writer_put_b_cond_label(cw, ARM_CC_EQ, done);
|
||||
|
||||
/* Optionally call the persistent hook */
|
||||
persistent_prologue_hook(cw, &saved_regs);
|
||||
|
||||
/* Restore our CPU context before we continue execution */
|
||||
instrument_persitent_restore_regs(cw, &saved_regs);
|
||||
gconstpointer original = cw->code + 1;
|
||||
/* call original */
|
||||
|
||||
gum_arm_writer_put_bl_label(cw, original);
|
||||
|
||||
/* jmp loop */
|
||||
gum_arm_writer_put_b_label(cw, loop);
|
||||
|
||||
/* done: */
|
||||
gum_arm_writer_put_label(cw, done);
|
||||
|
||||
instrument_exit(cw);
|
||||
|
||||
/* original: */
|
||||
gum_arm_writer_put_label(cw, original);
|
||||
|
||||
instrument_persitent_save_lr(cw);
|
||||
|
||||
if (persistent_debug) { gum_arm_writer_put_breakpoint(cw); }
|
||||
|
||||
@ -284,7 +247,8 @@ void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
|
||||
if (persistent_debug) { gum_arm_writer_put_breakpoint(cw); }
|
||||
|
||||
gum_arm_writer_put_ldr_reg_address(cw, ARM_REG_R0, GUM_ADDRESS(&saved_lr));
|
||||
gum_arm_writer_put_ldr_reg_address(cw, ARM_REG_R0,
|
||||
GUM_ADDRESS(&persistent_loop));
|
||||
|
||||
gum_arm_writer_put_ldr_reg_reg_offset(cw, ARM_REG_R0, ARM_REG_R0, 0);
|
||||
|
||||
|
@ -16,7 +16,7 @@ typedef struct {
|
||||
} persistent_ctx_t;
|
||||
|
||||
static persistent_ctx_t saved_regs = {0};
|
||||
static gpointer saved_lr = NULL;
|
||||
static gpointer persistent_loop = NULL;
|
||||
|
||||
gboolean persistent_is_supported(void) {
|
||||
|
||||
@ -216,17 +216,10 @@ static void instrument_persitent_restore_regs(GumArm64Writer *cw,
|
||||
|
||||
}
|
||||
|
||||
static void instrument_exit(GumArm64Writer *cw) {
|
||||
static void instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
gum_arm64_writer_put_mov_reg_reg(cw, ARM64_REG_X0, ARM64_REG_XZR);
|
||||
gum_arm64_writer_put_call_address_with_arguments(
|
||||
cw, GUM_ADDRESS(_exit), 1, GUM_ARG_REGISTER, ARM64_REG_X0);
|
||||
if (__afl_persistent_loop(persistent_count) == 0) { _exit(0); }
|
||||
|
||||
}
|
||||
|
||||
static int instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
int ret = __afl_persistent_loop(persistent_count);
|
||||
if (instrument_previous_pc_addr == NULL) {
|
||||
|
||||
FATAL("instrument_previous_pc_addr uninitialized");
|
||||
@ -234,7 +227,6 @@ static int instrument_afl_persistent_loop_func(void) {
|
||||
}
|
||||
|
||||
*instrument_previous_pc_addr = instrument_hash_zero;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@ -284,7 +276,7 @@ static void instrument_persitent_save_lr(GumArm64Writer *cw) {
|
||||
GUM_INDEX_PRE_ADJUST);
|
||||
|
||||
gum_arm64_writer_put_ldr_reg_address(cw, ARM64_REG_X0,
|
||||
GUM_ADDRESS(&saved_lr));
|
||||
GUM_ADDRESS(&persistent_ret));
|
||||
|
||||
gum_arm64_writer_put_str_reg_reg_offset(cw, ARM64_REG_LR, ARM64_REG_X0, 0);
|
||||
|
||||
@ -297,65 +289,35 @@ static void instrument_persitent_save_lr(GumArm64Writer *cw) {
|
||||
void persistent_prologue_arch(GumStalkerOutput *output) {
|
||||
|
||||
/*
|
||||
* SAVE RET (Used to write the epilogue if persistent_ret is not set)
|
||||
* SAVE REGS
|
||||
* SAVE RET
|
||||
* POP RET
|
||||
* loop:
|
||||
* loop: (Save address of where the eiplogue should jump back to)
|
||||
* CALL instrument_afl_persistent_loop
|
||||
* TEST EAX, EAX
|
||||
* JZ end:
|
||||
* call hook (optionally)
|
||||
* CALL hook (optionally)
|
||||
* RESTORE REGS
|
||||
* call original
|
||||
* jmp loop:
|
||||
*
|
||||
* end:
|
||||
* JMP SAVED RET
|
||||
*
|
||||
* original:
|
||||
* INSTRUMENTED PERSISTENT FUNC
|
||||
*/
|
||||
|
||||
GumArm64Writer *cw = output->writer.arm64;
|
||||
|
||||
gconstpointer loop = cw->code + 1;
|
||||
|
||||
FVERBOSE("Persistent loop reached");
|
||||
|
||||
if (persistent_ret == 0) { instrument_persitent_save_lr(cw); }
|
||||
|
||||
/* Save the current context */
|
||||
instrument_persitent_save_regs(cw, &saved_regs);
|
||||
|
||||
/* loop: */
|
||||
gum_arm64_writer_put_label(cw, loop);
|
||||
/* Store a pointer to where we should return for our next iteration */
|
||||
persistent_loop = gum_arm64_writer_cur(cw);
|
||||
|
||||
/* call instrument_prologue_func */
|
||||
/* call __afl_persistent_loop and _exit if zero. Also reset our previous_pc */
|
||||
instrument_afl_persistent_loop(cw);
|
||||
|
||||
/* jz done */
|
||||
gconstpointer done = cw->code + 1;
|
||||
gum_arm64_writer_put_cmp_reg_reg(cw, ARM64_REG_X0, ARM64_REG_XZR);
|
||||
gum_arm64_writer_put_b_cond_label(cw, ARM64_CC_EQ, done);
|
||||
|
||||
/* Optionally call the persistent hook */
|
||||
persistent_prologue_hook(cw, &saved_regs);
|
||||
|
||||
/* Restore our CPU context before we continue execution */
|
||||
instrument_persitent_restore_regs(cw, &saved_regs);
|
||||
gconstpointer original = cw->code + 1;
|
||||
/* call original */
|
||||
|
||||
gum_arm64_writer_put_bl_label(cw, original);
|
||||
|
||||
/* jmp loop */
|
||||
gum_arm64_writer_put_b_label(cw, loop);
|
||||
|
||||
/* done: */
|
||||
gum_arm64_writer_put_label(cw, done);
|
||||
|
||||
instrument_exit(cw);
|
||||
|
||||
/* original: */
|
||||
gum_arm64_writer_put_label(cw, original);
|
||||
|
||||
instrument_persitent_save_lr(cw);
|
||||
|
||||
if (persistent_debug) { gum_arm64_writer_put_brk_imm(cw, 0); }
|
||||
|
||||
@ -368,7 +330,7 @@ void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
if (persistent_debug) { gum_arm64_writer_put_brk_imm(cw, 0); }
|
||||
|
||||
gum_arm64_writer_put_ldr_reg_address(cw, ARM64_REG_X0,
|
||||
GUM_ADDRESS(&saved_lr));
|
||||
GUM_ADDRESS(&persistent_loop));
|
||||
|
||||
gum_arm64_writer_put_ldr_reg_reg_offset(cw, ARM64_REG_X0, ARM64_REG_X0, 0);
|
||||
|
||||
|
@ -17,7 +17,7 @@ typedef struct {
|
||||
} persistent_ctx_t;
|
||||
|
||||
static persistent_ctx_t saved_regs = {0};
|
||||
static gpointer saved_ret = NULL;
|
||||
static gpointer persistent_loop = NULL;
|
||||
|
||||
gboolean persistent_is_supported(void) {
|
||||
|
||||
@ -162,17 +162,10 @@ static void instrument_persitent_restore_regs(GumX86Writer *cw,
|
||||
|
||||
}
|
||||
|
||||
static void instrument_exit(GumX86Writer *cw) {
|
||||
static void instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_RAX, GUM_ADDRESS(_exit));
|
||||
gum_x86_writer_put_mov_reg_u32(cw, GUM_X86_RDI, 0);
|
||||
gum_x86_writer_put_call_reg(cw, GUM_X86_RAX);
|
||||
if (__afl_persistent_loop(persistent_count) == 0) { _exit(0); }
|
||||
|
||||
}
|
||||
|
||||
static int instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
int ret = __afl_persistent_loop(persistent_count);
|
||||
if (instrument_previous_pc_addr == NULL) {
|
||||
|
||||
FATAL("instrument_previous_pc_addr uninitialized");
|
||||
@ -180,7 +173,6 @@ static int instrument_afl_persistent_loop_func(void) {
|
||||
}
|
||||
|
||||
*instrument_previous_pc_addr = instrument_hash_zero;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@ -190,7 +182,6 @@ static void instrument_afl_persistent_loop(GumX86Writer *cw) {
|
||||
-(GUM_RED_ZONE_SIZE));
|
||||
gum_x86_writer_put_call_address_with_arguments(
|
||||
cw, GUM_CALL_CAPI, GUM_ADDRESS(instrument_afl_persistent_loop_func), 0);
|
||||
gum_x86_writer_put_test_reg_reg(cw, GUM_X86_RAX, GUM_X86_RAX);
|
||||
|
||||
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_X86_RSP, GUM_X86_RSP,
|
||||
(GUM_RED_ZONE_SIZE));
|
||||
@ -235,7 +226,8 @@ static void instrument_persitent_save_ret(GumX86Writer *cw) {
|
||||
gum_x86_writer_put_push_reg(cw, GUM_X86_RAX);
|
||||
gum_x86_writer_put_push_reg(cw, GUM_X86_RBX);
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_RAX, GUM_ADDRESS(&saved_ret));
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_RAX,
|
||||
GUM_ADDRESS(&persistent_ret));
|
||||
gum_x86_writer_put_mov_reg_reg_offset_ptr(cw, GUM_X86_RBX, GUM_X86_RSP,
|
||||
offset);
|
||||
gum_x86_writer_put_mov_reg_ptr_reg(cw, GUM_X86_RAX, GUM_X86_RBX);
|
||||
@ -252,70 +244,44 @@ static void instrument_persitent_save_ret(GumX86Writer *cw) {
|
||||
void persistent_prologue_arch(GumStalkerOutput *output) {
|
||||
|
||||
/*
|
||||
* SAVE RET (Used to write the epilogue if persistent_ret is not set)
|
||||
* SAVE REGS
|
||||
* SAVE RET
|
||||
* POP RET
|
||||
* loop:
|
||||
* loop: (Save address of where the eiplogue should jump back to)
|
||||
* CALL instrument_afl_persistent_loop
|
||||
* TEST EAX, EAX
|
||||
* JZ end:
|
||||
* call hook (optionally)
|
||||
* CALL hook (optionally)
|
||||
* RESTORE REGS
|
||||
* call original
|
||||
* jmp loop:
|
||||
*
|
||||
* end:
|
||||
* JMP SAVED RET
|
||||
*
|
||||
* original:
|
||||
* INSTRUMENTED PERSISTENT FUNC
|
||||
*/
|
||||
|
||||
GumX86Writer *cw = output->writer.x86;
|
||||
|
||||
gconstpointer loop = cw->code + 1;
|
||||
|
||||
FVERBOSE("Persistent loop reached");
|
||||
|
||||
/* Pop the return value */
|
||||
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_X86_RSP, GUM_X86_RSP, 8);
|
||||
/*
|
||||
* If we haven't set persistent_ret, then assume that we are dealing with a
|
||||
* function and we should loop when that function returns.
|
||||
*/
|
||||
if (persistent_ret == 0) { instrument_persitent_save_ret(cw); }
|
||||
|
||||
/* Save the current context */
|
||||
instrument_persitent_save_regs(cw, &saved_regs);
|
||||
|
||||
/* loop: */
|
||||
gum_x86_writer_put_label(cw, loop);
|
||||
/* Store a pointer to where we should return for our next iteration */
|
||||
persistent_loop = gum_x86_writer_cur(cw);
|
||||
|
||||
/* call instrument_prologue_func */
|
||||
/* call __afl_persistent_loop and _exit if zero. Also reset our previous_pc */
|
||||
instrument_afl_persistent_loop(cw);
|
||||
|
||||
/* jz done */
|
||||
gconstpointer done = cw->code + 1;
|
||||
gum_x86_writer_put_jcc_near_label(cw, X86_INS_JE, done, GUM_UNLIKELY);
|
||||
|
||||
/* Optionally call the persistent hook */
|
||||
persistent_prologue_hook(cw, &saved_regs);
|
||||
|
||||
/* Restore our CPU context before we continue execution */
|
||||
instrument_persitent_restore_regs(cw, &saved_regs);
|
||||
gconstpointer original = cw->code + 1;
|
||||
/* call original */
|
||||
|
||||
gum_x86_writer_put_call_near_label(cw, original);
|
||||
|
||||
/* jmp loop */
|
||||
gum_x86_writer_put_jmp_near_label(cw, loop);
|
||||
|
||||
/* done: */
|
||||
gum_x86_writer_put_label(cw, done);
|
||||
|
||||
instrument_exit(cw);
|
||||
|
||||
/* original: */
|
||||
gum_x86_writer_put_label(cw, original);
|
||||
|
||||
instrument_persitent_save_ret(cw);
|
||||
|
||||
if (persistent_debug) { gum_x86_writer_put_breakpoint(cw); }
|
||||
|
||||
/* The original instrumented code is emitted here. */
|
||||
|
||||
}
|
||||
|
||||
void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
@ -331,7 +297,8 @@ void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_X86_RSP, GUM_X86_RSP, -8);
|
||||
gum_x86_writer_put_label(cw, zero);
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_RAX, GUM_ADDRESS(&saved_ret));
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_RAX,
|
||||
GUM_ADDRESS(&persistent_loop));
|
||||
gum_x86_writer_put_jmp_reg_ptr(cw, GUM_X86_RAX);
|
||||
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ typedef struct {
|
||||
} persistent_ctx_t;
|
||||
|
||||
static persistent_ctx_t saved_regs = {0};
|
||||
|
||||
static gpointer saved_ret = NULL;
|
||||
static gpointer persistent_loop = NULL;
|
||||
|
||||
gboolean persistent_is_supported(void) {
|
||||
|
||||
@ -118,18 +117,10 @@ static void instrument_persitent_restore_regs(GumX86Writer *cw,
|
||||
|
||||
}
|
||||
|
||||
static void instrument_exit(GumX86Writer *cw) {
|
||||
static void instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_EAX, GUM_ADDRESS(_exit));
|
||||
gum_x86_writer_put_mov_reg_u32(cw, GUM_X86_EDI, 0);
|
||||
gum_x86_writer_put_push_reg(cw, GUM_X86_EDI);
|
||||
gum_x86_writer_put_call_reg(cw, GUM_X86_EAX);
|
||||
if (__afl_persistent_loop(persistent_count) == 0) { _exit(0); };
|
||||
|
||||
}
|
||||
|
||||
static int instrument_afl_persistent_loop_func(void) {
|
||||
|
||||
int ret = __afl_persistent_loop(persistent_count);
|
||||
if (instrument_previous_pc_addr == NULL) {
|
||||
|
||||
FATAL("instrument_previous_pc_addr uninitialized");
|
||||
@ -137,7 +128,6 @@ static int instrument_afl_persistent_loop_func(void) {
|
||||
}
|
||||
|
||||
*instrument_previous_pc_addr = instrument_hash_zero;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@ -145,7 +135,6 @@ static void instrument_afl_persistent_loop(GumX86Writer *cw) {
|
||||
|
||||
gum_x86_writer_put_call_address_with_arguments(
|
||||
cw, GUM_CALL_CAPI, GUM_ADDRESS(instrument_afl_persistent_loop_func), 0);
|
||||
gum_x86_writer_put_test_reg_reg(cw, GUM_X86_EAX, GUM_X86_EAX);
|
||||
|
||||
}
|
||||
|
||||
@ -179,7 +168,8 @@ static void instrument_persitent_save_ret(GumX86Writer *cw) {
|
||||
gum_x86_writer_put_push_reg(cw, GUM_X86_EAX);
|
||||
gum_x86_writer_put_push_reg(cw, GUM_X86_EBX);
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_EAX, GUM_ADDRESS(&saved_ret));
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_EAX,
|
||||
GUM_ADDRESS(&persistent_ret));
|
||||
gum_x86_writer_put_mov_reg_reg_offset_ptr(cw, GUM_X86_EBX, GUM_X86_ESP,
|
||||
offset);
|
||||
gum_x86_writer_put_mov_reg_ptr_reg(cw, GUM_X86_EAX, GUM_X86_EBX);
|
||||
@ -193,68 +183,44 @@ static void instrument_persitent_save_ret(GumX86Writer *cw) {
|
||||
void persistent_prologue_arch(GumStalkerOutput *output) {
|
||||
|
||||
/*
|
||||
* SAVE RET (Used to write the epilogue if persistent_ret is not set)
|
||||
* SAVE REGS
|
||||
* SAVE RET
|
||||
* POP RET
|
||||
* loop:
|
||||
* loop: (Save address of where the eiplogue should jump back to)
|
||||
* CALL instrument_afl_persistent_loop
|
||||
* TEST EAX, EAX
|
||||
* JZ end:
|
||||
* call hook (optionally)
|
||||
* CALL hook (optionally)
|
||||
* RESTORE REGS
|
||||
* call original
|
||||
* jmp loop:
|
||||
*
|
||||
* end:
|
||||
* JMP SAVED RET
|
||||
*
|
||||
* original:
|
||||
* INSTRUMENTED PERSISTENT FUNC
|
||||
*/
|
||||
|
||||
GumX86Writer *cw = output->writer.x86;
|
||||
|
||||
gconstpointer loop = cw->code + 1;
|
||||
|
||||
FVERBOSE("Persistent loop reached");
|
||||
|
||||
/* Pop the return value */
|
||||
gum_x86_writer_put_lea_reg_reg_offset(cw, GUM_X86_ESP, GUM_X86_ESP, 4);
|
||||
/*
|
||||
* If we haven't set persistent_ret, then assume that we are dealing with a
|
||||
* function and we should loop when that function returns.
|
||||
*/
|
||||
if (persistent_ret == 0) { instrument_persitent_save_ret(cw); }
|
||||
|
||||
/* Save the current context */
|
||||
instrument_persitent_save_regs(cw, &saved_regs);
|
||||
|
||||
/* loop: */
|
||||
gum_x86_writer_put_label(cw, loop);
|
||||
/* Store a pointer to where we should return for our next iteration */
|
||||
persistent_loop = gum_x86_writer_cur(cw);
|
||||
|
||||
/* call instrument_prologue_func */
|
||||
/* call __afl_persistent_loop and _exit if zero. Also reset our previous_pc */
|
||||
instrument_afl_persistent_loop(cw);
|
||||
|
||||
/* jz done */
|
||||
gconstpointer done = cw->code + 1;
|
||||
gum_x86_writer_put_jcc_near_label(cw, X86_INS_JE, done, GUM_UNLIKELY);
|
||||
|
||||
/* Optionally call the persistent hook */
|
||||
persistent_prologue_hook(cw, &saved_regs);
|
||||
|
||||
/* Restore our CPU context before we continue execution */
|
||||
instrument_persitent_restore_regs(cw, &saved_regs);
|
||||
gconstpointer original = cw->code + 1;
|
||||
/* call original */
|
||||
gum_x86_writer_put_call_near_label(cw, original);
|
||||
/* jmp loop */
|
||||
gum_x86_writer_put_jmp_near_label(cw, loop);
|
||||
|
||||
/* done: */
|
||||
gum_x86_writer_put_label(cw, done);
|
||||
|
||||
instrument_exit(cw);
|
||||
|
||||
/* original: */
|
||||
gum_x86_writer_put_label(cw, original);
|
||||
|
||||
instrument_persitent_save_ret(cw);
|
||||
|
||||
if (persistent_debug) { gum_x86_writer_put_breakpoint(cw); }
|
||||
|
||||
/* The original instrumented code is emitted here. */
|
||||
|
||||
}
|
||||
|
||||
void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
@ -263,7 +229,12 @@ void persistent_epilogue_arch(GumStalkerOutput *output) {
|
||||
|
||||
if (persistent_debug) { gum_x86_writer_put_breakpoint(cw); }
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_EAX, GUM_ADDRESS(&saved_ret));
|
||||
/* The stack should be aligned when we re-enter our loop */
|
||||
gum_x86_writer_put_and_reg_u32(cw, GUM_X86_ESP, 0xfffffff0);
|
||||
gum_x86_writer_put_sub_reg_imm(cw, GUM_X86_ESP, 0x4);
|
||||
|
||||
gum_x86_writer_put_mov_reg_address(cw, GUM_X86_EAX,
|
||||
GUM_ADDRESS(&persistent_loop));
|
||||
gum_x86_writer_put_jmp_reg_ptr(cw, GUM_X86_EAX);
|
||||
|
||||
}
|
||||
|
@ -110,7 +110,11 @@ gboolean util_verbose_enabled(void) {
|
||||
if (!initialized) {
|
||||
|
||||
initialized = TRUE;
|
||||
if (getenv("AFL_FRIDA_VERBOSE") != NULL) { util_verbose = TRUE; }
|
||||
if (getenv("AFL_FRIDA_VERBOSE") || getenv("AFL_DEBUG")) {
|
||||
|
||||
util_verbose = TRUE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
69
frida_mode/test/cache/cache.c
vendored
69
frida_mode/test/cache/cache.c
vendored
@ -6,46 +6,45 @@
|
||||
|
||||
void LLVMFuzzerTestOneInput(char *buf, int len);
|
||||
|
||||
__asm__ (
|
||||
"LLVMFuzzerTestOneInput:\n"
|
||||
".func LLVMFuzzerTestOneInput\n"
|
||||
".global LLVMFuzzerTestOneInput\n"
|
||||
" jmpq *jmp_offset(%rip)\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
"call_target:\n"
|
||||
" ret\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
"jmp_target:\n"
|
||||
" callq *call_offset(%rip)\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
" leaq rax_offset(%rip), %rax\n"
|
||||
" jmp (%rax)\n"
|
||||
" nop\n"
|
||||
" ud2\n"
|
||||
" nop\n"
|
||||
"rax_target:\n"
|
||||
" ret\n"
|
||||
"\n"
|
||||
"\n"
|
||||
".global jmp_offset\n"
|
||||
".p2align 3\n"
|
||||
"jmp_offset:\n"
|
||||
" .quad jmp_target\n"
|
||||
"call_offset:\n"
|
||||
" .quad call_target\n"
|
||||
"rax_offset:\n"
|
||||
" .quad rax_target\n"
|
||||
);
|
||||
__asm__(
|
||||
"LLVMFuzzerTestOneInput:\n"
|
||||
".func LLVMFuzzerTestOneInput\n"
|
||||
".global LLVMFuzzerTestOneInput\n"
|
||||
" jmpq *jmp_offset(%rip)\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
"call_target:\n"
|
||||
" ret\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
"jmp_target:\n"
|
||||
" callq *call_offset(%rip)\n"
|
||||
" nop\n"
|
||||
" nop\n"
|
||||
" leaq rax_offset(%rip), %rax\n"
|
||||
" jmp (%rax)\n"
|
||||
" nop\n"
|
||||
" ud2\n"
|
||||
" nop\n"
|
||||
"rax_target:\n"
|
||||
" ret\n"
|
||||
"\n"
|
||||
"\n"
|
||||
".global jmp_offset\n"
|
||||
".p2align 3\n"
|
||||
"jmp_offset:\n"
|
||||
" .quad jmp_target\n"
|
||||
"call_offset:\n"
|
||||
" .quad call_target\n"
|
||||
"rax_offset:\n"
|
||||
" .quad rax_target\n");
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
static bool cmov_test(char *x, char *y, size_t len) {
|
||||
|
||||
register char * __rdi __asm__("rdi") = x;
|
||||
register char * __rsi __asm__("rsi") = y;
|
||||
register char *__rdi __asm__("rdi") = x;
|
||||
register char *__rsi __asm__("rsi") = y;
|
||||
register size_t __rcx __asm__("rcx") = len;
|
||||
|
||||
register long __rax __asm__("rax");
|
||||
@ -49,10 +49,10 @@ void LLVMFuzzerTestOneInput(char *buf, int len) {
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -41,7 +41,7 @@ int run(char *file) {
|
||||
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
@ -51,6 +51,7 @@ int run(char *file) {
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
|
||||
perror("open");
|
||||
break;
|
||||
|
||||
@ -110,8 +111,10 @@ void slow() {
|
||||
|
||||
}
|
||||
|
||||
TESTINSTR_SECTION int do_run(char * file) {
|
||||
TESTINSTR_SECTION int do_run(char *file) {
|
||||
|
||||
return run(file);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -19,32 +19,40 @@
|
||||
typedef void (*fntestinstrlib)(char *buf, int len);
|
||||
|
||||
void testinstr(char *buf, int len) {
|
||||
|
||||
void *lib = dlopen("testinstrlib.so", RTLD_NOW);
|
||||
if (lib == NULL) {
|
||||
|
||||
puts("Library not found");
|
||||
abort();
|
||||
|
||||
}
|
||||
|
||||
fntestinstrlib fn = (fntestinstrlib)(dlsym(lib, "testinstrlib"));
|
||||
if (fn == NULL) {
|
||||
|
||||
puts("Function not found");
|
||||
abort();
|
||||
|
||||
}
|
||||
|
||||
fn(buf, len);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char * file;
|
||||
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
if (argc != 2) { return 1; }
|
||||
|
||||
do {
|
||||
|
||||
file = argv[1];
|
||||
printf("file: %s\n", file);
|
||||
|
||||
@ -52,33 +60,43 @@ int main(int argc, char **argv) {
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
|
||||
perror("open");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
len = lseek(fd, 0, SEEK_END);
|
||||
if (len < 0) {
|
||||
|
||||
perror("lseek (SEEK_END)");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) != 0) {
|
||||
|
||||
perror("lseek (SEEK_SET)");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
printf("len: %ld\n", len);
|
||||
|
||||
buf = malloc(len);
|
||||
if (buf == NULL) {
|
||||
|
||||
perror("malloc");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
n_read = read(fd, buf, len);
|
||||
if (n_read != len) {
|
||||
|
||||
perror("read");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
dprintf(STDERR_FILENO, "Running: %s: (%zd bytes)\n", file, n_read);
|
||||
@ -95,4 +113,6 @@ int main(int argc, char **argv) {
|
||||
if (fd != -1) { close(fd); }
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void testinstrlib(char *buf, int len) {
|
||||
|
||||
if (len < 1) return;
|
||||
buf[len] = 0;
|
||||
|
||||
@ -11,4 +12,6 @@ void testinstrlib(char *buf, int len) {
|
||||
printf("Pretty sure that is a one!\n");
|
||||
else
|
||||
printf("Neither one or zero? How quaint!\n");
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ int run(char *file) {
|
||||
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -39,10 +39,10 @@ void testinstr(char *buf, int len) {
|
||||
|
||||
TESTINSTR_SECTION int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -35,7 +35,7 @@ int run(char *file) {
|
||||
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -22,60 +22,60 @@
|
||||
#define IGNORED_RETURN(x) (void)!(x)
|
||||
|
||||
const uint32_t crc32_tab[] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
uint32_t
|
||||
crc32(const void *buf, size_t size)
|
||||
{
|
||||
const uint8_t *p = buf;
|
||||
uint32_t crc;
|
||||
crc = ~0U;
|
||||
while (size--)
|
||||
crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
|
||||
return crc ^ ~0U;
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
|
||||
|
||||
uint32_t crc32(const void *buf, size_t size) {
|
||||
|
||||
const uint8_t *p = buf;
|
||||
uint32_t crc;
|
||||
crc = ~0U;
|
||||
while (size--)
|
||||
crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
|
||||
return crc ^ ~0U;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -83,11 +83,13 @@ crc32(const void *buf, size_t size)
|
||||
* FRIDA to patch this function out and always return success. Otherwise, we
|
||||
* could change it to actually correct the checksum.
|
||||
*/
|
||||
int crc32_check (char * buf, int len) {
|
||||
int crc32_check(char *buf, int len) {
|
||||
|
||||
if (len < sizeof(uint32_t)) { return 0; }
|
||||
uint32_t expected = *(uint32_t *)&buf[len - sizeof(uint32_t)];
|
||||
uint32_t calculated = crc32(buf, len - sizeof(uint32_t));
|
||||
return expected == calculated;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -97,27 +99,31 @@ int crc32_check (char * buf, int len) {
|
||||
* cloud your output unnecessarily. Again, we can use FRIDA to patch it out.
|
||||
*/
|
||||
void some_boring_bug(char c) {
|
||||
|
||||
switch (c) {
|
||||
case 'A'...'Z':
|
||||
case 'a'...'z':
|
||||
|
||||
case 'A' ... 'Z':
|
||||
case 'a' ... 'z':
|
||||
__builtin_trap();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern void some_boring_bug2(char c);
|
||||
|
||||
__asm__ (
|
||||
".text \n"
|
||||
"some_boring_bug2: \n"
|
||||
".global some_boring_bug2 \n"
|
||||
".type some_boring_bug2, @function \n"
|
||||
"mov %edi, %eax \n"
|
||||
"cmp $0xb4, %al \n"
|
||||
"jne ok \n"
|
||||
"ud2 \n"
|
||||
"ok: \n"
|
||||
"ret \n");
|
||||
__asm__(
|
||||
".text \n"
|
||||
"some_boring_bug2: \n"
|
||||
".global some_boring_bug2 \n"
|
||||
".type some_boring_bug2, @function \n"
|
||||
"mov %edi, %eax \n"
|
||||
"cmp $0xb4, %al \n"
|
||||
"jne ok \n"
|
||||
"ud2 \n"
|
||||
"ok: \n"
|
||||
"ret \n");
|
||||
|
||||
void LLVMFuzzerTestOneInput(char *buf, int len) {
|
||||
|
||||
@ -127,16 +133,20 @@ void LLVMFuzzerTestOneInput(char *buf, int len) {
|
||||
some_boring_bug2(buf[0]);
|
||||
|
||||
if (buf[0] == '0') {
|
||||
|
||||
printf("Looks like a zero to me!\n");
|
||||
}
|
||||
else if (buf[0] == '1') {
|
||||
|
||||
} else if (buf[0] == '1') {
|
||||
|
||||
printf("Pretty sure that is a one!\n");
|
||||
}
|
||||
else if (buf[0] == '2') {
|
||||
|
||||
} else if (buf[0] == '2') {
|
||||
|
||||
printf("Oh we, weren't expecting that!");
|
||||
__builtin_trap();
|
||||
}
|
||||
else
|
||||
|
||||
} else
|
||||
|
||||
printf("Neither one or zero? How quaint!\n");
|
||||
|
||||
}
|
||||
@ -145,7 +155,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
@ -173,5 +183,6 @@ int main(int argc, char **argv) {
|
||||
printf("Done: %s: (%zd bytes)\n", argv[1], n_read);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,66 +4,68 @@
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
//typedef for our exported target function.
|
||||
// typedef for our exported target function.
|
||||
typedef void (*CRASHME)(const uint8_t *Data, size_t Size);
|
||||
|
||||
//globals
|
||||
// globals
|
||||
CRASHME fpn_crashme = NULL;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
|
||||
|
||||
fpn_crashme(data, size);
|
||||
return 0;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size){
|
||||
fpn_crashme(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char*)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
}
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char *)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor()))
|
||||
void constructor(void) {
|
||||
// handles to required libs
|
||||
void *dylib = NULL;
|
||||
__attribute__((constructor())) void constructor(void) {
|
||||
|
||||
dylib = dlopen("./libcrashme.dylib", RTLD_NOW);
|
||||
if (dylib == NULL)
|
||||
{
|
||||
// handles to required libs
|
||||
void *dylib = NULL;
|
||||
|
||||
printf("[-] Failed to load lib\n");
|
||||
printf("[-] Dlerror: %s\n", dlerror());
|
||||
exit(1);
|
||||
dylib = dlopen("./libcrashme.dylib", RTLD_NOW);
|
||||
if (dylib == NULL) {
|
||||
|
||||
}
|
||||
printf("[-] Failed to load lib\n");
|
||||
printf("[-] Dlerror: %s\n", dlerror());
|
||||
exit(1);
|
||||
|
||||
printf("[+] Resolve function\n");
|
||||
}
|
||||
|
||||
fpn_crashme = (CRASHME)dlsym(dylib, "crashme");
|
||||
if (!fpn_crashme)
|
||||
{
|
||||
printf("[+] Resolve function\n");
|
||||
|
||||
printf("[-] Failed to find function\n");
|
||||
exit(1);
|
||||
fpn_crashme = (CRASHME)dlsym(dylib, "crashme");
|
||||
if (!fpn_crashme) {
|
||||
|
||||
}
|
||||
printf("[-] Failed to find function\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
printf("[+] Found function.\n");
|
||||
|
||||
printf("[+] Found function.\n");
|
||||
}
|
||||
|
||||
|
@ -4,66 +4,68 @@
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
//typedef for our exported target function.
|
||||
// typedef for our exported target function.
|
||||
typedef void (*CRASHME)(const uint8_t *Data, size_t Size);
|
||||
|
||||
//globals
|
||||
// globals
|
||||
CRASHME fpn_crashme = NULL;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
|
||||
|
||||
fpn_crashme(data, size);
|
||||
return 0;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size){
|
||||
fpn_crashme(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char*)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
}
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char *)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor()))
|
||||
void constructor(void) {
|
||||
// handles to required libs
|
||||
void *dylib = NULL;
|
||||
__attribute__((constructor())) void constructor(void) {
|
||||
|
||||
dylib = dlopen("./libcrashme2.dylib", RTLD_NOW);
|
||||
if (dylib == NULL)
|
||||
{
|
||||
// handles to required libs
|
||||
void *dylib = NULL;
|
||||
|
||||
printf("[-] Failed to load lib\n");
|
||||
printf("[-] Dlerror: %s\n", dlerror());
|
||||
exit(1);
|
||||
dylib = dlopen("./libcrashme2.dylib", RTLD_NOW);
|
||||
if (dylib == NULL) {
|
||||
|
||||
}
|
||||
printf("[-] Failed to load lib\n");
|
||||
printf("[-] Dlerror: %s\n", dlerror());
|
||||
exit(1);
|
||||
|
||||
printf("[+] Resolve function\n");
|
||||
}
|
||||
|
||||
fpn_crashme = (CRASHME)dlsym(dylib, "crashme");
|
||||
if (!fpn_crashme)
|
||||
{
|
||||
printf("[+] Resolve function\n");
|
||||
|
||||
printf("[-] Failed to find function\n");
|
||||
exit(1);
|
||||
fpn_crashme = (CRASHME)dlsym(dylib, "crashme");
|
||||
if (!fpn_crashme) {
|
||||
|
||||
}
|
||||
printf("[-] Failed to find function\n");
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
printf("[+] Found function.\n");
|
||||
|
||||
printf("[+] Found function.\n");
|
||||
}
|
||||
|
||||
|
@ -4,37 +4,42 @@
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
||||
extern void crashme(const uint8_t *Data, size_t Size);
|
||||
|
||||
int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size){
|
||||
crashme(data, size);
|
||||
return 0;
|
||||
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
|
||||
|
||||
crashme(data, size);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void run (int argc, const char * argv[])
|
||||
{
|
||||
for (int i = 1; i < argc; i++) {
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char*)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
}
|
||||
void run(int argc, const char *argv[]) {
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
fprintf(stderr, "Running: %s\n", argv[i]);
|
||||
FILE *f = fopen(argv[i], "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char *)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
run(argc, argv);
|
||||
run(argc, argv);
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void __attribute__((noinline)) crashme(const uint8_t *Data, size_t Size) {
|
||||
|
||||
if (Size < 5) return;
|
||||
@ -13,5 +12,5 @@ void __attribute__((noinline)) crashme(const uint8_t *Data, size_t Size) {
|
||||
if (Data[3] == '$')
|
||||
if (Data[4] == '$') abort();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void __attribute__((noinline)) crashme(const uint8_t *Data, size_t Size) {
|
||||
|
||||
if (Size < 1) return;
|
||||
@ -56,6 +55,5 @@ void __attribute__((noinline)) crashme(const uint8_t *Data, size_t Size) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ void testinstr(char *buf, int len) {
|
||||
|
||||
TESTINSTR_SECTION int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -20,22 +20,32 @@ void LLVMFuzzerTestOneInput(char *buf, int len) {
|
||||
|
||||
int ret = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
switch(buf[i]) {
|
||||
case 'A': ret += 2; break;
|
||||
case '1': ret += 3; break;
|
||||
default: ret++;
|
||||
|
||||
switch (buf[i]) {
|
||||
|
||||
case 'A':
|
||||
ret += 2;
|
||||
break;
|
||||
case '1':
|
||||
ret += 3;
|
||||
break;
|
||||
default:
|
||||
ret++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("ret: %d\n", ret);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
void LLVMFuzzerTestOneInput(char *buf, int len) {
|
||||
|
||||
printf (">>> LLVMFuzzerTestOneInput >>>\n");
|
||||
printf(">>> LLVMFuzzerTestOneInput >>>\n");
|
||||
if (len < 1) return;
|
||||
buf[len] = 0;
|
||||
|
||||
@ -40,10 +40,10 @@ void slow() {
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -48,7 +48,7 @@ all: $(TEST_BIN)
|
||||
CFLAGS="-m32" LDFLAGS="-m32" make $(TEST_BIN)
|
||||
|
||||
arm:
|
||||
CFLAGS="-marm" LDFLAGS="-marm" CC="arm-linux-gnueabihf-gcc" CXX="arm-linux-gnueabihf-g++" make $(TEST_BIN)
|
||||
CFLAGS="-marm" LDFLAGS="-marm" CC="arm-linux-gnueabihf-gcc" CXX="arm-linux-gnueabihf-g++" PNG_ARCH="arm" make $(TEST_BIN)
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $@
|
||||
@ -93,8 +93,7 @@ $(LIBZ_PC): | $(LIBZ_DIR)
|
||||
cd $(LIBZ_DIR) && \
|
||||
CFLAGS="$(CFLAGS) -fPIC" \
|
||||
./configure \
|
||||
--static \
|
||||
--archs="$(ARCH)"
|
||||
--static
|
||||
|
||||
$(LIBZ_LIB): | $(LIBZ_PC)
|
||||
CFLAGS="$(CFLAGS) -fPIC" \
|
||||
@ -120,7 +119,7 @@ $(LIBPNG_MAKEFILE): $(LIBZ_LIB) | $(LIBPNG_DIR)
|
||||
CFLAGS="$(CFLAGS) -I$(LIBZ_DIR)" \
|
||||
LDFLAGS="-L$(LIBZ_DIR)" \
|
||||
./configure \
|
||||
--host="$(ARCH)"
|
||||
--host="$(PNG_ARCH)"
|
||||
|
||||
$(LIBPNG_LIB): $(LIBPNG_MAKEFILE)
|
||||
CFLAGS="$(CFLAGS) -I$(LIBZ_DIR)" \
|
||||
|
@ -39,10 +39,10 @@ void testinstr(char *buf, int len) {
|
||||
|
||||
TESTINSTR_SECTION int main(int argc, char **argv) {
|
||||
|
||||
char * file;
|
||||
char *file;
|
||||
int fd = -1;
|
||||
off_t len;
|
||||
char * buf = NULL;
|
||||
char *buf = NULL;
|
||||
size_t n_read;
|
||||
int result = -1;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define TESTINSTR_SECTION __attribute__((section(".testinstr")))
|
||||
#endif
|
||||
|
||||
void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
void LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
|
||||
if (size < 1) return;
|
||||
|
||||
@ -30,9 +30,13 @@ void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
if (gettimeofday(&tv, NULL) < 0) return;
|
||||
|
||||
if ((tv.tv_usec % 2) == 0) {
|
||||
printf ("Hooray all even\n");
|
||||
|
||||
printf("Hooray all even\n");
|
||||
|
||||
} else {
|
||||
printf ("Hmm that's odd\n");
|
||||
|
||||
printf("Hmm that's odd\n");
|
||||
|
||||
}
|
||||
|
||||
// we support three input cases
|
||||
@ -45,26 +49,33 @@ void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
|
||||
}
|
||||
|
||||
void run_test(char * file) {
|
||||
void run_test(char *file) {
|
||||
|
||||
fprintf(stderr, "Running: %s\n", file);
|
||||
FILE *f = fopen(file, "r");
|
||||
assert(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *buf = (unsigned char*)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
unsigned char *buf = (unsigned char *)malloc(len);
|
||||
size_t n_read = fread(buf, 1, len, f);
|
||||
fclose(f);
|
||||
assert(n_read == len);
|
||||
LLVMFuzzerTestOneInput(buf, len);
|
||||
free(buf);
|
||||
fprintf(stderr, "Done: %s: (%zd bytes)\n", file, n_read);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
srand(1);
|
||||
fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
|
||||
run_test(argv[i]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,10 @@
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#undef LIST_FOREACH /* clashes with FreeBSD */
|
||||
#include "list.h"
|
||||
#ifndef SIMPLE_FILES
|
||||
@ -236,7 +240,6 @@ struct queue_entry {
|
||||
custom, /* Marker for custom mutators */
|
||||
stats_mutated; /* stats: # of mutations performed */
|
||||
|
||||
u8 *trace_mini; /* Trace bytes, if kept */
|
||||
u32 tc_ref; /* Trace bytes ref count */
|
||||
|
||||
#ifdef INTROSPECTION
|
||||
@ -246,13 +249,11 @@ struct queue_entry {
|
||||
double perf_score, /* performance score */
|
||||
weight;
|
||||
|
||||
u8 *testcase_buf; /* The testcase buffer, if loaded. */
|
||||
|
||||
u8 *cmplog_colorinput; /* the result buf of colorization */
|
||||
struct tainted *taint; /* Taint information from CmpLog */
|
||||
|
||||
struct queue_entry *mother; /* queue entry this based on */
|
||||
|
||||
struct queue_entry *mother; /* queue entry this based on */
|
||||
u8 *trace_mini; /* Trace bytes, if kept */
|
||||
u8 *testcase_buf; /* The testcase buffer, if loaded. */
|
||||
u8 *cmplog_colorinput; /* the result buf of colorization */
|
||||
struct tainted *taint; /* Taint information from CmpLog */
|
||||
struct skipdet_entry *skipdet_e;
|
||||
|
||||
};
|
||||
@ -448,8 +449,9 @@ extern char *power_names[POWER_SCHEDULES_NUM];
|
||||
typedef struct afl_env_vars {
|
||||
|
||||
u8 afl_skip_cpufreq, afl_exit_when_done, afl_no_affinity, afl_skip_bin_check,
|
||||
afl_dumb_forksrv, afl_import_first, afl_custom_mutator_only, afl_no_ui,
|
||||
afl_force_ui, afl_i_dont_care_about_missing_crashes, afl_bench_just_one,
|
||||
afl_dumb_forksrv, afl_import_first, afl_custom_mutator_only,
|
||||
afl_custom_mutator_late_send, afl_no_ui, afl_force_ui,
|
||||
afl_i_dont_care_about_missing_crashes, afl_bench_just_one,
|
||||
afl_bench_until_crash, afl_debug_child, afl_autoresume, afl_cal_fast,
|
||||
afl_cycle_schedules, afl_expand_havoc, afl_statsd, afl_cmplog_only_new,
|
||||
afl_exit_on_seed_issues, afl_try_affinity, afl_ignore_problems,
|
||||
@ -457,7 +459,7 @@ typedef struct afl_env_vars {
|
||||
afl_no_startup_calibration, afl_no_warn_instability,
|
||||
afl_post_process_keep_original, afl_crashing_seeds_as_new_crash,
|
||||
afl_final_sync, afl_ignore_seed_problems, afl_disable_redundant,
|
||||
afl_sha1_filenames, afl_no_sync;
|
||||
afl_sha1_filenames, afl_no_sync, afl_no_fastresume;
|
||||
|
||||
u8 *afl_tmpdir, *afl_custom_mutator_library, *afl_python_module, *afl_path,
|
||||
*afl_hang_tmout, *afl_forksrv_init_tmout, *afl_preload,
|
||||
|
@ -26,7 +26,7 @@
|
||||
/* Version string: */
|
||||
|
||||
// c = release, a = volatile github dev, e = experimental branch
|
||||
#define VERSION "++4.21c"
|
||||
#define VERSION "++4.22a"
|
||||
|
||||
/******************************************************
|
||||
* *
|
||||
|
@ -24,23 +24,23 @@ static char *afl_environment_variables[] = {
|
||||
"AFL_DUMP_CYCLOMATIC_COMPLEXITY", "AFL_CMPLOG_MAX_LEN", "AFL_COMPCOV_LEVEL",
|
||||
"AFL_CRASH_EXITCODE", "AFL_CRASHING_SEEDS_AS_NEW_CRASH",
|
||||
"AFL_CUSTOM_MUTATOR_LIBRARY", "AFL_CUSTOM_MUTATOR_ONLY",
|
||||
"AFL_CUSTOM_INFO_PROGRAM", "AFL_CUSTOM_INFO_PROGRAM_ARGV",
|
||||
"AFL_CUSTOM_INFO_PROGRAM_INPUT", "AFL_CUSTOM_INFO_OUT", "AFL_CXX",
|
||||
"AFL_CYCLE_SCHEDULES", "AFL_DEBUG", "AFL_DEBUG_CHILD", "AFL_DEBUG_GDB",
|
||||
"AFL_DEBUG_UNICORN", "AFL_DISABLE_REDUNDANT", "AFL_NO_REDUNDANT",
|
||||
"AFL_DISABLE_TRIM", "AFL_NO_TRIM", "AFL_DISABLE_LLVM_INSTRUMENTATION",
|
||||
"AFL_DONT_OPTIMIZE", "AFL_DRIVER_STDERR_DUPLICATE_FILENAME",
|
||||
"AFL_DUMB_FORKSRV", "AFL_EARLY_FORKSERVER", "AFL_ENTRYPOINT",
|
||||
"AFL_EXIT_WHEN_DONE", "AFL_EXIT_ON_TIME", "AFL_EXIT_ON_SEED_ISSUES",
|
||||
"AFL_FAST_CAL", "AFL_FINAL_SYNC", "AFL_FORCE_UI", "AFL_FRIDA_DEBUG_MAPS",
|
||||
"AFL_CUSTOM_MUTATOR_LATE_SEND", "AFL_CUSTOM_INFO_PROGRAM",
|
||||
"AFL_CUSTOM_INFO_PROGRAM_ARGV", "AFL_CUSTOM_INFO_PROGRAM_INPUT",
|
||||
"AFL_CUSTOM_INFO_OUT", "AFL_CXX", "AFL_CYCLE_SCHEDULES", "AFL_DEBUG",
|
||||
"AFL_DEBUG_CHILD", "AFL_DEBUG_GDB", "AFL_DEBUG_UNICORN",
|
||||
"AFL_DISABLE_REDUNDANT", "AFL_NO_REDUNDANT", "AFL_DISABLE_TRIM",
|
||||
"AFL_NO_TRIM", "AFL_DISABLE_LLVM_INSTRUMENTATION", "AFL_DONT_OPTIMIZE",
|
||||
"AFL_DRIVER_STDERR_DUPLICATE_FILENAME", "AFL_DUMB_FORKSRV",
|
||||
"AFL_EARLY_FORKSERVER", "AFL_ENTRYPOINT", "AFL_EXIT_WHEN_DONE",
|
||||
"AFL_EXIT_ON_TIME", "AFL_EXIT_ON_SEED_ISSUES", "AFL_FAST_CAL",
|
||||
"AFL_FINAL_SYNC", "AFL_FORCE_UI", "AFL_FRIDA_DEBUG_MAPS",
|
||||
"AFL_FRIDA_DRIVER_NO_HOOK", "AFL_FRIDA_EXCLUDE_RANGES",
|
||||
"AFL_FRIDA_INST_CACHE_SIZE", "AFL_FRIDA_INST_COVERAGE_ABSOLUTE",
|
||||
"AFL_FRIDA_INST_COVERAGE_FILE", "AFL_FRIDA_INST_DEBUG_FILE",
|
||||
"AFL_FRIDA_INST_INSN", "AFL_FRIDA_INST_JIT", "AFL_FRIDA_INST_NO_CACHE",
|
||||
"AFL_FRIDA_INST_NO_DYNAMIC_LOAD", "AFL_FRIDA_INST_NO_OPTIMIZE",
|
||||
"AFL_FRIDA_INST_NO_PREFETCH", "AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH",
|
||||
"AFL_FRIDA_INST_NO_SUPPRESS"
|
||||
"AFL_FRIDA_INST_RANGES",
|
||||
"AFL_FRIDA_INST_NO_SUPPRESS", "AFL_FRIDA_INST_RANGES",
|
||||
"AFL_FRIDA_INST_REGS_FILE", "AFL_FRIDA_INST_SEED", "AFL_FRIDA_INST_TRACE",
|
||||
"AFL_FRIDA_INST_TRACE_UNIQUE", "AFL_FRIDA_INST_UNSTABLE_COVERAGE_FILE",
|
||||
"AFL_FRIDA_JS_SCRIPT", "AFL_FRIDA_OUTPUT_STDOUT", "AFL_FRIDA_OUTPUT_STDERR",
|
||||
@ -49,7 +49,7 @@ static char *afl_environment_variables[] = {
|
||||
"AFL_FRIDA_PERSISTENT_RET", "AFL_FRIDA_STALKER_ADJACENT_BLOCKS",
|
||||
"AFL_FRIDA_STALKER_IC_ENTRIES", "AFL_FRIDA_STALKER_NO_BACKPATCH",
|
||||
"AFL_FRIDA_STATS_FILE", "AFL_FRIDA_STATS_INTERVAL", "AFL_FRIDA_TRACEABLE",
|
||||
"AFL_FRIDA_VERBOSE",
|
||||
"AFL_FRIDA_VERBOSE", "AFL_OLD_FORKSERVER",
|
||||
"AFL_FUZZER_ARGS", // oss-fuzz
|
||||
"AFL_FUZZER_STATS_UPDATE_INTERVAL", "AFL_GDB", "AFL_GCC_ALLOWLIST",
|
||||
"AFL_GCC_DENYLIST", "AFL_GCC_BLOCKLIST", "AFL_GCC_INSTRUMENT_FILE",
|
||||
@ -115,7 +115,8 @@ static char *afl_environment_variables[] = {
|
||||
"AFL_TRACE_PC", "AFL_USE_ASAN", "AFL_USE_MSAN", "AFL_USE_TRACE_PC",
|
||||
"AFL_USE_UBSAN", "AFL_USE_TSAN", "AFL_USE_CFISAN", "AFL_USE_LSAN",
|
||||
"AFL_WINE_PATH", "AFL_NO_SNAPSHOT", "AFL_EXPAND_HAVOC_NOW", "AFL_USE_FASAN",
|
||||
"AFL_USE_QASAN", "AFL_PRINT_FILENAMES", "AFL_PIZZA_MODE", NULL
|
||||
"AFL_USE_QASAN", "AFL_PRINT_FILENAMES", "AFL_PIZZA_MODE",
|
||||
"AFL_NO_FASTRESUME", NULL
|
||||
|
||||
};
|
||||
|
||||
|
@ -206,6 +206,15 @@ typedef struct afl_forkserver {
|
||||
s32 nyx_log_fd;
|
||||
#endif
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
u8 *persistent_trace_bits; /* Persistent copy of bitmap */
|
||||
#endif
|
||||
|
||||
void *custom_data_ptr;
|
||||
u8 *custom_input;
|
||||
u32 custom_input_len;
|
||||
void (*late_send)(void *, const u8 *, size_t);
|
||||
|
||||
} afl_forkserver_t;
|
||||
|
||||
typedef enum fsrv_run_result {
|
||||
|
@ -214,8 +214,12 @@ class ModuleSanitizerCoverageLTO
|
||||
|
||||
void SetNoSanitizeMetadata(Instruction *I) {
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
I->setNoSanitizeMetadata();
|
||||
#else
|
||||
I->setMetadata(I->getModule()->getMDKindID("nosanitize"),
|
||||
MDNode::get(*C, None));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -225,7 +229,7 @@ class ModuleSanitizerCoverageLTO
|
||||
FunctionCallee SanCovTracePCIndir;
|
||||
FunctionCallee SanCovTracePC /*, SanCovTracePCGuard*/;
|
||||
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy,
|
||||
*Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty, *Int1PtrTy;
|
||||
*Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty, *Int1PtrTy, *PtrTy;
|
||||
Module *CurModule;
|
||||
std::string CurModuleUniqueId;
|
||||
Triple TargetTriple;
|
||||
@ -416,6 +420,7 @@ bool ModuleSanitizerCoverageLTO::instrumentModule(
|
||||
Int16Ty = IRB.getInt16Ty();
|
||||
Int8Ty = IRB.getInt8Ty();
|
||||
Int1Ty = IRB.getInt1Ty();
|
||||
PtrTy = PointerType::getUnqual(*C);
|
||||
|
||||
/* AFL++ START */
|
||||
char *ptr;
|
||||
@ -1350,7 +1355,7 @@ void ModuleSanitizerCoverageLTO::instrumentFunction(
|
||||
Function &F, DomTreeCallback DTCallback, PostDomTreeCallback PDTCallback) {
|
||||
|
||||
if (F.empty()) return;
|
||||
if (F.getName().find(".module_ctor") != std::string::npos)
|
||||
if (F.getName().contains(".module_ctor"))
|
||||
return; // Should not instrument sanitizer init functions.
|
||||
#if LLVM_VERSION_MAJOR >= 18
|
||||
if (F.getName().starts_with("__sanitizer_"))
|
||||
@ -1372,6 +1377,10 @@ void ModuleSanitizerCoverageLTO::instrumentFunction(
|
||||
if (F.hasPersonalityFn() &&
|
||||
isAsynchronousEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
|
||||
return;
|
||||
if (F.hasFnAttribute(Attribute::NoSanitizeCoverage)) return;
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation)) return;
|
||||
#endif
|
||||
// if (Allowlist && !Allowlist->inSection("coverage", "fun", F.getName()))
|
||||
// return;
|
||||
// if (Blocklist && Blocklist->inSection("coverage", "fun", F.getName()))
|
||||
@ -2023,16 +2032,20 @@ GlobalVariable *ModuleSanitizerCoverageLTO::CreatePCArray(
|
||||
|
||||
if (&F.getEntryBlock() == AllBlocks[i]) {
|
||||
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy));
|
||||
PCs.push_back((Constant *)IRB.CreateIntToPtr(
|
||||
ConstantInt::get(IntptrTy, 1), IntptrPtrTy));
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, PtrTy));
|
||||
PCs.push_back(
|
||||
(Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 1), PtrTy));
|
||||
|
||||
} else {
|
||||
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(
|
||||
BlockAddress::get(AllBlocks[i]), IntptrPtrTy));
|
||||
PCs.push_back((Constant *)IRB.CreateIntToPtr(
|
||||
ConstantInt::get(IntptrTy, 0), IntptrPtrTy));
|
||||
BlockAddress::get(AllBlocks[i]), PtrTy));
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
PCs.push_back(Constant::getNullValue(PtrTy));
|
||||
#else
|
||||
PCs.push_back(
|
||||
(Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 0), PtrTy));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,9 @@ class ModuleSanitizerCoverageAFL
|
||||
|
||||
void SetNoSanitizeMetadata(Instruction *I) {
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
I->setNoSanitizeMetadata();
|
||||
#elif LLVM_VERSION_MAJOR >= 16
|
||||
I->setMetadata(LLVMContext::MD_nosanitize, MDNode::get(*C, std::nullopt));
|
||||
#else
|
||||
I->setMetadata(I->getModule()->getMDKindID("nosanitize"),
|
||||
@ -179,7 +181,7 @@ class ModuleSanitizerCoverageAFL
|
||||
FunctionCallee SanCovTraceSwitchFunction;
|
||||
GlobalVariable *SanCovLowestStack;
|
||||
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy,
|
||||
*Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty, *Int1PtrTy;
|
||||
*Int16Ty, *Int8Ty, *Int8PtrTy, *Int1Ty, *Int1PtrTy, *PtrTy;
|
||||
Module *CurModule;
|
||||
std::string CurModuleUniqueId;
|
||||
Triple TargetTriple;
|
||||
@ -272,13 +274,19 @@ std::pair<Value *, Value *> ModuleSanitizerCoverageAFL::CreateSecStartEnd(
|
||||
if (!TargetTriple.isOSBinFormatCOFF())
|
||||
return std::make_pair(SecStart, SecEnd);
|
||||
|
||||
// Account for the fact that on windows-msvc __start_* symbols actually
|
||||
// point to a uint64_t before the start of the array.
|
||||
// Account for the fact that on windows-msvc __start_* symbols actually
|
||||
// point to a uint64_t before the start of the array.
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
auto GEP =
|
||||
IRB.CreatePtrAdd(SecStart, ConstantInt::get(IntptrTy, sizeof(uint64_t)));
|
||||
return std::make_pair(GEP, SecEnd);
|
||||
#else
|
||||
auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy);
|
||||
auto GEP = IRB.CreateGEP(Int8Ty, SecStartI8Ptr,
|
||||
ConstantInt::get(IntptrTy, sizeof(uint64_t)));
|
||||
return std::make_pair(IRB.CreatePointerCast(GEP, PointerType::getUnqual(Ty)),
|
||||
SecEnd);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -370,6 +378,7 @@ bool ModuleSanitizerCoverageAFL::instrumentModule(
|
||||
Int16Ty = IRB.getInt16Ty();
|
||||
Int8Ty = IRB.getInt8Ty();
|
||||
Int1Ty = IRB.getInt1Ty();
|
||||
PtrTy = PointerType::getUnqual(*C);
|
||||
|
||||
LLVMContext &Ctx = M.getContext();
|
||||
AFLMapPtr =
|
||||
@ -572,7 +581,8 @@ void ModuleSanitizerCoverageAFL::instrumentFunction(
|
||||
|
||||
if (F.empty()) return;
|
||||
if (!isInInstrumentList(&F, FMNAME)) return;
|
||||
if (F.getName().find(".module_ctor") != std::string::npos)
|
||||
// if (F.getName().find(".module_ctor") != std::string::npos)
|
||||
if (F.getName().contains(".module_ctor"))
|
||||
return; // Should not instrument sanitizer init functions.
|
||||
#if LLVM_VERSION_MAJOR >= 18
|
||||
if (F.getName().starts_with("__sanitizer_"))
|
||||
@ -595,6 +605,9 @@ void ModuleSanitizerCoverageAFL::instrumentFunction(
|
||||
isAsynchronousEHPersonality(classifyEHPersonality(F.getPersonalityFn())))
|
||||
return;
|
||||
if (F.hasFnAttribute(Attribute::NoSanitizeCoverage)) return;
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
if (F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation)) return;
|
||||
#endif
|
||||
if (Options.CoverageType >= SanitizerCoverageOptions::SCK_Edge)
|
||||
SplitAllCriticalEdges(
|
||||
F, CriticalEdgeSplittingOptions().setIgnoreUnreachableDests());
|
||||
@ -692,16 +705,16 @@ GlobalVariable *ModuleSanitizerCoverageAFL::CreatePCArray(
|
||||
|
||||
if (&F.getEntryBlock() == AllBlocks[i]) {
|
||||
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy));
|
||||
PCs.push_back((Constant *)IRB.CreateIntToPtr(
|
||||
ConstantInt::get(IntptrTy, 1), IntptrPtrTy));
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, PtrTy));
|
||||
PCs.push_back(
|
||||
(Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 1), PtrTy));
|
||||
|
||||
} else {
|
||||
|
||||
PCs.push_back((Constant *)IRB.CreatePointerCast(
|
||||
BlockAddress::get(AllBlocks[i]), IntptrPtrTy));
|
||||
BlockAddress::get(AllBlocks[i]), PtrTy));
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
PCs.push_back(Constant::getNullValue(IntptrPtrTy));
|
||||
PCs.push_back(Constant::getNullValue(PtrTy));
|
||||
#else
|
||||
PCs.push_back((Constant *)IRB.CreateIntToPtr(
|
||||
ConstantInt::get(IntptrTy, 0), IntptrPtrTy));
|
||||
@ -711,10 +724,10 @@ GlobalVariable *ModuleSanitizerCoverageAFL::CreatePCArray(
|
||||
|
||||
}
|
||||
|
||||
auto *PCArray = CreateFunctionLocalArrayInSection(N * 2, F, IntptrPtrTy,
|
||||
SanCovPCsSectionName);
|
||||
auto *PCArray =
|
||||
CreateFunctionLocalArrayInSection(N * 2, F, PtrTy, SanCovPCsSectionName);
|
||||
PCArray->setInitializer(
|
||||
ConstantArray::get(ArrayType::get(IntptrPtrTy, N * 2), PCs));
|
||||
ConstantArray::get(ArrayType::get(PtrTy, N * 2), PCs));
|
||||
PCArray->setConstant(true);
|
||||
|
||||
return PCArray;
|
||||
@ -822,7 +835,12 @@ bool ModuleSanitizerCoverageAFL::InjectCoverage(
|
||||
StringRef FuncName = Callee->getName();
|
||||
if (FuncName.compare(StringRef("__afl_coverage_interesting"))) continue;
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 20
|
||||
// test canary
|
||||
InstrumentationIRBuilder IRB(callInst);
|
||||
#else
|
||||
IRBuilder<> IRB(callInst);
|
||||
#endif
|
||||
|
||||
if (!FunctionGuardArray) {
|
||||
|
||||
|
@ -118,6 +118,7 @@ u32 __afl_map_size = MAP_SIZE;
|
||||
u32 __afl_dictionary_len;
|
||||
u64 __afl_map_addr;
|
||||
u32 __afl_first_final_loc;
|
||||
u32 __afl_old_forkserver;
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
typedef struct afl_module_info_t afl_module_info_t;
|
||||
@ -616,7 +617,7 @@ static void __afl_map_shm(void) {
|
||||
fprintf(stderr,
|
||||
"DEBUG: (2) id_str %s, __afl_area_ptr %p, __afl_area_initial %p, "
|
||||
"__afl_area_ptr_dummy %p, __afl_map_addr 0x%llx, MAP_SIZE "
|
||||
"%u, __afl_final_loc %u, __afl_map_size %u",
|
||||
"%u, __afl_final_loc %u, __afl_map_size %u\n",
|
||||
id_str == NULL ? "<null>" : id_str, __afl_area_ptr,
|
||||
__afl_area_initial, __afl_area_ptr_dummy, __afl_map_addr, MAP_SIZE,
|
||||
__afl_final_loc, __afl_map_size);
|
||||
@ -856,7 +857,7 @@ static void __afl_start_forkserver(void) {
|
||||
signal(SIGTERM, at_exit);
|
||||
|
||||
u32 already_read_first = 0;
|
||||
u32 was_killed;
|
||||
u32 was_killed = 0;
|
||||
u32 version = 0x41464c00 + FS_NEW_VERSION_MAX;
|
||||
u32 tmp = version ^ 0xffffffff, status2, status = version;
|
||||
u8 *msg = (u8 *)&status;
|
||||
@ -866,75 +867,95 @@ static void __afl_start_forkserver(void) {
|
||||
|
||||
void (*old_sigchld_handler)(int) = signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
if (getenv("AFL_OLD_FORKSERVER")) {
|
||||
|
||||
__afl_old_forkserver = 1;
|
||||
status = 0;
|
||||
|
||||
if (__afl_final_loc > MAP_SIZE) {
|
||||
|
||||
fprintf(stderr,
|
||||
"Warning: AFL_OLD_FORKSERVER is used with a target compiled with "
|
||||
"non-colliding coverage instead of AFL_LLVM_INSTRUMENT=CLASSIC - "
|
||||
"this target may crash!\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Phone home and tell the parent that we're OK. If parent isn't there,
|
||||
assume we're not running in forkserver mode and just execute program. */
|
||||
|
||||
// return because possible non-forkserver usage
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { return; }
|
||||
|
||||
if (read(FORKSRV_FD, reply, 4) != 4) { _exit(1); }
|
||||
if (tmp != status2) {
|
||||
if (!__afl_old_forkserver) {
|
||||
|
||||
write_error("wrong forkserver message from AFL++ tool");
|
||||
_exit(1);
|
||||
if (read(FORKSRV_FD, reply, 4) != 4) { _exit(1); }
|
||||
if (tmp != status2) {
|
||||
|
||||
}
|
||||
|
||||
// send the set/requested options to forkserver
|
||||
status = FS_NEW_OPT_MAPSIZE; // we always send the map size
|
||||
if (__afl_sharedmem_fuzzing) { status |= FS_NEW_OPT_SHDMEM_FUZZ; }
|
||||
if (__afl_dictionary_len && __afl_dictionary) {
|
||||
|
||||
status |= FS_NEW_OPT_AUTODICT;
|
||||
|
||||
}
|
||||
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
|
||||
// Now send the parameters for the set options, increasing by option number
|
||||
|
||||
// FS_NEW_OPT_MAPSIZE - we always send the map size
|
||||
status = __afl_map_size;
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
|
||||
// FS_NEW_OPT_SHDMEM_FUZZ - no data
|
||||
|
||||
// FS_NEW_OPT_AUTODICT - send autodictionary
|
||||
if (__afl_dictionary_len && __afl_dictionary) {
|
||||
|
||||
// pass the dictionary through the forkserver FD
|
||||
u32 len = __afl_dictionary_len, offset = 0;
|
||||
|
||||
if (write(FORKSRV_FD + 1, &len, 4) != 4) {
|
||||
|
||||
write(2, "Error: could not send dictionary len\n",
|
||||
strlen("Error: could not send dictionary len\n"));
|
||||
write_error("wrong forkserver message from AFL++ tool");
|
||||
_exit(1);
|
||||
|
||||
}
|
||||
|
||||
while (len != 0) {
|
||||
// send the set/requested options to forkserver
|
||||
status = FS_NEW_OPT_MAPSIZE; // we always send the map size
|
||||
if (__afl_sharedmem_fuzzing) { status |= FS_NEW_OPT_SHDMEM_FUZZ; }
|
||||
if (__afl_dictionary_len && __afl_dictionary) {
|
||||
|
||||
s32 ret;
|
||||
ret = write(FORKSRV_FD + 1, __afl_dictionary + offset, len);
|
||||
status |= FS_NEW_OPT_AUTODICT;
|
||||
|
||||
if (ret < 1) {
|
||||
}
|
||||
|
||||
write_error("could not send dictionary");
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
|
||||
// Now send the parameters for the set options, increasing by option number
|
||||
|
||||
// FS_NEW_OPT_MAPSIZE - we always send the map size
|
||||
status = __afl_map_size;
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
|
||||
// FS_NEW_OPT_SHDMEM_FUZZ - no data
|
||||
|
||||
// FS_NEW_OPT_AUTODICT - send autodictionary
|
||||
if (__afl_dictionary_len && __afl_dictionary) {
|
||||
|
||||
// pass the dictionary through the forkserver FD
|
||||
u32 len = __afl_dictionary_len, offset = 0;
|
||||
|
||||
if (write(FORKSRV_FD + 1, &len, 4) != 4) {
|
||||
|
||||
write(2, "Error: could not send dictionary len\n",
|
||||
strlen("Error: could not send dictionary len\n"));
|
||||
_exit(1);
|
||||
|
||||
}
|
||||
|
||||
len -= ret;
|
||||
offset += ret;
|
||||
while (len != 0) {
|
||||
|
||||
s32 ret;
|
||||
ret = write(FORKSRV_FD + 1, __afl_dictionary + offset, len);
|
||||
|
||||
if (ret < 1) {
|
||||
|
||||
write_error("could not send dictionary");
|
||||
_exit(1);
|
||||
|
||||
}
|
||||
|
||||
len -= ret;
|
||||
offset += ret;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// send welcome message as final message
|
||||
status = version;
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
|
||||
// send welcome message as final message
|
||||
status = version;
|
||||
if (write(FORKSRV_FD + 1, msg, 4) != 4) { _exit(1); }
|
||||
}
|
||||
|
||||
// END forkserver handshake
|
||||
|
||||
@ -948,13 +969,13 @@ static void __afl_start_forkserver(void) {
|
||||
|
||||
/* Wait for parent by reading from the pipe. Abort if read fails. */
|
||||
|
||||
if (already_read_first) {
|
||||
if (unlikely(already_read_first)) {
|
||||
|
||||
already_read_first = 0;
|
||||
|
||||
} else {
|
||||
|
||||
if (read(FORKSRV_FD, &was_killed, 4) != 4) {
|
||||
if (unlikely(read(FORKSRV_FD, &was_killed, 4) != 4)) {
|
||||
|
||||
write_error("read from AFL++ tool");
|
||||
_exit(1);
|
||||
@ -993,10 +1014,10 @@ static void __afl_start_forkserver(void) {
|
||||
condition and afl-fuzz already issued SIGKILL, write off the old
|
||||
process. */
|
||||
|
||||
if (child_stopped && was_killed) {
|
||||
if (unlikely(child_stopped && was_killed)) {
|
||||
|
||||
child_stopped = 0;
|
||||
if (waitpid(child_pid, &status, 0) < 0) {
|
||||
if (unlikely(waitpid(child_pid, &status, 0) < 0)) {
|
||||
|
||||
write_error("child_stopped && was_killed");
|
||||
_exit(1);
|
||||
@ -1005,12 +1026,12 @@ static void __afl_start_forkserver(void) {
|
||||
|
||||
}
|
||||
|
||||
if (!child_stopped) {
|
||||
if (unlikely(!child_stopped)) {
|
||||
|
||||
/* Once woken up, create a clone of our process. */
|
||||
|
||||
child_pid = fork();
|
||||
if (child_pid < 0) {
|
||||
if (unlikely(child_pid < 0)) {
|
||||
|
||||
write_error("fork");
|
||||
_exit(1);
|
||||
@ -1019,7 +1040,7 @@ static void __afl_start_forkserver(void) {
|
||||
|
||||
/* In child process: close fds, resume execution. */
|
||||
|
||||
if (!child_pid) {
|
||||
if (unlikely(!child_pid)) { // just to signal afl-fuzz faster
|
||||
|
||||
//(void)nice(-20);
|
||||
|
||||
@ -1044,14 +1065,15 @@ static void __afl_start_forkserver(void) {
|
||||
|
||||
/* In parent process: write PID to pipe, then wait for child. */
|
||||
|
||||
if (write(FORKSRV_FD + 1, &child_pid, 4) != 4) {
|
||||
if (unlikely(write(FORKSRV_FD + 1, &child_pid, 4) != 4)) {
|
||||
|
||||
write_error("write to afl-fuzz");
|
||||
_exit(1);
|
||||
|
||||
}
|
||||
|
||||
if (waitpid(child_pid, &status, is_persistent ? WUNTRACED : 0) < 0) {
|
||||
if (unlikely(waitpid(child_pid, &status, is_persistent ? WUNTRACED : 0) <
|
||||
0)) {
|
||||
|
||||
write_error("waitpid");
|
||||
_exit(1);
|
||||
@ -1062,11 +1084,11 @@ static void __afl_start_forkserver(void) {
|
||||
a successful run. In this case, we want to wake it up without forking
|
||||
again. */
|
||||
|
||||
if (WIFSTOPPED(status)) child_stopped = 1;
|
||||
if (likely(WIFSTOPPED(status))) { child_stopped = 1; }
|
||||
|
||||
/* Relay wait status to pipe, then loop back. */
|
||||
|
||||
if (write(FORKSRV_FD + 1, &status, 4) != 4) {
|
||||
if (unlikely(write(FORKSRV_FD + 1, &status, 4) != 4)) {
|
||||
|
||||
write_error("writing to afl-fuzz");
|
||||
_exit(1);
|
||||
@ -2704,7 +2726,7 @@ void __afl_coverage_skip() {
|
||||
// mark this area as especially interesting
|
||||
void __afl_coverage_interesting(u8 val, u32 id) {
|
||||
|
||||
__afl_area_ptr[id] = val;
|
||||
__afl_area_ptr[id % __afl_map_size] = val;
|
||||
|
||||
}
|
||||
|
||||
|
@ -661,6 +661,13 @@ bool AFLdict2filePass::runOnModule(Module &M) {
|
||||
Value *op2 = callInst->getArgOperand(2);
|
||||
ConstantInt *ilen = dyn_cast<ConstantInt>(op2);
|
||||
|
||||
if (!ilen) {
|
||||
|
||||
op2 = callInst->getArgOperand(1);
|
||||
ilen = dyn_cast<ConstantInt>(op2);
|
||||
|
||||
}
|
||||
|
||||
if (ilen) {
|
||||
|
||||
uint64_t literalLength = optLen;
|
||||
|
@ -23,7 +23,7 @@ requires an Intel processor (6th generation onwards) and a special 5.10 kernel
|
||||
2. Additionally, install the following packages:
|
||||
|
||||
```shell
|
||||
apt-get install -y libgtk-3-dev pax-utils python3-msgpack python3-jinja2
|
||||
apt-get install -y libgtk-3-dev pax-utils python3-msgpack python3-jinja2 libcapstone-dev
|
||||
```
|
||||
|
||||
3. As Nyx is written in Rust, install the newest rust compiler (rust packages in
|
||||
@ -33,7 +33,7 @@ requires an Intel processor (6th generation onwards) and a special 5.10 kernel
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||
```
|
||||
|
||||
4. Finally build Nyx mode:
|
||||
4. Finally build Nyx mode (or use `make distrib` at the repo root to build all AFL++ modes):
|
||||
|
||||
```shell
|
||||
./build_nyx_support.sh
|
||||
@ -92,7 +92,7 @@ sudo modprobe -r kvm-intel
|
||||
sudo modprobe -r kvm
|
||||
sudo modprobe kvm enable_vmware_backdoor=y
|
||||
sudo modprobe kvm-intel
|
||||
cat /sys/module/kvm/parameters/enable_vmware_backdoor | grep -q Y && echi OK || echo KVM module problem
|
||||
cat /sys/module/kvm/parameters/enable_vmware_backdoor | grep -q Y && echo OK || echo KVM module problem
|
||||
```
|
||||
|
||||
All the hard parts are done, fuzzing with Nyx mode is easy - just supply the
|
||||
@ -186,7 +186,7 @@ make CC=afl-clang-fast CXX=afl-clang-fast++ LD=afl-clang-fast
|
||||
|
||||
#### Nyx share directories
|
||||
|
||||
Nyx expects that the target is provided in a certain format. More specifically, the target is passed as a so-called „share directory“ to a Nyx-frontend implementation. The share directory contains the target as well as a folder containing all dependencies and other files that are copied over to the guest. But more importantly, this share directory also contains a bootstrap script (`fuzz.sh`if you are using `KVM-Nyx`otherwise `fuzz_no_pt.sh`) that is also executed right after launching the fuzzer. Both bootstrap scripts use several tools to communicate with the "outer world":
|
||||
Nyx expects that the target is provided in a certain format. More specifically, the target is passed as a so-called „share directory“ to a Nyx-frontend implementation. The share directory contains the target as well as a folder containing all dependencies and other files that are copied over to the guest. But more importantly, this share directory also contains a bootstrap script (`fuzz.sh`if you are using `KVM-Nyx`otherwise `fuzz_no_pt.sh`) that is also executed right after launching the fuzzer. Either of these scripts can be edited to more fully prepare an environment for the target, like transferring configuration files to the target's filesystem. Both bootstrap scripts use several tools to communicate with the "outer world":
|
||||
|
||||
- `hcat` - this tool copies a given string to the host
|
||||
- `hget` - this program requests a file from the host's share directory
|
||||
|
@ -1 +1 @@
|
||||
a6f0632a65
|
||||
847b43acb1
|
||||
|
@ -386,6 +386,19 @@ else
|
||||
make -C libqasan CC="$CROSS $CROSS_FLAGS" && echo "[+] libqasan ready"
|
||||
fi
|
||||
|
||||
#### Hooking support
|
||||
if [ "$ENABLE_HOOKING" = "1" ];then
|
||||
echo "[+] ENABLING HOOKING"
|
||||
set -e
|
||||
cd ./hooking_bridge || exit 255
|
||||
mkdir -p ./build
|
||||
echo "[+] Hook compiler = $CROSS"
|
||||
make CC="$CROSS $CROSS_FLAGS" GLIB_H="$GLIB_H" GLIB_CONFIG_H="$GLIB_CONFIG_H"
|
||||
set +e
|
||||
cd ..
|
||||
fi
|
||||
#### End of hooking support
|
||||
|
||||
echo "[+] All done for qemu_mode, enjoy!"
|
||||
|
||||
exit 0
|
||||
|
18
qemu_mode/hooking_bridge/Makefile
Normal file
18
qemu_mode/hooking_bridge/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
.PHONY: clean
|
||||
|
||||
all: plugin
|
||||
SRC=./src
|
||||
BLD=./build
|
||||
INC=-I./inc -I../qemuafl/include -I$(GLIB_H) -I$(GLIB_CONFIG_H)
|
||||
# CC=gcc
|
||||
|
||||
$(BLD)/patching.o:$(SRC)/patching.c
|
||||
$(CC) -c -fPIC $(INC) -o $(BLD)/patching.o $(SRC)/patching.c
|
||||
|
||||
plugin:$(SRC)/main.c $(BLD)/patching.o
|
||||
$(CC) -c -fPIC $(INC) -o $(BLD)/plugin.o $(SRC)/main.c
|
||||
$(CC) -shared -o $(BLD)/plugin.so $(BLD)/plugin.o $(BLD)/patching.o
|
||||
|
||||
clean:
|
||||
rm -rf $(BLD)/*.o
|
||||
rm -rf $(BLD)/*.so
|
96
qemu_mode/hooking_bridge/README.md
Normal file
96
qemu_mode/hooking_bridge/README.md
Normal file
@ -0,0 +1,96 @@
|
||||
# Native hooking support into QEMUAFL
|
||||
* The essential idea is to have inbuilt hooking support into QEMU, instead of relying on the more expensive options UNICORN and its children.
|
||||
* This solution comprises a bridge (QEMU plugin) that connects your hooks (in a shared library (.so)) with the QEMU usermode ecosystem.
|
||||
* Currently, LINUX only
|
||||
|
||||
## Bridge compilation
|
||||
Run build_qemu_support.sh as you do to compile qemuafl, additionally with three args namely:
|
||||
* `ENABLE_HOOKING=1` to compile the bridge
|
||||
* `GLIB_H` and `GLIB_CONFIG_H` point to headers `glib.h` and `glibconfig.h` to wherever they are installed on your system
|
||||
|
||||
## Writting hooks
|
||||
1. Create one or more hooking functions in a shared library, say `hook.so`.
|
||||
2. Include `exports.h` in your hook build. You can find this header at `<your AFL++ path>/qemu_mode/hooking_bridge/inc`.
|
||||
3. Shown below is an example which will use to walkthrough hook creation
|
||||
```C
|
||||
struct ret* hook_000000400deadc08(){
|
||||
memset (buf, 0, 8);
|
||||
scanf("%s",buf);
|
||||
r_reg(RSI,(void *)&h_addr);
|
||||
w_mem(h_addr,8, buf);
|
||||
to_ret = (struct ret){0x400deadcab, 0};
|
||||
return &to_ret;
|
||||
}
|
||||
```
|
||||
i. Hook functions must be named as `hook_<left padded hook location>`. Here, `<left padded hook location>` means `<hook location>` left padded with 0's to until 16 hex characters. The unpaded part of `<hook location>` is the absolute address where you want to place the hook. It is basically the file base address (which does not change in QEMU as of now) plus the instruction offset where the hooks is to be placed. The hook function must return a `struct ret *`, which is touched upon later.
|
||||
|
||||
ii. Most likely you will need to access memory or registers in the hook. So we provide four functions
|
||||
```C
|
||||
// Read memory (from address, num. bytes, destination buffer) -> returns 0 on success
|
||||
int r_mem(unsigned long long addr, unsigned long long len, void *dest);
|
||||
// Write memory (to address, num. bytes, source buffer) -> returns 0 on success
|
||||
int w_mem(unsigned long long addr, unsigned long long len, void *src);
|
||||
// Read register (identifier, destination buffer) -> returns number of bytes read
|
||||
int r_reg(unsigned char reg, void *dest);
|
||||
// Read register (identifier, source buffer) -> returns number of bytes written
|
||||
int w_reg(unsigned char reg, char *src);
|
||||
```
|
||||
When operating on registers, the functions require a `reg` identifier. This is basically a number gdb uses to lookup a register and can be found under `<qemu(afl) path>/gdb-xml` in the architecture specific xml files. For the example case from above, `RSI` is 4 as obtained from `i386-64bit.xml`.
|
||||
|
||||
iii. Once done with the processing, the hooks needs to return a `struct ret` type pointer, the struct format being
|
||||
```C
|
||||
struct ret{
|
||||
unsigned long long addr;
|
||||
char remove_bp;
|
||||
};
|
||||
```
|
||||
As we can see, there are two fields: first that indicates the address to return to and second that indicates whether the installed hook should be removed after the return. The second field becomes critical if the hook is within an ongoing loop and should be kept intact for future references.
|
||||
|
||||
iv. Finally, mention the list of hooks in a `configure` function that we can call and install your hooks
|
||||
```C
|
||||
struct conf config;
|
||||
struct conf* configure(){
|
||||
config.IP_reg_num = 16;
|
||||
config.entry_addr = 0x4000001000;
|
||||
config.num_hooks = NUMHOOKS; //1,2,3...
|
||||
hooks[0] = 0x400deadc08;
|
||||
// hooks[1] = 0xcafecace
|
||||
// ....
|
||||
config.hooks = hooks;
|
||||
|
||||
//Any other processing stuff you need done before fuzztime
|
||||
|
||||
return &config;
|
||||
}
|
||||
```
|
||||
The `configure` function must have the signature `struct conf* configure()` i.e. it must return a pointer to the `config` object. The format of the `config` object is
|
||||
```C
|
||||
struct conf{
|
||||
unsigned char IP_reg_num; //found in <qemudir>/gdb-xml
|
||||
unsigned long long entry_addr; //Main, init, or any entry point that is executed by QEMU prior to hooking targets
|
||||
unsigned long long* hooks; //list of hooked addresses
|
||||
unsigned long long num_hooks; // Number of hooks
|
||||
};
|
||||
```
|
||||
`IP_reg_num` here is the register number assigned under the architecture specific xml file under `<qemu(afl) path>/gdb-xml` to the instruction pointer.
|
||||
|
||||
## Running with hooks
|
||||
Set `QEMU_PLUGIN="file=<AFL download path>qemu_mode/hooking_bridge/build/plugin.so,arg=<your hook .so>"` before running AFL++ in QEMU mode. Note `<your hook .so>` is the absolute path to your hooks library.
|
||||
|
||||
## Current limitations
|
||||
1. Cannot be used to debug (-g option) when using the bridge as it uses the gdbstub internally. This is not a problem if used with AFL++, so not such a big issue.
|
||||
2. Cannot put a hook on the first block after `<entry point>`. Not typically a hookable location.
|
||||
3. The current implementation can only function on Linux. We have tested on the following configuration
|
||||
```Bash
|
||||
lsb_release -a
|
||||
---------------
|
||||
Distributor ID: Ubuntu
|
||||
Description: Ubuntu 22.04.3 LTS
|
||||
Release: 22.04
|
||||
Codename: jammy
|
||||
```
|
||||
```Bash
|
||||
uname -a
|
||||
----------
|
||||
Linux someone 6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
|
||||
```
|
11
qemu_mode/hooking_bridge/inc/common.h
Normal file
11
qemu_mode/hooking_bridge/inc/common.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <qemu/qemu-plugin.h>
|
||||
|
||||
void patch_finish_cb(void *userdata);
|
||||
void patch_block_trans_cb(struct qemu_plugin_tb *tb);
|
||||
void patch_vpu_init_cb(unsigned int vcpu_index);
|
||||
void patch_init(char *hook_library);
|
||||
|
||||
#endif
|
29
qemu_mode/hooking_bridge/inc/exports.h
Normal file
29
qemu_mode/hooking_bridge/inc/exports.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef API_H
|
||||
#define API_H
|
||||
|
||||
//# EXPORTS
|
||||
// Returns 0 on success
|
||||
int r_mem(unsigned long long addr, unsigned long long len, void *dest);
|
||||
// // Returns 0 on success
|
||||
int w_mem(unsigned long long addr, unsigned long long len, void *src);
|
||||
// Returns num of bytes read;
|
||||
int r_reg(unsigned char reg, void *dest);
|
||||
// // Returns num of bytes written
|
||||
int w_reg(unsigned char reg, char *src);
|
||||
|
||||
|
||||
//NOTE hook function must be named hook_<16 hex character at_addr>
|
||||
//NOTE must define function `struct conf* configure()`
|
||||
struct conf{
|
||||
unsigned char IP_reg_num;
|
||||
unsigned long long entry_addr;
|
||||
unsigned long long* hooks;
|
||||
unsigned long long num_hooks;
|
||||
}conf;
|
||||
|
||||
struct ret{
|
||||
unsigned long long addr;
|
||||
char remove_bp;
|
||||
};
|
||||
|
||||
#endif
|
36
qemu_mode/hooking_bridge/src/main.c
Normal file
36
qemu_mode/hooking_bridge/src/main.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||
|
||||
static void finish_cb(qemu_plugin_id_t id, void *userdata) {
|
||||
|
||||
patch_finish_cb(userdata);
|
||||
|
||||
}
|
||||
|
||||
static void block_trans_cb(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {
|
||||
|
||||
patch_block_trans_cb(tb);
|
||||
|
||||
}
|
||||
|
||||
static void vpu_init_cb(qemu_plugin_id_t id, unsigned int vcpu_index) {
|
||||
|
||||
patch_vpu_init_cb(vcpu_index);
|
||||
|
||||
}
|
||||
|
||||
QEMU_PLUGIN_EXPORT
|
||||
int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc,
|
||||
char **argv) {
|
||||
|
||||
patch_init(argv[0]);
|
||||
qemu_plugin_register_vcpu_init_cb(id, vpu_init_cb);
|
||||
qemu_plugin_register_vcpu_tb_trans_cb(id, block_trans_cb);
|
||||
qemu_plugin_register_atexit_cb(id, finish_cb, NULL);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
173
qemu_mode/hooking_bridge/src/patching.c
Normal file
173
qemu_mode/hooking_bridge/src/patching.c
Normal file
@ -0,0 +1,173 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <glib.h>
|
||||
#include "common.h"
|
||||
#include "exports.h"
|
||||
|
||||
void *handle;
|
||||
struct conf *config;
|
||||
struct conf *(*configure)();
|
||||
GByteArray *out;
|
||||
void *cpu;
|
||||
char cbuf[100];
|
||||
|
||||
// region GDB Imports
|
||||
#pragma region GDB Imports
|
||||
void cpu_single_step(void *cpu, int enabled);
|
||||
int get_sstep_flags(void);
|
||||
void gdb_accept_init(int fd);
|
||||
int gdb_breakpoint_insert(int type, unsigned long long addr,
|
||||
unsigned long long len);
|
||||
int gdb_breakpoint_remove(int type, unsigned long long addr,
|
||||
unsigned long long len);
|
||||
void *qemu_get_cpu(int index);
|
||||
int target_memory_rw_debug(void *cpu, unsigned long long addr, void *ptr,
|
||||
unsigned long long len, char is_write);
|
||||
int gdb_read_register(void *cs, GByteArray *mem_buf, int n);
|
||||
int gdb_write_register(void *cs, char *mem_buf, int n);
|
||||
void gdb_set_cpu_pc(unsigned long long pc);
|
||||
void gdb_continue(void);
|
||||
#pragma endregion GDB Imports
|
||||
|
||||
// region API
|
||||
int r_mem(unsigned long long addr, unsigned long long len, void *dest) {
|
||||
|
||||
return target_memory_rw_debug(cpu, addr, dest, len, 0);
|
||||
|
||||
}
|
||||
|
||||
int w_mem(unsigned long long addr, unsigned long long len, void *src) {
|
||||
|
||||
return target_memory_rw_debug(cpu, addr, src, len, 1);
|
||||
|
||||
}
|
||||
|
||||
int r_reg(unsigned char reg, void *dest) {
|
||||
|
||||
g_byte_array_steal(out, NULL);
|
||||
int op = gdb_read_register(cpu, out, reg);
|
||||
memcpy(dest, out->data, out->len);
|
||||
return op;
|
||||
|
||||
}
|
||||
|
||||
int w_reg(unsigned char reg, char *src) {
|
||||
|
||||
return gdb_write_register(cpu, src, reg);
|
||||
|
||||
}
|
||||
|
||||
// region Breakpoint handling
|
||||
char single_stepped;
|
||||
unsigned long long gen_addr;
|
||||
struct ret *(*hook)();
|
||||
struct ret *returned;
|
||||
// Defined and imported gdbstub.c
|
||||
void set_signal_callback(void (*cb)(int));
|
||||
// Breakpoints are set here
|
||||
void patch_block_trans_cb(struct qemu_plugin_tb *tb) {
|
||||
|
||||
unsigned long long addr;
|
||||
addr = qemu_plugin_tb_vaddr(tb);
|
||||
|
||||
if (addr == config->entry_addr) {
|
||||
|
||||
// NOTE This means we cannot put a BP in the first basic block
|
||||
gdb_accept_init(-1);
|
||||
for (int i = 0; i < config->num_hooks; i++) {
|
||||
|
||||
gdb_breakpoint_insert(0, config->hooks[i], 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handle_signal_callback(int sig) {
|
||||
|
||||
if (single_stepped) {
|
||||
|
||||
single_stepped = 0;
|
||||
gdb_breakpoint_insert(0, gen_addr, 1);
|
||||
cpu_single_step(cpu, 0);
|
||||
gdb_continue();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
r_reg(config->IP_reg_num, cbuf);
|
||||
gen_addr = *(unsigned long long *)cbuf;
|
||||
|
||||
sprintf(cbuf, "hook_%016llx", gen_addr);
|
||||
// TODO maybe find a way to put the hook function pointers in the TCG data
|
||||
// structure instead of this dlsym call
|
||||
*(unsigned long long **)(&hook) = dlsym(handle, cbuf);
|
||||
if (!hook) {
|
||||
|
||||
exit(-1);
|
||||
|
||||
}
|
||||
|
||||
returned = hook();
|
||||
|
||||
if (returned->remove_bp ||
|
||||
(returned->addr ==
|
||||
gen_addr)) { //* force removal of bp in returning to the same address,
|
||||
//otherwise hook will be called again
|
||||
gdb_breakpoint_remove(0, gen_addr, 1);
|
||||
|
||||
}
|
||||
|
||||
if (returned->addr == gen_addr) {
|
||||
|
||||
single_stepped = 1;
|
||||
cpu_single_step(cpu, get_sstep_flags());
|
||||
|
||||
} else {
|
||||
|
||||
//* no need to rexecute the IP instruction
|
||||
gdb_set_cpu_pc(returned->addr);
|
||||
|
||||
}
|
||||
|
||||
gdb_continue();
|
||||
|
||||
}
|
||||
|
||||
// region Constructor/Destructor
|
||||
void patch_finish_cb(void *userdata) {
|
||||
|
||||
g_byte_array_free(out, 1);
|
||||
dlclose(handle);
|
||||
|
||||
}
|
||||
|
||||
void patch_vpu_init_cb(unsigned int vcpu_index) {
|
||||
|
||||
cpu = qemu_get_cpu(vcpu_index);
|
||||
|
||||
}
|
||||
|
||||
void patch_init(char *hook_lib) {
|
||||
|
||||
// TODO make OS agnostic, remove dlopen
|
||||
handle = dlopen(hook_lib, RTLD_NOW);
|
||||
if (!handle) {
|
||||
|
||||
fprintf(stderr, "DLOPEN Error: %s\n", dlerror());
|
||||
exit(-1);
|
||||
|
||||
}
|
||||
|
||||
single_stepped = 0;
|
||||
|
||||
*(void **)(&configure) = dlsym(handle, "configure");
|
||||
config = configure();
|
||||
|
||||
set_signal_callback(handle_signal_callback);
|
||||
out = g_byte_array_new();
|
||||
|
||||
}
|
||||
|
Submodule qemu_mode/qemuafl updated: a6f0632a65...847b43acb1
@ -979,6 +979,7 @@ inline u64 get_cur_time(void) {
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
// TO NOT REPLACE WITH clock_gettime!!!
|
||||
gettimeofday(&tv, &tz);
|
||||
|
||||
return (tv.tv_sec * 1000ULL) + (tv.tv_usec / 1000);
|
||||
@ -992,6 +993,7 @@ inline u64 get_cur_time_us(void) {
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
// TO NOT REPLACE WITH clock_gettime!!!
|
||||
gettimeofday(&tv, &tz);
|
||||
|
||||
return (tv.tv_sec * 1000000ULL) + tv.tv_usec;
|
||||
|
@ -241,6 +241,7 @@ void afl_fsrv_init(afl_forkserver_t *fsrv) {
|
||||
fsrv->mem_limit = MEM_LIMIT;
|
||||
fsrv->out_file = NULL;
|
||||
fsrv->child_kill_signal = SIGKILL;
|
||||
fsrv->max_length = MAX_FILE;
|
||||
|
||||
/* exec related stuff */
|
||||
fsrv->child_pid = -1;
|
||||
@ -252,6 +253,10 @@ void afl_fsrv_init(afl_forkserver_t *fsrv) {
|
||||
fsrv->uses_crash_exitcode = false;
|
||||
fsrv->uses_asan = false;
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
fsrv->persistent_trace_bits = NULL;
|
||||
#endif
|
||||
|
||||
fsrv->init_child_func = fsrv_exec_child;
|
||||
list_append(&fsrv_list, fsrv);
|
||||
|
||||
@ -278,12 +283,19 @@ void afl_fsrv_init_dup(afl_forkserver_t *fsrv_to, afl_forkserver_t *from) {
|
||||
fsrv_to->fsrv_kill_signal = from->fsrv_kill_signal;
|
||||
fsrv_to->debug = from->debug;
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
fsrv_to->persistent_trace_bits = from->persistent_trace_bits;
|
||||
#endif
|
||||
|
||||
// These are forkserver specific.
|
||||
fsrv_to->out_dir_fd = -1;
|
||||
fsrv_to->child_pid = -1;
|
||||
fsrv_to->use_fauxsrv = 0;
|
||||
fsrv_to->last_run_timed_out = 0;
|
||||
|
||||
fsrv_to->late_send = from->late_send;
|
||||
fsrv_to->custom_data_ptr = from->custom_data_ptr;
|
||||
|
||||
fsrv_to->init_child_func = from->init_child_func;
|
||||
// Note: do not copy ->add_extra_func or ->persistent_record*
|
||||
|
||||
@ -1944,6 +1956,13 @@ afl_fsrv_run_target(afl_forkserver_t *fsrv, u32 timeout,
|
||||
|
||||
}
|
||||
|
||||
if (unlikely(fsrv->late_send)) {
|
||||
|
||||
fsrv->late_send(fsrv->custom_data_ptr, fsrv->custom_input,
|
||||
fsrv->custom_input_len);
|
||||
|
||||
}
|
||||
|
||||
exec_ms = read_s32_timed(fsrv->fsrv_st_fd, &fsrv->child_status, timeout,
|
||||
stop_soon_p);
|
||||
|
||||
|
@ -75,9 +75,13 @@ u32 count_bits(afl_state_t *afl, u8 *mem) {
|
||||
|
||||
}
|
||||
|
||||
#if __has_builtin(__builtin_popcount)
|
||||
ret += __builtin_popcount(v);
|
||||
#else
|
||||
v -= ((v >> 1) & 0x55555555);
|
||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
||||
ret += (((v + (v >> 4)) & 0xF0F0F0F) * 0x01010101) >> 24;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -459,7 +463,7 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
|
||||
|
||||
if (unlikely(fault == FSRV_RUN_TMOUT && afl->afl_env.afl_ignore_timeouts)) {
|
||||
|
||||
if (likely(afl->schedule >= FAST && afl->schedule <= RARE)) {
|
||||
if (unlikely(afl->schedule >= FAST && afl->schedule <= RARE)) {
|
||||
|
||||
classify_counts(&afl->fsrv);
|
||||
u64 cksum = hash64(afl->fsrv.trace_bits, afl->fsrv.map_size, HASH_CONST);
|
||||
@ -485,7 +489,7 @@ save_if_interesting(afl_state_t *afl, void *mem, u32 len, u8 fault) {
|
||||
|
||||
/* Generating a hash on every input is super expensive. Bad idea and should
|
||||
only be used for special schedules */
|
||||
if (likely(afl->schedule >= FAST && afl->schedule <= RARE)) {
|
||||
if (unlikely(afl->schedule >= FAST && afl->schedule <= RARE)) {
|
||||
|
||||
classify_counts(&afl->fsrv);
|
||||
classified = 1;
|
||||
|
@ -455,13 +455,13 @@ void deunicode_extras(afl_state_t *afl) {
|
||||
|
||||
case 2:
|
||||
if (!afl->extras[i].data[j]) { ++z3; }
|
||||
// fall through
|
||||
__attribute__((fallthrough));
|
||||
case 0:
|
||||
if (!afl->extras[i].data[j]) { ++z1; }
|
||||
break;
|
||||
case 3:
|
||||
if (!afl->extras[i].data[j]) { ++z4; }
|
||||
// fall through
|
||||
__attribute__((fallthrough));
|
||||
case 1:
|
||||
if (!afl->extras[i].data[j]) { ++z2; }
|
||||
break;
|
||||
|
@ -1019,7 +1019,7 @@ void perform_dry_run(afl_state_t *afl) {
|
||||
|
||||
}
|
||||
|
||||
if (!q->was_fuzzed) {
|
||||
if (unlikely(!q->was_fuzzed)) {
|
||||
|
||||
q->was_fuzzed = 1;
|
||||
afl->reinit_table = 1;
|
||||
@ -2717,7 +2717,11 @@ void fix_up_sync(afl_state_t *afl) {
|
||||
|
||||
}
|
||||
|
||||
if (strlen(afl->sync_id) > 32) { FATAL("Fuzzer ID too long"); }
|
||||
if (strlen(afl->sync_id) > 50) {
|
||||
|
||||
FATAL("sync_id max length is 50 characters");
|
||||
|
||||
}
|
||||
|
||||
x = alloc_printf("%s/%s", afl->out_dir, afl->sync_id);
|
||||
|
||||
|
@ -87,155 +87,32 @@ void create_alias_table(afl_state_t *afl) {
|
||||
memset((void *)Small, 0, n * sizeof(u32));
|
||||
memset((void *)Large, 0, n * sizeof(u32));
|
||||
|
||||
if (likely(afl->schedule < RARE)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
double avg_exec_us = 0.0;
|
||||
double avg_bitmap_size = 0.0;
|
||||
double avg_len = 0.0;
|
||||
u32 active = 0;
|
||||
struct queue_entry *q = afl->queue_buf[i];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
// disabled entries might have timings and bitmap values
|
||||
if (likely(!q->disabled)) {
|
||||
|
||||
struct queue_entry *q = afl->queue_buf[i];
|
||||
|
||||
// disabled entries might have timings and bitmap values
|
||||
if (likely(!q->disabled)) {
|
||||
|
||||
avg_exec_us += q->exec_us;
|
||||
avg_bitmap_size += log(q->bitmap_size);
|
||||
avg_len += q->len;
|
||||
++active;
|
||||
|
||||
}
|
||||
q->weight = q->perf_score = calculate_score(afl, q);
|
||||
if (unlikely(!q->was_fuzzed)) { q->weight *= 2.0; }
|
||||
if (unlikely(q->fs_redundant)) { q->weight *= 0.75; }
|
||||
sum += q->weight;
|
||||
|
||||
}
|
||||
|
||||
avg_exec_us /= active;
|
||||
avg_bitmap_size /= active;
|
||||
avg_len /= active;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
struct queue_entry *q = afl->queue_buf[i];
|
||||
// weight is always 0 for disabled entries
|
||||
if (unlikely(afl->queue_buf[i]->disabled)) {
|
||||
|
||||
if (likely(!q->disabled)) {
|
||||
P[i] = 0;
|
||||
|
||||
double weight = 1.0;
|
||||
{ // inline does result in a compile error with LTO, weird
|
||||
} else {
|
||||
|
||||
if (likely(afl->schedule >= FAST && afl->schedule <= RARE)) {
|
||||
|
||||
u32 hits = afl->n_fuzz[q->n_fuzz_entry];
|
||||
if (likely(hits)) { weight /= (log10(hits) + 1); }
|
||||
|
||||
}
|
||||
|
||||
if (likely(afl->schedule < RARE)) {
|
||||
|
||||
double t = q->exec_us / avg_exec_us;
|
||||
if (likely(t < 0.1)) {
|
||||
|
||||
// nothing
|
||||
|
||||
} else if (likely(t <= 0.25))
|
||||
|
||||
weight *= 0.9;
|
||||
else if (likely(t <= 0.5)) {
|
||||
|
||||
// nothing
|
||||
|
||||
} else if (likely(t < 1.0))
|
||||
|
||||
weight *= 1.15;
|
||||
else if (unlikely(t > 2.5 && t < 5.0))
|
||||
weight *= 1.1;
|
||||
// else nothing
|
||||
|
||||
}
|
||||
|
||||
double l = q->len / avg_len;
|
||||
if (likely(l < 0.1))
|
||||
weight *= 0.75;
|
||||
else if (likely(l < 0.25))
|
||||
weight *= 1.1;
|
||||
else if (unlikely(l >= 10))
|
||||
weight *= 1.1;
|
||||
|
||||
double bms = q->bitmap_size / avg_bitmap_size;
|
||||
if (likely(bms < 0.5))
|
||||
weight *= (1.0 + ((bms - 0.5) / 2));
|
||||
else if (unlikely(bms > 1.33))
|
||||
weight *= 1.1;
|
||||
|
||||
if (unlikely(!q->was_fuzzed)) { weight *= 2.5; }
|
||||
if (unlikely(q->fs_redundant)) { weight *= 0.75; }
|
||||
|
||||
}
|
||||
|
||||
q->weight = weight;
|
||||
q->perf_score = calculate_score(afl, q);
|
||||
sum += q->weight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (unlikely(afl->schedule == MMOPT) && afl->queued_discovered) {
|
||||
|
||||
u32 cnt = afl->queued_discovered >= 5 ? 5 : afl->queued_discovered;
|
||||
|
||||
for (i = n - cnt; i < n; i++) {
|
||||
|
||||
struct queue_entry *q = afl->queue_buf[i];
|
||||
|
||||
if (likely(!q->disabled)) { q->weight *= 2.0; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
// weight is always 0 for disabled entries
|
||||
if (unlikely(afl->queue_buf[i]->disabled)) {
|
||||
|
||||
P[i] = 0;
|
||||
|
||||
} else {
|
||||
|
||||
P[i] = (afl->queue_buf[i]->weight * n) / sum;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
struct queue_entry *q = afl->queue_buf[i];
|
||||
|
||||
if (likely(!q->disabled)) {
|
||||
|
||||
q->perf_score = calculate_score(afl, q);
|
||||
sum += q->perf_score;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
// perf_score is always 0 for disabled entries
|
||||
if (unlikely(afl->queue_buf[i]->disabled)) {
|
||||
|
||||
P[i] = 0;
|
||||
|
||||
} else {
|
||||
|
||||
P[i] = (afl->queue_buf[i]->perf_score * n) / sum;
|
||||
|
||||
}
|
||||
P[i] = (afl->queue_buf[i]->weight * n) / sum;
|
||||
|
||||
}
|
||||
|
||||
@ -401,7 +278,9 @@ void mark_as_redundant(afl_state_t *afl, struct queue_entry *q, u8 state) {
|
||||
|
||||
} else {
|
||||
|
||||
if (unlink(fn)) { PFATAL("Unable to remove '%s'", fn); }
|
||||
if (unlink(fn)) { /*PFATAL("Unable to remove '%s'", fn);*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -699,12 +578,11 @@ void add_to_queue(afl_state_t *afl, u8 *fname, u32 len, u8 passed_det) {
|
||||
|
||||
void destroy_queue(afl_state_t *afl) {
|
||||
|
||||
u32 i;
|
||||
u32 i;
|
||||
struct queue_entry *q;
|
||||
|
||||
for (i = 0; i < afl->queued_items; i++) {
|
||||
|
||||
struct queue_entry *q;
|
||||
|
||||
q = afl->queue_buf[i];
|
||||
ck_free(q->fname);
|
||||
ck_free(q->trace_mini);
|
||||
@ -740,7 +618,7 @@ void update_bitmap_score(afl_state_t *afl, struct queue_entry *q) {
|
||||
u64 fav_factor;
|
||||
u64 fuzz_p2;
|
||||
|
||||
if (likely(afl->schedule >= FAST && afl->schedule < RARE)) {
|
||||
if (unlikely(afl->schedule >= FAST && afl->schedule < RARE)) {
|
||||
|
||||
fuzz_p2 = 0; // Skip the fuzz_p2 comparison
|
||||
|
||||
@ -776,7 +654,7 @@ void update_bitmap_score(afl_state_t *afl, struct queue_entry *q) {
|
||||
u64 top_rated_fav_factor;
|
||||
u64 top_rated_fuzz_p2;
|
||||
|
||||
if (likely(afl->schedule >= FAST && afl->schedule < RARE)) {
|
||||
if (unlikely(afl->schedule >= FAST && afl->schedule < RARE)) {
|
||||
|
||||
top_rated_fuzz_p2 = 0; // Skip the fuzz_p2 comparison
|
||||
|
||||
|
@ -60,6 +60,27 @@ fuzz_run_target(afl_state_t *afl, afl_forkserver_t *fsrv, u32 timeout) {
|
||||
|
||||
fsrv_run_result_t res = afl_fsrv_run_target(fsrv, timeout, &afl->stop_soon);
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
if (unlikely(!fsrv->persistent_trace_bits)) {
|
||||
|
||||
// On the first run, we allocate the persistent map to collect coverage.
|
||||
fsrv->persistent_trace_bits = (u8 *)malloc(fsrv->map_size);
|
||||
memset(fsrv->persistent_trace_bits, 0, fsrv->map_size);
|
||||
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < fsrv->map_size; ++i) {
|
||||
|
||||
if (fsrv->persistent_trace_bits[i] != 255 && fsrv->trace_bits[i]) {
|
||||
|
||||
fsrv->persistent_trace_bits[i]++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* If post_run() function is defined in custom mutator, the function will be
|
||||
called each time after AFL++ executes the target program. */
|
||||
|
||||
@ -173,7 +194,17 @@ write_to_testcase(afl_state_t *afl, void **mem, u32 len, u32 fix) {
|
||||
|
||||
if (el->afl_custom_fuzz_send) {
|
||||
|
||||
el->afl_custom_fuzz_send(el->data, *mem, new_size);
|
||||
if (!afl->afl_env.afl_custom_mutator_late_send) {
|
||||
|
||||
el->afl_custom_fuzz_send(el->data, *mem, new_size);
|
||||
|
||||
} else {
|
||||
|
||||
afl->fsrv.custom_input = *mem;
|
||||
afl->fsrv.custom_input_len = new_size;
|
||||
|
||||
}
|
||||
|
||||
sent = 1;
|
||||
|
||||
}
|
||||
|
@ -286,6 +286,13 @@ void read_afl_environment(afl_state_t *afl, char **envp) {
|
||||
afl->afl_env.afl_no_sync =
|
||||
get_afl_env(afl_environment_variables[i]) ? 1 : 0;
|
||||
|
||||
} else if (!strncmp(env, "AFL_NO_FASTRESUME",
|
||||
|
||||
afl_environment_variable_len)) {
|
||||
|
||||
afl->afl_env.afl_no_fastresume =
|
||||
get_afl_env(afl_environment_variables[i]) ? 1 : 0;
|
||||
|
||||
} else if (!strncmp(env, "AFL_CUSTOM_MUTATOR_ONLY",
|
||||
|
||||
afl_environment_variable_len)) {
|
||||
@ -293,6 +300,13 @@ void read_afl_environment(afl_state_t *afl, char **envp) {
|
||||
afl->afl_env.afl_custom_mutator_only =
|
||||
get_afl_env(afl_environment_variables[i]) ? 1 : 0;
|
||||
|
||||
} else if (!strncmp(env, "AFL_CUSTOM_MUTATOR_LATE_SEND",
|
||||
|
||||
afl_environment_variable_len)) {
|
||||
|
||||
afl->afl_env.afl_custom_mutator_late_send =
|
||||
get_afl_env(afl_environment_variables[i]) ? 1 : 0;
|
||||
|
||||
} else if (!strncmp(env, "AFL_CMPLOG_ONLY_NEW",
|
||||
|
||||
afl_environment_variable_len)) {
|
||||
|
@ -76,7 +76,13 @@ char *get_fuzzing_state(afl_state_t *afl) {
|
||||
|
||||
void write_setup_file(afl_state_t *afl, u32 argc, char **argv) {
|
||||
|
||||
u8 fn[PATH_MAX];
|
||||
u8 fn[PATH_MAX], fn2[PATH_MAX];
|
||||
|
||||
snprintf(fn2, PATH_MAX, "%s/target_hash", afl->out_dir);
|
||||
FILE *f2 = create_ffile(fn2);
|
||||
fprintf(f2, "%p\n", (void *)get_binary_hash(afl->fsrv.target_path));
|
||||
fclose(f2);
|
||||
|
||||
snprintf(fn, PATH_MAX, "%s/fuzzer_setup", afl->out_dir);
|
||||
FILE *f = create_ffile(fn);
|
||||
u32 i;
|
||||
|
404
src/afl-fuzz.c
404
src/afl-fuzz.c
@ -36,6 +36,67 @@
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
|
||||
#define ck_gzread(fd, buf, len, fn) \
|
||||
do { \
|
||||
\
|
||||
s32 _len = (s32)(len); \
|
||||
s32 _res = gzread(fd, buf, _len); \
|
||||
if (_res != _len) RPFATAL(_res, "Short read from %s", fn); \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#define ck_gzwrite(fd, buf, len, fn) \
|
||||
do { \
|
||||
\
|
||||
if (len <= 0) break; \
|
||||
s32 _written = 0, _off = 0, _len = (s32)(len); \
|
||||
\
|
||||
do { \
|
||||
\
|
||||
s32 _res = gzwrite(fd, (buf) + _off, _len); \
|
||||
if (_res != _len && (_res > 0 && _written + _res != _len)) { \
|
||||
\
|
||||
if (_res > 0) { \
|
||||
\
|
||||
_written += _res; \
|
||||
_len -= _res; \
|
||||
_off += _res; \
|
||||
\
|
||||
} else { \
|
||||
\
|
||||
RPFATAL(_res, "Short write to %s (%d of %d bytes)", fn, _res, \
|
||||
_len); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} else { \
|
||||
\
|
||||
break; \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} while (1); \
|
||||
\
|
||||
\
|
||||
\
|
||||
} while (0)
|
||||
|
||||
#include <zlib.h>
|
||||
#define ZLIBOPEN gzopen
|
||||
#define ZLIBREAD ck_gzread
|
||||
#define NZLIBREAD gzread
|
||||
#define ZLIBWRITE ck_gzwrite
|
||||
#define ZLIBCLOSE gzclose
|
||||
#define ZLIB_EXTRA "9"
|
||||
#else
|
||||
#define ZLIBOPEN open
|
||||
#define NZLIBREAD read
|
||||
#define ZLIBREAD ck_read
|
||||
#define ZLIBWRITE ck_write
|
||||
#define ZLIBCLOSE close
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/qos.h>
|
||||
@ -181,7 +242,7 @@ static void usage(u8 *argv0, int more_help) {
|
||||
"it.\n"
|
||||
" if using QEMU/FRIDA or the fuzzing target is "
|
||||
"compiled\n"
|
||||
" for CmpLog then use '-c 0'. To disable Cmplog use '-c "
|
||||
" for CmpLog then use '-c 0'. To disable CMPLOG use '-c "
|
||||
"-'.\n"
|
||||
" -l cmplog_opts - CmpLog configuration values (e.g. \"2ATR\"):\n"
|
||||
" 1=small files, 2=larger files (default), 3=all "
|
||||
@ -335,6 +396,7 @@ static void usage(u8 *argv0, int more_help) {
|
||||
"AFL_STATSD_PORT: change default statsd port (default: 8125)\n"
|
||||
"AFL_STATSD_TAGS_FLAVOR: set statsd tags format (default: disable tags)\n"
|
||||
" suported formats: dogstatsd, librato, signalfx, influxdb\n"
|
||||
"AFL_NO_FASTRESUME: do not read or write a fast resume file\n"
|
||||
"AFL_NO_SYNC: disables all syncing\n"
|
||||
"AFL_SYNC_TIME: sync time between fuzzing instances (in minutes)\n"
|
||||
"AFL_FINAL_SYNC: sync a final time when exiting (will delay the exit!)\n"
|
||||
@ -960,7 +1022,11 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
if (afl->fsrv.mem_limit < 5) { FATAL("Dangerously low value of -m"); }
|
||||
if (afl->fsrv.mem_limit && afl->fsrv.mem_limit < 5) {
|
||||
|
||||
FATAL("Dangerously low value of -m");
|
||||
|
||||
}
|
||||
|
||||
if (sizeof(rlim_t) == 4 && afl->fsrv.mem_limit > 2000) {
|
||||
|
||||
@ -1544,17 +1610,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
#endif
|
||||
|
||||
if (afl->sync_id) {
|
||||
|
||||
if (strlen(afl->sync_id) > 50) {
|
||||
|
||||
FATAL("sync_id max length is 50 characters");
|
||||
|
||||
}
|
||||
|
||||
fix_up_sync(afl);
|
||||
|
||||
}
|
||||
if (afl->sync_id) { fix_up_sync(afl); }
|
||||
|
||||
if (!strcmp(afl->in_dir, afl->out_dir)) {
|
||||
|
||||
@ -1868,6 +1924,15 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
OKF("Using Frida Address Sanitizer Mode");
|
||||
|
||||
if (afl->fsrv.mem_limit) {
|
||||
|
||||
WARNF(
|
||||
"in the Frida Address Sanitizer Mode we disable all memory "
|
||||
"limits");
|
||||
afl->fsrv.mem_limit = 0;
|
||||
|
||||
}
|
||||
|
||||
fasan_check_afl_preload(afl_preload);
|
||||
|
||||
setenv("ASAN_OPTIONS", "detect_leaks=false", 1);
|
||||
@ -2067,6 +2132,31 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
if (afl->custom_mutators_count && afl->afl_env.afl_custom_mutator_late_send) {
|
||||
|
||||
u32 count_send = 0;
|
||||
LIST_FOREACH(&afl->custom_mutator_list, struct custom_mutator, {
|
||||
|
||||
if (el->afl_custom_fuzz_send) {
|
||||
|
||||
if (count_send) {
|
||||
|
||||
FATAL(
|
||||
"You can only have one custom send() function if you are using "
|
||||
"AFL_CUSTOM_MUTATOR_LATE_SEND!");
|
||||
|
||||
}
|
||||
|
||||
afl->fsrv.late_send = el->afl_custom_fuzz_send;
|
||||
afl->fsrv.custom_data_ptr = el->data;
|
||||
count_send = 1;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (afl->limit_time_sig > 0 && afl->custom_mutators_count) {
|
||||
|
||||
if (afl->custom_only) {
|
||||
@ -2101,13 +2191,92 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
setup_cmdline_file(afl, argv + optind);
|
||||
check_binary(afl, argv[optind]);
|
||||
|
||||
u64 prev_target_hash = 0;
|
||||
s32 fast_resume = 0;
|
||||
#ifdef HAVE_ZLIB
|
||||
gzFile fr_fd = NULL;
|
||||
#else
|
||||
s32 fr_fd = -1;
|
||||
#endif
|
||||
|
||||
if (afl->in_place_resume && !afl->afl_env.afl_no_fastresume) {
|
||||
|
||||
u8 fn[PATH_MAX], buf[32];
|
||||
snprintf(fn, PATH_MAX, "%s/target_hash", afl->out_dir);
|
||||
s32 fd = open(fn, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
|
||||
if (read(fd, buf, 32) >= 16) {
|
||||
|
||||
sscanf(buf, "%p", (void **)&prev_target_hash);
|
||||
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
write_setup_file(afl, argc, argv);
|
||||
|
||||
setup_cmdline_file(afl, argv + optind);
|
||||
if (afl->in_place_resume && !afl->afl_env.afl_no_fastresume) {
|
||||
|
||||
u64 target_hash = get_binary_hash(afl->fsrv.target_path);
|
||||
|
||||
if (!target_hash || prev_target_hash != target_hash) {
|
||||
|
||||
ACTF("Target binary is different, cannot perform FAST RESUME!");
|
||||
|
||||
} else {
|
||||
|
||||
u8 fn[PATH_MAX];
|
||||
snprintf(fn, PATH_MAX, "%s/fastresume.bin", afl->out_dir);
|
||||
#ifdef HAVE_ZLIB
|
||||
if ((fr_fd = ZLIBOPEN(fn, "rb")) != NULL) {
|
||||
|
||||
#else
|
||||
if ((fr_fd = open(fn, O_RDONLY)) >= 0) {
|
||||
|
||||
#endif
|
||||
|
||||
u8 ver_string[8];
|
||||
u64 *ver = (u64 *)ver_string;
|
||||
u64 expect_ver =
|
||||
afl->shm.cmplog_mode + (sizeof(struct queue_entry) << 1);
|
||||
|
||||
if (NZLIBREAD(fr_fd, ver_string, sizeof(ver_string)) !=
|
||||
sizeof(ver_string))
|
||||
WARNF("Emtpy fastresume.bin, ignoring, cannot perform FAST RESUME");
|
||||
else if (expect_ver != *ver)
|
||||
WARNF(
|
||||
"Different AFL++ version or feature usage, cannot perform FAST "
|
||||
"RESUME");
|
||||
else {
|
||||
|
||||
OKF("Will perform FAST RESUME");
|
||||
fast_resume = 1;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
ACTF("fastresume.bin not found, cannot perform FAST RESUME!");
|
||||
|
||||
}
|
||||
|
||||
// If the fast resume file is not valid we will be unable to start, so
|
||||
// we remove the file but keep the file descriptor open.
|
||||
unlink(fn);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
read_testcases(afl, NULL);
|
||||
// read_foreign_testcases(afl, 1); for the moment dont do this
|
||||
OKF("Loaded a total of %u seeds.", afl->queued_items);
|
||||
|
||||
pivot_inputs(afl);
|
||||
|
||||
@ -2140,6 +2309,9 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
// read_foreign_testcases(afl, 1); for the moment dont do this
|
||||
OKF("Loaded a total of %u seeds.", afl->queued_items);
|
||||
|
||||
/* If we don't have a file name chosen yet, use a safe default. */
|
||||
|
||||
if (!afl->fsrv.out_file) {
|
||||
@ -2196,8 +2368,6 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
check_binary(afl, argv[optind]);
|
||||
|
||||
#ifdef AFL_PERSISTENT_RECORD
|
||||
if (unlikely(afl->fsrv.persistent_record)) {
|
||||
|
||||
@ -2416,7 +2586,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
}
|
||||
|
||||
OKF("Cmplog forkserver successfully started");
|
||||
OKF("CMPLOG forkserver successfully started");
|
||||
|
||||
}
|
||||
|
||||
@ -2454,29 +2624,102 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
dedup_extras(afl);
|
||||
if (afl->extras_cnt) { OKF("Loaded a total of %u extras.", afl->extras_cnt); }
|
||||
|
||||
// after we have the correct bitmap size we can read the bitmap -B option
|
||||
// and set the virgin maps
|
||||
if (afl->in_bitmap) {
|
||||
if (unlikely(fast_resume)) {
|
||||
|
||||
read_bitmap(afl->in_bitmap, afl->virgin_bits, afl->fsrv.map_size);
|
||||
u64 resume_start = get_cur_time_us();
|
||||
// if we get here then we should abort on errors
|
||||
ZLIBREAD(fr_fd, afl->virgin_bits, afl->fsrv.map_size, "virgin_bits");
|
||||
ZLIBREAD(fr_fd, afl->virgin_tmout, afl->fsrv.map_size, "virgin_tmout");
|
||||
ZLIBREAD(fr_fd, afl->virgin_crash, afl->fsrv.map_size, "virgin_crash");
|
||||
ZLIBREAD(fr_fd, afl->var_bytes, afl->fsrv.map_size, "var_bytes");
|
||||
|
||||
u8 res[1] = {0};
|
||||
u8 *o_start = (u8 *)&(afl->queue_buf[0]->colorized);
|
||||
u8 *o_end = (u8 *)&(afl->queue_buf[0]->mother);
|
||||
u32 r = 8 + afl->fsrv.map_size * 4;
|
||||
u32 q_len = o_end - o_start;
|
||||
u32 m_len = (afl->fsrv.map_size >> 3);
|
||||
struct queue_entry *q;
|
||||
|
||||
for (u32 i = 0; i < afl->queued_items; i++) {
|
||||
|
||||
q = afl->queue_buf[i];
|
||||
ZLIBREAD(fr_fd, (u8 *)&(q->colorized), q_len, "queue data");
|
||||
ZLIBREAD(fr_fd, res, 1, "check map");
|
||||
if (res[0]) {
|
||||
|
||||
q->trace_mini = ck_alloc(m_len);
|
||||
ZLIBREAD(fr_fd, q->trace_mini, m_len, "trace_mini");
|
||||
r += q_len + m_len + 1;
|
||||
|
||||
} else {
|
||||
|
||||
r += q_len + 1;
|
||||
|
||||
}
|
||||
|
||||
afl->total_bitmap_size += q->bitmap_size;
|
||||
++afl->total_bitmap_entries;
|
||||
update_bitmap_score(afl, q);
|
||||
|
||||
if (q->was_fuzzed) { --afl->pending_not_fuzzed; }
|
||||
|
||||
if (q->disabled) {
|
||||
|
||||
if (!q->was_fuzzed) { --afl->pending_not_fuzzed; }
|
||||
--afl->active_items;
|
||||
|
||||
}
|
||||
|
||||
if (q->var_behavior) { ++afl->queued_variable; }
|
||||
if (q->favored) {
|
||||
|
||||
++afl->queued_favored;
|
||||
if (!q->was_fuzzed) { ++afl->pending_favored; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
u8 buf[4];
|
||||
if (NZLIBREAD(fr_fd, buf, 3) > 0) {
|
||||
|
||||
FATAL("invalid trailing data in fastresume.bin");
|
||||
|
||||
}
|
||||
|
||||
OKF("Successfully loaded fastresume.bin (%u bytes)!", r);
|
||||
ZLIBCLOSE(fr_fd);
|
||||
afl->reinit_table = 1;
|
||||
update_calibration_time(afl, &resume_start);
|
||||
|
||||
} else {
|
||||
|
||||
memset(afl->virgin_bits, 255, map_size);
|
||||
// after we have the correct bitmap size we can read the bitmap -B option
|
||||
// and set the virgin maps
|
||||
if (afl->in_bitmap) {
|
||||
|
||||
}
|
||||
read_bitmap(afl->in_bitmap, afl->virgin_bits, afl->fsrv.map_size);
|
||||
|
||||
memset(afl->virgin_tmout, 255, map_size);
|
||||
memset(afl->virgin_crash, 255, map_size);
|
||||
} else {
|
||||
|
||||
if (likely(!afl->afl_env.afl_no_startup_calibration)) {
|
||||
memset(afl->virgin_bits, 255, map_size);
|
||||
|
||||
perform_dry_run(afl);
|
||||
}
|
||||
|
||||
} else {
|
||||
memset(afl->virgin_tmout, 255, map_size);
|
||||
memset(afl->virgin_crash, 255, map_size);
|
||||
|
||||
ACTF("skipping initial seed calibration due option override!");
|
||||
usleep(1000);
|
||||
if (likely(!afl->afl_env.afl_no_startup_calibration)) {
|
||||
|
||||
perform_dry_run(afl);
|
||||
|
||||
} else {
|
||||
|
||||
ACTF("Skipping initial seed calibration due option override!");
|
||||
usleep(1000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2562,7 +2805,7 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
// (void)nice(-20); // does not improve the speed
|
||||
|
||||
#ifdef INTROSPECTION
|
||||
u32 prev_saved_crashes = 0, prev_saved_tmouts = 0;
|
||||
u32 prev_saved_crashes = 0, prev_saved_tmouts = 0, stat_prev_queued_items = 0;
|
||||
#endif
|
||||
u32 prev_queued_items = 0, runs_in_current_cycle = (u32)-1;
|
||||
u8 skipped_fuzz;
|
||||
@ -2879,10 +3122,11 @@ int main(int argc, char **argv_orig, char **envp) {
|
||||
|
||||
} else {
|
||||
|
||||
if (unlikely(afl->queued_items > prev_queued_items)) {
|
||||
if (unlikely(afl->queued_items > stat_prev_queued_items)) {
|
||||
|
||||
afl->queue_cur->stats_finds += afl->queued_items - prev_queued_items;
|
||||
prev_queued_items = afl->queued_items;
|
||||
afl->queue_cur->stats_finds +=
|
||||
afl->queued_items - stat_prev_queued_items;
|
||||
stat_prev_queued_items = afl->queued_items;
|
||||
|
||||
}
|
||||
|
||||
@ -2984,6 +3228,28 @@ stop_fuzzing:
|
||||
write_bitmap(afl);
|
||||
save_auto(afl);
|
||||
|
||||
#ifdef __AFL_CODE_COVERAGE
|
||||
if (afl->fsrv.persistent_trace_bits) {
|
||||
|
||||
char cfn[4096];
|
||||
snprintf(cfn, sizeof(cfn), "%s/covmap.dump", afl->out_dir);
|
||||
|
||||
FILE *cov_fd;
|
||||
if ((cov_fd = fopen(cfn, "w")) == NULL) {
|
||||
|
||||
PFATAL("could not create '%s'", cfn);
|
||||
|
||||
}
|
||||
|
||||
// Write the real map size, as the map size must exactly match the pointer
|
||||
// map in length.
|
||||
fwrite(afl->fsrv.persistent_trace_bits, 1, afl->fsrv.real_map_size, cov_fd);
|
||||
fclose(cov_fd);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (afl->pizza_is_served) {
|
||||
|
||||
SAYF(CURSOR_SHOW cLRD "\n\n+++ Baking aborted %s +++\n" cRST,
|
||||
@ -3067,6 +3333,72 @@ stop_fuzzing:
|
||||
fclose(afl->fsrv.det_plot_file);
|
||||
#endif
|
||||
|
||||
if (!afl->afl_env.afl_no_fastresume) {
|
||||
|
||||
/* create fastresume.bin */
|
||||
u8 fr[PATH_MAX];
|
||||
snprintf(fr, PATH_MAX, "%s/fastresume.bin", afl->out_dir);
|
||||
ACTF("Writing %s ...", fr);
|
||||
#ifdef HAVE_ZLIB
|
||||
if ((fr_fd = ZLIBOPEN(fr, "wb9")) != NULL) {
|
||||
|
||||
#else
|
||||
if ((fr_fd = open(fr, O_WRONLY | O_TRUNC | O_CREAT, DEFAULT_PERMISSION)) >=
|
||||
#endif
|
||||
|
||||
u8 ver_string[8];
|
||||
u32 w = 0;
|
||||
u64 *ver = (u64 *)ver_string;
|
||||
*ver = afl->shm.cmplog_mode + (sizeof(struct queue_entry) << 1);
|
||||
|
||||
ZLIBWRITE(fr_fd, ver_string, sizeof(ver_string), "ver_string");
|
||||
ZLIBWRITE(fr_fd, afl->virgin_bits, afl->fsrv.map_size, "virgin_bits");
|
||||
ZLIBWRITE(fr_fd, afl->virgin_tmout, afl->fsrv.map_size, "virgin_tmout");
|
||||
ZLIBWRITE(fr_fd, afl->virgin_crash, afl->fsrv.map_size, "virgin_crash");
|
||||
ZLIBWRITE(fr_fd, afl->var_bytes, afl->fsrv.map_size, "var_bytes");
|
||||
w += sizeof(ver_string) + afl->fsrv.map_size * 4;
|
||||
|
||||
u8 on[1] = {1}, off[1] = {0};
|
||||
u8 *o_start = (u8 *)&(afl->queue_buf[0]->colorized);
|
||||
u8 *o_end = (u8 *)&(afl->queue_buf[0]->mother);
|
||||
u32 q_len = o_end - o_start;
|
||||
u32 m_len = (afl->fsrv.map_size >> 3);
|
||||
struct queue_entry *q;
|
||||
|
||||
afl->pending_not_fuzzed = afl->queued_items;
|
||||
afl->active_items = afl->queued_items;
|
||||
|
||||
for (u32 i = 0; i < afl->queued_items; i++) {
|
||||
|
||||
q = afl->queue_buf[i];
|
||||
ZLIBWRITE(fr_fd, (u8 *)&(q->colorized), q_len, "queue data");
|
||||
if (!q->trace_mini) {
|
||||
|
||||
ZLIBWRITE(fr_fd, off, 1, "no_mini");
|
||||
w += q_len + 1;
|
||||
|
||||
} else {
|
||||
|
||||
ZLIBWRITE(fr_fd, on, 1, "yes_mini");
|
||||
ZLIBWRITE(fr_fd, q->trace_mini, m_len, "trace_mini");
|
||||
w += q_len + m_len + 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ZLIBCLOSE(fr_fd);
|
||||
afl->var_byte_count = count_bytes(afl, afl->var_bytes);
|
||||
OKF("Written fastresume.bin with %u bytes!", w);
|
||||
|
||||
} else {
|
||||
|
||||
WARNF("Could not create fastresume.bin");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
destroy_queue(afl);
|
||||
destroy_extras(afl);
|
||||
destroy_custom_mutators(afl);
|
||||
|
@ -99,11 +99,13 @@ inline u64 hash64(u8 *key, u32 len, u64 seed) {
|
||||
|
||||
u64 get_binary_hash(u8 *fn) {
|
||||
|
||||
if (!fn) { return 0; }
|
||||
int fd = open(fn, O_RDONLY);
|
||||
if (fd < 0) { PFATAL("Unable to open '%s'", fn); }
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) < 0) { PFATAL("Unable to fstat '%s'", fn); }
|
||||
u32 f_len = st.st_size;
|
||||
if (!f_len) { return 0; }
|
||||
u8 *f_data = mmap(0, f_len, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (f_data == MAP_FAILED) { PFATAL("Unable to mmap file '%s'", fn); }
|
||||
close(fd);
|
||||
|
@ -59,7 +59,7 @@ static inline unsigned int hash(uint64_t key) {
|
||||
bool hashmap_search_and_add(uint8_t type, uint64_t key) {
|
||||
|
||||
if (unlikely(type >= 8)) return false;
|
||||
uint64_t val = (key & 0xf8ffffffffffffff) + (type << 56);
|
||||
uint64_t val = (key & 0xf8ffffffffffffff) + ((uint64_t)type << 56);
|
||||
unsigned int index = hash(val);
|
||||
HashNode *node = _hashmap->table[index];
|
||||
while (node) {
|
||||
|
@ -38,7 +38,7 @@ test -e test-custom-mutator.c -a -e ${CUSTOM_MUTATOR_PATH}/example.c -a -e ${CUS
|
||||
# Run afl-fuzz w/ the C mutator
|
||||
$ECHO "$GREY[*] running afl-fuzz for the C mutator, this will take approx 10 seconds"
|
||||
{
|
||||
AFL_CUSTOM_MUTATOR_LIBRARY=./libexamplemutator.so AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V07 -m ${MEM_LIMIT} -i in -o out -d -- ./test-custom-mutator >>errors 2>&1
|
||||
AFL_CUSTOM_MUTATOR_LIBRARY=./libexamplemutator.so AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V20 -m ${MEM_LIMIT} -i in -o out -d -- ./test-custom-mutator >>errors 2>&1
|
||||
} >>errors 2>&1
|
||||
|
||||
# Check results
|
||||
@ -58,7 +58,7 @@ test -e test-custom-mutator.c -a -e ${CUSTOM_MUTATOR_PATH}/example.c -a -e ${CUS
|
||||
# Run afl-fuzz w/ multiple C mutators
|
||||
$ECHO "$GREY[*] running afl-fuzz with multiple custom C mutators, this will take approx 10 seconds"
|
||||
{
|
||||
AFL_CUSTOM_MUTATOR_LIBRARY="./libexamplemutator.so;./libexamplemutator2.so" AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V07 -m ${MEM_LIMIT} -i in -o out -d -- ./test-multiple-mutators >>errors 2>&1
|
||||
AFL_CUSTOM_MUTATOR_LIBRARY="./libexamplemutator.so;./libexamplemutator2.so" AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V20 -m ${MEM_LIMIT} -i in -o out -d -- ./test-multiple-mutators >>errors 2>&1
|
||||
} >>errors 2>&1
|
||||
|
||||
test -n "$( ls out/default/crashes/id:000000* 2>/dev/null )" && { # TODO: update here
|
||||
@ -88,7 +88,7 @@ test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
|
||||
{
|
||||
export PYTHONPATH=${CUSTOM_MUTATOR_PATH}
|
||||
export AFL_PYTHON_MODULE=example
|
||||
AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V07 -m ${MEM_LIMIT} -i in -o out -- ./test-custom-mutator >>errors 2>&1
|
||||
AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V20 -m ${MEM_LIMIT} -i in -o out -- ./test-custom-mutator >>errors 2>&1
|
||||
unset PYTHONPATH
|
||||
unset AFL_PYTHON_MODULE
|
||||
} >>errors 2>&1
|
||||
|
@ -144,7 +144,7 @@ The following examples exist at the time of writing:
|
||||
blocks
|
||||
- persistent: A C example using persistent mode for maximum speed, and resetting
|
||||
the target state between each iteration
|
||||
- simple: A simple Python example
|
||||
- python_simple: A simple Python example
|
||||
- speedtest/c: The C harness for an example target, used to compare C, Python,
|
||||
and Rust bindings and fix speed issues
|
||||
- speedtest/python: Fuzzing the same target in Python
|
||||
@ -158,4 +158,4 @@ get shipped pre-built (plus their source).
|
||||
|
||||
Especially take a look at the
|
||||
[speedtest documentation](./samples/speedtest/README.md) to see how the
|
||||
languages compare.
|
||||
languages compare.
|
||||
|
@ -90,7 +90,7 @@ class UnicornSimpleHeap(object):
|
||||
_chunks_freed = [] # List of all freed chunks
|
||||
_debug_print = False # True to print debug information
|
||||
|
||||
def __init__(self, uc, debug_print=False, uaf_check=False):
|
||||
def __init__(self, uc, debug_print=False, uaf_check=False):
|
||||
self._uc = uc
|
||||
self._debug_print = debug_print
|
||||
|
||||
|
@ -12,7 +12,7 @@ fi
|
||||
|
||||
|
||||
|
||||
if [ ! test -e $DIR/harness]; then
|
||||
if [ ! -e $DIR/harness ]; then
|
||||
echo "[!] harness not found in $DIR"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
Reference in New Issue
Block a user