分析:instagram APP远程代码漏洞

Read_jpg_copy_loop代码段

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


  1. width = rect->right – rect->bottom; 
  2. height = rect->top – rect->left
  3. allocated_address = __wrap_malloc(width*height*cinfo->output_components);// output_scanline; 
  4.    if ( (unsigned int)output_scanline >= cinfo->output_height ) 
  5.       break; 
  6.     //reads one line from the file into the cinfo buffer 
  7.     jpeg_read_scanlines(cinfo, line_buffer, 1); 
  8.     if ( output_scanline >= Rect->left && output_scanline < Rect->top ) 
  9.     { 
  10.         memcpy(allocated_address + bytes_copied , line_buffer, width*output_component);// <–Oops 
  11.         bytes_copied += width * output_component; 
  12.     } 
  13.  } 

其中:

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

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

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

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

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


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

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

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

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


  1. memcpy(allocated_address + bytes_copied ,line_buffer, width*output_component);//<–Oops 

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

【声明】:芜湖站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

相关文章