CVE-2009-0927:PDF中的JS

0x00:分析环境
使用的环境 | 备注 | |
---|---|---|
操作系统 | Windows XP SP3 | Vmware 16 |
Adobe Reader版本 | 9.0中文版 | |
动态调试 | OllyDbg v2.01 | 用的原版的OD其它的OD可能会断不下来 |
静态调试 | IDA7.0 |
0x01
首先用OD打开Adobe Reader 按F5使其正常运行(调试器需要设置步过int3中断和内存异常访问)

然后运行 poc.pdf ,OD会中断在0x00130000处产生内存写入异常。产生异常的原因是0x00130000这个地址已经超出了程序的内存空间范围,出现这种异常一般是复制了超长字符串导致的。

可以通过查看模块(alt+E),查看模块属性发现0x130000为只读属性
0x2
接下来我们开始分析异常产生的具体原因,先观察一下堆栈情况,可以看到程序在0x2210fe27中调用了strncpy,问题有可能就在这个函数里面,我们可以在汇编窗口中观察一下这个函数。

进入0x2210fe27之后我们可以看到0x2210FE25处 CALL EDI 调用了 strncp函数,按alt+E查看一下这个地址所在的模块用IDA打开查看一下函数结构。

用IDA打开此文件找到这个函数的位置按F5查看一下伪C代码

通过分析这段汇编代码发现strncpy的长度来源于字符串

0x03
接下来我们重新用OD重新动态分析,首先在0x2210FDEB处下条件断点’EAX-EDI>600’(这个长度一般情况下大于正常字符串的长度小于异常情况下堆利用的字符串长度)

然后重新用OD加载AdobeReader,并打开POC,程序会断在我们设置的条件断点处,可以看到此时EAX-EDI=0X8005,再减一等于0X8004,并且此时EDI指向的位置存放数据为0C0C0C0C

继续往下调试到0x2210FE25 CALL EDI 处,可以发现src指向的位置的数据为0C0C0C0C,要复制的长度为0x8004


(dest=0x12E4B0) + (N=0x8004) = 0x1364B4,这个地址大于了0x130000前面我们通过查看模块发现0x130000为只读模块,所以这里写入会产生异常,这下可以确认这里就是溢出的根源了.
正常来说这个时候程序抛出异常之后会进入异常处理函数,先查看一下异常处理链

调用strncpy之前0x12E6B4中存放下一个SEH记录的位置,0x12E6B8存放本次异常处理的地址

现在我们按F8步过执行strncpy(),发现程序产生了写入0x130000异常中断,此时我们再来查看异常处理结构的内容,如下所示之前存放下一个SEH记录位置的数据已经被0C0C0C0C覆盖掉了


然后再调用异常处理函数就会执行0C0C0C0C处的内容,可以看到全部都是NOP指令

根据POC的执行我们知道最后弹出了一个MessageBox,所以我们可以在MessageBoxA处下断点,然后栈回溯查看poc的代码

查看0x0C100008处的汇编代码,通过寻找user32找到kernel32的基址,然后通过hash值的对比来找到需要的导出函数,来实现了弹出MessageBox.

分析完成~
- 标题: CVE-2009-0927:PDF中的JS
- 作者: xiaoeryu
- 创建于 : 2021-05-20 09:37:02
- 更新于 : 2023-11-17 19:37:15
- 链接: https://github.com/xiaoeryu/2021/05/20/CVE-2009-0927-PDF中的JS/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。