Defeating Data Execution Prevention and Aslr in Windows XP Sp3
Defeating Data Execution Prevention and Aslr in Windows XP Sp3
What is DEP?
Your texte here .
Data Execution Prevention (DEP) is a set of hardware and software technologies It performs additional checks on memory to help prevent malicious code from running on a system
Hardware-enforced DEP
Your texte here .
Hardware-enforced DEP causes an attempt to transfer control to an instruction in a memory page marked as no execute to generate an access fault. Relies on processor hardware to mark memory with an attribute that indicates that code should not be executed from that memory region DEP functions on a per-virtual memory page basis, usually changing a bit in the page table entry (PTE) to mark the memory page The actual hardware implementation of DEP and marking of the virtual memory page varies by processor architecture: The no-execute page-protection (NX) processor feature as defined by AMD The Execute Disable Bit (XD) feature as defined by Intel. To use these processor features, the processor must be running in Physical Address Extension (PAE) mode. Windows will automatically enable PAE mode to support DEP.
Intel Hardware-enforced
Your texte here .
DEP
Software-enforced DEP
Your texte here .
Software-enforced DEP runs on any processor that can run Windows XP SP2 By default, software-enforced DEP helps protect only limited system binaries, regardless of the hardware-enforced DEP capabilities of the processor It protects only user-mode processes. It must be supported by the operating system. Software-enforced DEP does not protect from execution of code in data pages but instead from another type of attack which is called Security Exception Handling (SEH) overwrite
DEP settings
Your texte here .
/NOEXECUTE= OptIn Turn on DEP for necessary Windows programs and services only /NOEXECUTE= OptOut Turn on DEP for all programs and services except for those that I select /NOEXECUTE= AlwaysOn permanently enables DEP /NOEXECUTE= AlwaysOff permanently disables DEP The default setting on Windows XP SP2 is OptIn, while the default setting on Windows 2003 Server SP1 is OptOut
ASLR
Your texte here .
The PaX project first coined the term "ASLR". Implementations of ASLR in July, 2001. Exploits attacks rely on programmer skills to identify where specific processes or system functions live in memory In order for an attacker to leverage a function, he must first be able to tell the code where to find the function Before ASLR implementation memory locations were easily discovered by attackers and malware code ASLR (Address space layout randomization) involves randomly positioning memory areas, usually areas the base address of the binary file and position of libraries, heap and stack Without ASLR, a library will always going to be loaded at a predictable address and can be leverage by an exploit Bypassing ASLR means targeting non-ASLR libraries to build a reliable exploit
ASLR DEFEATED
Your texte here .
DEP in action
Your texte here .
(1)
The routine inject_shellcode_in_stack push the payload into the stack Once the shellcode has been injected the code jumps to the execute routine The CALL ESP instruction fetch the beginning of the shellcode
DEP in action
Your texte here .
(2)
Since the page 0x0022e000 size 00002000 has only Read and Write attributes an access violation is triggered at the address 0x0022feb4 DEP has successfully stop shellcode execution from the stack
Bypassing DEP
Your texte here .
(1)
When hardware DEP is enabled, we are not able to jump to our shellcode on the stack, because this one will not be executed. An access violation will terminate the process. (slide 10) Different techniques are available to accomplish this task DEP can be disabled if the later is running in OptIn or OptOut mode Another approach is to call API functions that are able to change the memory attributes (PAGE_READ_EXECUTE) from where the payload lives Some of the techniques are introduced in the next slides
VirtualAlloc technique
Your texte here .
(2)
We can create a new memory region with executable attributes We then copy our shellcode to this memory region (WriteProcessMemory or memcpy APIs) This technique needs at least the use of two different APIs
Comparable to VirtualAlloc()
SetProcessDEPPolicy technique
Your texte here .
(4)
This allows to disable the DEP policy for the current process It will work for Vista SP1, XP SP3, Server 2008, and only when DEP Policy is set to OptIn or OptOut modes
VirtualProtect technique
Your texte here .
(5)
This function will change the access protection level of a given memory page It will allow to mark the location where our shellcode lives as PAGE_READ_EXECUTE
WriteProcessMemory technique
Your texte here .
(6)
This technique will permit us to copy the shellcode to a memory region with EXECUTE attributes Later we can jump to it The target location must be Writable and Executable
HeapCreate in action
Your texte here .
A new heap of 296 bytes is created with PAGE_READ_EXECUTE attributes. The heap base address returned in EAX is then passed to WriteProcessMemory The final RET instruction execute the shellcode from the new heap
WriteProcessMemory in action
Your texte here .
The shellcode is copied to a kernel32.dll memory address which the memory attributes are Read and Execute The example is using a memory harcoded address in windows xp sp3 which does not contain any relevant code It is important to choose the correct memory address, otherwise the system could crash after copying the shellcode
Your texte here . the application with a simple <Evil Buffer> + <CALL ESP> <NOP> <SHELLCODE> When we try to exploit
technique it throws an STATUS_ACCESS_VIOLATION (0xC0000005) DEP is sucessfully preventing code execution from the actual thread stack
Conclusions
Your texte here .
DEP and ASLR are designed to increase an attacker's exploit development costs ASLR is easy bypassed if we can count on memory modules which do not have this feature turn on The return oriented programming can be used to with no trouble get around dep protections This techniques can be also used in others windows flavors such as windows Vista or Windows 7
References
Your texte here .
http://www.uninformed.org/?v=2&a=4&t=txt http://support.microsoft.com/kb/875352 http://technet.microsoft.com/en-us/library/bb457155.aspx http://technet.microsoft.com/en-us/library/cc738483%28WS.10%29.aspx http://msdn.microsoft.com/en-us/library/ms633548%28v=vs.85%29.aspx http://opc0de.tuxfamily.org/?p=430 http://www.cs.bham.ac.uk/~covam/blog/binary/ http://www.corelan.be Windows Internals fourth edition https://www.blackhat.com/presentations/bh-usa08/Shacham/BH_US_08_Shacham_Return_Oriented_Programming.pdf