From 194c7de657fe5a05a8d37ee8eaf0e15660b675f5 Mon Sep 17 00:00:00 2001 From: Micah Snyder <30635813+micah-at-talos@users.noreply.github.com> Date: Fri, 21 Dec 2018 14:19:14 -0500 Subject: [PATCH] Added the clamav project. (#2047) --- projects/clamav/Dockerfile | 24 +++++ projects/clamav/build.sh | 102 ++++++++++++++++++ .../clamav/clamav-scanfile-fuzzer.options | 1 + projects/clamav/project.yaml | 8 ++ 4 files changed, 135 insertions(+) create mode 100644 projects/clamav/Dockerfile create mode 100755 projects/clamav/build.sh create mode 100644 projects/clamav/clamav-scanfile-fuzzer.options create mode 100644 projects/clamav/project.yaml diff --git a/projects/clamav/Dockerfile b/projects/clamav/Dockerfile new file mode 100644 index 000000000..bebc3c4e4 --- /dev/null +++ b/projects/clamav/Dockerfile @@ -0,0 +1,24 @@ +# Copyright (C) 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. +# +# 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/oss-fuzz-base/base-builder +MAINTAINER clamav.fuzz@gmail.com +RUN apt-get update && apt-get install -y libssl-dev +RUN git clone --depth 1 https://github.com/Cisco-Talos/clamav-devel.git +RUN git clone --depth 1 https://github.com/Cisco-Talos/clamav-fuzz-corpus.git + +WORKDIR clamav-devel +COPY build.sh $SRC/ diff --git a/projects/clamav/build.sh b/projects/clamav/build.sh new file mode 100755 index 000000000..4dfb61ddf --- /dev/null +++ b/projects/clamav/build.sh @@ -0,0 +1,102 @@ +#!/bin/bash -eu +# Copyright (C) 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. +# +# 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. +# +################################################################################ + +export CXXFLAGS="-std=c++11 -stdlib=libc++ $CXXFLAGS" + +# +# Build the library. +# +./configure --with-libjson=no --with-pcre=no --enable-static=yes --enable-shared=no --disable-llvm --host=x86_64-unknown-linux-gnu +make clean +make -j"$(nproc)" + +# +# Build the fuzz targets. +# + +# `scanmap` +# ---------- +$CXX $CXXFLAGS -Ilibclamav/ ./fuzz/clamav_scanmap_fuzzer.cpp \ + -o $OUT/clamav_scanmap_fuzzer \ + ${LIB_FUZZING_ENGINE} libclamav/.libs/libclamav.a libclamav/.libs/libclammspack.a \ + -Wl,-Bstatic -lssl -lcrypto -lz -Wl,-Bdynamic -lc -lpthread -ldl + +for type in ARCHIVE MAIL OLE2 PDF HTML PE ELF SWF XMLDOCS HWP3; do + $CXX $CXXFLAGS -Ilibclamav/ ./fuzz/clamav_scanmap_fuzzer.cpp \ + -o "${OUT}/clamav_scanmap_${type}_fuzzer" "-DCLAMAV_FUZZ_${type}" \ + ${LIB_FUZZING_ENGINE} libclamav/.libs/libclamav.a libclamav/.libs/libclammspack.a \ + -Wl,-Bstatic -lssl -lcrypto -lz -Wl,-Bdynamic -lc -lpthread -ldl +done + +# `scanfile` +# ---------- +$CXX $CXXFLAGS -Ilibclamav/ ./fuzz/clamav_scanfile_fuzzer.cpp \ + -o $OUT/clamav_scanfile_fuzzer \ + ${LIB_FUZZING_ENGINE} libclamav/.libs/libclamav.a libclamav/.libs/libclammspack.a \ + -Wl,-Bstatic -lssl -lcrypto -lz -Wl,-Bdynamic -lc -lpthread -ldl + +for type in ARCHIVE MAIL OLE2 PDF HTML PE ELF SWF XMLDOCS HWP3; do + $CXX $CXXFLAGS -Ilibclamav/ ./fuzz/clamav_scanfile_fuzzer.cpp \ + -o "${OUT}/clamav_scanfile_${type}_fuzzer" "-DCLAMAV_FUZZ_${type}" \ + ${LIB_FUZZING_ENGINE} libclamav/.libs/libclamav.a libclamav/.libs/libclammspack.a \ + -Wl,-Bstatic -lssl -lcrypto -lz -Wl,-Bdynamic -lc -lpthread -ldl +done + +# `dbload` +# -------- +for type in CDB CFG CRB FP FTM HDB HSB IDB IGN IGN2 LDB MDB MSB NDB PDB WDB YARA; do + $CXX $CXXFLAGS -Ilibclamav/ ./fuzz/clamav_dbload_fuzzer.cpp \ + -o "${OUT}/clamav_dbload_${type}_fuzzer" "-DCLAMAV_FUZZ_${type}" \ + ${LIB_FUZZING_ENGINE} libclamav/.libs/libclamav.a libclamav/.libs/libclammspack.a \ + -Wl,-Bstatic -lssl -lcrypto -lz -Wl,-Bdynamic -lc -lpthread -ldl +done + +# +# Collect the fuzz corpora. +# + +# `scanfile` & `scanmap` +# ---------- +mkdir all-scantype-seeds + +for type in ARCHIVE MAIL OLE2 PDF HTML PE ELF SWF XMLDOCS HWP3; do + # Prepare seed corpus for the type-specific fuzz targets. + zip $OUT/clamav_scanfile_${type}_fuzzer_seed_corpus.zip $SRC/clamav-fuzz-corpus/scantype/${type}/* + zip $OUT/clamav_scanmap_${type}_fuzzer_seed_corpus.zip $SRC/clamav-fuzz-corpus/scantype/${type}/* + + # Prepare dictionary for the type-specific fuzz targets (may not exist for all types). + cp $SRC/clamav-fuzz-corpus/scantype/${type}.dict $OUT/clamav_scanfile_${type}_fuzzer.dict 2>/dev/null || : + cp $SRC/clamav-fuzz-corpus/scantype/${type}.dict $OUT/clamav_scanmap_${type}_fuzzer.dict 2>/dev/null || : + + # Copy seeds for the generic fuzz target. + cp $SRC/clamav-fuzz-corpus/scantype/${type}/* all-scantype-seeds/ +done + +# Prepare seed corpus for the generic fuzz target. +cp $SRC/clamav-fuzz-corpus/scantype/other/* all-scantype-seeds/ +zip $OUT/clamav_scanfile_fuzzer_seed_corpus.zip all-scantype-seeds/* +zip $OUT/clamav_scanmap_fuzzer_seed_corpus.zip all-scantype-seeds/* + +# `dbload` +# -------- +for type in CDB CFG CRB FP FTM HDB HSB IDB IGN IGN2 LDB MDB MSB NDB PDB WDB YARA; do + # Prepare seed corpus for the type-specific fuzz targets. + zip $OUT/clamav_dbload_${type}_fuzzer_seed_corpus.zip $SRC/clamav-fuzz-corpus/database/${type}/* + + # Prepare dictionary for the type-specific fuzz targets (may not exist for all types). + cp $SRC/clamav-fuzz-corpus/database/${type}.dict $OUT/clamav_dbload_${type}_fuzzer.dict 2>/dev/null || : +done diff --git a/projects/clamav/clamav-scanfile-fuzzer.options b/projects/clamav/clamav-scanfile-fuzzer.options new file mode 100644 index 000000000..77ad380d4 --- /dev/null +++ b/projects/clamav/clamav-scanfile-fuzzer.options @@ -0,0 +1 @@ +[libfuzzer] diff --git a/projects/clamav/project.yaml b/projects/clamav/project.yaml new file mode 100644 index 000000000..c723a8e9f --- /dev/null +++ b/projects/clamav/project.yaml @@ -0,0 +1,8 @@ +homepage: "https://www.clamav.net/" +primary_contact: "clamav.fuzz@gmail.com" +auto_ccs: + - clamav-bugs@external.cisco.com +sanitizers: + - address + - undefined + - memory