
Mayhem으로 CVE-2022-3786(openssl) 찾기
이 저장소에는 "Finding CVE-2022-3786 (openssl) with Mayhem"이라는 제목의 동반 블로그 게시물이 있으며, 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 에서 수정되었습니다. 을 사용하여 취약한 버전을 쉽게 얻을 수 있습니다:
680e65b94c916af259bfdc2e25f1ab6e0c7a97d6git# 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을 사용하면 계속 undefined reference 오류가 발생했기 때문입니다). 작은 버퍼 오버플로 오프셋 때문에 주소 검사(ASAN)도 사용하려고 합니다. 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
시스템 리소스에 따라 시간이 좀 걸릴 수 있습니다. 컴파일 후에는 하네스를 컴파일해야 합니다. 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 @@