Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: support the real coverage in fuzzer #59

Merged
merged 37 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
95ce04f
Executing no docker wafl
Jacarte Aug 21, 2020
d07abf8
Building locally script
Jacarte Aug 21, 2020
b7c4623
Adding timeout and killng the server at the end
Jacarte Aug 21, 2020
4269c9f
WIP
Jacarte Aug 25, 2020
2be9760
RM swam as submodule
Jacarte Aug 25, 2020
b34001e
Downloading and building swam in wafl
Jacarte Aug 25, 2020
7e15592
Infering init values from seed all equal
Jacarte Aug 25, 2020
4e3ee3e
Merge branch 'wasm-fuzzer' into feature/handle-crashed-server
Jacarte Aug 25, 2020
b52053c
Merge pull request #60 from KTH/feature/handle-crashed-server
Jacarte Aug 25, 2020
e333f3d
HOTFIX: LOG function not found
Jacarte Aug 25, 2020
b176502
Removed everything related to docker-compose
olapiv Aug 27, 2020
3998e1a
Put SWAM_SOCKET_HOST into ./env
olapiv Aug 27, 2020
167bf64
Being sure about CURRENT_DIR in build.sh && included run_client.cpp
olapiv Aug 27, 2020
e513bdd
Renamed DOCKER_ envs && put wafl.sh as entrypoint
olapiv Aug 27, 2020
100055f
Placed all directory preparations from wafl to prepare_env && placed …
olapiv Aug 27, 2020
90bbbca
Added arguments to docker run; Adjusted README; Re-did .env for Docke…
olapiv Aug 27, 2020
cafea9e
Using default temp DIR when running locally; Also parsing arguments w…
olapiv Aug 27, 2020
2f5740a
Uncommented multi-processing again
olapiv Aug 27, 2020
2a7fd0f
Moved all cpp_out into wafl-temp folder
olapiv Aug 27, 2020
87be841
Sourcing prepare_env.sh
olapiv Aug 27, 2020
2d1c564
Fixed supervisord path in Dockerfile
olapiv Aug 28, 2020
653f195
Changed SWAM_CMD
olapiv Aug 28, 2020
b4e3860
Adjusted references to files
olapiv Aug 28, 2020
d55f941
SWAM in master branch
Jacarte Aug 28, 2020
bbcf302
Fixed Code references in build.sh
olapiv Aug 28, 2020
b872bf5
Using pwd for mounting Docker volumes
olapiv Aug 28, 2020
743ccb9
Merge branch 'wasm-fuzzer' of https://github.com/KTH/slumps into wasm…
Jacarte Aug 28, 2020
5a2238e
HOTFIX: build script looking for server-wasm swam
Jacarte Aug 28, 2020
1c066ca
Merge branch 'feature/handle-crashed-server' into wasm-fuzzer
olapiv Aug 28, 2020
930e4bd
Merge branch 'wasm-fuzzer' of https://github.com/KTH/slumps into wasm…
olapiv Aug 28, 2020
982f9ff
FIX
Jacarte Aug 28, 2020
b816879
FIX: Fixing mill-server-entrypoint script with logs
Jacarte Aug 28, 2020
321b2f9
Changing supervisord entrypoin script location
Jacarte Aug 28, 2020
5891f92
Updating Dockerfile for wafl
Jacarte Aug 28, 2020
b9b1a4d
Adjusted entrypoint_mill_server.sh reference in Dockerfile
olapiv Aug 28, 2020
6ccd3bc
Adjusted multi-processing.sh with wafl-temp dir
olapiv Aug 28, 2020
08dc80b
Merge branch 'master' into wasm-fuzzer
olapiv Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ traces
utils/reports

### Wasm-Fuzzer ###
wasm-fuzzer/fuzzing-client-afl/afl_out
wasm-fuzzer/fuzzing-client-afl/cpp_out
wasm-fuzzer/logs/*
wasm-fuzzer/wafl-temp/*

*.log
*.log.txt
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@
path = llvm
url = https://github.com/Jacarte/llvm-project
branch = master
[submodule "wasm-fuzzer/fuzzing-server-swam"]
path = wasm-fuzzer/fuzzing-server-swam
url = https://github.com/KTH/swam
branch = feature/swam-server
4 changes: 3 additions & 1 deletion wasm-fuzzer/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.out
*.dat
*.dat
./fuzzing-server-swam/out
./wafl-temp
35 changes: 11 additions & 24 deletions wasm-fuzzer/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,21 @@ LOG_LEVEL=INFO
# 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.
REUSE_DATA_AFL=True

# Path to the parent directory of our local .wasm/.wat executable
LOCAL_WASM=/tmp/fuzzer-wat_files

# Name of our local .wasm/.wat executable
WASM_EXECUTABLE=fibo.wat

# Path on our local machine for us to read AFL's output
LOCAL_AFL_OUTPUT=/tmp/afl_out

# Path on our local machine for us to read our own logs
LOCAL_LOGS=/tmp/fuzzer/fuzzerlogs

# Path on our local machine for us to read SWAM's output (if any)
# SWAM_OUTPUT_LOCAL=/tmp/swam-out

# Function to be executed in .wasm/.wat ("_start" is default)
TARGET_FUNCTION=clever
# Filter out WASI coverage
WASI_FILTER=True

# Parameter types for target function. Comma-separated list of types Int32, Int64, Float32, Float64.
WASM_ARG_TYPES_LIST=Int64
########################################
##### Necessary for Docker volumes #####
########################################

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

# Executable has wasi format
WASI=False
#############################
##### No need to change #####
#############################

##### No need to change: #####
SWAM_SOCKET_HOST=localhost
SWAM_SOCKET_PORT=9999

# Filter out WASI
Expand Down
4 changes: 4 additions & 0 deletions wasm-fuzzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aflpp
wafl
out*
fuzzing-server-swam
63 changes: 35 additions & 28 deletions wasm-fuzzer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM aflplusplus/aflplusplus
RUN yes | apt-get install curl
RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata wget
RUN apt-get update
RUN yes | apt-get install software-properties-common
RUN apt-get update
RUN yes | add-apt-repository ppa:openjdk-r/ppa
Expand All @@ -30,58 +31,64 @@ WORKDIR /root
##### fuzzing-server-swam ######
################################

ENV DOCKER_SWAM_SRC=/home/server/src
ENV DOCKER_WASM=/home/server/wasm
ENV SRC_SWAM_DIR=/home/server/src
ENV WASM_DIR=/home/server/wasm

# Create the appropriate directories
RUN mkdir -p $DOCKER_SWAM_SRC
RUN mkdir -p $DOCKER_WASM
RUN mkdir -p $SRC_SWAM_DIR
RUN mkdir -p $WASM_DIR

WORKDIR $DOCKER_SWAM_SRC
WORKDIR $SRC_SWAM_DIR

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

ADD ./fuzzing-server-entry/entrypoint_mill_server.sh $DOCKER_SWAM_SRC

# DOWNLOAD latest version of SWAM cli jar file
ADD https://github.com/KTH/swam/releases/download/v0.6.0-RC3/cli-0.6.0-RC3.jar $DOCKER_SWAM_SRC

ADD https://github.com/KTH/swam/releases/download/v0.6.0-RC3/cli-0.6.0-RC3.jar $SRC_SWAM_DIR

RUN chmod +x $DOCKER_SWAM_SRC/entrypoint_mill_server.sh
ADD entrypoint_mill_server.sh /home
RUN chmod +x /home/entrypoint_mill_server.sh

#############################
#### fuzzing-client-afl #####
#############################

ENV DOCKER_INTERFACE_SRC=/home/client/interface
ENV DOCKER_AFL_INPUT=/home/client/in
ENV DOCKER_AFL_OUTPUT=/home/client/out
ENV SRC_INTERFACE_DIR=/home/client/interface
ENV OUT_INTERFACE_DIR=/home/client/interface/cpp_out
ENV INPUT_AFL_DIR=/home/client/in
ENV OUTPUT_AFL_DIR=/home/client/out

# Create the appropriate directories
RUN mkdir -p $DOCKER_INTERFACE_SRC
RUN mkdir -p $DOCKER_AFL_INPUT
RUN mkdir -p $DOCKER_AFL_OUTPUT
WORKDIR $DOCKER_INTERFACE_SRC
RUN mkdir -p $SRC_INTERFACE_DIR
RUN mkdir -p $OUT_INTERFACE_DIR
RUN mkdir -p $INPUT_AFL_DIR
RUN mkdir -p $OUTPUT_AFL_DIR
WORKDIR $SRC_INTERFACE_DIR

ADD ./fuzzing-client-afl $DOCKER_INTERFACE_SRC
ADD ./fuzzing-client-afl $SRC_INTERFACE_DIR

RUN g++ -o ./prepare_wasm_input.out ./prepare_wasm_input.cpp ./utils.cpp
RUN g++ -o ./getFileSize.out ./getFileSize.cpp ./utils.cpp
RUN g++ -o ./wait_for_server.out ./wait_for_server.cpp ./utils.cpp ./socket_client.cpp
RUN g++ -o ./interface.out ./interface.cpp ./socket_client.cpp ./utils.cpp
RUN g++ -o $OUT_INTERFACE_DIR/prepare_wasm_input.out ./prepare_wasm_input.cpp ./utils.cpp
RUN g++ -o $OUT_INTERFACE_DIR/getFileSize.out ./getFileSize.cpp ./utils.cpp
RUN g++ -o $OUT_INTERFACE_DIR/wait_for_server.out ./wait_for_server.cpp ./utils.cpp ./socket_client.cpp
RUN g++ -o $OUT_INTERFACE_DIR/interface.out ./interface.cpp ./socket_client.cpp ./utils.cpp

RUN chmod +x $DOCKER_INTERFACE_SRC/entrypoint_afl.sh
RUN chmod +x $SRC_INTERFACE_DIR/entrypoint_afl.sh

#########################
######## Shared #########
#########################

ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
WORKDIR /home

ENV LOGS_DIR=/home/shared/logs

RUN mkdir -p $LOGS_DIR

ENV DOCKER_SHARED=/home/shared
ENV DOCKER_LOGS=$DOCKER_SHARED/logs
ADD supervisord.conf /home/supervisord.conf
ADD wafl.sh /home/wafl.sh
ADD prepare_env.sh /home/prepare_env.sh

RUN mkdir -p $DOCKER_LOGS
RUN chmod +x /home/wafl.sh
RUN chmod +x /home/prepare_env.sh

ENTRYPOINT ["/usr/bin/supervisord"]
ENTRYPOINT ["/home/wafl.sh"]
16 changes: 8 additions & 8 deletions wasm-fuzzer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Right now, we support fuzzing of four data types as function parameter:
* int32
* int64
* float32
* float 64
* float64

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

Expand Down Expand Up @@ -112,14 +112,14 @@ docker build -t wafl .
3. Run the Docker image.

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

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

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

## Building & running without Docker
Expand Down
44 changes: 44 additions & 0 deletions wasm-fuzzer/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

echo "Cloning SWAM"
if [ ! -d fuzzing-server-swam ]; then
git clone --single-branch --branch master https://github.com/KTH/swam.git fuzzing-server-swam
fi

echo "Building SWAM"
cd fuzzing-server-swam
git pull
./millw cli.assembly
export SWAM_JAR=$(CURRENT_DIR)/fuzzing-server-swam/out/cli/assembly/dest/out.jar
echo $SWAM_JAR
cd ..


# Download afl plus plus
if [ ! -d aflpp ]; then
echo "Downloading aflplusplus..."
git clone https://github.com/AFLplusplus/AFLplusplus.git aflpp

echo "Building aflplusplus..."
cd aflpp
make distrib
sudo make install
cd ..
fi


echo "Building the wafl interface..."

mkdir -p $CURRENT_DIR/wafl-temp
CPP_OUT_DIR=$CURRENT_DIR/wafl-temp/cpp-out
mkdir -p $CPP_OUT_DIR

g++ -o $CPP_OUT_DIR/prepare_wasm_input.out ./fuzzing-client-afl/prepare_wasm_input.cpp ./fuzzing-client-afl/utils.cpp
g++ -o $CPP_OUT_DIR/getFileSize.out ./fuzzing-client-afl/getFileSize.cpp ./fuzzing-client-afl/utils.cpp
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
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
g++ -o $CPP_OUT_DIR/interface.out ./fuzzing-client-afl/interface.cpp ./fuzzing-client-afl/socket_client.cpp ./fuzzing-client-afl/utils.cpp

echo "DONE !"
29 changes: 0 additions & 29 deletions wasm-fuzzer/docker-compose.base.yml

This file was deleted.

34 changes: 0 additions & 34 deletions wasm-fuzzer/docker-compose.stack.yml

This file was deleted.

17 changes: 0 additions & 17 deletions wasm-fuzzer/docker-compose.yml

This file was deleted.

33 changes: 33 additions & 0 deletions wasm-fuzzer/entrypoint_mill_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# TODO: Put this file back into the SWAM repo

# TODO: Put this into entrypoint_afl.sh as well as soon as the server infers the signature itself.
# So that this script can be run by itself as
# well (same commands as wafl.sh)
if [[ $ENV_PREPARED != "True" ]]; then
echo "Preparing environment!"
source ../prepare_env.sh $@
fi

# Get wasm/wat from $WASM_DIR directory
echo "WASM_OR_WAT_FILE: $WASM_OR_WAT_FILE"

# Parse WASM_ARG_TYPES_CSV: "Int64,Int32" to "--argType Int64 --argType Int32"
ALL_ARG_TYPES=""
IFS=',' read -r -a WASM_ARG_TYPES_ARRAY <<<"$WASM_ARG_TYPES_CSV"
for element in "${WASM_ARG_TYPES_ARRAY[@]}"; do
ALL_ARG_TYPES="$ALL_ARG_TYPES --argType $element"
done
echo "ALL_ARG_TYPES: $ALL_ARG_TYPES"

if [[ $WASM_OR_WAT_FILE == *.wat ]]; then WAT_ARG="--wat"; fi
if [[ $WASI == "True" ]]; then WASI_ARG="--wasi"; fi
if [[ $WASI_FILTER == "True" ]]; then WASI_ARG="$WASI_ARG -r"; fi

cd $SRC_SWAM_DIR

LOGGING_ARG="1> $LOGS_DIR/swam.std.txt 2> $LOGS_DIR/swam.err.txt &"

echo "$SWAM_CMD run_server $WASM_OR_WAT_FILE --main $TARGET_FUNCTION $WAT_ARG $WASI_ARG $ALL_ARG_TYPES $LOGGING_ARG"
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
Loading