flash漏洞调试技巧

本周中心抓到一个在野的flash 0day(相关信息见此链接),于是又捡起了一年多的flash 漏洞的相关知识,遂总结一下。

普通的trace

调试flasher样本一般建议使用调试版的flash player,在调试版本下可以输出swf文件运行时的相关日志,便于进行相关的分析,安装之后会在家目录(C:\User\<your name>mm.cfg)生成该文件(早期的flash调试版本不会生成该文件,需要手动生成)。

 

文件中包含以下配置选项,手动生成的话红色框中的选项为必选项,用于告诉flash生成错误日志及trace日志(对应的日志文件保存在C:\Users\<your name>\AppData\Roaming\Macromedia\Flash Player\Logs目录下)。

 

通过FFdec,可以直接往flash中打trace补丁,用于输出对应的参数,变量。

findpropstrict Qname(PackageNamespace(""),"trace")

pushstring "Hello World!"

callpropvoid Qname(PackageNamespace(""),"trace") 1

  

Jit函数监控

但是大多数漏洞调试中,trace不够强大,这就需要通过调试器了,因为flash里的脚本在执行的时候会转为jit,因此调试非常不便,这也是早期flash很难搞的一个问题,但是可以通过以下断点解决。

29.r0.140  flash.ocx

.dvalloc /b 0x79990000 30;eb 0x79990000 5e;ew 0x79990001 c3

bp Flash32_29_0_0_140 + 0x8D03D2 ".printf \"the method_name is: %ma\\n\",poi(eax+8);.if(poi(esi+20)=0xFFFFFFFF){bp poi(esi+4}.else{gc}"

bp Flash32_29_0_0_140 + 0x8BA425 ".printf \"the method_index is:%p the method_info_pointer is:%p the jit code is:%p the method_body is:%p\\n\",poi(esi+20),esi,poi(esi+4),poi(esi+24);r ecx = esi;r $t0 = poi(esp);ed esp eip+1;r esp = esp - 4;ed esp @$t0;r esp = esp -4;ed esp 0x79990000;r eip = Flash32_29_0_0_140 + 0x8D03AF;g"

原理

fun_verifyMethod,该函数是flash引擎中用于对jit函数校验的地方,该函数返回的esi其实是一个jit method的对象,里面包含了具体生成的jit函数的index,method ,jit code等属性,其中index是引擎内部用于识别jit函数的标记(就一数字),jit code标记了生成的对应地址,但是对应正常人而言index这种数字明显没有意义,我们需要具体的函数名,这就引出之后的fun_getMethodName函数。

fun_getMethodName,其ecx接受一个method的对象(即fun_verifyMethod返回的对象),结果会返回一个具体函数的函数名,但是该函数默认在flash运行时不会调用,因此需要在fun_verifyMethod调用后手动调用一下fun_getMethodName,既可以获得对应的函数名,此时结合fun_verifyMethod返回的地址,就能实现正常的调试。

 

使用

脚本中一共三条命令,第一条用于生成一段内存,主要用于在fun_verifyMethod后,改变程序流程去执行fun_getMethodName(你可以理解为hook),之后分别是这两个函数的断点。

.dvalloc /b 0x79990000 30;eb 0x79990000 5e;ew 0x79990001 c3

bp Flash32_29_0_0_140 + 0x8D03D2 ".printf \"the method_name is: %ma\\n\",poi(eax+8);.if(poi(esi+20)=0xFFFFFFFF){bp poi(esi+4}.else{gc}"

bp Flash32_29_0_0_140 + 0x8BA425 ".printf \"the method_index is:%p the method_info_pointer is:%p the jit code is:%p the method_body is:%p\\n\",poi(esi+20),esi,poi(esi+4),poi(esi+24);r ecx = esi;r $t0 = poi(esp);ed esp eip+1;r esp = esp - 4;ed esp @$t0;r esp = esp -4;ed esp 0x79990000;r eip = Flash32_29_0_0_140 + 0x8D03AF;g"

调试的时候,下这两个断点,运行之后生成整个jit函数的信息,记下来,每个函数index很重要。

运行第二遍就可以正常调试了,此时只要将红字换成对应的函数index即可(对同一个swf,index是固定的),此时运行,即可在指定jit函数生成的时候断下。

bp Flash32_29_0_0_140 + 0x8D03D2 ".printf \"the method_name is: %ma\\n\",poi(eax+8);.if(poi(esi+20)=0xFFFFFFFF){bp poi(esi+4}.else{gc}"

此时针对replace的jit code地址下断点,及可以断下。

 

通用性

替换,该脚本是针对29.r0.140  flash.ocx,之后需要使用其他版本的时候需要改对应的地址,这就涉及到如何快速获取对应的fun_getMethodName和fun_verifyMethod函数。

fun_getMethodName,ida里找cinit字符,对应引用的函数。

 

引用函数如下。 

再向上一层就是了。 

fun_verifyMethod函数,搜JIT failed字符。

 

对应的引用。

 

对该函数的引用,第一个就是,不是就找找反正不多。

 

需要修改以下三个值(蓝色部分根据你要跟的函数index自己替换),

第一个红色地址为fun_getMethodName返回的ret地址。

第二个红色地址为fun_verifyMethod返回前的pop esi的地址。

第三个红色地址为fun_getMethodName的起始地址减一(为啥减一是为了windbg中断点hook的需要)。

.dvalloc /b 0x79990000 30;eb 0x79990000 5e;ew 0x79990001 c3

bp Flash32_29_0_0_140 + 0x8D03D2 ".printf \"the method_name is: %ma\\n\",poi(eax+8);.if(poi(esi+20)=0xFFFFFFFF){bp poi(esi+4}.else{gc}"

bp Flash32_29_0_0_140 + 0x8BA425 ".printf \"the method_index is:%p the method_info_pointer is:%p the jit code is:%p the method_body is:%p\\n\",poi(esi+20),esi,poi(esi+4),poi(esi+24);r ecx = esi;r $t0 = poi(esp);ed esp eip+1;r esp = esp - 4;ed esp @$t0;r esp = esp -4;ed esp 0x79990000;r eip = Flash32_29_0_0_140 + 0x8D03AF;g"

 

 转载请注明出处

猜你喜欢

转载自www.cnblogs.com/goabout2/p/9158051.html