
Codice PoC per scaricare file con CVE-2024-32830
Codice PoC per scaricare file con CVE-2024-32830
getimagesize bypassPer bypassare la restrizione di getimagesize, possiamo creare una semplice immagine image/vnd.wap.wbmp per PHP.
Il controllo per il tipo di file è molto semplice:
// 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;
}
Il modo più semplice per costruire un'immagine valida sarebbe con due byte NUL, seguiti da due byte < 0x80 per la larghezza e l'altezza.
È possibile farlo per qualsiasi file, utilizzando php://filter.
Il primo strato dovrebbe applicare una codifica base64 per garantire che tutti i dati siano ASCII, soddisfacendo così il vincolo < 0x80.
Il secondo filtro dovrebbe aggiungere i primi due byte NUL. Ciò è possibile forzando una conversione da UTF-16BE a UTF-32BE. Questo costringerà iconv a interpretare ogni blocco di due byte come un carattere UTF-16BE valido, e poi a prependere due byte NUL prima di esso per renderlo UTF-32BE. Il filtro effettivo da usare è: convert.iconv.utf-16be.utf-32be.
Il nostro payload finale è php://filter/convert.base64-encode/convert.iconv.utf-16be.utf-32be/resource=<file here>.