12
Aug

Windows Buffer Overflow Protection

   Posted by: Joshbw   in Secure Development

At Blackhat this year Mark Dowd of IBM and Alexander Sotirov or VMware presented a paper concerning how to bypass Vista’s Buffer Overflow Countermeasures. The paper is worth a read both because of the vulnerabilities, and because it does a great job detailing how much protection Microsoft has provided to people who can’t write good code. The analysis of the paper by various people on the Internet is mind numbing though (probably this post included).

Before continuing, I think some things need to be established up front. Vista provides protection that no other OS does against poorly written code. Even if the security features were completely worthless Vista would not be more dangerous than any other OS- just more dangerous than Vista from last month. This additional protection was meant to be a stop gap to secure bad code, not an excuse not to fix the bad code. The root cause is that some code sucks to begin with. It is like throwing a WAF on a wide open Internet app. That buffer overflows still exist to the extent they do is just disgraceful to us as an industry. We know exactly what causes buffer overflows and we know how to avoid them. Do not use unchecked buffer copies. Explicitly copy no more data than a buffer can hold (and please, please do not use inline calculations in strncpy, since that may as well be an unchecked buffer copy). Don’t dynamically create the first argument for *printf/*scanf without knowing exactly how many other parameters will need to be provided. And the list goes on. These are all things that static source code analysis tools are remarkably competent at finding. A clever source control system will flat out ban people from checking code in with bad APIs (strcpy and its unchecked brotheren). Finally, fuzz the crap out of all your input points (hey Jim, this is why input validation is important :-p). You will find and kill 99% of your buffer overflows if you do that, and the remaining 1% won’t be very discoverable (bad guys do fuzz testing too you know).

Anyway, there is a reason why MS has had a huge decline in buffer overflows relative to the industry, and it is because they do all of the above. They have too much legacy code and third party giblets to fully get rid of overflows, but all of the extra protection in Vista is primarily to provide some level of protection for the OS because a retarded third party (*cough*quicktime*cough*acrobat*cough*flash*cough) has yet one more buffer overflow that can be used to compromise the box. The protection was not a permanent fix, but simply something to raise the bar to perform exploitation, and I think Microsoft has been reasonably good about presenting it in that light while still trying to sell 3rd party developers on the protection. The biggest flaw in the protections that Vista presents is that applications opt into using them. Programs need to explicitly state they want the protection which is why the paper focuses on exploiting applications that do not have all of the protections (like IE 7 which doesn’t use data execution prevention because the poorly written piece of junk sun java plugin would blow chunks if they did; fortunately IE 8 does use it, as does firefox 3).

Now on to the commentary on the web. Peter Bright of Ars Technica tries to downplay it and many of his points are valid. Bruce Schneier thinks it is a big deal, which is true. A month ago people didn’t know how to bypass these protections but now they do. That is a big deal, but Adrian Kingsley-Hughes of ZDnet is still a moron for saying it renders Vista security next to useless.

So to respond to the commentary, the reason this is a big deal (moreso than Bright believes) but not the end of the world (as Kingsley-Hughes thinks) is that it makes exploits feasible but more costly. Any technological measure that increases the cost of exploiting something will decrease the number of instances that blackhats bother exploiting it. For example, to defeat ASLR the authors advocates hosting a .Net Web Component of sufficient size to dramatically impact how the address space can be randomized, and in order to facilitate downloads they also recommend the webserver hosting the component use gzip compression (which in turn means controlling web server configuration). That’s entirely possible, but if a malware author had the choice between an exploit targetting all of XP that didn’t require that extra work or an exploit for both XP and Vista, I suspect 90% will choose to just go after XP. (the exploit using Java applets is a bit more likely at the moment do to the GIFAR hack recently discussed, since you can very easily get hundreds of sites to host that for you).

On top of that, to bypass the multitude of protections requires some sophistication, which is just going to raise the bar on who crafts the exploits (well, until all of the bypasses are just built into metasploit). Raising the bar lowers the number of attackers capable of compromising the system.

Additionally, the easiest work around for DEP was to target applications that don’t use it, but this will become increasingly difficult, especially as MS enforces DEP to a greater degree. Finally, at least in terms of IE, one feature that was not addressed with the process isolation of the browser in Vista. It remains an open question on whether the IE sandbox in Vista is vulnerable, as it may still contain the attack.

So attacks are now possible, but the exploitability is still more difficult than other platforms. That’s big, but it by no means renders the protection next to useless. As the authors conclude

In this paper we demonstrated that the memory protection mechanisms available in the latest versions of Windows are not always effective when it comes to preventing the exploitation of
memory corruption vulnerabilities in browsers. They raise the bar, but the attacker still has a
good chance of being able to bypass them. Two factors contribute to this problem: the degree to
which the browser state is controlled by the attacker; and the extensible plugin architecture of
modern browsers.

At the end of the day, good OS design cannot completely mitigate bad code. Get rid of buffer overflows and this is all a moot point anyway. Its 2008 people, why aren’t buffer overflows extinct?

~ Joshbw

This entry was posted on Tuesday, August 12th, 2008 at 9:18 am and is filed under Secure Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 comments so far

DrPizza
 1 

“To to respond to the commentary, the reason this is a big deal (moreso than Bright believes) but not the end of the world (as Kingsley-Hughes thinks) is that it makes exploits feasible but more costly”

I would think that the cost increase is likely to be negligible. The paper comes with full source code that’s well-commented and pretty general.

“For example, to defeat ASLR the authors advocates hosting a .Net Web Component of sufficient size to dramatically impact how the address space can be randomized, and in order to facilitate downloads they also recommend the webserver hosting the component use gzip compression (which in turn means controlling web server configuration). ”

You don’t need a huge .NET DLL–the paper shows a couple of ways to make that a non-issue (either create a large padding section, or use a malformed header to make the assembly incompatible with ASLR). Hopefully the latter issue will be fixed sooner rather than later. The former will continue to be an issue until we move to 64-bit processes (it’s not possible to cover any appreciable portion of a 64-bit address space, so randomized 64-bit processes could be sufficiently sparse as to make ASLR decently robust).

In any case, Flash is probably the better vector, since it’s far and away the most widely deployed plugin, and never ASLR protected anyway. No need to circumvent what isn’t there.

August 12th, 2008 at 3:19 pm
Joshbw
 2 

I would think that the cost increase is likely to be negligible. The paper comes with full source code that’s well-commented and pretty general.

The difficulty for seasoned folks has not increased substantially but anything you do to make them take extra steps buys you something. CAPTCHAs for example are pretty much broken, but there is still value in having a good one. Determined attackers can still get through, but if your system is slightly more difficult than a similar size competing target people will tend to choose it over you. Vista can be broken, but is it worth the extra effort when it isn’t even needed for XP, a much larger target (granted you can get both going after Vista, but path of least resistance is usually the chosen one).

either create a large padding section

Yeah, that and the no-op segments were the best recomendations, but while the actual logic code of the binary is quite small in those situations the physical size would not be. To get around this they advocate using gzip compression so the physical size is negligable, but there are many servers that don’t have this enabled by default. Thus they would either own their own servers or be choosey in which compromised servers they use to serve the control. Either way simply introducing the need for a hosted control increases the cost of the attack, if one was trying to break ASLR rather than simply avoid it.

In any case, Flash is probably the better vector, since it’s far and away the most widely deployed plugin, and never ASLR protected anyway. No need to circumvent what isn’t there.

Well, quite true, and it is not as if flash is lacking in vulnerabilities at the moment. That said, the browser isolation of IE 7 was specifically designed with that scenario in mind, so I am quite curious if it mitigates this threat. The paper seemed very short on details concerning the browser isolation so I don’t know what conclusion to draw. I honestly would think it much bigger news that the logical isolation was broken so I’d love to hear confirmation one way or another.

I wasn’t trying to downplay that this is big, but some context is necessary. This is not Vista security rendered next to worthless as is being reported. The paper primarily targets browsers and many of the tactics will not work in, say, WMP, which is compiled with DEP and doesn’t have anywhere near as vulnerable a plugin model (even though in the past it was a popular target of buffer overflows). Additionally, while browsers were the primary target the paper was generally mum about the IE 7 isolation protection. Specific aspects of Vista security, very important aspects to be sure, but only specific aspects none the less are not as effective. That is hardly the end of the world, and I think the authors were pretty open about even those aspects going forward in new versions of windows (for example, 64 bit Win2k8 server which is much less susceptable because of policy enforcement).

August 12th, 2008 at 5:43 pm

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment