CVE-2023-1906 - Heap-based Buffer Overflow in ImageMagick
After running the fuzzer for 24 hours, we discovered a crash in ImageMagick that was caused by a heap-based buffer overflow. This vulnerability, assigned CVE-2023-1906 / GHSA-35Q2-86C7-9247, could have potentially allowed an attacker to cause a denial of service condition or possibly an execution of arbitrary code.
To help other security researchers reproduce our findings and improve the security of ImageMagick, we wanted to share our steps for compiling ImageMagick with afl-clang-fast and afl-clang-fast++.
Here are the steps we followed:
Install afl-clang-fast and afl-clang-fast++ :
You can install these compilers by following the instructions on the AFL++ GitHub repository .
Compile ImageMagick with afl-clang-fast and afl-clang-fast ++:
To compile ImageMagick with afl-clang-fast and afl-clang-fast ++, you'll need to use the CC and CXX environment variables to specify the afl-clang-fast and afl-clang-fast ++ compilers. Here's an example command:
AFL_USE_ASAN=1 CC=/usr/local/bin/afl-clang-fast CXX=/usr/local/bin/afl-clang-fast++ ./configure && make -j$(nproc)
Generate test cases:
To generate test cases for ImageMagick, we used AFL's afl-fuzz command by providing the initial corpus from this link. Here's an example command to generate test cases using AFL++ 's default settings:
afl-fuzz -i /path/to/testcases -o /path/to/output -- /path/to/compiled/imagemagick @@
Run the PoC crash file:
After running the fuzzer for 24 hours, we discovered a crash in ImageMagick that was caused by a heap-based buffer overflow.
Here's an example command to run the PoC crash file with the compiled ImageMagick:
This issue was fixed on last weekend at commit and a update was released as 7.1.1-6 version - We're sharing these steps in the hopes that other security researchers can use them to discover and report vulnerabilities in other C and C++ programs.
If you have any questions or feedback, please don't hesitate to reach out to me at email@example.com .