0%

CVE-2013-1347 漏洞分析与利用

这块内存已被释放

image-20220102112450910

通过调用CSpanElement::CreateElement函数创建span元素

image-20220102113558401

函数内部通过HeapAlloc申请长度为0x28大小内存空间

image-20220102114100898

查找插入位置,这里查找到了body元素

image-20220102141539670

CTreeNode元素

image-20220102150101085

image-20220103143414127

image-20220103144243241

image-20220103143548884

下面开始分析CElement,CTreeNode的释放情况.

当去掉f0.offsetParent=null,两者都会被释放.

当加上f0.offsetParent=null,CTreeNode不会被释放,CElement会被释放,同时CTreeNode对象依然保存着CElement对象的地址,导致后面CollectGarbage调用时引用到了这个地址的函数,造成了漏洞的发生.所以问题的关键就在于为什么CTreeNode元素没有被释放.

image-20220105151706142

TreeNode

image-20220105151638784

CElement

image-20220105151700542

对比一下f0.offsetParent=null去除与未去除状态下的堆栈情况

为了明白CTreeNode没有被释放的原因,要弄清楚f0.offsetParent=null在内存中做了什么,通过搜索offsetParent,可以找到对应函数CElement::GetOffsetParentHelper,对GetOffsetParentHelper执行前后的CTreeNode进行一个对比,看看修改了哪些值.

+8,+C位置发送了变化.

image-20220103143414127

image-20220103144234127

对比着IE5的源码看一下这两个值.

+4+8位置是CElement对象地址和父节点CTreeNode对象地址,后面4个字节是一些标志位,+C位置是定义CharFormat的值,这个值的作用暂时不知道,对这个值下读断点调一下.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Class Data
CElement* _pElement; // The element for this node
CTreeNode* _pNodeParent; // The parent in the CTreeNode tree

// DWORD 1
BYTE _etag; // 0-7: element tag
BYTE _fFirstCommonAncestorNode : 1; // 8: for finding common ancestor
BYTE _fInMarkup : 1; // 9: this node is in a markup and shouldn't die
BYTE _fInMarkupDestruction : 1; // 10: Used by CMarkup::DestroySplayTree
BYTE _fHasLookasidePtr : 2; // 11-12 Lookaside flags
BYTE _fBlockNess : 1; // 13: Cached from format -- valid if _iFF != -1
BYTE _fHasLayout : 1; // 14: Cached from format -- valid if _iFF != -1
BYTE _fUnused : 1; // 15: Unused

SHORT _iPF; // 16-31: Paragraph Format

// DWORD 2
SHORT _iCF; // 0-15: Char Format
SHORT _iFF; // 16-31: Fancy Format

sxe ld:mshtml

bp mshtml+17d715 “ln eax;g”

bp mshtml!CElement::CElement+0x1e “.echo ‘===CElement===’;dd esi l(28/4);g “

bp mshtml+fb0af “.echo ‘===CTreeNode===’;dd eax l13;g”

bp mshtml!CElement::GetOffsetParentHelper

bu jscript!JsAtan2 “.printf "%mu",poi(poi(poi(esp+14)+8)+8);.echo;”

bp mshtml!+92ab8

bp mshtml+8bed9 “.echo ‘===eax+4===’;dd eax+4;g”

ba w4