加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 安全 > 正文

分析:instagram APP远程代码漏洞

发布时间:2021-06-10 01:57:33 所属栏目:安全 来源:互联网
导读:Read_jpg_copy_loop代码段 在处理JPEG 图像文件时,有漏洞的函数会处理图像尺寸。下面是有漏洞的代码的伪代码: width=rect-right-rect-bottom; height=rect-top-rect-left; allocated_address=__wrap_malloc(width*height*cinfo-output_components);//out

Read_jpg_copy_loop代码段

在处理JPEG 图像文件时,有漏洞的函数会处理图像尺寸。下面是有漏洞的代码的伪代码:

width = rect->right - rect->bottom; 

height = rect->top - rect->left; 

allocated_address = __wrap_malloc(width*height*cinfo->output_components);// output_scanline; 

   if ( (unsigned int)output_scanline >= cinfo->output_height ) 

      break; 

    //reads one line from the file into the cinfo buffer 

    jpeg_read_scanlines(cinfo, line_buffer, 1); 

    if ( output_scanline >= Rect->left && output_scanline < Rect->top ) 

    { 

        memcpy(allocated_address + bytes_copied , line_buffer, width*output_component);// <--Oops 

        bytes_copied += width * output_component; 

    } 

 } 

其中:

_wrap_malloc 函数会根据图像尺寸的3个参数来分配内存块。Width和height 都是16位的整数(uint16_t)。

cinfo->output_component 告诉我们有多少个字节用来表示每个像素。变量的值分别代表不同的意思,1表示Greyscale、3表示RGB、4表示RGB + AlphaCMYK等。

除了height和width外,output_component 也可以完全被攻击者控制。因为在分析的过程中并不会与文件中的其他数据进行验证。

__warp_malloc 希望其参数在32位的寄存器中进行处理。也就是说如果分配的大小超过 (2^32) 字节,那么就可以引发整数溢出。

分配的大小是通过图像的width乘 height再乘以 output_components 得到的。因为没有检查,那么一旦被攻击者所控制,进一步滥用后就会引发整数溢出。

_wrap_malloc(width * height * cinfo->output_components);// <---- Integer overflow 

然后缓存被传递给memcpy,引发基于堆的缓存溢出。

分配后,memcpy 函数会被调用,然后复制图像数据到分配的内存中。

复制的过程是一行一行进行的:

memcpy(allocated_address + bytes_copied ,line_buffer, width*output_component);//<--Oops 

size (width*output_component)数据也会被复制 height 次。

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!