
Trovare CVE-2022-3786 (openssl) con Mayhem
Questo repository ha un post del blog associato intitolato "Finding CVE-2022-3786 (openssl) with Mayhem" all'indirizzo https://www.seandeaton.com.
Tutto questo è già gestito per te dal Dockerfile incluso (disponibile anche su DockerHub). Puoi eseguirlo così:
# 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
L'entrypoint del contenitore esegue semplicemente afl, così puoi iniziare subito a fare fuzzing. Per sovrascrivere questo comportamento, aggiungi /bin/bash alla fine della riga docker run.
L'ultimo commit che include la vulnerabilità è il commit SHA 3b421ebc64c7b52f1b9feb3812bdc7781c784332 del 1° novembre 2022. La vulnerabilità è stata corretta nel commit SHA 680e65b94c916af259bfdc2e25f1ab6e0c7a97d6. Possiamo ottenere facilmente la versione vulnerabile con 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
Per la compilazione, usiamo il compilatore gcc di AFL (perché continuavo a ottenere riferimenti non definiti con clang). A causa del piccolo offset del buffer overflow, vogliamo anche usare l'address sanitization (ASAN), abilitata tramite la variabile d'ambiente AFL_USE_ASAN di AFL. Dato che ASAN utilizza grandi quantità di memoria, dobbiamo anche limitare lo spazio degli indirizzi, cosa che possiamo fare compilando il programma per un'architettura a 32 bit. Maggiori dettagli qui.
La configurazione di OpenSSL per 32 bit accetta i flag -m32 e linux-generic32. Lo script compile.sh fa tutto questo per te.
# 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
Questa operazione potrebbe richiedere del tempo a seconda delle risorse del tuo sistema. Dopo la compilazione, dobbiamo compilare il nostro harness. Viene fornito un Makefile.
# Compile the harness.
$ make harness
# Run the harness.
$ ./harness input/seed0.txt
ossl_a2ulabel returned: 1
Ed ecco fatto: puoi iniziare a fare fuzzing su ossl_a2ulabel in openssl. Con AFL il comando assomiglia a qualcosa del genere (oppure usa semplicemente lo script run.sh incluso).
afl-fuzz -i /input -o /output /harness/harness @@