
PoC code to download files with CVE-2024-32830
Código PoC para baixar arquivos com CVE-2024-32830
getimagesizePara contornar a restrição do getimagesize, podemos criar uma imagem image/vnd.wap.wbmp simples para PHP.
A verificação do tipo de arquivo é muito simples:
// 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;
}
A maneira mais simples de construir uma imagem válida seria com dois bytes NUL, seguidos por dois bytes < 0x80 para largura e altura.
É possível fazer isso para qualquer arquivo, usando php://filter.
A primeira camada precisaria aplicar uma codificação base64 para garantir que todos os dados sejam ASCII, satisfazendo assim a restrição < 0x80.
O segundo filtro precisaria adicionar os dois primeiros bytes NUL. Isso é possível forçando uma conversão de UTF-16BE para UTF-32BE. Isso forçará o iconv a interpretar cada bloco de dois bytes como um caractere UTF-16BE válido e, em seguida, adicionar dois bytes NUL antes dele para torná-lo UTF-32BE. O filtro real a ser usado é: convert.iconv.utf-16be.utf-32be.
Nosso payload final é php://filter/convert.base64-encode/convert.iconv.utf-16be.utf-32be/resource=<arquivo aqui>.