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 InfoSec 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 about Windows gadgets, of course, I have never had a good opinion about this but I would say that the price is not so bad. Yeah. So the question is, what is your opinion about Windows gadgets? And, I'm going to give you a long answer, but I love Windows gadgets because it's a great little thing to handle. So, I'm going to give you a few questions. Some of the questions So, we're going to have some questions. So, we're going to have some questions. I'm going to go through them all. Okay. Today we're going to go through a bunch of different things. First we're going to spend a 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, the 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 Itzik FX, Ian, Jason Street, SoftSec folks, Wim, Aviv, Raph, Galdiskin and Suzuki, I don't know how to pronounce that. But they helped us a lot, their work. Try this one. 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 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 your gadgets. You can use gadgets that range from a simple clock up to GPU performance handlers. They're very simple to use. A couple 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 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 we've seen from Windows XP is the concept of the active desktop. You can basically run little tiny things. You can go to the desktop and you can see the desktop 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 side bar. It was fairly simple. We'll show you in half a second. It looked like this. Literally it was just a side bar. 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 like in Windows 7. We're actually both quite fond of the Pandora gadget. It's a fairly handy thing to have. It's literally just a way to listen to Pandora on the system. I think I was listening to Ween at that time. These are some other examples besides the ones that 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 five days in the three weeks to convince me to do the research. 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 to be a problem. And so we're going to continue to be a problem. And so we're going to continue to be in 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. Yeah, it's a zip file. The 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 have a CSS folder, images folder, JavaScript folder, a couple of HTML files, code and code files then a few This is neon CAD 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. It can get simpler. This is the template. This is the HTML template. You can also develop gadgets with silver light. It's even more 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. Microsoft actually provides a very detailed explanation of security, you can see in the description. 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 is 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 an 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. You can find that on the Microsoft website. we saw out of 60 or 70 gadgets that we were able to pull down, one or two, maybe three. One vendor. 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 I'm 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? Okay. Just checking that there was actually a difference in response. So, I'm going to go ahead and show you the difference. 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 is you can instantiate any ActiveX 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 exact from the gadget can then itself raise a UAC prompt and since you can use, for instance, the ActiveX shell dot run function or shell dot 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 a 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 basic things that you can use, do via GPO. You can manage them in a couple different ways. One, you can turn off the side bar 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 you can do a lot of things. 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'd 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? Yes. Okay. As far as I know, I guess since neither of us 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 anything about the metro app. Any other questions? Yeah. I think the question was, is Microsoft really going to move the 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 first things that we're going to do is we're going to run a little bit of code. And 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. 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 exact code. Do I need to do anything? Well, just in case anyone's 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 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. You want to run it? Let's see. Let me make sure this works. Proxy setup is going to be one. Maybe a little one. No, I think that was the, never mind. Just type it in Gmail. We're going to show you a little demonstration of what you can do with a malicious gadget. Just going to make sure I'm connected. Okay, so. 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. And a little explanation. The gadget opens Gmail assuming, well, quick question. How many of you use Gmail? Okay. How many of you, yeah. How many of you make sure you log out after you and stop using Gmail? Every single time? Every single time. How many of you are lying? That's not good. What the? Okay. Can we get sound from, okay. I apologize in advance. You should be so ashamed. I'm sorry. Select contacts. Select them all. Create a new email. Add a subject. Add a link. And we'll send it. Then, when it's done, it will close the window. . All right. Now, just to clarify how is this. First of all, I would like to stress that there is no security vulnerability in Gmail. It's kind of workaround for a setting. Gmail allows users to use keyboard shortcuts. And to enable that, usually what you do is to go in to settings and select an option saying enable keyboard shortcuts. However, if you're However, if you open a URL with KBD equals one 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. 16 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's got all of the access it needs to all of your functions. 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. And it's not just about the web. It's about what it can do, basically. We actually ran out of time to find out all of the things we kept finding. We'd try something and say, oh, that's possible. 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? Unfortunately, they're just common. I've had a lot of teams that're just doing the 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? No. 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 are used to doing development and they 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 are used to doing web development in which case you'd see one big HTML file that contained everything, 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 pillages. 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 structure. So it's a lot of different styles. So you'd see a lot of different strategies which is just find some gadgets, analyze them, pause, and profit. So what did we find? Well, when you start 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 kind of SSL we found was the 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 interesting educations. You want to give them the run down? 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. Saw a lot of connections to ad servers that seemed 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. Literally the paths are, 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're not listing that there's anything compared or 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, but 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. You're going to end up with this kind of flaw. 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 reference and just took and implemented a directly into everything. Baseband for satellites, cable, ISDN, SNMP, everything uses ASN1. And 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 could easily sniff traffic and it was phenomenally easy to spot. Mickey really likes this one. Yeah. This is a funny one. As we're 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. It's a little bit more complicated. UA dash 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. Except here, yeah. The only use that we've seen is in gadgets, 64 bit platforms. 32 bits are unsupport. The 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. The only use that we found with those And we have no official numbers, but we assume that most of the Windows 7 machines are 64 bit based. So I 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? 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 a lot of text. You can't expect someone to do it properly. And 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 Miller demonstrated except it's a little bit more complex and 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 check or header that you can check for. You can use something as simple as HTML. You can use something as simple as HTML. You can use something as simple as Zerpone. 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, though, you couldn't just do a race attack and do an injection without actually having to use a proxy for this. Okay. . . Oh, okay. . . . . . now. What we have here is proxy running in this window. Bottom right window. Proxy set to listen to gadget traffic and intercept it and replace the response with something interesting. I'm going to display this using ‑‑ yeah. No, that was just the port that we set up for the proxy. The question was does all gadget traffic hit 8181? 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 Neon Cat which you have 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. Hello, this is your computer. I'm tired of the way you have been treating me. I am going to self‑destruct in five seconds. Goodbye. 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, there 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. Here we go. Imagine hearing that when you least expect it. So the simple example we gave you of a 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 working. So I'm going to show you 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, excuse me, serving a file. In this case, the file it's serving is a very simple metasploit meterpreter 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 meterpreter or metasploit waiting for a recurrent connection and as Mickey already showed you, you've got a proxy in this corner. You've got a proxy in this corner. And we're going to do one small change the 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 straight forward. So 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 message that says, this is a file to the desktop. 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 start-up folder. You can write anywhere the user has permissions to. But notice there is no prompt that you're running an unsigned binary. Notice there is no prompt that you were kicking off anything from a script or running a script. All you saw and one last thing, the gadget's functional. 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 see the exact code for an example. Now, the interesting thing about this is that if you run the exact function from JavaScript, it will warn you that you are trying to execute something that's not signed from an untrusted zone. It tries to do the right thing. However, if you run a binary from PowerShell, it doesn't warn you at all. Now, of course the default policy for shell 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 power shell attacks and documented some really nice power shell 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 power shell script which is meant to execute the binary and then it writes a batch file which is used to bypass the power shell policy so that you've got a batch script running power 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. 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 that you're asking for JavaScript from. Any time 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 that 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. It's going to be a problem. It's going to be a problem. 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. I'm going to go back to this. 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 Raff in 2007. That's five years ago. There's been prior work by Ian and Aviv on DEFCON 15. And Yitzik and Jonathan for the Jenks 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 I'm going to turn it back over to you guys. Thank you. 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. We've got only a couple of minutes. After that, we're going to be in the Q&A room number four, right? So I guess maybe we'll move to the QA room and take questions there. Thank you. Thank you.