
اكتشاف CVE-2022-3786 (openssl) باستخدام Mayhem
هذا المستودع مصحوب بمقالة مدونة بعنوان "العثور على CVE-2022-3786 (openssl) باستخدام 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 فقط لتبدأ الاختبار بالتغذية العشوائية فورًا. لتجاوز هذا السلوك، أضف /bin/bash في نهاية سطر docker run.
آخر commit يتضمن الثغرة هو commit SHA 3b421ebc64c7b52f1b9feb3812bdc7781c784332 بتاريخ 1 نوفمبر 2022. تم إصلاحها في commit 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
للتجميع، نستخدم مترجم gcc الخاص بـ AFL (لأنني كنت أحصل على مراجع غير معرفة مع clang). بسبب صغر حجم تجاوز سعة المخزن المؤقت، نريد أيضًا استخدام تعقيم العناوين (ASAN)، الذي يتم تفعيله بواسطة متغير البيئة AFL_USE_ASAN الخاص بـ AFL. نظرًا لاستخدام 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
وهكذا، يمكنك البدء في اختبار ossl_a2ulabel بالتغذية العشوائية في openssl. باستخدام AFL، يكون الأمر مشابهًا لما يلي (أو استخدم النص البرمجي run.sh المضمن).
afl-fuzz -i /input -o /output /harness/harness @@