Skip to content

Commit bc5279f

Browse files
authored
Merge pull request #59 from KTH/wasm-fuzzer
WIP: support the real coverage in fuzzer
2 parents 6cf5590 + ef15fcc commit bc5279f

22 files changed

+276
-222
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ traces
3131
utils/reports
3232

3333
### Wasm-Fuzzer ###
34-
wasm-fuzzer/fuzzing-client-afl/afl_out
35-
wasm-fuzzer/fuzzing-client-afl/cpp_out
36-
wasm-fuzzer/logs/*
34+
wasm-fuzzer/wafl-temp/*
35+
36+
*.log
37+
*.log.txt

.gitmodules

-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@
1010
path = llvm
1111
url = https://github.com/Jacarte/llvm-project
1212
branch = master
13-
[submodule "wasm-fuzzer/fuzzing-server-swam"]
14-
path = wasm-fuzzer/fuzzing-server-swam
15-
url = https://github.com/KTH/swam
16-
branch = feature/swam-server

wasm-fuzzer/.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.out
2-
*.dat
2+
*.dat
3+
./fuzzing-server-swam/out
4+
./wafl-temp

wasm-fuzzer/.env

+11-24
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,21 @@ LOG_LEVEL=INFO
77
# Set True if AFL should always continue where it left off (and not delete old findings). Useful if AFL/SWAM may crash and auto-restart.
88
REUSE_DATA_AFL=True
99

10-
# Path to the parent directory of our local .wasm/.wat executable
11-
LOCAL_WASM=/tmp/fuzzer-wat_files
12-
13-
# Name of our local .wasm/.wat executable
14-
WASM_EXECUTABLE=fibo.wat
15-
16-
# Path on our local machine for us to read AFL's output
17-
LOCAL_AFL_OUTPUT=/tmp/afl_out
18-
19-
# Path on our local machine for us to read our own logs
20-
LOCAL_LOGS=/tmp/fuzzer/fuzzerlogs
21-
22-
# Path on our local machine for us to read SWAM's output (if any)
23-
# SWAM_OUTPUT_LOCAL=/tmp/swam-out
24-
25-
# Function to be executed in .wasm/.wat ("_start" is default)
26-
TARGET_FUNCTION=clever
10+
# Filter out WASI coverage
11+
WASI_FILTER=True
2712

28-
# Parameter types for target function. Comma-separated list of types Int32, Int64, Float32, Float64.
29-
WASM_ARG_TYPES_LIST=Int64
13+
########################################
14+
##### Necessary for Docker volumes #####
15+
########################################
3016

31-
# Sample input for target function. Comma-separated list of numbers.
32-
WASM_ARG_LIST=14
17+
# Path on our local machine where wasm/wat file is located
18+
LOCAL_WASM_DIR=/tmp/wasm
3319

34-
# Executable has wasi format
35-
WASI=False
20+
#############################
21+
##### No need to change #####
22+
#############################
3623

37-
##### No need to change: #####
24+
SWAM_SOCKET_HOST=localhost
3825
SWAM_SOCKET_PORT=9999
3926

4027
# Filter out WASI

wasm-fuzzer/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aflpp
2+
wafl
3+
out*
4+
fuzzing-server-swam

wasm-fuzzer/Dockerfile

+35-28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FROM aflplusplus/aflplusplus
99
RUN yes | apt-get install curl
1010
RUN apt-get update
1111
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata wget
12+
RUN apt-get update
1213
RUN yes | apt-get install software-properties-common
1314
RUN apt-get update
1415
RUN yes | add-apt-repository ppa:openjdk-r/ppa
@@ -30,58 +31,64 @@ WORKDIR /root
3031
##### fuzzing-server-swam ######
3132
################################
3233

33-
ENV DOCKER_SWAM_SRC=/home/server/src
34-
ENV DOCKER_WASM=/home/server/wasm
34+
ENV SRC_SWAM_DIR=/home/server/src
35+
ENV WASM_DIR=/home/server/wasm
3536

3637
# Create the appropriate directories
37-
RUN mkdir -p $DOCKER_SWAM_SRC
38-
RUN mkdir -p $DOCKER_WASM
38+
RUN mkdir -p $SRC_SWAM_DIR
39+
RUN mkdir -p $WASM_DIR
3940

40-
WORKDIR $DOCKER_SWAM_SRC
41+
WORKDIR $SRC_SWAM_DIR
4142

4243
# TODO: Find way of installing dependencies with Mill without copying over entire repo
4344
# See: https://stackoverflow.com/questions/62834693/mill-build-tool-install-dependencies-without-compiling-source-code
4445

45-
ADD ./fuzzing-server-entry/entrypoint_mill_server.sh $DOCKER_SWAM_SRC
46-
4746
# DOWNLOAD latest version of SWAM cli jar file
48-
ADD https://github.com/KTH/swam/releases/download/v0.6.0-RC3/cli-0.6.0-RC3.jar $DOCKER_SWAM_SRC
49-
47+
ADD https://github.com/KTH/swam/releases/download/v0.6.0-RC3/cli-0.6.0-RC3.jar $SRC_SWAM_DIR
5048

51-
RUN chmod +x $DOCKER_SWAM_SRC/entrypoint_mill_server.sh
49+
ADD entrypoint_mill_server.sh /home
50+
RUN chmod +x /home/entrypoint_mill_server.sh
5251

5352
#############################
5453
#### fuzzing-client-afl #####
5554
#############################
5655

57-
ENV DOCKER_INTERFACE_SRC=/home/client/interface
58-
ENV DOCKER_AFL_INPUT=/home/client/in
59-
ENV DOCKER_AFL_OUTPUT=/home/client/out
56+
ENV SRC_INTERFACE_DIR=/home/client/interface
57+
ENV OUT_INTERFACE_DIR=/home/client/interface/cpp_out
58+
ENV INPUT_AFL_DIR=/home/client/in
59+
ENV OUTPUT_AFL_DIR=/home/client/out
6060

6161
# Create the appropriate directories
62-
RUN mkdir -p $DOCKER_INTERFACE_SRC
63-
RUN mkdir -p $DOCKER_AFL_INPUT
64-
RUN mkdir -p $DOCKER_AFL_OUTPUT
65-
WORKDIR $DOCKER_INTERFACE_SRC
62+
RUN mkdir -p $SRC_INTERFACE_DIR
63+
RUN mkdir -p $OUT_INTERFACE_DIR
64+
RUN mkdir -p $INPUT_AFL_DIR
65+
RUN mkdir -p $OUTPUT_AFL_DIR
66+
WORKDIR $SRC_INTERFACE_DIR
6667

67-
ADD ./fuzzing-client-afl $DOCKER_INTERFACE_SRC
68+
ADD ./fuzzing-client-afl $SRC_INTERFACE_DIR
6869

69-
RUN g++ -o ./prepare_wasm_input.out ./prepare_wasm_input.cpp ./utils.cpp
70-
RUN g++ -o ./getFileSize.out ./getFileSize.cpp ./utils.cpp
71-
RUN g++ -o ./wait_for_server.out ./wait_for_server.cpp ./utils.cpp ./socket_client.cpp
72-
RUN g++ -o ./interface.out ./interface.cpp ./socket_client.cpp ./utils.cpp
70+
RUN g++ -o $OUT_INTERFACE_DIR/prepare_wasm_input.out ./prepare_wasm_input.cpp ./utils.cpp
71+
RUN g++ -o $OUT_INTERFACE_DIR/getFileSize.out ./getFileSize.cpp ./utils.cpp
72+
RUN g++ -o $OUT_INTERFACE_DIR/wait_for_server.out ./wait_for_server.cpp ./utils.cpp ./socket_client.cpp
73+
RUN g++ -o $OUT_INTERFACE_DIR/interface.out ./interface.cpp ./socket_client.cpp ./utils.cpp
7374

74-
RUN chmod +x $DOCKER_INTERFACE_SRC/entrypoint_afl.sh
75+
RUN chmod +x $SRC_INTERFACE_DIR/entrypoint_afl.sh
7576

7677
#########################
7778
######## Shared #########
7879
#########################
7980

80-
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
81+
WORKDIR /home
82+
83+
ENV LOGS_DIR=/home/shared/logs
84+
85+
RUN mkdir -p $LOGS_DIR
8186

82-
ENV DOCKER_SHARED=/home/shared
83-
ENV DOCKER_LOGS=$DOCKER_SHARED/logs
87+
ADD supervisord.conf /home/supervisord.conf
88+
ADD wafl.sh /home/wafl.sh
89+
ADD prepare_env.sh /home/prepare_env.sh
8490

85-
RUN mkdir -p $DOCKER_LOGS
91+
RUN chmod +x /home/wafl.sh
92+
RUN chmod +x /home/prepare_env.sh
8693

87-
ENTRYPOINT ["/usr/bin/supervisord"]
94+
ENTRYPOINT ["/home/wafl.sh"]

wasm-fuzzer/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Right now, we support fuzzing of four data types as function parameter:
1919
* int32
2020
* int64
2121
* float32
22-
* float 64
22+
* float64
2323

2424
Reference documentation in (see part 1, Coverage Measurements): https://github.com/google/AFL/blob/master/docs/technical_details.txt
2525

@@ -112,14 +112,14 @@ docker build -t wafl .
112112
3. Run the Docker image.
113113

114114
```bash
115-
docker run -it --rm --env-file=./.env \
116-
-e SWAM_SOCKET_HOST=localhost \
115+
docker run --env-file=./.env \
117116
-v maven_data:/root/.cache/coursier/v1/https/repo1.maven.org/maven2 \
118117
-v compiled_sources:/home/server/src/out/ \
119-
-v ${LOCAL_WASM:?err}:/home/server/wasm/ \
120-
-v ${LOCAL_AFL_OUTPUT:?err}:/home/client/out/ \
121-
-v ${LOCAL_LOGS:?err}:/home/shared/logs/ \
122-
wafl:latest
118+
-v ${LOCAL_WASM_DIR:?err}:/home/server/wasm/ \
119+
-v ${PWD}/wafl-temp/afl-out:/home/client/out/ \
120+
-v ${PWD}/wafl-temp/logs:/home/shared/logs/ \
121+
wafl:latest \
122+
<.wasm/.wat filename> <target function> <seed arguments csv>
123123
```
124124

125125
### Multi-processing
@@ -128,7 +128,7 @@ AFLplusplus is encouraged to be run with multiple instances if multiple cores ar
128128

129129
```bash
130130
# 3 for the number of AFL instances.
131-
./multi-processing.sh 3
131+
./multi-processing.sh 3 <.wasm/.wat filename> <target function> <seed arguments csv>
132132
```
133133

134134
## Building & running without Docker

wasm-fuzzer/build.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
echo "Cloning SWAM"
6+
if [ ! -d fuzzing-server-swam ]; then
7+
git clone --single-branch --branch master https://github.com/KTH/swam.git fuzzing-server-swam
8+
fi
9+
10+
echo "Building SWAM"
11+
cd fuzzing-server-swam
12+
git pull
13+
./millw cli.assembly
14+
export SWAM_JAR=$(CURRENT_DIR)/fuzzing-server-swam/out/cli/assembly/dest/out.jar
15+
echo $SWAM_JAR
16+
cd ..
17+
18+
19+
# Download afl plus plus
20+
if [ ! -d aflpp ]; then
21+
echo "Downloading aflplusplus..."
22+
git clone https://github.com/AFLplusplus/AFLplusplus.git aflpp
23+
24+
echo "Building aflplusplus..."
25+
cd aflpp
26+
make distrib
27+
sudo make install
28+
cd ..
29+
fi
30+
31+
32+
echo "Building the wafl interface..."
33+
34+
mkdir -p $CURRENT_DIR/wafl-temp
35+
CPP_OUT_DIR=$CURRENT_DIR/wafl-temp/cpp-out
36+
mkdir -p $CPP_OUT_DIR
37+
38+
g++ -o $CPP_OUT_DIR/prepare_wasm_input.out ./fuzzing-client-afl/prepare_wasm_input.cpp ./fuzzing-client-afl/utils.cpp
39+
g++ -o $CPP_OUT_DIR/getFileSize.out ./fuzzing-client-afl/getFileSize.cpp ./fuzzing-client-afl/utils.cpp
40+
g++ -o $CPP_OUT_DIR/wait_for_server.out ./fuzzing-client-afl/wait_for_server.cpp ./fuzzing-client-afl/utils.cpp ./fuzzing-client-afl/socket_client.cpp
41+
g++ -o $CPP_OUT_DIR/run_client.out ./fuzzing-client-afl/run_client.cpp ./fuzzing-client-afl/socket_client.cpp ./fuzzing-client-afl/utils.cpp
42+
g++ -o $CPP_OUT_DIR/interface.out ./fuzzing-client-afl/interface.cpp ./fuzzing-client-afl/socket_client.cpp ./fuzzing-client-afl/utils.cpp
43+
44+
echo "DONE !"

wasm-fuzzer/docker-compose.base.yml

-29
This file was deleted.

wasm-fuzzer/docker-compose.stack.yml

-34
This file was deleted.

wasm-fuzzer/docker-compose.yml

-17
This file was deleted.

wasm-fuzzer/entrypoint_mill_server.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# TODO: Put this file back into the SWAM repo
4+
5+
# TODO: Put this into entrypoint_afl.sh as well as soon as the server infers the signature itself.
6+
# So that this script can be run by itself as
7+
# well (same commands as wafl.sh)
8+
if [[ $ENV_PREPARED != "True" ]]; then
9+
echo "Preparing environment!"
10+
source ../prepare_env.sh $@
11+
fi
12+
13+
# Get wasm/wat from $WASM_DIR directory
14+
echo "WASM_OR_WAT_FILE: $WASM_OR_WAT_FILE"
15+
16+
# Parse WASM_ARG_TYPES_CSV: "Int64,Int32" to "--argType Int64 --argType Int32"
17+
ALL_ARG_TYPES=""
18+
IFS=',' read -r -a WASM_ARG_TYPES_ARRAY <<<"$WASM_ARG_TYPES_CSV"
19+
for element in "${WASM_ARG_TYPES_ARRAY[@]}"; do
20+
ALL_ARG_TYPES="$ALL_ARG_TYPES --argType $element"
21+
done
22+
echo "ALL_ARG_TYPES: $ALL_ARG_TYPES"
23+
24+
if [[ $WASM_OR_WAT_FILE == *.wat ]]; then WAT_ARG="--wat"; fi
25+
if [[ $WASI == "True" ]]; then WASI_ARG="--wasi"; fi
26+
if [[ $WASI_FILTER == "True" ]]; then WASI_ARG="$WASI_ARG -r"; fi
27+
28+
cd $SRC_SWAM_DIR
29+
30+
LOGGING_ARG="1> $LOGS_DIR/swam.std.txt 2> $LOGS_DIR/swam.err.txt &"
31+
32+
echo "$SWAM_CMD run_server $WASM_OR_WAT_FILE --main $TARGET_FUNCTION $WAT_ARG $WASI_ARG $ALL_ARG_TYPES $LOGGING_ARG"
33+
exec $SWAM_CMD run_server $WASM_OR_WAT_FILE --main $TARGET_FUNCTION $WAT_ARG $WASI_ARG $ALL_ARG_TYPES 1> $LOGS_DIR/swam.std.txt 2> $LOGS_DIR/swam.err.txt

0 commit comments

Comments
 (0)