本仓库有一篇配套博客文章,标题为“使用 Mayhem 发现 CVE-2022-3786 (openssl)”,链接为 https://www.seandeaton.com。
所有这些都通过随附的 Dockerfile(也发布在 DockerHub 上)为您处理好了。您可以这样运行:
# Build the container
docker build --tag openssl-cve-2022-3768 .
# Or if you just want to pull down the existing one:
TODO
# Ensure that you're in this project's root directory (ie you can see ./output/)
# Mount the ./input/ directory to the containers /input. This is for fuzz input.
# This is Linux specific, Windows I think has %CD% in lieu of $(pwd)?
docker run --interactive --tty --volume $(pwd)/input:/input
容器的入口点就是直接运行 afl,因此您可以立即开始模糊测试。要覆盖此行为,请在 docker run 命令末尾追加 /bin/bash。
包含该漏洞的最后一个提交是 2022 年 11 月 1 日的提交 SHA 3b421ebc64c7b52f1b9feb3812bdc7781c784332。该漏洞在提交 SHA 680e65b94c916af259bfdc2e25f1ab6e0c7a97d6 中被修复。我们可以轻松地用 git 获取存在漏洞的版本:
# Clone the repository.
git clone git://git.openssl.org/openssl.git
# Change into the working directory.
cd openssl
# Detach HEAD from origin to examine the code as it was when it was vulnerable.
git checkout 3b421ebc64c7b52f1b9feb3812bdc7781c784332
为了编译,我们使用 AFL 的 gcc 编译器(因为我用 clang 时一直遇到未定义的引用)。由于缓冲区溢出偏移量很小,我们还想使用地址消毒(ASAN),通过 AFL 的环境变量 AFL_USE_ASAN 启用。考虑到 ASAN 会占用大量内存,我们还需要限制地址空间,可以通过将程序编译为 32 位架构来实现。更多详情见此处。
OpenSSL 的 32 位配置接受 -m32 和 linux-generic32 这两个标志。compile.sh 脚本会为您完成这些操作。
# Configuration
AFL_USE_ASAN=1 CC=afl-gcc-fast CXX=afl-g++-fast ./Configure -m32 linux-generic32
# Make
AFL_USE_ASAN=1 CC=afl-gcc-fast CXX=afl-g++-fast CFLAGS="-m32" CXXFLAGS="-m32" make
根据您系统的资源情况,这可能需要一段时间。编译完成后,我们需要编译我们的测试工具(harness)。这里提供了一个 Makefile。
# Compile the harness.
$ make harness
# Run the harness.
$ ./harness input/seed0.txt
ossl_a2ulabel returned: 1
就这样,您可以开始对 openssl 中的 ossl_a2ulabel 进行模糊测试了。使用 AFL 时,命令大致如下(或者直接使用随附的 run.sh 脚本)。
afl-fuzz -i /input -o /output /harness/harness @@