My name is Toby, this is Mickey. We're glad you could make it this morning. We're going to talk to you about Windows gadgets. First, our standard disclaimer, none of this has anything to do with anyone we've ever worked for, do work for or might ever work for in the future. We have our own opinions. They have no opinions about anything and the two connections aren't connected in absolutely no way, shape or form. They have no knowledge of anything we do ever and they're not even sure we exist. Well, aside from not being sure that I exist, my name is Toby. I'm a senior info sec geek for a Fortune 50 company. I do all sorts of things that mostly involve telling people their ideas are bad and then trying to keep their ideas from being compromised once they insist on doing them anyways. And an opinion in a loud mouth. That too, you forgot to say that. My name is Mickey. I used to work for a Fortune 50 company. I used to break software firmware and hardware in my spare time and well, that's it basically. We're going to keep do-si-do-ing because we don't have wireless mics. Excuse us for being a bit rough this morning. Today we're going to go through a bunch of different things. First we're going to spend some little time. We've already talked about who we are. We're going to talk about what gadgets are. By the way, you all know we're talking about Windows gadgets, right? Yeah? We're good? Okay. We're going to tell you a little bit about what Windows gadgets are. A little history, little details about them. Then we're going to go into what's wrong with them. We're going to talk about first attacking with gadgets and then we're going to talk about how you can attack gadgets. Then we'll spend a little bit of time talking about once it's all done what you can do about it and what the solutions are. Long term, short term solutions that Microsoft chose and otherwise. A couple of thank yous because this talk is based on civil things made by other people. And the support of other people. So I'd like to thank Ethics, Ian, Jason Street, SoftSec folks, Wim, Aviv, Raph, Galdiskin, and Suzuki, Sal, Mitsuki, Mitku, I don't think I pronounced that. But they helped us a lot with their work. Also, CG, or not. I guess we'll use that. We apologize. Clearly technology is complex and we're not very good at it. Also, CG from Carnal Ownage blog for his work on PowerShell bypass, PowerShell Metasploit, and just being a lot of fun to read. So for those of you who don't own Windows systems, what are gadgets? Gadgets are those tiny little applications you have on your desktop and you do a right click and it's like gadgets. You can use gadgets that range from a simple clock up to GPU performance handlers. They're very simple to use. A couple of examples on screen. Those are the default Microsoft gadgets. The CPU clock, the RSS feed, and the weather. A little history about gadgets. The first references we've actually seen documented were to show the active desktop in Windows XP. Over the course of the last week or so, we've had a couple of people mention that they remember seeing similar things that there was actually an active desktop in 98 as well, but we weren't able to find any traces of it or any documentation on it. So the first thing that we've seen from Windows XP is the concept of the active desktop. You could just basically run little tiny things on the desktop and get dynamic updates. It was fairly simple. In Vista, they started moving around, moving to the concept of actually having something called a gadget. They had the sidebar. It was fairly simple. We'll show you in half a second. It looked like this. Literally it was just a sidebar. All of the things ran along it and were very tightly tied to it, but they were referred to as gadgets. In Windows 7, they actually did a significant number of improvements to the capabilities. First, they combined it to a single process. They made it much easier to manage them. They could be placed all over the desktop. They also added a number of new capabilities to make it easier to develop and they added a bunch of enterprise security features. The development points are obviously irrelevant at this point. So Windows Vista, this is what it looked in Windows 7. We're actually both quite fond of the Pandora gadget. It's a fairly handy thing to have and it's literally just a way to listen to Pandora on the system. I think I was listening to Wien at that time. But these are some other examples besides the ones you saw previously. So the question is, why does this matter? To be quite honest, Mickey came to me and said, we should do this. And I said, why would anyone care? It took him about three weeks to convince me. Yeah, you tell me. About three weeks to convince me to do the research. And frankly, it's not news. If you write bad code, you're going to get compromised, right? If you run somebody else's code on your system, they're going to compromise you, right? This isn't novel. Turns out, though, the same issues that made this an actual interesting target and a problem are being moved forward consistently as a clear and enthusiastic business model. We're seeing everything being done by vendors to try and make it easier and easier for people who have less and less experience and knowledge about development to actually do development. And so the sorts of mistakes that we found and that we were able to exploit and take advantage of on these systems are going to continue being common as long as you can do something as silly as write an entire application in JavaScript and HTML. So a little bit of what is a gadget. A gadget is a zip file. Technically, it's a zip file renamed to be .gadget. If you didn't get that, that's cat.zip. A gadget has several screens on it. The main one, which you see when you use a gadget, there is an about, a fly out, and a setting screen. As you can see, they have correlating HTML files. This is, by the way, the simplest directory structure for a gadget. You've got a CSS folder, images folder, JavaScript folder, a couple of HTML files. This is, sorry, this is NeonCAD gadget, which you'll see soon enough. The part that is not standard is the gadget.xml, which is the gadget manifest. It holds the information on a gadget, manufacturer, copyright, URLs, permission level, which is always set to full and is expected to be full by Microsoft for some reason. And, well, did I forget anything? It can get simpler. This is the template. This is the HTML template. But you can also develop gadgets with silver light, so it's even more simpler. It's simpler. English is not my first language, I apologize. WPF and silver light will make it easier to code malicious code into your gadget. So a little bit about the security model. Microsoft actually provides a very detailed explanation. We were surprised by how much effort Microsoft has put in to documenting the security model and to documenting good security practices for writing gadgets, especially considering the general lack of security quality we found in the development of gadgets. They didn't, for lack of trying, we didn't see quality for lack of Microsoft trying to do it right. What we're going to do though is we're going to call out some of the highlights of the security model. And if you want to see more, you can still find the documentation for it on Microsoft's site. There's a URL in the background. First, code signing is actually possible. It's not standard. It's not common. It isn't required, but it is absolutely possible. We saw out of 60 or 70 gadgets that we were able to pull down, one or two, maybe three. One single vendor and not very many gadgets from any vendor that were actually signed. The prompt looks pretty similar to the actual installation for any standard application. The action behind it is much less complex in that it's just dropping everything into a directory, but making a couple configuration changes, very small stuff. But as you can see, it looks pretty standard. Show of hands, who's familiar with an HTML application, HTAs? Show of hands, who can give me the square root of 1,563? Just checking that there was actually a difference in response. So, they're fairly similar to HTAs, HTML applications. There are some differences in that they still run in the local machine zone, but they have some additional privileges that you wouldn't otherwise be able to take advantage of. And they have some limitations that aren't always in place. First, one of the advantages and something we found tremendously useful, you can instantiate any active X object on the system. Doesn't matter what it's for, doesn't matter whether it's a reasonable or sane thing to be able to do from an HTML function, you can do it from here. However, you can't actually kick off a UAC prompt. Doesn't matter what privilege you're actually running as for the user, this is always going to run as a standard user, even if you're in the admin group. On the other hand, any process that's been exec'd from the gadget can then itself raise a UAC prompt. And since you can use, for instance, the active X shell.run function or shell.exec function, you can still pretty much do what you want from here. Parental controls do apply as you would expect for any HTML based thing. It's running in an IE container. It's just a modified set of permissions to do so. Anything? Want to add anything? Some of the enterprise features that were added in Windows 7, there are a couple of basic things that you can use, you do via GPO, you can manage them in a couple of different ways. One, you can turn off the sidebar completely as a function. Two, you can set policies to control unpacking and installing of Windows gadgets that aren't signed. Unfortunately, this doesn't actually prevent somebody from installing them manually. And it doesn't remove gadgets that have already been installed. It just prevents new ones from being automatically installed when they double click and want to run them. You can disable user installed gadgets which is basically just locking down the permissions for a specific directory. And finally, you can actually override the get more gadgets online link which is now dead anyways. So at this point, normally I know the standard is to ask questions at the end. Feel free though, does anyone have any questions about anything we've covered on the development side of it that you want to ask now? Yeah. The question was is there any concept of this moving to Windows 8. Do you mean is there anything being done in Windows 8 that has a similar sort of idea behind it? Okay. As far as I know, I guess since neither of these work for Microsoft, we can speculate wildly. But as far as we know, you've got the metro app store sort of thing that is similar, but it's wrapped in the app container capability which locks it down much, much more tightly. And I haven't looked at the development for the metro app so I don't know if you know anything about metro app. Any other questions? Yeah. Okay. I think the question was is Microsoft really going to remove gadgets from Windows 8 or something? Or are they going to make it optional? Our understanding is they removed the feature completely. Other questions? Okay. Attack surface. We're going to now go into a little bit of the attacking actually through gadgets and with gadgets. We're going to start off with attacking with gadgets. One of the fundamental problems here is that it's just another piece of code somebody is running. We've all known for 20 years that if you download and run someone's code, you're going to get compromised. That's what happens. Unfortunately people don't actually think of gadgets for some reason as code. We weren't quite sure why. Mickey speculated that it was because they're cute and small and run around with little hats and pants on all the time. So he took a picture of them. Honestly, they are just as dangerous as any other piece of software. So the question is what can you do with this? Well, is it really just another piece of software after all? It's just this little tiny container thing. It shouldn't have all the capabilities that you would expect. Here are some of the things that you're actually able to do from a gadget. I can't do everything I might want. Well, oh yes, wait a minute, I can. I can exec code. Do I need to say anything? Well, just in case anyone is curious, you can also open URLs. So if you didn't want to carry something with you in the HTML that you're downloading with the gadget, you can go get more. If you want to change what you downloaded, you can do that too. You want to update? No problem. You want to create files with arbitrary content, binary or otherwise on the system? We can do that. You want to be able to read files? Anything that the user has permission to, you're good for. And if you want to get past that permission, obviously you can just spawn something and raise the UAC prompt and do so. Make your computer speak? Sure. You can do that too. And I guess we should actually show you what that looks like. Want to run it? We're going to show you a little demonstration of what you can do with a malicious gadget. This is a POC of a gadget that will self-spread to all your contacts. It is not fully weaponized, it's just a POC. A little explanation, the gadget opens Gmail. Quick question, how many of you use Gmail? How many of you make sure you log out and stop using Gmail? Every single time? How many of you are lying? That's not good. Can we get sound from... okay. I apologize in advance. You should be so ashamed. Now we are back. Create a new email. Add a subject. Add a link. And we'll send it. And when it's done it will close the window. Now, just to clarify, first of all, I would like to stress that there is no security vulnerability in Gmail. It's kind of a work around for a setting. Gmail allows users to use keyboard shortcuts. And to enable that, usually what you do is go into settings and select an option saying enable keyboard shortcuts. However, if you open a URL with KBD equals 1 in the query string, you will get that feature enabled. And gadgets very easily send keystrokes to the screen. This is the code that sends the Gmail. Sixteen lines. That's how simple this is. So, simple example, you saw what can be done. Very standard malicious sort of gadget activity. The key is that it's got all of the access it needs to all of your cookies and all of the information in your browser, which means it also has your proxy configurations. It can manipulate anything else it wants on the system. It's got all of that state that you're giving it at any point in time. Another addition. We discovered also that gadgets can also read map network drives, delete map network drives, handle map network drives, add them. Everything that Windows supports, it can do, basically. We actually ran out of time to find out all of the things we kept finding. We tried something and say, oh, that's possible. How about, oh, that's possible. It just kept going. So, you've been something, we've talked about attacking with gadgets. Simple demo. Hopefully you understand it is just a POC. The question is now, what can you do in terms of attacking gadgets? Well, unfortunately, they're just code. And in many cases, they're written by people who don't have a lot of experience writing code. It was fairly interesting as we went through the collection of gadgets and we found about, is that a question? I'm going to attack? Okay. We found about 65, 70 gadgets that were floating around that people were actually using. And it was very easy to distinguish between the gadgets that were written by people who were used to doing development and they'd break it down as you'd expect with any developer in terms of having separate files for different function families and all sorts of clean object-oriented design and people who were used to doing web development, in which case you'd see one big HTML file that contained everything in the JavaScript. And you can do this. It's really just a web page to some extent that's running locally with a lot of extra privileges. So you'd see a lot of different styles. And of course, that leaves you with a lot of vulnerable systems. So you end up with a fairly basic strategy, which is just find some gadgets, analyze them, pause, and profit. So what did we find? Well, when you started looking around, we found a lot of sites offering malware that were claiming to be gadgets. We found a fair number of gadgets, but we found more in terms of total number of sites that were offering it, there was more malware out there than there were actual gadgets. We found really limited use of SSL. In fact, the only consistent cases that we found SSL being used were in the cases where the websites that were being connected to required it. Otherwise, they didn't use it. And we actually found a couple of interesting educations. You want to give them the rundown? Yeah. We saw one use, one good use of SSL in a gadget. But the funny thing was that the website hosting the file that was being accessed through SSL also hosted it in normal HTTP. So all you got to do is SSL strip and you win. And this is the sort of behavior that we saw. That was actually some of the more well intentioned behavior we saw. Most of the time we didn't even see that used. So a lot of connections to ad servers that seem to have no purpose for the gadget. They never notified the user that they were being connected to. They never prompted the user for any permission or activity around it. It was just generically run. We also found that there were a small number of producers that produced all the gadgets which meant that there was a lot of shared code. At one point, Mickey got this random text from me saying, there's something really strange going on. I've got gadgets that are coming from different sources that have the exact same update patterns in their fully qualified domains. He said, no, that can't be right. I said, the paths are exactly the same. We start looking into the domains a little bit and they have not listed anything related between them. We find out they're owned by the same company and that the developers are the same and all of a sudden it makes sense. They're using the exact same code base. There's just no reference. Question? The question is, was there any warning for self-signed certs or anything like that? Certainly you would hope to see that and we did not. We also didn't see any prompting for cookies. Now, that may have been the configuration. I don't think so because we tried it with about half a dozen different configurations and it just didn't seem to prompt the way you would expect. So the interesting thing is that if you find something in one gadget, you're probably going to find it in other ones as well. This comes up a lot in any framework. If you're building a framework and a lot of these are built from simple frameworks, you're going to end up with shared flaws. This is just another instance of shared code giving you underlying problems. How many remember the ASN1 bug? One, two, really? Wow. Okay. ASN1 is an underlying parsing protocol that the U.S. government defined. They offered a reference implementation of it that nobody bothered to use as a baseband for satellites, cable, ISDN, SNMP, everything uses ASN1. So there was this really pernicious flaw that showed up everywhere because of the shared code problem. It was a long-lasting flaw. So like we said, we found a bunch of actual really poor practices which led us to plenty of options for how to inject code. Your default permissions were full. We found it was phenomenally easy to spot. Mickey really likes this one. Yeah. This is a funny one. As we were looking through traffic, seeing what the gadgets send through HTTP requests, on 64-bit platforms we noticed that gadgets will send a request, every request will be sent with an HTTP header. UA-CPU. Does anyone know what that header is? Show of hands. Okay. That header is to indicate the kind of platform you're using. As far as I know, I can tell from the large scope searches I did online and Wikipedia, which is not really accurate most of the times. UA-CPU has been used in IE3 and 4 and has not been used since. Except here. The only use that we've seen is in gadgets on 64-bit platforms. 32 bits are unimportant. More interesting thing is most of the systems that I've been in contact with through all my corporate life experience have been Windows 64-bit machines. And we have no official numbers, but we assume that most of the Windows 7 machines are 64-bit based. So I've got to do a sniff to traffic and you'll see it. Easy to spot. It was. So SSL, we all know it's really complex. It's not like there's good references for it. It's not like it's well documented. There certainly aren't libraries that are available for everyone to use. It certainly hasn't been explained again and again and again and again and again how to do it right. So why would you expect anyone to do it properly? And since you can't expect someone to do it properly, what you end up with is a strange habit where gadgets want to update themselves. It's reasonable. Auto update is a reasonable thing, but what we found was you have clear text downloads of updates. And since gadgets are written in JavaScript and HTML, what you've got is clear text download of JavaScript and HTML, which is then fully updating the entire cache of the gadget itself, which means you've just replaced all of the code for the gadget, which unfortunately means that whatever you looked at at the beginning may have absolutely no reference or relevance to what is actually going on, to what's actually executed. This is sort of like what Charlie Milley demonstrated, except nowhere near as complex or challenging and not quite as cool. Well, nowhere near as cool, frankly. But the same sort of consequence. You think you get one thing and you get something completely different. As a result, it makes it really simple to perform a man-in-the-middle attack. As Mickey pointed out, there's a really simple HTTP header that you can check for. You can use something as simple as earphone. To be clear, the demos we're showing you and the demos that we've done, we're using a proxy. We're actually doing full man-in-the-middle. We configured a proxy. This isn't because it's required. It's because the demo gods are capricious and fickle and really, really nasty. And we just don't want to have any more variability in it than we absolutely have to. There's no reason that you couldn't just do a race attack and do an injection without actually having to use a proxy for this. Okay. So, I'm going to talk a little bit about this for now. What we have here is a proxy running in this window, bottom right window. A proxy is set to listen to gadget traffic and intercept it and replace the response with something interesting. I'm going to display this using... yeah. I'm going to show you this. No, that was just the port that we set up for the proxy. The question was, does all gadget traffic hit 81, 81? No, that was just the proxy port that we chose because it was a nice number. No meaning otherwise. The question is, is it typically using any... gadget traffic is just running in an IE process, so it's going to use whatever ports IE is configured to use. By default, it will use 443, 80. If you've got a proxy that's on an off-numbered port, it will use whatever is on the off-numbered port. So this is the normal screen in Windows, the default gadgets. The only two different ones are the Nyan Cat, which you've already seen, and the Piano. The Piano gadget is, this one is exactly the one that was in the Microsoft gallery, live gallery, before they killed it. No modifications have been done to it. Reminder, this computer is running through a proxy right now. The gadget isn't supposed to do that. That's, by the way, three lines of code. The hardest part of that was actually, well, that wasn't really a hard part of that one. That was an easy one. To be fair, your computer does complain at you a lot. Imagine hearing that when you least expect it. So the simple example we gave you of running just injection, making your computer say something, this is kind of cute, trite, a little silly. We've seen it before. The question is, of course, can we get a shell? That's always the real interesting question. And the interesting thing is, as we said, since you've just got the ability to write anything you want to the system, and you've got the updates in many cases, or not even the updates, you've got the request for HTML and JavaScript running in clear text, and it's going to then go execute your JavaScript and parse your HTML, you've got a tremendous amount of power in the process. You can write any scripting language you want to the system. You can exec anything you want. In our case, we started playing with PowerShell. So at this point, that's not what we want right now. Okay. So what you've got now is three windows. Top left is a simple HTTP web server that we set up. It's serving a shell. Serving a file. In this case, the file it's serving is a very simple metasploit interpreter reverse TCP shell. We didn't do any modifications by itself. This shell would be detected by any decent antivirus. That's purely for POC because we're lazy. The fact is obviously that you could download any binary that you want, and you could write anything you want. In the upper right corner, you've got metasploit waiting for a connection, and as Mickey already showed you, you've got a proxy in this corner. We're going to do one small change to payload that's delivered. Because it is a gadget just like, or because it runs in the IE process, you've basically still got to clear the cache. It'll store things. There were a number of times where one of us or the other would forget and try to figure out why something suddenly stopped working. It was more than a little frustrating. But it's pretty straightforward. What you're going to see from this side is not particularly exciting. Fairly intentionally. From this side, all you get is that. All you see is a file written to the desktop. Now, this is for a POC. We chose to write to the desktop. You can write anywhere you want. There's no reason you have to write to the desktop. You can write to the startup folder. You can write anywhere the user has permissions to. But notice that there was no prompt that you're running an unsigned binary. Notice that there was no prompt that you were kicking off anything from a script or running a script. All you saw. And one last thing, the gadget is functional. Still works. In contrast, what you see when you've got back here is that you see the request was detected and injected. You see a request here for the URL and for the file that it downloaded. And over here, what do we have but actually a Windows shell. So, you can in fact... Now, the interesting thing about this is that if you run the exact function from JavaScript, it will warn the user that you are trying to execute something that's not signed, that was downloaded from an untrusted zone. It tries to do the right thing. However, if you run a binary from Power Script, PowerShell, it doesn't warn you at all. Now, of course, the default policy for PowerShell is you can't run scripts on the system. Luckily, CG and some of the other folks out there have been looking around and talking about PowerShell attacks and documented some really nice PowerShell policy bypasses. So what we're actually doing in this attack is we are using JavaScript to write, first to pull down the binary onto the system, then it writes a PowerShell script which is meant to execute the binary and then it writes a batch file which is used to bypass the PowerShell policy so that you've got a batch script running PowerShell, executing the shell, the result of which is the user sees nothing and it bypasses all of the basic controls on the system to do so. It was actually mostly the pain in the neck of getting all of that escaping properly set up between multiple languages and getting it to write to the disk. So, at this point you can see, we feel pretty comfortable that you've got complete compromise of the system. We've owned it, you've got shell, we can do this with anything you're asking for JavaScript from. Anytime you ask for JavaScript with a gadget, we can do this. What do you do about this? It's fun to find flaws, but you've got to find something you can do about this. Well, at a basic level, if you're going to write applications, you have to remember code is code. It's going to be vulnerable. If you're going to download and execute stuff, don't take candy from strangers. Think about what you're downloading, think about what you're executing. If you're someone involved in writing an application framework, and this is an open request to anyone writing application frameworks, if it matters that something be done properly, don't leave it to chance. The easier you make it for people to write code, the less well written the code will be and the less experience they're going to have writing code. Finally, there's always Microsoft's solution, which is they removed the feature completely and they moved over to the Windows 8 model, which has the app container instead, which has much, much tighter controls over it completely. They're moving into the Windows Store, they've updated all the documentation for developers and everything else. This research could not have been done without the help of others. Interesting history. The three CVEs you see are remote code execution in default, Windows, Gadgets and Vista. Reported by Aviv Raf in 2007. That's five years ago. There's been prior work by Ian and Aviv on DEF CON 15 and Yitzik and Yoratan for the jinx malware for a lot of reference. Even though it's not listed under the references, the fact is that all of the functions we found, the PowerShell policy bypass, all of those things, we borrowed proudly and stole enthusiastically from people who did and published and were good enough to share the original research that they found. We couldn't have done it without them. So if you've got any interest, there's additional references here and at this point, if you've got questions, we're happy to take them. And we've got only a couple of minutes, after that we're going to be in the Q&A room number four. So I guess maybe we'll move to the Q&A room and take questions there. Thank you.