Skip to content

Commit b6fca1f

Browse files
committed
Add libafl grimoire example for AFLplusplus/libafl_fuzzbench#13
1 parent f427cc3 commit b6fca1f

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG parent_image
16+
FROM $parent_image
17+
18+
# Uninstall old Rust & Install the latest one.
19+
RUN if which rustup; then rustup self uninstall -y; fi && \
20+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /rustup.sh && \
21+
sh /rustup.sh --default-toolchain nightly-2024-08-12 -y && \
22+
rm /rustup.sh
23+
24+
# Install dependencies.
25+
RUN apt-get update && \
26+
apt-get remove -y llvm-10 && \
27+
apt-get install -y \
28+
build-essential \
29+
lsb-release wget software-properties-common gnupg && \
30+
apt-get install -y wget libstdc++5 libtool-bin automake flex bison \
31+
libglib2.0-dev libpixman-1-dev python3-setuptools unzip \
32+
apt-utils apt-transport-https ca-certificates joe curl && \
33+
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 17
34+
35+
RUN wget https://gist.githubusercontent.com/tokatoka/26f4ba95991c6e33139999976332aa8e/raw/698ac2087d58ce5c7a6ad59adce58dbfdc32bd46/createAliases.sh && chmod u+x ./createAliases.sh && ./createAliases.sh
36+
37+
38+
# Download libafl
39+
RUN git clone https://github.com/AFLplusplus/libafl_fuzzbench /libafl_fuzzbench && \
40+
cd /libafl_fuzzbench && \
41+
git checkout 876f383339a78415b402ddba0829bf2448be202a && \
42+
git submodule update --init
43+
44+
# Compile libafl
45+
RUN cd /libafl_fuzzbench/ && unset CFLAGS && unset CXXFLAGS && \
46+
export CC=clang && export CXX=clang++ && \
47+
export LIBAFL_EDGES_MAP_SIZE=65536 && \
48+
PATH="/root/.cargo/bin/:$PATH" cargo build --release --features no_link_main
49+
50+
# Auxiliary weak references.
51+
RUN cd /libafl_fuzzbench && \
52+
clang -c stub_rt.c && \
53+
ar r /stub_rt.a stub_rt.o
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# libafl
2+
3+
libafl fuzzer instance
4+
- cmplog feature
5+
- persistent mode
6+
7+
Repository: [https://github.com/AFLplusplus/libafl/](https://github.com/AFLplusplus/libafl/)
8+
9+
[builder.Dockerfile](builder.Dockerfile)
10+
[fuzzer.py](fuzzer.py)
11+
[runner.Dockerfile](runner.Dockerfile)

fuzzers/libafl_grimoire/fuzzer.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Integration code for a LibAFL-based fuzzer."""
16+
17+
import os
18+
import subprocess
19+
20+
from fuzzers import utils
21+
22+
23+
def prepare_fuzz_environment(input_corpus):
24+
"""Prepare to fuzz with a LibAFL-based fuzzer."""
25+
os.environ['ASAN_OPTIONS'] = 'abort_on_error=1:detect_leaks=0:'\
26+
'malloc_context_size=0:symbolize=0:'\
27+
'allocator_may_return_null=1:'\
28+
'detect_odr_violation=0:handle_segv=0:'\
29+
'handle_sigbus=0:handle_abort=0:'\
30+
'handle_sigfpe=0:handle_sigill=0'
31+
os.environ['UBSAN_OPTIONS'] = 'abort_on_error=1:'\
32+
'allocator_release_to_os_interval_ms=500:'\
33+
'handle_abort=0:handle_segv=0:'\
34+
'handle_sigbus=0:handle_sigfpe=0:'\
35+
'handle_sigill=0:print_stacktrace=0:'\
36+
'symbolize=0:symbolize_inline_frames=0'
37+
# Create at least one non-empty seed to start.
38+
utils.create_seed_file_for_empty_corpus(input_corpus)
39+
40+
41+
def build(): # pylint: disable=too-many-branches,too-many-statements
42+
"""Build benchmark."""
43+
os.environ['CC'] = '/libafl_fuzzbench/target/release/grimoire_cc'
44+
os.environ['CXX'] = '/libafl_fuzzbench/target/release/grimoire_cxx'
45+
46+
os.environ['ASAN_OPTIONS'] = 'abort_on_error=0:allocator_may_return_null=1'
47+
os.environ['UBSAN_OPTIONS'] = 'abort_on_error=0'
48+
49+
cflags = ['--libafl']
50+
cxxflags = ['--libafl', '--std=c++14']
51+
utils.append_flags('CFLAGS', cflags)
52+
utils.append_flags('CXXFLAGS', cxxflags)
53+
utils.append_flags('LDFLAGS', cflags)
54+
55+
os.environ['FUZZER_LIB'] = '/stub_rt.a'
56+
utils.build_benchmark()
57+
58+
59+
def fuzz(input_corpus, output_corpus, target_binary):
60+
"""Run fuzzer."""
61+
prepare_fuzz_environment(input_corpus)
62+
dictionary_path = utils.get_dictionary_path(target_binary)
63+
command = [target_binary]
64+
if dictionary_path:
65+
command += (['-x', dictionary_path])
66+
command += (['-o', output_corpus, '-i', input_corpus])
67+
fuzzer_env = os.environ.copy()
68+
fuzzer_env['LD_PRELOAD'] = '/usr/lib/x86_64-linux-gnu/libjemalloc.so.2'
69+
print(command)
70+
subprocess.check_call(command, cwd=os.environ['OUT'], env=fuzzer_env)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM gcr.io/fuzzbench/base-image
16+
17+
RUN apt install libjemalloc2
18+
19+
# This makes interactive docker runs painless:
20+
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/out"
21+
#ENV AFL_MAP_SIZE=2621440
22+
ENV PATH="$PATH:/out"
23+
ENV AFL_SKIP_CPUFREQ=1
24+
ENV AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1
25+
ENV AFL_TESTCACHE_SIZE=2

0 commit comments

Comments
 (0)