Skip to content

Commit

Permalink
aarnav
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhauser-thc committed Sep 3, 2024
1 parent c227f5b commit db1e095
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
56 changes: 56 additions & 0 deletions fuzzers/libafl_fuzz/builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG parent_image
FROM $parent_image

# Install dependencies.
RUN apt-get update && \
apt-get install -y build-essential libstdc++5 libtool-bin automake flex \
bison libglib2.0-dev python3-setuptools unzip python3-dev joe curl \
cmake git apt-utils apt-transport-https ca-certificates libdbus-1-dev

# Uninstall old Rust & Install the latest one.
RUN if which rustup; then rustup self uninstall -y; fi && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /rustup.sh && \
sh /rustup.sh --default-toolchain nightly-2024-07-04 -y && \
rm /rustup.sh

# Download afl++.
RUN git clone https://github.com/AFLplusplus/AFLplusplus /afl

# Checkout a current commit
RUN cd /afl && git pull && git checkout ab5f95e17ac7d957e26f5c1789a8624a238ac0e0

# Build without Python support as we don't need it.
# Set AFL_NO_X86 to skip flaky tests.
RUN cd /afl && \
unset CFLAGS CXXFLAGS && \
export CC=clang AFL_NO_X86=1 AFL_PATH=/afl && \
PYTHON_INCLUDE=/ make && \
make install && \
cp utils/aflpp_driver/libAFLDriver.a /

# Download libafl.
RUN git clone https://github.com/R9295/LibAFL /libafl

# Checkout a current commit
RUN cd /libafl && git pull && \
git checkout 1113879a345146b737994ed1361663c53025dbc2

# Compile libafl.
RUN cd /libafl && \
unset CFLAGS CXXFLAGS && \
cd ./fuzzers/others/libafl-fuzz && \
PATH="/root/.cargo/bin/:$PATH" cargo build --profile release
68 changes: 68 additions & 0 deletions fuzzers/libafl_fuzz/fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Integration code for libafl-fuzz; Dervied from AFLRustRust"""

import os
import shutil
import subprocess

from fuzzers import utils
from fuzzers.aflplusplus import fuzzer as aflplusplus_fuzzer
from fuzzers.libafl import fuzzer as libafl_fuzzer


def build():
"""Build benchmark."""
# Build the target with AFL++
aflplusplus_fuzzer.build('tracepc', 'cmplog', 'dict2file')

# Copy to fuzzer to OUT
build_directory = os.environ['OUT']
fuzzer = '/libafl/fuzzers/others/libafl-fuzz/target/release/libafl-fuzz'
shutil.copy(fuzzer, build_directory)


def fuzz(input_corpus, output_corpus, target_binary):
"""Run fuzzer."""
# Calculate CmpLog binary path from the instrumented target binary.
target_binary_directory = os.path.dirname(target_binary)
cmplog_target_binary_directory = \
aflplusplus_fuzzer.get_cmplog_build_directory(target_binary_directory)
target_binary_name = os.path.basename(target_binary)
cmplog_target_binary = os.path.join(cmplog_target_binary_directory,
target_binary_name)

# Setup env vars
libafl_fuzzer.prepare_fuzz_environment(input_corpus)

# Merge dictionaries
dictionary_path = utils.get_dictionary_path(target_binary)
if os.path.exists('./afl++.dict'):
if dictionary_path:
with open('./afl++.dict', encoding='utf-8') as dictfile:
autodict = dictfile.read()
with open(dictionary_path, 'a', encoding='utf-8') as dictfile:
dictfile.write(autodict)
else:
dictionary_path = './afl++.dict'

# Run the fuzzer
command = ['./libafl-fuzz', '-c', cmplog_target_binary]
if dictionary_path:
command += (['-x', dictionary_path])
command += (['-o', output_corpus, '-i', input_corpus, target_binary])
#command += (['-t', '1000'])
print(command)
env = {'AFL_CORES': '1', 'AFL_IGNORE_TIMEOUT': '1', 'AFL_CMPLOG_ONLY_NEW': '1'}
subprocess.check_call(command, cwd=os.environ['OUT'], env=env)
26 changes: 26 additions & 0 deletions fuzzers/libafl_fuzz/runner.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM gcr.io/fuzzbench/base-image

# This makes interactive docker runs painless:
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/out"
#ENV AFL_MAP_SIZE=2621440
ENV PATH="$PATH:/out"
ENV AFL_SKIP_CPUFREQ=1
ENV AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1
ENV AFL_TESTCACHE_SIZE=2
# RUN apt-get update && apt-get upgrade && apt install -y unzip git gdb joe
RUN apt install libjemalloc2

0 comments on commit db1e095

Please sign in to comment.