yahoo!messenger 的一个远程堆溢出问题

来源:互联网 发布:四川省畜牧兽医大数据 编辑:程序博客网 时间:2024/04/30 23:18
下面就把一个堆溢出问题讲讲,这个问题我在最新的8.1.0.413下测试的确存
在。

Yahoo!messenger有个功能叫webcam,webcam传输的数据是jpc格式的,jpc是jpeg2000的一种,具体的文件格式我没
有找到,我根据jpeg文件格式和一些opensource的软件的实现,我猜想大概是这样的,下面是一个传输包的内容:

ff 4f ff 51 00 2f 00 00 00 00

01 40 00 00 00 f0 00 00 00 00 00 00 00 00 80 00

01 40 00 00 00 f0 00 00 00 00 00 00 00 00 00 03

Ff 4f ff 51 你可以简单的看作是jpc文件的标志符,后面那个2f是这个block的长度,00 00 01 40是图片的长度,00
00 00 f0是宽度,后面的0140和f0叫做tile长度和tile宽度,对我们发现漏洞有用的就是这四个数了(图片的长度,宽度和tile的长
度和宽度),组合这四个数,可以发现很多的漏洞,呵呵,很多是远程DoS,先来看一个DoS的问题,下面是kdu_v32m.dll的代码片断:

mov eax, [esi+3Ch] ; pic width

.text:10015505 mov edi, [esi+44h] ;

.text:10015508 mov edx, [esi+34h] ;

.text:1001550B mov ecx, [esi+4Ch] ; tile width

.text:1001550E sub eax, edi

.text:10015510 or ebx, 0FFFFFFFFh

.text:10015513 add eax, edx

.text:10015515 js short loc_1001551B

.text:10015517 lea eax, [ecx+eax-1]

.text:1001551B

.text:1001551B loc_1001551B: ; CODE XREF: my_get_error_param1+415j

.text:1001551B cdq

.text:1001551C idiv ecx

.text:1001551E mov edx, [esi+48h]

.text:10015521 mov ecx, [esi+50h] ; tile length

.text:10015524 mov edi, eax

.text:10015526 mov eax, [esi+40h] ; pic width

.text:10015529 sub eax, edx

.text:1001552B mov edx, [esi+38h]

.text:1001552E add eax, edx

.text:10015530 mov [esi+54h], edi

.text:10015533 js short loc_10015539

.text:10015535 lea eax, [eax+ecx-1]

.text:10015539

.text:10015539 loc_10015539: ; CODE XREF: my_get_error_param1+433j

.text:10015539 cdq

.text:1001553A idiv ecx

.text:1001553C mov [esi+58h], eax

.text:1001553F imul eax, edi

.text:10015542 cmp eax, 0FFFFh

.text:10015547 jle short bug_bug

.text:10015549 lea ecx, [esp+70h+var_44]

.text:1001554D call ??0kdu_error@@QAE@XZ ; kdu_error::kdu_error(void)

.text:10015552 mov edx, [esp+70h+var_44]

.text:10015556 push offset aMaximumNumberO ; "Maximum number of
allowable tiles is 65"...

.text:1001555B lea ecx, [esp+74h+var_44]

.text:1001555F mov [esp+74h+var_24], 8

.text:10015567 call dword ptr [edx+4]

.text:1001556A mov [esp+74h+var_48], offset off_10035078

.text:10015572 mov ecx, [esp+74h+var_40]

.text:10015576 mov [esp+74h+var_28], 9

.text:1001557E cmp ecx, ebp

.text:10015580 jz short loc_10015589

.text:10015582 mov eax, [ecx]

.text:10015584 push 1

.text:10015586 call dword ptr [eax+8]

.text:10015589

.text:10015589 loc_10015589: ; CODE XREF: my_get_error_param1+480j

.text:10015589 mov [esp+78h+var_2C], ebx

.text:1001558D

.text:1001558D bug_bug: ; CODE XREF: my_get_error_param1+447j

.text:1001558D mov ecx, [esi+58h]

.text:10015590 imul ecx, [esi+54h]

.text:10015594 shl ecx, 2

.text:10015597 push ecx

.text:10015598 call ??2@YAPAXI@Z ; bug is here ,function new.

看到没有,它是利用我们提供的数据来作为new的参数,我们可以合理的构造那四个参数,使得提供给new的参数为0的时候,DoS就产生了。

好了,我们言归正传,看看那个remote heap overflow是怎么回事,首先,当一个webcam请求初始化的时候yahoo!
Messenger会生成一个class(webcamclass), webcamclass会在这个地方(ywcvwr.dll)申请一段内存,这
段内存的长度是0x400:

.text:10001737 cmp edi, [esp+0Ch+arg_0]

.text:1000173B jl short loc_10001735

.text:1000173D cmp edi, 1400000h

.text:10001743 jg short loc_10001752

.text:10001745 push edi

.text:10001746 call j_??2@YAPAXI@Z ; operator new(uint)

.text:1000174B mov ebx, eax

.text:1000174D test ebx, ebx

这段内存的作用是存放从jpc解压出来的bitmap的内容,很不幸的是在这里,它居然会用我们数据包内提供的数据来作为边界判断条件:

.text:10002C5C mov [eax+2], cl ; eax是前面这个长度为0x400的buffer

............................

.text:10002CA9 mov [eax], cl

.text:10002CAB mov ecx, [ebp+var_4]

.text:10002CAE add eax, [edi+5Ch]

.text:10002CB1 inc esi

.text:10002CB2 inc esi

.text:10002CB3 cmp ecx, [edi+64h] ;bug is here

.text:10002CB6 jl short loc_10002C38

[edi+64h]的内容是我们提供的pic length,只要我们合理的构造这个值及其它相关的值,我们就可以成功的实现堆溢出,呵呵。

我写了一个测试程序(http://www.team509.com/expyahoo.rar),只能实现远程DoS,不过通过这个程序你可以调试,
发现这个remote heap overflow问题。

1.compile the dll.
2. choose "invite to view my webcam" to a contact id who is online
using yahoo! messenger.
3.when the otherside accept the invatation , inject the dll to local
yahoo! messenger 8.1.0.413 's process.
4 . the otherside's yahoo! messenger will be crashed.
其他的im 从在的问题也不少就看谁外放了