A DEP evasion technique
<script> // policy issue hide_googlead(); </script>
In an earlier post, I pointed out a possible way to evade Data Execution Prevention in Microsoft Windows XP Service Pack 2. I feel this deserves its own blog post, so I've decided to go on here.
I'd like to first point out that this is a speculative method to evade hardware-enforced DEP based on various documentation. There is not yet a proof-of-concept, but this does not mean there is not a vulnerability. I will make a short blog if and when a POC is available, or if it turns out that I was wrong in my analysis.
This method applies to any system where proper protections on memory can prevent it from being executable, whether by hardware facilities or software emulation, if and only if those systems do not employ appropriate countermeasures such as memory protection restrictions (mprotect() or VirtualProtect()) or Address Space Layout Randomization.
This means that systems such as PaX, Exec Shield, and W^X are not vulnerable. PaX supplies high quality ASLR and mprotect() restrictions on Linux; while Exec Shield and W^X both supply ASLR for shared libraries at least. This technique still applies if certain information leaks (/proc/[pid]/maps) are not obscured, however.
The original problem that deploying these memory protections was meant to solve is shellcode injection. Some vulnerabilities, such as those in US-CERT Technical Alerts TA04-315A, TA04-260A, and TA04-293A lead to arbitrary code execution. While in these cases upgrading to Service Pack 2 brings fixes to Internet Explorer, future vulnerabilites similar to these will not be protected by DEP itself.
There are two reasons why DEP can be exploited. First, the VirtualProtect() function can still be called with any protecitons. There is no restriction at the time of this writing to VirtualProtect(), and so arbitrary memory can be made executable, or executable and writable.
Second, there is also ASLR, which makes locating the address of the VirtualProtect() function both easy and reliable. Even if VirtualProtect() were restricted properly, CreateFileMapping() and other functions could be used with open() and write() to simply write the data to a file and map it in as executable data.
Additionally, VirtualAlloc() and memcpy() could be used, since "VirtualAlloc can commit [(allocate)] an already committed page." It will seriously corrupt memory, but this is already a memory corruption attack so who cares?
To explain this exploit, we'll start with a normal proof-of-concept overflow. eEye Digital Security discovered a vulnerability in USER32.dll allowing animated cursor files to cause a buffer overflow and execute arbitrary code. A proof-of-concept was later released by Assaf Reshef to demonstrate this vulnerability.
This proof-of-concept falls in a class that would be stopped by DEP. It uses a buffer overflow to inject code into the stack and modify the return pointer to execute that code. Upon execution, the CPU raises a Segmentation Fault because the memory area is not executable. Thus, Windows is able to stop this exploit on Service Pack 2 on supporting processors.
Below is explained a hypothetical modification to the above cited proof-of-concept exploit for this particular overflow. The exploit as described below has not been written or tested, and is purely theoretical.
The process can be modified to inject a modified sest of data during the overflow. This data would contain a modified stack frame pointer, return pointer, a stack frame, and a block of payload shellcode, as shown below.
[SFPT][RETP][STACK FRAME][STACK FRAME2][SHELLCODE]
The SFPT would point at the STACK FRAME, and RETP would point to VirtualAlloc(). The STACK FRAME would have a return pointer to SHELLCODE, and appropriate layout for a call to VirtualAlloc() as shown below.
VirtualAlloc(REMOTE_BASE, SHELLCODE_LENGTH, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Upon RET from the overflowed function, the above call to VirtualAlloc() would be made to allocate an area big enough for the shellcode with protecitons PAGE_EXECUTE_READWRITE. This would leave the area readable, writable, and executable, all at the same time. Because VirtualAlloc() will allocate overtop of already allocated memory, REMOTE_BASE need only to be some remote address not near VirtualProtect(), memcpy(), or the injected stack frames and shellcode.
Because the stack frame for the call to VirtualAlloc() was part of the initial overflow, the attacker has complete control of its contents. The return pointer in the stack frame therefore should point to memcpy(), with a proper pointer to STACK FRAME2. This means that, upon RET, memcpy() is executed. It should be executed as shown below.
memcpy(REMOTE_BASE, SHELLCODE_BASE, SHELLCODE_LENGTH);
This copies SHELLCODE into the newly allocated area of memory. Again, the attacker has complete control over the stack frame. On RET, SHELLCODE is returned to. This causes SHELLCODE to execute.
When SHELLCODE is executed at the end of this process, it has been copied to a newly created executable area by existing code supplied by the Windows operating system. This means, as stated above, that SHELLCODE can safely be executed without DEP interfering. This attack method should be plausible for any attack in which shellcode is injected, and is compatible with older, non-DEP Microsoft Windows systems as well.
Note that the original overflow string must not contain NULL characters in buffer overflows involving strcpy() and related functions. This is because the string will end there and not be copied to the stack. Access to ASCII armored areas (addresses containing a NULL byte) will not normally be possible, although there may be ways to load the heap with prepared data, such as by loading certain data files or running certain scripts.
The NULL byte dilema may be evadable if a UUE, Base64, or MIME decoding function is available, and does not start at an ASCII armored address. In these cases, the first return can be a return-to-UUDecode() and can decode the rest of the attack, then continue with it. The UUDecode() address and stack frame must not contain any NULL bytes for this to work.
In conclusion, Microsoft's Hardware DEP protection does not prevent future exploits from being successful; it only adds a trivial amount of complexity to the attack. I believe that any attacker able to create the exploit as it would normally work will be able to handle the less complex task of incorporating a return-to-VirtualAlloc() and memcpy() attack into the process. This could only be properly protected against by incorporating Address Space Layout Randomization into the protection scheme.

16 Comments:
My understand of the software DEP (which only applies to "core system files", which I guess includes IE) which would interfere with this is canary/cookie seeding. Basically, on the stack you'd have:
[start cookie][buffer][end cookie]...[return pointer]
Before the function returns, the end and start cookies are checked to verify they've not been altered. If either of them have, there's an exception and the program closes. So, obviously in at least some of the programs you'd have to figure out the end cookie. I can only guess that the cookie is generated at runtime because otherwise it'd be relatively trivial to locally find the cookie of a variety of system libraries and use it as a basis for attack. Seeing as the program reports to you the exception and allows handling it, a debugger would even kindly point to you when to look and the exact value to seed if it were static.
So, yes, your suggestion works on at least some (most?) of the libraries in use on a lot of machines. But those with the cookie stubs are relatively safe from a ret2libc attack, I hope. If the cookie stubs are static, then you're right that it's just a few more steps to building a successful exploit.
Not quite. The canary on the stack requires the program to be recompiled. I recognize that SSP and other systems would actually do something; but there are other ways than stack buffer overflows to execute arbitrary code. There's no guarantee that the SSP is used, too.
I've posted a working example, albeit working on a trivial host program, just to check/prove the feasibility of the technique whenever the /GS compiler switch is disabled.
Thank you for the great article.
http://www.mastropaolo.com/?p=13
Hey, you have a great blog here!
I have a ascii site. It pretty much covers ascii related stuff.
Come and check it out if you get time :-)
Free Blog Hosting Using Wordpress Blog Software At www.Blogsilla..com
Yo, you have a Terrific blog here! Lots of content means more readers, more readers means more interaction!
I'm definitely going to bookmark you!
I have a
slipstreaming sp2 window xp site/blog. It pretty much covers slipstreaming sp2 window xp Problems with your Windows Xp Computing !
Come take a Look when you get a chance. :-)
Hi Im not sure if ne1 can help me but Im hopeing sum1 can... jus recently when i restarted my com it first asked me to enter a pasword to log into windows, i had not set it up for that and this was the first time it happened.. i clicked ok and as soon as my desktop background came up I got a msg from Data Execution Prevention saying " To help protect your computer, windows has closed this program" Name - Userinit Logon Application. Publisher- Microsoft corporation. and when I click close msg, it says Userinit Logon Application has encountered a problem and needs to close and then nothing happens i only see the mouse and the back ground nothing loads up I formated my com and jus as i finished reinstalling most of my software when i restarted the com it happened again... What do i have to do to fix this or disable DEP???
welcome to the wow gold, cheap WoW Power Leveling, service site,wotlk gold buy cheap wow gold,wow gold,world of warcraft power leveling buy wow gold
buy wow goldbuy wow goldbuy wow accountbuy wow gold
Why was there no follow on bankruptcy then? The bailout of AIG FP went to (wow power leveling) hedge funds that bound credit swaps on Lehman failing or others betting on rating (wow power leveling) declines. AIG has drained over 100 billion from the government. Which had to go to those who bet on failures and downgrades. Many of whom (power leveling)were hedge funds. I-banks that had offsetting swaps needed the money from the AIG bailout or they would have been caught. Its an (wow powerleveling) insiders game and it takes just a little bit too much time for most people to think (wow gold) through where the AIG 100 billion bailout money went to, hedge funds and players, many of whom hire from the top ranks of DOJ, Fed, Treasury, CAOBO
wow goldwow goldwow goldwow gold CAOBO
buy wow gold,buy wow gold,cheap wow gold.buy wow gold,cheap wow gold,power wow power leveling,Buy wow gold.world of warcrft gold.
Compaq 371785-001 laptop battery
Gateway MX3562 ac adapter
DELL 710M laptop battery
Gateway CX2610 ac adapter
Gateway M320 ac adapter
Gateway CX200X ac adapter
Gateway CX2618 ac adapter
Compaq Presario M2000 ac Adapter
Gateway 4540GZ ac adapter
Gateway M500 ac adapter
Gateway 3040GZ ac adapter
HP DV9000 Lcd
MK911 ac adapter
PA-1900-05C1 ac adapter
HP DV1000 ac Adapter
hp 375143-001 ac adapter
B154EW01 lcd screen
Apple M8943LL/A ac Adapter
Gateway CX2608 ac adapter
Dell Latitude D610 ac Adapter
I like your blog, it's very good!
By the way, do you like spyder down jackets, I think they are very fashionable and chic, especially the spyder ski jackets, I love them so much. In my spare time, I also like playing tennis rackets, it can keep healthy, what do you like to do?
kids north face jackets
polo vest
polo jacket
abercrombie fitch mens shirts
polo jackets for men
polo jackets for women
burberry shirts for men
polo hoodies for women
columbia jackets women
polo sweatshirts for women
north face jackets on sale
polo shirts for women
polo shirts wholesale
spyder jackets
ralph lauren polo shirt
polo pants for men
abercrombie fitch shirt
wholesale abercrombie fitch shirts
polo vests
polo jackets
polo hoodies for men
burberry shirts for women
burberry shirts on sale
polo shirts for men
north face jackets cheap
north face jackets for women
north face jackets for men
polo sweatshirts for men
columbia jackets for men
columbia jackets discount
spyder jackets for men
discount spyder jackets
cheap spyder jackets
spyder jacket
spyder jackets for women
tennis racquets
cheap tennis rackets
discount tennis rackets
tennis rackets on sale
prince tennis racquets
head tennis racquets
wilson tennis racquets
babolat tennis racquets
Hello, everybody. I am a new hand to be here. So nice to meet you all. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
I like the side of the article, and very like your blog, to write well and hope to continue their efforts, we can see more of your articles. ed hardy clothes. After reading this article has strong feelings, the future will be ed hardy womens longsleeve.ed hardy longsleeve
ed hardy hoodies
ed hardy jeans
ed hardy
ed hardy clothing
ed hardy t-shirts
cheap ed hardy clothing
ed-hardy.co.uk
ed hardy shirts
wholesale ed hardy clothing
ed hardy outerwear
ed hardy mens outerwear
ed hardy womens outerwear
ed hardy clothes
ed hardy boots
ed hardy outerwear
ed hardy hoodies
ed hardy Jeans
ed hardy hoodies
ed hardy jackets
ed hardy womens jackets
ed hardy mens jackets
ed hardy bags
ed hardy trousers
ed hardy shoes
ed hardy longsleeve
ed hardy mens longsleeve
ed hardy womens longsleeve
ed hardy jackets
ed hardy suits
ed hardy clothing
ed hardy shoes
ed hardy jeans
ed hardy boots
ed hardy mens sweater
ed hardy womens cotton
ed hardy womens boots
ed hardy
ed hardy womens clothing
Your blog is wonderful, I like it very much, thank you!
By the way, do you like polo shirts, which are very chic, especially the polo t shirts, I love them very much. I also like playing tennis rackets, it can keep healthy, what do you like to do?
polo t shirts women
polo t shirts on sale
polo t shirts for women
polo shirts on sale
polo shirts men
men's polo shirt
men polo shirt
mens polo shirts
mens polo shirt
cheap polo shirts
discount polo shirts
men's polo shirts
women's polo shirts
cheap tennis racket
discount tennis racket
prince tennis racquet
head tennis rackets
wilson tennis racket
babolat tennis racquet
Post a Comment
<< Home