1 00:00:00,000 --> 00:00:04,660 Hello, everyone. Welcome to our talk, and welcome to DEF CON 0x0F. 2 00:00:05,380 --> 00:00:10,100 Let me just do a brief introduction, since this is our first time ever presenting at DEF CON. 3 00:00:10,740 --> 00:00:14,860 I'm Ben Feinstein. I'm a security researcher with SecureWorks in Atlanta, Georgia. 4 00:00:15,380 --> 00:00:21,020 My background is primarily as a software engineer for a variety of security tools and security products, 5 00:00:22,320 --> 00:00:25,160 and I have a background early on in IDS. 6 00:00:25,160 --> 00:00:30,760 To my right is Daniel Peck. He's also a researcher with SecureWorks, 7 00:00:30,800 --> 00:00:34,080 proud graduate of the Georgian Institute of Technology. 8 00:00:35,200 --> 00:00:41,220 He's likely our strongest reverse engineer and jack-of-all-trades in a lot of other tasks 9 00:00:41,220 --> 00:00:43,420 that we tackle on the research team in Atlanta. 10 00:00:45,520 --> 00:00:51,300 So our talk involves malicious JavaScript, and for some of you, you may ask the question, 11 00:00:51,500 --> 00:00:52,500 why should you care? 12 00:00:53,200 --> 00:00:55,040 Well, if you've seen some of the talks, 13 00:00:55,160 --> 00:00:57,360 this week over at Black Hat and here at DEF CON, 14 00:00:58,140 --> 00:01:02,100 you could see that JavaScript is a pretty severe security problem. 15 00:01:03,140 --> 00:01:12,540 A lot of malware and spyware downloaders use JavaScript to get malicious code onto your system and execute it. 16 00:01:12,960 --> 00:01:17,940 As we've seen with some interesting talks this week, browser exploitation is a major topic. 17 00:01:18,340 --> 00:01:23,200 Basically, dynamic scripting in the browser can be used to basically use your browser 18 00:01:23,200 --> 00:01:25,140 as an attack point into your internal network. 19 00:01:25,160 --> 00:01:33,060 Also, scripting is frequently used for information leakage purposes, such as your browser history, 20 00:01:33,420 --> 00:01:40,600 cookies you have stored on your system, lists of sites you frequently go to, stored passwords 21 00:01:40,600 --> 00:01:42,980 and credentials that are cached in the browser. 22 00:01:43,540 --> 00:01:49,940 So basically, JavaScript has access to a lot of dangerous information and a lot of pretty 23 00:01:49,940 --> 00:01:51,220 severe functionality there. 24 00:01:51,700 --> 00:01:55,140 What we're primarily looking at today is its use as an evasion tool in the browser. 25 00:01:55,140 --> 00:01:57,100 and security bypass technology. 26 00:02:00,320 --> 00:02:03,200 So just to give a real brief background of JavaScript, 27 00:02:03,620 --> 00:02:06,400 I apologize for those of you that you're already familiar with this. 28 00:02:06,600 --> 00:02:09,720 Back in the 90s, Netscape came up with this concept 29 00:02:10,920 --> 00:02:12,260 in their early browsers, 30 00:02:12,420 --> 00:02:15,080 and the idea really was to offer a scripting language 31 00:02:15,080 --> 00:02:18,260 so that website authors could make the browser experience 32 00:02:18,260 --> 00:02:19,360 richer for the user. 33 00:02:20,100 --> 00:02:22,740 After Netscape introduced JavaScript, 34 00:02:22,740 --> 00:02:26,580 Microsoft came along with their own version called JScript, 35 00:02:26,860 --> 00:02:30,920 and eventually it was standardized under ECMA or ECMA script 36 00:02:30,920 --> 00:02:33,660 under the auspices of the ECMA group. 37 00:02:34,880 --> 00:02:37,880 And what is not generally understood 38 00:02:37,880 --> 00:02:41,980 is that a lot of parts that we associate with JavaScript 39 00:02:41,980 --> 00:02:43,280 aren't really part of the standard. 40 00:02:43,640 --> 00:02:45,900 One example of this is the document object, 41 00:02:46,120 --> 00:02:49,540 which is really defined in the browsers. 42 00:02:50,380 --> 00:02:52,720 It's typically just an extension in the browser, 43 00:02:52,720 --> 00:02:56,140 and it happens to be mostly compatible across them, 44 00:02:56,240 --> 00:02:58,700 but if you've ever tried to write scripting 45 00:02:58,700 --> 00:03:00,620 to work reliably across a lot of these browsers 46 00:03:00,620 --> 00:03:03,080 for website purposes, it can be a challenge. 47 00:03:03,720 --> 00:03:06,960 And one of the reasons this is a security issue 48 00:03:06,960 --> 00:03:10,520 is this JavaScript tends to blur the line 49 00:03:10,520 --> 00:03:11,540 between data and code. 50 00:03:12,360 --> 00:03:14,380 And what I mean by that is that 51 00:03:14,380 --> 00:03:15,880 to a lot of security devices, 52 00:03:16,440 --> 00:03:19,240 the JavaScript that's coming back from a web server 53 00:03:19,240 --> 00:03:20,680 is really just viewed as data. 54 00:03:20,960 --> 00:03:22,260 It's simply part... 55 00:03:22,260 --> 00:03:24,420 The response of that web request that you sent 56 00:03:24,420 --> 00:03:25,600 and it's coming back over the wire. 57 00:03:25,920 --> 00:03:27,680 In reality, it's code, 58 00:03:27,900 --> 00:03:29,840 and it's going to be dynamically interpreted 59 00:03:29,840 --> 00:03:32,140 and executed inside your browser 60 00:03:32,140 --> 00:03:33,960 running on your local area network. 61 00:03:34,880 --> 00:03:36,780 We'll talk about that a little bit more later. 62 00:03:38,980 --> 00:03:40,660 So, like all great tools, 63 00:03:41,330 --> 00:03:42,340 or all great technologies, 64 00:03:42,600 --> 00:03:44,920 there tends to be feature and functionality bloat. 65 00:03:46,180 --> 00:03:50,260 A lot of this involves AJAX and Web 2.0 technology. 66 00:03:51,180 --> 00:03:52,080 The XML, 67 00:03:52,260 --> 00:03:53,460 HTTP request object 68 00:03:53,460 --> 00:03:56,140 is a very powerful part of JavaScript 69 00:03:56,140 --> 00:03:59,980 that allows you to really asynchronously control requests 70 00:03:59,980 --> 00:04:02,320 to and from the browser and the web server. 71 00:04:03,020 --> 00:04:04,900 And, as our experience has shown, 72 00:04:05,680 --> 00:04:08,640 more features always equals a larger attack service 73 00:04:08,640 --> 00:04:09,420 which to exploit, 74 00:04:09,600 --> 00:04:12,620 and greater potential for security-critical bugs. 75 00:04:16,580 --> 00:04:18,300 So, I'll hand off to Daniel. 76 00:04:18,360 --> 00:04:20,880 He'll talk a little bit more about the Web 2.0 effect. 77 00:04:22,260 --> 00:04:23,700 Web 2.0, ain't it grand? 78 00:04:24,100 --> 00:04:26,580 If you've tried using a browser lately 79 00:04:26,580 --> 00:04:27,980 with JavaScript turned off, 80 00:04:28,080 --> 00:04:32,700 using the NoScript plug-ins for Mozilla 81 00:04:32,700 --> 00:04:34,840 and various other things to turn off JavaScript, 82 00:04:35,160 --> 00:04:36,960 it's pretty unusable these days. 83 00:04:37,220 --> 00:04:39,720 Most of your major sites have so much JavaScript 84 00:04:39,720 --> 00:04:40,760 integrated into it 85 00:04:40,760 --> 00:04:43,020 that it's just not feasible as a security measure 86 00:04:43,020 --> 00:04:44,360 to turn off JavaScript. 87 00:04:44,940 --> 00:04:46,700 While this advice might have been good 88 00:04:46,700 --> 00:04:48,980 in the early 2000s, late 90s, 89 00:04:48,980 --> 00:04:51,840 when a lot of security problems with JavaScript 90 00:04:51,840 --> 00:04:52,240 were found, 91 00:04:53,140 --> 00:04:54,680 they're not really practical anymore 92 00:04:54,680 --> 00:04:57,600 for anybody but the most hardcore security people. 93 00:04:57,800 --> 00:05:01,160 It's not practical for grandma, mom kind of atmospheres. 94 00:05:01,340 --> 00:05:02,740 So, there's some real problems here. 95 00:05:04,380 --> 00:05:05,700 JavaScript is a vice 96 00:05:05,700 --> 00:05:07,500 of your typical web developer and designer. 97 00:05:07,840 --> 00:05:09,940 It's thrown out there without a lot of thought. 98 00:05:10,240 --> 00:05:12,320 It's just put in there to make something happen. 99 00:05:12,680 --> 00:05:14,560 There's not a lot of training involved in it. 100 00:05:14,740 --> 00:05:16,720 And most of the scripts are put together 101 00:05:16,720 --> 00:05:18,880 with examples from the web. 102 00:05:19,720 --> 00:05:22,180 These examples tend to be not the most secure. 103 00:05:23,180 --> 00:05:26,260 Or the most well-written in any way, shape, or form. 104 00:05:26,360 --> 00:05:29,000 There's just big JavaScript library repositories online 105 00:05:29,000 --> 00:05:30,880 that you pull down stuff from, 106 00:05:31,060 --> 00:05:33,060 edit the code just enough to make it do what you want. 107 00:05:33,460 --> 00:05:35,300 And you're not really sure what's going on 108 00:05:35,300 --> 00:05:36,020 in a lot of cases. 109 00:05:38,160 --> 00:05:40,580 Continuing with the most many popular sites, 110 00:05:40,820 --> 00:05:42,500 try MySpace, try YouTube, 111 00:05:42,700 --> 00:05:44,140 try any number of other sites. 112 00:05:44,500 --> 00:05:46,000 They're pretty much unusable. 113 00:05:46,140 --> 00:05:48,380 It's a staple of the web and it's here to stay. 114 00:05:48,640 --> 00:05:50,760 And it's only going to get more and more involved 115 00:05:50,760 --> 00:05:52,160 in our daily website. 116 00:05:52,160 --> 00:05:52,180 And it's going to get more and more involved 117 00:05:52,180 --> 00:05:53,180 in our web surfing browsing habits. 118 00:05:54,280 --> 00:05:55,640 Is it really that dangerous? 119 00:05:55,940 --> 00:05:58,620 We get this question a lot in regards to JavaScript. 120 00:05:58,880 --> 00:05:59,740 Is it all theoretical? 121 00:06:00,080 --> 00:06:02,680 Is it things that are just, you know, out there 122 00:06:02,680 --> 00:06:04,540 but not really being exploited? 123 00:06:05,060 --> 00:06:07,660 Well, we saw some examples in the month of browser bugs. 124 00:06:08,120 --> 00:06:10,640 Number 25 is a good example of a vulnerability 125 00:06:10,640 --> 00:06:11,940 in JavaScript itself. 126 00:06:12,680 --> 00:06:14,200 Where the vulnerability involved 127 00:06:14,940 --> 00:06:17,100 iterating over a native JavaScript function. 128 00:06:17,420 --> 00:06:19,260 Using a for loop to go through it. 129 00:06:19,340 --> 00:06:21,860 And after a while you would get a denial of service 130 00:06:21,860 --> 00:06:22,140 and you'd have to go through it again. 131 00:06:22,160 --> 00:06:23,960 And potentially remote code exploitation 132 00:06:23,960 --> 00:06:24,820 or execution. 133 00:06:25,860 --> 00:06:27,920 Number 8 was an example 134 00:06:27,920 --> 00:06:30,100 of how JavaScript makes exploitation 135 00:06:30,100 --> 00:06:32,020 easier, but isn't an exploit 136 00:06:32,020 --> 00:06:32,760 with JavaScript. 137 00:06:33,180 --> 00:06:35,160 Which is primarily what we'll be talking about. 138 00:06:35,460 --> 00:06:38,460 In this case, an ActiveX control was created. 139 00:06:38,880 --> 00:06:40,260 And it used a function that was 140 00:06:40,260 --> 00:06:42,620 called 65,000 times 141 00:06:42,620 --> 00:06:43,540 to iterate, 142 00:06:43,820 --> 00:06:45,100 get an integer underflow, 143 00:06:45,340 --> 00:06:47,540 and then you've got successfully, 144 00:06:47,560 --> 00:06:49,600 you're successfully able to access pretty much 145 00:06:50,070 --> 00:06:51,600 whatever part of the memory you want. 146 00:06:53,340 --> 00:06:54,320 Some other things 147 00:06:54,320 --> 00:06:55,960 that are happening with these tools these days. 148 00:06:56,260 --> 00:06:57,860 The GNU Citizen group has 149 00:06:57,860 --> 00:06:59,400 the JavaScript attack API. 150 00:06:59,880 --> 00:07:02,060 Which I don't know how many of you are familiar with it. 151 00:07:02,140 --> 00:07:03,420 I haven't used it extensively myself. 152 00:07:03,960 --> 00:07:05,780 But it's becoming a more and more popular 153 00:07:05,780 --> 00:07:08,240 and quite mature tool for what it's doing. 154 00:07:08,800 --> 00:07:10,140 And things are really coming 155 00:07:10,140 --> 00:07:12,060 together there and it gives a 156 00:07:12,060 --> 00:07:13,860 great framework and tool set 157 00:07:13,860 --> 00:07:15,320 for JavaScript exploitation. 158 00:07:16,540 --> 00:07:17,800 Other things we've seen, 159 00:07:17,980 --> 00:07:20,080 last year the browser based port scanning 160 00:07:20,080 --> 00:07:20,900 was a big deal. 161 00:07:22,160 --> 00:07:24,340 I was at Spy Dynamics along with Jeremiah Grossman 162 00:07:24,340 --> 00:07:25,820 and a handful of other people 163 00:07:25,820 --> 00:07:27,900 kind of had the same idea at the same time. 164 00:07:28,160 --> 00:07:29,800 And started working through these. 165 00:07:30,260 --> 00:07:31,400 And recently 166 00:07:31,900 --> 00:07:33,520 Dan Kaminski at his talk 167 00:07:33,960 --> 00:07:35,640 at Black Hat and here this week 168 00:07:35,640 --> 00:07:36,820 just a few hours ago, 169 00:07:37,320 --> 00:07:39,920 talked about scanning inside the network 170 00:07:39,920 --> 00:07:41,200 using Flash. 171 00:07:42,160 --> 00:07:43,700 Which is sort of similar 172 00:07:43,700 --> 00:07:45,520 and there's some overlap there 173 00:07:45,520 --> 00:07:46,640 that we'll talk about briefly. 174 00:07:47,740 --> 00:07:49,780 But there's a lot of things that the browser 175 00:07:49,780 --> 00:07:50,980 allows the user to do 176 00:07:52,160 --> 00:07:52,540 that aren't normal. 177 00:07:53,760 --> 00:07:55,420 Aren't part of your usual 178 00:07:56,220 --> 00:07:56,700 applications. 179 00:07:59,160 --> 00:08:00,760 Phishing and cross-site scripting. 180 00:08:01,360 --> 00:08:02,600 Cross-site scripting 181 00:08:02,600 --> 00:08:04,260 is the seemingly ubiquitous 182 00:08:04,260 --> 00:08:04,640 vulnerability. 183 00:08:05,500 --> 00:08:07,120 More are being created each day 184 00:08:07,120 --> 00:08:07,960 than are being found. 185 00:08:08,400 --> 00:08:10,320 And they're just going to continue to be there. 186 00:08:11,360 --> 00:08:13,820 What used to be just a cute little attack 187 00:08:13,820 --> 00:08:15,200 that you could show how a website 188 00:08:15,200 --> 00:08:16,700 was coded poorly to show an alert 189 00:08:16,700 --> 00:08:18,640 is now being usable for 190 00:08:18,640 --> 00:08:20,080 serious malicious activity. 191 00:08:22,160 --> 00:08:22,640 More every day. 192 00:08:24,000 --> 00:08:26,100 Some examples of things involving that 193 00:08:26,100 --> 00:08:27,920 were the eBay seller ratings recently. 194 00:08:28,380 --> 00:08:29,880 Which allowed the seller 195 00:08:29,880 --> 00:08:31,760 to change their icon 196 00:08:31,760 --> 00:08:32,800 to be a power seller. 197 00:08:33,000 --> 00:08:34,280 To have over a thousand positive 198 00:08:35,680 --> 00:08:37,480 remarks or positive transactions. 199 00:08:38,540 --> 00:08:40,000 And you know 200 00:08:40,000 --> 00:08:41,480 that might not matter to you and me again. 201 00:08:41,720 --> 00:08:43,500 But it matters to most normal people. 202 00:08:43,680 --> 00:08:45,320 They're going to check and see oh well this has 203 00:08:45,320 --> 00:08:47,240 over a thousand quality sales. 204 00:08:47,480 --> 00:08:49,120 I'm safe doing business with this guy. 205 00:08:49,340 --> 00:08:51,520 Which lures you further into the phishing 206 00:08:52,160 --> 00:08:52,800 vulnerability mode. 207 00:08:55,020 --> 00:08:55,720 Following that, 208 00:08:55,800 --> 00:08:57,000 address bar spoofing. 209 00:08:57,020 --> 00:08:58,340 There's been so many vulnerabilities 210 00:08:58,340 --> 00:08:59,620 that allow this to happen. 211 00:08:59,740 --> 00:09:01,640 It would be a waste of time to enumerate them all. 212 00:09:01,880 --> 00:09:04,100 But it seems like there's one every couple of months. 213 00:09:04,340 --> 00:09:06,540 And this is incredibly useful in phishing 214 00:09:06,540 --> 00:09:08,120 or any number of other attacks 215 00:09:08,120 --> 00:09:10,020 that involve information stealing. 216 00:09:11,900 --> 00:09:13,820 Couple of postmortems of real life 217 00:09:13,820 --> 00:09:15,020 events from the last year also. 218 00:09:15,320 --> 00:09:16,800 There was the Super Bowl 40 219 00:09:16,800 --> 00:09:18,580 Dolphin Stadium site hack. 220 00:09:19,140 --> 00:09:21,660 It was dealt with the web server 221 00:09:22,160 --> 00:09:22,520 compromised. 222 00:09:22,760 --> 00:09:25,360 There was iframe injection which tried to exploit 223 00:09:26,020 --> 00:09:27,800 two already patched 224 00:09:27,800 --> 00:09:29,960 but widely unpatched 225 00:09:29,960 --> 00:09:30,760 in the populace 226 00:09:31,760 --> 00:09:33,120 Microsoft vulnerabilities. 227 00:09:33,520 --> 00:09:35,840 One involving VML and the other one 228 00:09:35,840 --> 00:09:37,280 I believe it was MDAC 229 00:09:37,280 --> 00:09:39,260 but don't quote me on that for the 230 00:09:39,900 --> 00:09:40,700 07-004. 231 00:09:41,720 --> 00:09:43,200 So this brings to light 232 00:09:43,200 --> 00:09:45,020 the whole JavaScript issue 233 00:09:45,020 --> 00:09:47,460 as Ben spoke about earlier. 234 00:09:47,820 --> 00:09:49,780 It really blurs the line between 235 00:09:49,780 --> 00:09:50,720 code and data. 236 00:09:52,160 --> 00:09:52,440 And that's what we've got in these 237 00:09:52,440 --> 00:09:54,900 QuickTime embedded movie files. 238 00:09:55,180 --> 00:09:56,880 They can now have JavaScript in them. 239 00:09:57,640 --> 00:09:59,240 Maybe not the best design decision 240 00:09:59,240 --> 00:10:01,160 but it's there and you can run 241 00:10:01,160 --> 00:10:02,660 arbitrary code through a movie. 242 00:10:03,480 --> 00:10:05,060 Years ago would you have thought 243 00:10:05,060 --> 00:10:05,860 that was possible? 244 00:10:06,300 --> 00:10:08,460 Probably not. They were just movie files. 245 00:10:09,080 --> 00:10:09,820 Shockwave Flash. 246 00:10:10,700 --> 00:10:11,940 Shockwave is going with the 247 00:10:11,940 --> 00:10:13,120 inner-inner platform effect 248 00:10:13,120 --> 00:10:15,340 where you have not only the browser running on the OS 249 00:10:15,340 --> 00:10:18,080 you have Shockwave and Flash running in the browser 250 00:10:18,080 --> 00:10:20,520 and you have full access to a network stack now. 251 00:10:22,180 --> 00:10:24,060 We're starting to see things creep up 252 00:10:24,060 --> 00:10:26,360 and they're probably only going to get worse. 253 00:10:27,400 --> 00:10:28,420 A big thing 254 00:10:28,420 --> 00:10:29,860 and fairly underrated this year 255 00:10:29,860 --> 00:10:32,440 is the Adobe PDF cross-site scripting 256 00:10:32,440 --> 00:10:32,680 vulnerability. 257 00:10:33,160 --> 00:10:35,280 This was released early in the year 258 00:10:35,280 --> 00:10:36,080 I think around March. 259 00:10:38,460 --> 00:10:40,180 Basically arbitrary JavaScript 260 00:10:40,180 --> 00:10:42,440 alerts, cross-site scriptings 261 00:10:42,440 --> 00:10:43,720 anything else 262 00:10:43,720 --> 00:10:45,020 very easily. 263 00:10:45,220 --> 00:10:46,960 It was trivial to exploit. 264 00:10:48,600 --> 00:10:49,940 So now we're going to move into 265 00:10:49,940 --> 00:10:51,960 talking about some of the obfuscation and evasion 266 00:10:52,160 --> 00:10:52,920 techniques that are used 267 00:10:53,880 --> 00:10:55,660 by JavaScript to hide what 268 00:10:55,660 --> 00:10:57,340 the actual exploit is doing 269 00:10:57,340 --> 00:10:59,520 and really evade IDS, IPS 270 00:10:59,520 --> 00:11:01,860 and all sorts of other detection mechanisms. 271 00:11:05,480 --> 00:11:07,980 There are a variety of evasion 272 00:11:07,980 --> 00:11:09,760 and obfuscation techniques that are 273 00:11:09,760 --> 00:11:11,600 typically used in the wild and that we see 274 00:11:11,920 --> 00:11:13,140 in JavaScripts. 275 00:11:13,360 --> 00:11:15,640 Probably the simplest to 276 00:11:15,980 --> 00:11:17,520 understand and the simplest to implement 277 00:11:17,900 --> 00:11:19,660 is white space randomization 278 00:11:19,660 --> 00:11:21,120 or randomized comments. 279 00:11:22,160 --> 00:11:23,200 The reason this is effective 280 00:11:23,200 --> 00:11:25,320 against certain security technologies 281 00:11:25,840 --> 00:11:27,400 is if you're inspecting 282 00:11:27,400 --> 00:11:29,680 the return content from a website 283 00:11:29,680 --> 00:11:31,780 or web request on the wire 284 00:11:31,780 --> 00:11:33,820 and you're using a signature based 285 00:11:33,820 --> 00:11:35,880 analysis technology or detection technology 286 00:11:35,880 --> 00:11:38,660 you can insert 287 00:11:38,660 --> 00:11:40,320 any amount of 288 00:11:40,320 --> 00:11:42,120 white space or random comments 289 00:11:42,120 --> 00:11:43,180 throughout that JavaScript 290 00:11:43,180 --> 00:11:45,260 and it's going to break signature detection. 291 00:11:45,900 --> 00:11:47,960 Basically the byte stream on the wire 292 00:11:47,960 --> 00:11:49,460 is going to be completely different 293 00:11:49,900 --> 00:11:51,960 than the signature based 294 00:11:52,160 --> 00:11:53,540 content that you're looking for 295 00:11:53,860 --> 00:11:55,880 for a particular malicious JavaScript call 296 00:11:55,880 --> 00:11:57,620 or a particular 297 00:11:58,160 --> 00:12:00,000 section of script that you've 298 00:12:00,000 --> 00:12:00,880 written a signature for. 299 00:12:02,260 --> 00:12:04,200 Another common technique 300 00:12:04,200 --> 00:12:05,980 that's not only applicable to 301 00:12:05,980 --> 00:12:07,840 JavaScript but is basically 302 00:12:07,840 --> 00:12:09,680 used in a lot of attacks 303 00:12:09,680 --> 00:12:12,040 is string encoding and unencoding. 304 00:12:13,740 --> 00:12:15,820 Typically you can encode 305 00:12:15,820 --> 00:12:18,120 strings using hex characters 306 00:12:18,120 --> 00:12:19,340 the ASCII equivalent 307 00:12:20,020 --> 00:12:21,320 percent encodings 308 00:12:22,160 --> 00:12:23,060 or unicode encodings. 309 00:12:23,760 --> 00:12:26,380 Some ones I did not list up here 310 00:12:26,380 --> 00:12:27,880 include wide and extended 311 00:12:27,880 --> 00:12:29,420 unicode character sets. 312 00:12:29,860 --> 00:12:31,800 We've seen recently some vulnerabilities 313 00:12:31,800 --> 00:12:33,660 or some bypasses of 314 00:12:34,660 --> 00:12:36,060 intrusion detection 315 00:12:36,060 --> 00:12:38,240 technologies based on some unusual 316 00:12:38,240 --> 00:12:40,200 wide and extended unicode 317 00:12:40,200 --> 00:12:41,020 encodings. 318 00:12:42,180 --> 00:12:43,940 Another relatively simple 319 00:12:43,940 --> 00:12:45,560 technique that we see in the wild 320 00:12:45,560 --> 00:12:46,400 is string splitting. 321 00:12:47,380 --> 00:12:49,760 So if you anticipate 322 00:12:49,760 --> 00:12:52,140 that a security technology is going to 323 00:12:52,160 --> 00:12:53,580 be looking for a particular 324 00:12:53,580 --> 00:12:55,520 string value on the wire 325 00:12:55,520 --> 00:12:57,500 or in a web page in the browser 326 00:12:58,080 --> 00:12:59,800 you could take that payload 327 00:12:59,800 --> 00:13:01,800 essentially and break it up into any number 328 00:13:01,800 --> 00:13:04,360 of strings, concatenate 329 00:13:04,360 --> 00:13:05,560 those strings together dynamically 330 00:13:06,100 --> 00:13:08,060 during interpretation and execution time 331 00:13:08,060 --> 00:13:10,080 and naive 332 00:13:10,080 --> 00:13:12,040 or signature based analysis 333 00:13:12,040 --> 00:13:13,520 of the content on the wire 334 00:13:13,520 --> 00:13:14,500 is going to fail. 335 00:13:15,740 --> 00:13:17,240 This is a very simple example. 336 00:13:17,540 --> 00:13:19,620 Lots of detections fail and you could 337 00:13:19,620 --> 00:13:21,420 simply break that up into four strings 338 00:13:22,160 --> 00:13:23,660 throughout the script, concatenate those 339 00:13:23,660 --> 00:13:26,020 together and dynamically in the browser 340 00:13:26,020 --> 00:13:27,520 that string will be produced 341 00:13:27,930 --> 00:13:29,780 but on the wire you're never going to see that 342 00:13:29,780 --> 00:13:30,220 all together. 343 00:13:32,800 --> 00:13:33,880 Another technique 344 00:13:33,880 --> 00:13:35,180 is integer obfuscation. 345 00:13:35,920 --> 00:13:37,820 If you could imagine if you will that 346 00:13:37,820 --> 00:13:39,940 you're an attacker and you want to encode a particular 347 00:13:39,940 --> 00:13:41,820 integer value in your script 348 00:13:41,820 --> 00:13:43,060 be it a port number, 349 00:13:43,420 --> 00:13:45,120 a key to some value, 350 00:13:45,400 --> 00:13:46,540 any number of reasons. 351 00:13:47,060 --> 00:13:49,880 Well, there's essentially infinite ways you can represent 352 00:13:49,880 --> 00:13:50,860 that integer. 353 00:13:52,160 --> 00:13:53,400 You could basically create that 354 00:13:53,400 --> 00:13:55,500 integer dynamically using any of the mathematical 355 00:13:55,500 --> 00:13:57,520 operators at your disposal 356 00:13:58,160 --> 00:13:59,720 and a very 357 00:13:59,720 --> 00:14:02,240 simple example is if you wanted to encode 358 00:14:02,240 --> 00:14:03,260 31337 359 00:14:03,260 --> 00:14:05,820 you could simply perform five 360 00:14:05,820 --> 00:14:07,960 additions and dynamically 361 00:14:07,960 --> 00:14:10,040 that value will be created in your 362 00:14:10,040 --> 00:14:11,440 script. Very simple stuff. 363 00:14:12,360 --> 00:14:13,780 On to a more 364 00:14:13,780 --> 00:14:15,900 sophisticated JavaScript attack 365 00:14:15,900 --> 00:14:17,560 technique, heap spray 366 00:14:17,920 --> 00:14:19,720 and it's more advanced cousin 367 00:14:19,720 --> 00:14:20,740 feng shui. 368 00:14:22,160 --> 00:14:23,700 Our presenter Sadorov gave a great talk 369 00:14:23,700 --> 00:14:25,080 this week at Black Hat 370 00:14:25,080 --> 00:14:27,480 kind of reviewing heap spray 371 00:14:27,480 --> 00:14:29,700 and his feng shui attack technique 372 00:14:29,700 --> 00:14:31,440 and his heap lib tool. 373 00:14:32,440 --> 00:14:33,880 I hope to do it justice 374 00:14:33,880 --> 00:14:35,980 but the basic description is 375 00:14:35,980 --> 00:14:36,220 that 376 00:14:37,440 --> 00:14:39,740 the JavaScript is executing in the browser 377 00:14:39,740 --> 00:14:41,720 the activity of that JavaScript 378 00:14:41,720 --> 00:14:44,080 is allocating memory in the browser's 379 00:14:44,080 --> 00:14:45,240 heap. So 380 00:14:46,040 --> 00:14:48,080 if you have the client 381 00:14:48,080 --> 00:14:49,680 dynamically interpreting your script 382 00:14:49,680 --> 00:14:52,140 you can allocate arbitrary segments in the heap 383 00:14:52,160 --> 00:14:54,560 fill it with nop sleds and shellcode 384 00:14:54,560 --> 00:14:55,980 and then basically 385 00:14:55,980 --> 00:14:57,980 what you need is an exploit that's going to 386 00:14:57,980 --> 00:14:59,760 overwrite a function pointer 387 00:14:59,760 --> 00:15:01,940 and redirect it back into the heap. 388 00:15:02,300 --> 00:15:04,020 Typically you would use 389 00:15:04,020 --> 00:15:05,720 a nop sled that would be a valid heap 390 00:15:06,260 --> 00:15:07,220 memory address 391 00:15:07,220 --> 00:15:09,680 so that when you overwrite the function pointer 392 00:15:09,680 --> 00:15:11,240 redirect back into the heap 393 00:15:11,240 --> 00:15:13,080 it'll interpret that as a memory address 394 00:15:13,080 --> 00:15:15,580 jump to it and then you're in your nop sled 395 00:15:15,580 --> 00:15:16,280 or your shellcode. 396 00:15:17,760 --> 00:15:19,660 And I would recommend you check out 397 00:15:19,660 --> 00:15:22,140 his slides or look up on that 398 00:15:22,160 --> 00:15:23,560 more, it's a great technique. 399 00:15:24,240 --> 00:15:25,780 And JavaScript 400 00:15:25,780 --> 00:15:27,220 is very dynamic. 401 00:15:27,540 --> 00:15:30,140 Any function or any variable can be renamed. 402 00:15:30,420 --> 00:15:32,120 You could rename the document object 403 00:15:32,120 --> 00:15:33,200 foobar. 404 00:15:33,540 --> 00:15:35,920 So for a security technology 405 00:15:35,920 --> 00:15:37,520 that's looking for particular calls 406 00:15:37,520 --> 00:15:39,740 or instantiating a particular object 407 00:15:39,740 --> 00:15:40,280 or class 408 00:15:42,200 --> 00:15:43,520 earlier in the script 409 00:15:43,520 --> 00:15:45,540 that attacker could have redefined that name 410 00:15:45,540 --> 00:15:47,220 to whatever he or she chooses. 411 00:15:47,500 --> 00:15:49,640 So that's another way you can defeat 412 00:15:49,640 --> 00:15:51,800 security technologies is basically dynamically 413 00:15:52,160 --> 00:15:53,580 reassigning the names of your functions. 414 00:15:53,800 --> 00:15:56,040 You could, for instance, assign 415 00:15:56,040 --> 00:15:57,320 unencode or encode 416 00:15:57,320 --> 00:15:59,940 to different function names that seem more benign. 417 00:16:00,080 --> 00:16:02,140 And that's a potential way you could bypass 418 00:16:02,140 --> 00:16:03,300 a security technology. 419 00:16:05,140 --> 00:16:05,960 On to 420 00:16:05,960 --> 00:16:07,900 a slightly more sophisticated cousin here 421 00:16:07,900 --> 00:16:09,020 is block randomization. 422 00:16:11,000 --> 00:16:11,600 Typically 423 00:16:12,280 --> 00:16:13,860 security technologies aren't going to 424 00:16:13,860 --> 00:16:15,900 interpret this JavaScript 425 00:16:15,900 --> 00:16:17,880 and walk through loops 426 00:16:17,880 --> 00:16:18,360 in it. 427 00:16:20,860 --> 00:16:21,860 Pairing this with 428 00:16:22,160 --> 00:16:23,900 string splitting or integer obfuscation 429 00:16:23,900 --> 00:16:26,080 you can create for loops, while loops 430 00:16:26,080 --> 00:16:27,700 do while loops that 431 00:16:27,700 --> 00:16:29,160 within the code of that loop 432 00:16:29,160 --> 00:16:32,080 you're dynamically crafting your payload 433 00:16:32,080 --> 00:16:33,220 for exploitation. 434 00:16:34,100 --> 00:16:36,220 And most technologies aren't going to 435 00:16:36,220 --> 00:16:38,140 understand and execute 436 00:16:38,140 --> 00:16:39,520 this loop properly 437 00:16:40,160 --> 00:16:41,540 create the shellcode 438 00:16:41,960 --> 00:16:44,060 and then be able to match that 439 00:16:44,060 --> 00:16:46,100 against whatever signature 440 00:16:46,100 --> 00:16:47,960 or analysis they're trying to do. 441 00:16:48,960 --> 00:16:49,680 Typically 442 00:16:50,740 --> 00:16:52,140 these techniques are used 443 00:16:52,160 --> 00:16:53,360 in conjunction with one another 444 00:16:53,360 --> 00:16:54,840 and that also affects 445 00:16:54,840 --> 00:16:57,260 or increases the effectiveness of them. 446 00:16:57,780 --> 00:16:59,220 So you're seeing more and more 447 00:16:59,920 --> 00:17:01,840 malicious JavaScripts that combine all these 448 00:17:01,840 --> 00:17:03,960 techniques into one really 449 00:17:03,960 --> 00:17:04,580 ugly mess. 450 00:17:05,440 --> 00:17:08,060 We want to credit the folks over at 451 00:17:08,060 --> 00:17:09,840 Metasploit for coming up with the 452 00:17:09,840 --> 00:17:11,760 Aveda-matic module. They really 453 00:17:11,760 --> 00:17:14,060 kind of discussed these 454 00:17:14,060 --> 00:17:15,940 techniques and wrote about 455 00:17:15,940 --> 00:17:17,200 them so 456 00:17:18,300 --> 00:17:19,900 they kind of came up with this 457 00:17:19,900 --> 00:17:21,320 classification that we're using here. 458 00:17:22,460 --> 00:17:23,680 To put up an 459 00:17:23,680 --> 00:17:25,820 example of what we considered 460 00:17:25,820 --> 00:17:27,140 a highly obfuscated JavaScript 461 00:17:27,940 --> 00:17:30,260 this is something that was found in the wild 462 00:17:31,200 --> 00:17:32,080 and it 463 00:17:32,640 --> 00:17:34,120 is very difficult for 464 00:17:34,120 --> 00:17:35,380 an analyst to manually 465 00:17:35,980 --> 00:17:38,180 figure out what this is doing 466 00:17:38,180 --> 00:17:39,600 either as part of an incident response 467 00:17:39,600 --> 00:17:42,220 or an intrusion detection 468 00:17:42,220 --> 00:17:43,980 analyst trying to look at this 469 00:17:43,980 --> 00:17:45,800 attack and see what the implications are 470 00:17:45,800 --> 00:17:47,920 or even if it is an attack, could it be benign? 471 00:17:49,000 --> 00:17:50,060 By the way, I'll buy 472 00:17:50,060 --> 00:17:52,100 anyone a beer if they can tell me what this 473 00:17:52,160 --> 00:17:53,780 does before we get to that slide later. 474 00:17:54,100 --> 00:17:56,260 Anyone who wasn't at the Black Hat talk? 475 00:17:56,480 --> 00:17:58,000 Ah, good caveat there. 476 00:18:04,480 --> 00:18:06,100 So like so many good ideas 477 00:18:06,600 --> 00:18:08,020 Caffeine Monkey was born at the local 478 00:18:08,020 --> 00:18:09,940 bar. Sitting around, myself, 479 00:18:10,180 --> 00:18:11,740 Ben, and another security researcher 480 00:18:11,740 --> 00:18:13,740 discussing current and future 481 00:18:13,740 --> 00:18:15,860 exploitation techniques and just where 482 00:18:15,860 --> 00:18:18,100 browser exploitation and the web is going 483 00:18:18,100 --> 00:18:19,860 in general when it comes to security. 484 00:18:20,760 --> 00:18:22,080 So we wanted a couple 485 00:18:22,160 --> 00:18:24,280 of things in this tool that we wanted to categorize 486 00:18:24,280 --> 00:18:26,420 and do a lot of 487 00:18:26,420 --> 00:18:28,020 fingerprinting and such with this. 488 00:18:28,180 --> 00:18:30,140 We're on a central database for collection 489 00:18:30,140 --> 00:18:32,260 and an easy way to get to the analysis. 490 00:18:33,160 --> 00:18:34,380 We wanted this collection 491 00:18:34,380 --> 00:18:36,260 to include web pages, 492 00:18:36,480 --> 00:18:38,300 JavaScript, and anything else 493 00:18:38,300 --> 00:18:40,420 that you find on the web. We want it categorized 494 00:18:40,420 --> 00:18:41,840 you know, in 495 00:18:42,560 --> 00:18:43,000 various 496 00:18:44,180 --> 00:18:45,940 different buckets where you could combine 497 00:18:45,940 --> 00:18:48,600 them or break them apart and get down to the lowest level. 498 00:18:49,180 --> 00:18:50,120 We also wanted 499 00:18:50,120 --> 00:18:52,080 a great and very easy 500 00:18:52,160 --> 00:18:54,020 mechanism to feed into the 501 00:18:54,020 --> 00:18:55,900 various browsers and other things 502 00:18:55,900 --> 00:18:57,680 that we were using to identify and 503 00:18:57,680 --> 00:18:59,340 analyze these results. 504 00:18:59,980 --> 00:19:01,680 One caveat in 505 00:19:01,680 --> 00:19:04,060 fairness is that in 506 00:19:04,060 --> 00:19:05,400 the browser or spidering 507 00:19:05,400 --> 00:19:07,900 these JavaScripts were identified by 508 00:19:07,900 --> 00:19:09,920 MIME types, which we realized 509 00:19:09,920 --> 00:19:11,040 does not catch everything 510 00:19:12,020 --> 00:19:13,860 but allows us 511 00:19:13,860 --> 00:19:15,920 to very quickly get through it without dealing with 512 00:19:15,920 --> 00:19:18,080 a lot of HTML parsing and reparsing 513 00:19:18,080 --> 00:19:19,620 as the onion script happens. 514 00:19:19,860 --> 00:19:22,140 And we felt it gave us enough to get there. 515 00:19:22,160 --> 00:19:24,260 We also wanted 516 00:19:24,260 --> 00:19:25,920 a safe and lightweight alternative. 517 00:19:26,380 --> 00:19:27,700 As we'll talk about later, 518 00:19:27,860 --> 00:19:30,180 in a lot of the current methodologies of detecting 519 00:19:30,180 --> 00:19:32,160 and analyzing 520 00:19:32,880 --> 00:19:33,480 malicious 521 00:19:34,040 --> 00:19:36,000 JavaScript, they're neither 522 00:19:36,000 --> 00:19:37,500 lightweight as they involve 523 00:19:37,980 --> 00:19:40,140 multiple VMware images, lots of 524 00:19:40,140 --> 00:19:42,200 snapshots, restarts, and lots of time 525 00:19:42,200 --> 00:19:44,200 and resources for the individual researcher 526 00:19:44,200 --> 00:19:46,180 or analyst to set up. 527 00:19:46,500 --> 00:19:47,780 And if you're working in 528 00:19:47,780 --> 00:19:50,080 on the spot incident and trying to figure out 529 00:19:50,080 --> 00:19:52,140 exactly what this is doing, then you 530 00:19:52,160 --> 00:19:53,260 don't want to deal with all that. 531 00:19:53,380 --> 00:19:55,660 You want a quick and easy way to tell what's going on. 532 00:19:56,800 --> 00:19:57,680 Safe also, 533 00:19:57,820 --> 00:20:00,020 a lot of these exploits that we have seen 534 00:20:00,020 --> 00:20:02,000 are taking care of 535 00:20:02,000 --> 00:20:04,320 the current ways of getting around it. 536 00:20:04,520 --> 00:20:05,680 They do things like 537 00:20:06,440 --> 00:20:07,820 closing off text areas, 538 00:20:08,380 --> 00:20:10,280 breaking out of sandboxed 539 00:20:10,280 --> 00:20:12,180 areas, which are kind of 540 00:20:12,180 --> 00:20:14,020 naive approaches with the way a lot of analysts 541 00:20:14,020 --> 00:20:16,020 are doing it right now. And we'll talk 542 00:20:16,020 --> 00:20:17,020 about those some more later. 543 00:20:18,320 --> 00:20:19,820 So, to get this across, 544 00:20:20,140 --> 00:20:22,080 thankfully we have a lot of great open source 545 00:20:22,160 --> 00:20:23,080 software to work on. 546 00:20:23,860 --> 00:20:26,260 SpiderMonkey is what we worked on as our basis. 547 00:20:26,400 --> 00:20:28,260 We extended that into the CaffeineMonkey. 548 00:20:28,940 --> 00:20:30,180 This is a great piece 549 00:20:30,180 --> 00:20:32,100 of software. It's been around for a long time. 550 00:20:32,260 --> 00:20:34,120 It's very mature. It's been being developed 551 00:20:34,120 --> 00:20:36,260 since 1995 in one form or another. 552 00:20:36,740 --> 00:20:38,440 And it's extremely extendable. 553 00:20:39,140 --> 00:20:40,000 And basically 554 00:20:40,000 --> 00:20:42,000 you can drop a JavaScript 555 00:20:42,760 --> 00:20:44,220 interpreter into any program 556 00:20:44,220 --> 00:20:45,980 you write with very 557 00:20:45,980 --> 00:20:47,980 easy bindings between the two. 558 00:20:48,180 --> 00:20:49,980 And you can control your function input 559 00:20:49,980 --> 00:20:51,000 and output with JavaScript. 560 00:20:52,160 --> 00:20:53,860 So this made it very easy for us to 561 00:20:53,860 --> 00:20:55,980 work this into a quick 562 00:20:55,980 --> 00:20:57,840 prototype. We also 563 00:20:57,840 --> 00:21:00,040 had the Heritrix web crawler from the good people 564 00:21:00,040 --> 00:21:01,500 at archive.org. 565 00:21:01,660 --> 00:21:03,460 Another very mature piece of software. 566 00:21:04,100 --> 00:21:05,940 If you ever need to spider a collection 567 00:21:05,940 --> 00:21:07,840 of web pages, it's a great tool to use. 568 00:21:08,280 --> 00:21:10,040 And the good people at the University of 569 00:21:10,040 --> 00:21:11,980 Michigan who had some scripts for taking apart 570 00:21:11,980 --> 00:21:13,960 those archive files and allowing us easy 571 00:21:13,960 --> 00:21:15,620 access into them. 572 00:21:16,960 --> 00:21:18,040 So this tool 573 00:21:18,040 --> 00:21:19,860 has and will be released 574 00:21:20,440 --> 00:21:21,780 under the GPL 575 00:21:22,160 --> 00:21:22,540 version 3. 576 00:21:23,800 --> 00:21:26,100 Everything about it is pretty much 577 00:21:26,100 --> 00:21:28,040 GPL. It's on our website that we'll get 578 00:21:28,040 --> 00:21:29,780 to the links later on in the page. 579 00:21:29,940 --> 00:21:32,120 But we hope that the community will continue to use 580 00:21:32,120 --> 00:21:34,260 it and extend it if they find it useful 581 00:21:34,780 --> 00:21:35,860 and work from there. 582 00:21:37,360 --> 00:21:38,180 So basically 583 00:21:38,180 --> 00:21:40,160 the heart of SpiderMonkey 584 00:21:40,160 --> 00:21:42,220 is that it wraps and logs functions 585 00:21:42,220 --> 00:21:44,180 in almost 586 00:21:44,180 --> 00:21:46,040 the syscall area of JavaScript. 587 00:21:46,560 --> 00:21:48,020 We're not just 588 00:21:48,740 --> 00:21:50,340 walking through it syntactically. 589 00:21:50,640 --> 00:21:52,140 We're hooked in at a deeper level 590 00:21:52,160 --> 00:21:54,000 somewhere with the debugger. 591 00:21:54,100 --> 00:21:56,460 And instead of manually running a debugger 592 00:21:56,460 --> 00:21:57,620 and running through all the JavaScript 593 00:21:57,620 --> 00:22:00,260 and all the loops and such and cataloging it 594 00:22:00,260 --> 00:22:01,380 you have logging functionality 595 00:22:02,020 --> 00:22:03,500 that's occurring and outputting. 596 00:22:03,720 --> 00:22:05,480 And currently it's very verbose. 597 00:22:06,040 --> 00:22:07,440 But that's because we wanted 598 00:22:07,440 --> 00:22:09,580 an easy way to get statistical analysis 599 00:22:09,580 --> 00:22:12,240 and the best way to do that is to be as verbose as possible. 600 00:22:13,740 --> 00:22:16,500 So here's a screenshot of the Heritrix web crawler. 601 00:22:16,600 --> 00:22:17,980 You see a couple of the jobs 602 00:22:17,980 --> 00:22:19,820 being done. Finished, finished. 603 00:22:20,000 --> 00:22:20,900 Enabled by operator. 604 00:22:22,160 --> 00:22:23,120 Very easy to work through. 605 00:22:24,240 --> 00:22:24,760 Just 606 00:22:24,760 --> 00:22:27,680 I can't say enough about how easy it was 607 00:22:27,680 --> 00:22:29,120 to set up and use effectively. 608 00:22:30,280 --> 00:22:31,860 Some more things of it is 609 00:22:31,860 --> 00:22:33,500 downloading some progress bars. 610 00:22:34,340 --> 00:22:35,940 Nothing special but again 611 00:22:35,940 --> 00:22:37,900 very easy and very 612 00:22:37,900 --> 00:22:39,320 grateful to have this to build on. 613 00:22:40,580 --> 00:22:42,080 But moving into what you're here 614 00:22:42,080 --> 00:22:44,140 to see is the demo for CaffeineMonkey. 615 00:22:44,400 --> 00:22:45,980 Here you'll see we're at the command 616 00:22:45,980 --> 00:22:47,540 line and Unix based 617 00:22:48,180 --> 00:22:49,840 and we've got 618 00:22:49,840 --> 00:22:51,860 the JavaScript from the earlier 619 00:22:52,160 --> 00:22:53,660 slide, the highly obfuscated 620 00:22:54,860 --> 00:22:55,600 pasted in there. 621 00:22:56,860 --> 00:22:58,160 And we were going to do 622 00:22:58,160 --> 00:22:59,660 this live but like all demos 623 00:22:59,660 --> 00:23:01,620 those are doomed to fail so we figured 624 00:23:01,620 --> 00:23:02,920 screenshots are the best bet. 625 00:23:03,120 --> 00:23:05,880 If you want to play with the tool yourself later you can download it. 626 00:23:06,800 --> 00:23:08,140 So here's some of the logging 627 00:23:08,140 --> 00:23:09,940 being printed out and we 628 00:23:09,940 --> 00:23:11,260 just write these to files. 629 00:23:11,600 --> 00:23:13,080 You can't analyze 630 00:23:13,960 --> 00:23:15,900 a big file as it's scrolling 631 00:23:15,900 --> 00:23:18,140 across the screen because it just produces too much output. 632 00:23:18,700 --> 00:23:19,620 But as you see 633 00:23:20,040 --> 00:23:21,560 new strings are being created here. 634 00:23:22,160 --> 00:23:23,840 Every time a string 635 00:23:23,840 --> 00:23:25,600 concatenation occurs which is a 636 00:23:25,600 --> 00:23:27,660 very large occurrence in both malicious 637 00:23:27,660 --> 00:23:30,180 JavaScript and simply 638 00:23:30,180 --> 00:23:31,560 just obfuscated JavaScript. 639 00:23:32,040 --> 00:23:33,940 New strings are created 640 00:23:33,940 --> 00:23:36,040 thousands of times throughout the script. 641 00:23:36,440 --> 00:23:38,080 You see here documents being built 642 00:23:38,080 --> 00:23:40,380 up, document.write, document.write 643 00:23:40,380 --> 00:23:41,860 and as you can see 644 00:23:41,860 --> 00:23:44,000 further it's producing the strings 645 00:23:44,000 --> 00:23:46,020 that it's going to write into the HTML 646 00:23:46,020 --> 00:23:46,560 web page. 647 00:23:47,780 --> 00:23:49,560 Moving further down the line 648 00:23:50,160 --> 00:23:52,020 you see eval is 649 00:23:52,160 --> 00:23:54,160 hooked in. You can see exactly 650 00:23:54,160 --> 00:23:55,880 what's being passed into eval. 651 00:23:55,980 --> 00:23:57,480 It's a document.write. 652 00:23:57,720 --> 00:24:00,020 You see it continues down as it's 653 00:24:00,020 --> 00:24:01,820 having to make some new strings because it 654 00:24:01,820 --> 00:24:04,500 again passed in some string concatenation 655 00:24:04,500 --> 00:24:05,120 to eval. 656 00:24:05,950 --> 00:24:08,060 And finally you see document.write being 657 00:24:08,060 --> 00:24:09,560 called with 658 00:24:09,910 --> 00:24:11,820 the script and a source 659 00:24:11,820 --> 00:24:13,520 to an external JavaScript. 660 00:24:14,200 --> 00:24:16,280 For completeness as it turns out 661 00:24:16,280 --> 00:24:18,280 this particular one was a 662 00:24:18,280 --> 00:24:19,720 highly nested 663 00:24:19,720 --> 00:24:21,900 advertisement for the Spanish 664 00:24:22,160 --> 00:24:23,460 speaking adult friend finder world. 665 00:24:25,920 --> 00:24:27,880 And that's what you'll find is there's 666 00:24:27,880 --> 00:24:29,860 a lot of redirection and you just keep passing 667 00:24:29,860 --> 00:24:31,940 through these onions. So imagine if you 668 00:24:31,940 --> 00:24:33,980 walked through this script yourself only to get 669 00:24:33,980 --> 00:24:35,920 to find out that it's just pointing 670 00:24:35,920 --> 00:24:37,860 somewhere else where you have to go through it again. 671 00:24:38,360 --> 00:24:39,320 Not a fun day. 672 00:24:40,880 --> 00:24:42,200 So here's the result 673 00:24:42,200 --> 00:24:42,820 like I said. 674 00:24:43,220 --> 00:24:45,820 The obfuscated JavaScript all 675 00:24:45,820 --> 00:24:46,940 boiled down into this. 676 00:24:47,540 --> 00:24:50,280 Not a lot there but a lot of code around it to make it happen. 677 00:24:52,800 --> 00:24:53,240 Yeah. 678 00:24:56,480 --> 00:24:57,880 So they wanted to 679 00:24:57,880 --> 00:24:59,400 see the original. Here it is again. 680 00:24:59,840 --> 00:25:02,160 You can see here how it's working. It's just a lot of 681 00:25:02,160 --> 00:25:04,100 care adds. A lot of string from 682 00:25:04,100 --> 00:25:05,920 cares. And it's got a little 683 00:25:05,920 --> 00:25:07,480 cipher in there. I think this 684 00:25:07,480 --> 00:25:09,540 turned out to be your typical 685 00:25:09,540 --> 00:25:11,980 Caesar cipher. You know moving by 686 00:25:11,980 --> 00:25:13,320 an offset of 687 00:25:13,320 --> 00:25:15,120 24 to go around. 688 00:25:15,720 --> 00:25:16,160 Yeah. 689 00:25:18,300 --> 00:25:19,900 So that's what it started at. 690 00:25:20,840 --> 00:25:22,060 And after the tool ran 691 00:25:22,160 --> 00:25:23,580 through it, this is what it ended up. 692 00:25:23,800 --> 00:25:25,840 And the tool is very quick. This is 693 00:25:25,840 --> 00:25:27,480 a matter of a second. It's 694 00:25:27,960 --> 00:25:28,720 zero time at all. 695 00:25:30,300 --> 00:25:32,140 Moving into some of the pitfalls of current 696 00:25:32,140 --> 00:25:33,900 technologies and why we developed the tool. 697 00:25:34,180 --> 00:25:36,000 Well there's a lot of honey clients out there. 698 00:25:36,180 --> 00:25:38,100 It's an area that's been very 699 00:25:38,100 --> 00:25:39,740 ripe for research in the past few 700 00:25:39,740 --> 00:25:40,920 months and years. 701 00:25:41,520 --> 00:25:43,900 Had the MS Strider project which was 702 00:25:43,900 --> 00:25:46,000 kind of the first widespread use of a honey monkey 703 00:25:46,000 --> 00:25:47,760 type product project 704 00:25:48,400 --> 00:25:50,040 of a piece of software going 705 00:25:50,040 --> 00:25:51,260 out, scouring the web, 706 00:25:52,160 --> 00:25:53,880 running against multiple versions of IE. 707 00:25:54,780 --> 00:25:56,080 Now there's not a lot of info 708 00:25:56,080 --> 00:25:57,900 published about this. But 709 00:25:57,900 --> 00:25:59,980 from what I understand and from the 710 00:25:59,980 --> 00:26:01,980 information I've gathered is that 711 00:26:01,980 --> 00:26:04,080 a lot of exploits were found using 712 00:26:04,080 --> 00:26:06,020 these tools and a lot of patches were made 713 00:26:06,020 --> 00:26:07,240 that we've seen come out. 714 00:26:08,160 --> 00:26:09,940 Other things that have come across 715 00:26:09,940 --> 00:26:12,140 are the Mitre honey client project, 716 00:26:12,860 --> 00:26:13,900 Capture, Honey C. 717 00:26:14,340 --> 00:26:15,940 These are all relatively similar 718 00:26:15,940 --> 00:26:17,900 in the way they act. They have caveats 719 00:26:17,900 --> 00:26:19,940 one way or the other of what they're designed 720 00:26:19,940 --> 00:26:21,020 to do better or worse. 721 00:26:22,160 --> 00:26:23,440 The problem with a lot of them though 722 00:26:23,440 --> 00:26:25,920 is that they're very heavyweight and resource intensive 723 00:26:25,920 --> 00:26:27,380 like I spoke about earlier. 724 00:26:27,600 --> 00:26:29,840 Using either VMs and multiple snapshots 725 00:26:29,840 --> 00:26:30,840 or heavy duty hardware, 726 00:26:31,440 --> 00:26:34,120 lots of drive space and just in general 727 00:26:34,120 --> 00:26:36,100 taking a long time and a lot of resources 728 00:26:36,100 --> 00:26:38,000 to use. There's also 729 00:26:38,000 --> 00:26:39,420 the other methods being used 730 00:26:39,420 --> 00:26:42,020 which are very high interaction from the human 731 00:26:42,020 --> 00:26:44,100 perspective and are very slow 732 00:26:44,100 --> 00:26:46,120 to work. Imagine there are 733 00:26:46,120 --> 00:26:48,080 analysts and I've seen them do it 734 00:26:48,080 --> 00:26:50,080 that step through this code 735 00:26:50,080 --> 00:26:52,080 manually by hand writing down the results 736 00:26:52,160 --> 00:26:54,220 as they go through this obfuscated 737 00:26:54,220 --> 00:26:55,840 JavaScript. It'll take them hours 738 00:26:55,840 --> 00:26:57,740 to step through it and figure out exactly 739 00:26:57,740 --> 00:27:00,120 what's happening. It's a real waste of human 740 00:27:00,120 --> 00:27:02,300 time. Not to mention 741 00:27:02,300 --> 00:27:03,480 it's very error prone. 742 00:27:03,860 --> 00:27:05,700 You mess up one or two steps 743 00:27:06,760 --> 00:27:08,120 in something like the 744 00:27:08,120 --> 00:27:10,080 example we showed and you're not going to have a clue 745 00:27:10,080 --> 00:27:10,640 what happened. 746 00:27:11,340 --> 00:27:11,900 Because if 747 00:27:13,760 --> 00:27:15,720 that result is used later on 748 00:27:15,720 --> 00:27:17,760 then you've thrown off your whole analysis 749 00:27:17,760 --> 00:27:19,040 and you're going to have to start over. 750 00:27:21,580 --> 00:27:22,060 Speaking 751 00:27:22,160 --> 00:27:24,040 of the safety issue, again the text area 752 00:27:24,040 --> 00:27:24,400 wrap, 753 00:27:25,840 --> 00:27:28,120 I wouldn't trust it under O-Day conditions. 754 00:27:28,380 --> 00:27:29,480 I don't think anyone should. 755 00:27:29,740 --> 00:27:32,080 It's a good way to get your browser DOST 756 00:27:32,080 --> 00:27:32,340 and 757 00:27:33,920 --> 00:27:35,800 bypass your analysis and make you 758 00:27:35,800 --> 00:27:38,000 have to start all over and find a different approach. 759 00:27:44,680 --> 00:27:45,940 So Daniel talked 760 00:27:45,940 --> 00:27:47,420 about the web crawler component 761 00:27:47,420 --> 00:27:49,980 of the software. Essentially 762 00:27:49,980 --> 00:27:51,780 we wanted to spider some 763 00:27:52,160 --> 00:27:53,720 websites or 764 00:27:53,720 --> 00:27:55,940 basically start spidering with seeds 765 00:27:55,940 --> 00:27:57,700 of some websites we thought would yield 766 00:27:57,700 --> 00:27:59,000 interesting samples of JavaScript. 767 00:27:59,760 --> 00:28:01,700 What immediately came to mind was 768 00:28:01,700 --> 00:28:03,380 MySpace social networking site. 769 00:28:04,040 --> 00:28:06,000 Basically this is a site you're all familiar 770 00:28:06,000 --> 00:28:07,440 with and one of the 771 00:28:07,960 --> 00:28:09,760 characteristics of it is it allows user 772 00:28:09,760 --> 00:28:12,000 defined content to be uploaded 773 00:28:12,000 --> 00:28:13,460 including scripting. 774 00:28:14,720 --> 00:28:15,620 To hop 775 00:28:16,040 --> 00:28:16,900 right back to 776 00:28:17,940 --> 00:28:19,920 the Heritrix crawler, you could see 777 00:28:19,920 --> 00:28:21,940 essentially we defined 778 00:28:22,160 --> 00:28:24,200 several jobs in the Heritrix 779 00:28:24,200 --> 00:28:25,120 terminology. 780 00:28:25,540 --> 00:28:28,080 A job essentially starts with a list of seed 781 00:28:28,080 --> 00:28:30,060 URLs that it's going to start crawling 782 00:28:30,060 --> 00:28:32,140 with. From those seed URLs 783 00:28:32,140 --> 00:28:34,020 it basically will run either till 784 00:28:34,020 --> 00:28:36,020 it's completed the task and it's 785 00:28:36,020 --> 00:28:38,200 basically spidered the entire 786 00:28:38,200 --> 00:28:39,880 tree to completion or 787 00:28:39,880 --> 00:28:41,960 until the operator essentially 788 00:28:41,960 --> 00:28:43,320 cuts it off. 789 00:28:44,760 --> 00:28:46,140 As you can 790 00:28:46,140 --> 00:28:47,640 see we've targeted 791 00:28:47,940 --> 00:28:49,960 MySpace initially. We also targeted 792 00:28:49,960 --> 00:28:51,840 Whereas and Serial 793 00:28:52,160 --> 00:28:53,920 sites for pirated software. 794 00:28:54,820 --> 00:28:55,920 Using some Google 795 00:28:55,920 --> 00:28:58,100 hacking, we identified a list of 796 00:28:58,100 --> 00:29:00,020 .edu servers that had been compromised 797 00:29:00,020 --> 00:29:02,180 and that were hosting pornography 798 00:29:02,180 --> 00:29:02,800 and malware. 799 00:29:04,640 --> 00:29:06,240 Basically after those results 800 00:29:06,240 --> 00:29:08,200 we decided maybe we should check out 801 00:29:08,200 --> 00:29:09,780 some .mil, .countrycode 802 00:29:09,780 --> 00:29:12,020 sites that had been compromised 803 00:29:12,020 --> 00:29:13,400 and were hosting malware and porn. 804 00:29:13,620 --> 00:29:14,700 There are some out there. 805 00:29:17,880 --> 00:29:19,960 It's quite easy with Google using 806 00:29:19,960 --> 00:29:21,580 the NURL flag 807 00:29:22,160 --> 00:29:23,520 looking for .mil 808 00:29:24,000 --> 00:29:25,460 and then looking for various 809 00:29:26,260 --> 00:29:27,940 terms indicative of 810 00:29:27,940 --> 00:29:28,320 pornography. 811 00:29:30,580 --> 00:29:32,440 Also stopbadware.org 812 00:29:32,440 --> 00:29:33,600 is a great site for 813 00:29:34,060 --> 00:29:35,940 if you're looking for compromised 814 00:29:35,940 --> 00:29:37,780 web servers. Also 815 00:29:37,780 --> 00:29:40,120 shadowserver.org I believe is another one. 816 00:29:40,680 --> 00:29:41,660 The guys at 817 00:29:41,660 --> 00:29:43,960 stopbadware have an exhaustive list of 818 00:29:44,780 --> 00:29:46,080 sites they've identified 819 00:29:46,080 --> 00:29:47,920 as being malicious or attempting to 820 00:29:47,920 --> 00:29:48,780 exploit your browser. 821 00:29:49,860 --> 00:29:51,980 If you're a security researcher you could use these 822 00:29:52,160 --> 00:29:54,060 lists. Some of these sites will have already 823 00:29:54,060 --> 00:29:55,940 been taken down but many of them will have not been 824 00:29:55,940 --> 00:29:58,080 taken down. You could use 825 00:29:58,080 --> 00:29:59,300 these to perform some research. 826 00:30:00,960 --> 00:30:02,040 Also I've heard 827 00:30:02,040 --> 00:30:03,820 that Google, which has their own internal 828 00:30:03,820 --> 00:30:05,620 effort to identify malicious sites 829 00:30:05,620 --> 00:30:07,540 and filter their search results out, 830 00:30:08,000 --> 00:30:09,820 is now starting to share more information 831 00:30:09,820 --> 00:30:11,980 and more of their list of bad sites 832 00:30:11,980 --> 00:30:12,760 that they've identified. 833 00:30:14,180 --> 00:30:15,740 So what did we find here? 834 00:30:16,560 --> 00:30:18,140 Well, I'm basically talking about 835 00:30:18,140 --> 00:30:18,920 the MySpace run. 836 00:30:19,680 --> 00:30:22,080 We spidered MySpace for about three and a half days 837 00:30:22,160 --> 00:30:24,100 we collected about eight gigabytes of data. 838 00:30:24,500 --> 00:30:26,320 In that eight gigabytes of data 839 00:30:26,320 --> 00:30:28,180 there are approximately four to five 840 00:30:28,180 --> 00:30:29,980 hundred unique JavaScript 841 00:30:29,980 --> 00:30:31,220 documents that we collected. 842 00:30:31,560 --> 00:30:33,220 So the vast majority 843 00:30:35,200 --> 00:30:36,200 was text 844 00:30:36,200 --> 00:30:38,100 HTML. This is a crawl report 845 00:30:38,100 --> 00:30:39,420 of our MySpace crawl. 846 00:30:39,760 --> 00:30:42,420 So you can see there's almost 121,000 847 00:30:42,420 --> 00:30:44,120 unique HTML documents that were returned. 848 00:30:44,420 --> 00:30:45,920 There's 78,000 849 00:30:46,580 --> 00:30:47,140 JPEGs. 850 00:30:47,660 --> 00:30:50,200 But we only found 500 Javascripts. 851 00:30:50,200 --> 00:30:52,060 And again, as Daniel said, we were 852 00:30:52,160 --> 00:30:53,960 identifying Javascripts by their mind type. 853 00:30:54,400 --> 00:30:55,900 Obviously that's an incomplete solution 854 00:30:55,900 --> 00:30:58,180 because you can embed scripts in various 855 00:30:58,180 --> 00:31:00,040 ways. You don't necessarily even need a script 856 00:31:00,040 --> 00:31:02,060 tag for your Javascript 857 00:31:02,060 --> 00:31:03,360 to be dynamically interpreted. 858 00:31:03,740 --> 00:31:06,100 But that really wasn't the problem we were trying to solve 859 00:31:06,100 --> 00:31:07,940 and we thought, just looking at mind type 860 00:31:07,940 --> 00:31:09,100 would be a good enough approximation 861 00:31:09,100 --> 00:31:10,980 and get us some data pretty quickly. 862 00:31:11,340 --> 00:31:16,500 Those are unique documents. 863 00:31:19,180 --> 00:31:20,000 And you see 864 00:31:20,000 --> 00:31:21,900 we had 4.9 gigabytes of text 865 00:31:22,160 --> 00:31:22,400 in HTML. 866 00:31:27,140 --> 00:31:29,580 So we found lots of obfuscated scripts, 867 00:31:30,500 --> 00:31:31,220 cookie 868 00:31:31,960 --> 00:31:32,320 manipulation, 869 00:31:33,940 --> 00:31:35,460 adware or ad syndication, 870 00:31:36,400 --> 00:31:37,120 tracking 871 00:31:37,120 --> 00:31:38,920 of your behaviors. 872 00:31:39,440 --> 00:31:42,120 But essentially, it was all benign. 873 00:31:42,480 --> 00:31:44,060 We did not identify 874 00:31:44,060 --> 00:31:45,240 of those 400 from 875 00:31:46,160 --> 00:31:48,120 MySpace, anything that we could 876 00:31:48,120 --> 00:31:50,060 really determine that was 877 00:31:50,060 --> 00:31:51,420 trying to exploit your browser. 878 00:31:52,160 --> 00:31:53,920 Sure, there was ad 879 00:31:53,920 --> 00:31:56,080 syndicators that were trying to get their advertisements 880 00:31:56,080 --> 00:31:57,640 past ad filters. 881 00:31:58,140 --> 00:32:00,020 But that's really not what 882 00:32:00,020 --> 00:32:01,420 we were concerned about at this point. 883 00:32:02,340 --> 00:32:04,020 There's all sorts of technologies for 884 00:32:04,020 --> 00:32:06,200 tracking people visiting your website, 885 00:32:06,540 --> 00:32:08,320 where they click on, how long they linger 886 00:32:08,320 --> 00:32:10,120 at places. And a lot of these scripts 887 00:32:10,120 --> 00:32:11,980 also use these obfuscation and evasion 888 00:32:11,980 --> 00:32:13,760 techniques because they 889 00:32:13,760 --> 00:32:15,980 don't want various filtering technologies 890 00:32:15,980 --> 00:32:16,920 to be able to block them. 891 00:32:17,700 --> 00:32:19,560 So we were somewhat surprised 892 00:32:21,400 --> 00:32:22,140 based on 893 00:32:22,160 --> 00:32:23,560 our limited run at MySpace. 894 00:32:24,000 --> 00:32:25,720 It seemed to be a relatively cleaner 895 00:32:25,720 --> 00:32:26,980 ship than we thought we'd find. 896 00:32:27,700 --> 00:32:29,780 So kudos to the security team at MySpace, 897 00:32:29,900 --> 00:32:30,200 I assume. 898 00:32:32,880 --> 00:32:34,060 So how do 899 00:32:34,060 --> 00:32:36,260 we go about classifying these JavaScripts? 900 00:32:36,260 --> 00:32:37,400 Now that we've collected 901 00:32:37,400 --> 00:32:39,700 a corpus of JavaScripts from MySpace, 902 00:32:40,020 --> 00:32:41,660 we went along in the 903 00:32:41,660 --> 00:32:43,620 research community and we found some 904 00:32:44,040 --> 00:32:45,980 researchers' websites that had examples of 905 00:32:45,980 --> 00:32:47,600 some nasty JavaScripts. 906 00:32:47,820 --> 00:32:49,940 So as Daniel 907 00:32:49,940 --> 00:32:51,960 talked about, we had hooked in the JavaScript 908 00:32:52,160 --> 00:32:53,920 interpreter a bunch of key functions, 909 00:32:54,200 --> 00:32:55,900 everything from object instantiation, 910 00:32:56,300 --> 00:32:58,080 string concatenation, escape 911 00:32:58,080 --> 00:32:59,860 and unescape, CHR functions, 912 00:33:00,260 --> 00:33:01,460 those kind of things. 913 00:33:02,240 --> 00:33:03,760 So the idea we had 914 00:33:03,760 --> 00:33:05,820 was basically to look at the usage of all these 915 00:33:05,820 --> 00:33:07,200 methods and these calls 916 00:33:07,200 --> 00:33:08,680 and compare 917 00:33:10,320 --> 00:33:11,980 running the corpus of 918 00:33:11,980 --> 00:33:13,580 benign JavaScript through the tool 919 00:33:13,920 --> 00:33:15,680 versus some samples of known 920 00:33:15,680 --> 00:33:17,920 malicious JavaScript. Essentially 921 00:33:17,920 --> 00:33:19,400 we were profiling the script execution 922 00:33:19,960 --> 00:33:21,840 by instrumenting the interpreter. 923 00:33:22,660 --> 00:33:23,300 And 924 00:33:24,020 --> 00:33:25,980 like I said before, we saw some benign 925 00:33:25,980 --> 00:33:28,020 uses of these obfuscation and evasion techniques. 926 00:33:29,380 --> 00:33:30,020 So 927 00:33:30,020 --> 00:33:31,820 this first graph here, 928 00:33:32,560 --> 00:33:34,160 I apologize if you 929 00:33:34,160 --> 00:33:35,780 can't make out the titles, 930 00:33:36,620 --> 00:33:37,780 is four 931 00:33:37,780 --> 00:33:39,920 samples of malicious JavaScript, 932 00:33:40,600 --> 00:33:42,080 monkey chow one through 933 00:33:42,080 --> 00:33:43,480 four, and 934 00:33:44,160 --> 00:33:46,120 basically we broke it down 935 00:33:46,120 --> 00:33:48,020 into stacked bar graphs based on 936 00:33:48,020 --> 00:33:50,020 the frequency of calls that we had 937 00:33:50,020 --> 00:33:51,020 hooked in the interpreter. 938 00:33:52,160 --> 00:33:54,080 The very bottom of the stacked bar graph 939 00:33:54,080 --> 00:33:55,580 in light blue is document write. 940 00:33:55,860 --> 00:33:58,000 So you see, document write isn't 941 00:33:58,000 --> 00:34:00,060 called very frequently, once or twice or three 942 00:34:00,060 --> 00:34:01,080 times in these samples. 943 00:34:01,600 --> 00:34:03,780 The large stack over that is 944 00:34:03,780 --> 00:34:05,460 string instantiation. 945 00:34:05,860 --> 00:34:08,020 And string instantiation turns out to be 946 00:34:08,020 --> 00:34:09,980 very frequent in these malicious 947 00:34:09,980 --> 00:34:11,880 JavaScripts. In fact, 948 00:34:12,060 --> 00:34:13,780 to generate usable 949 00:34:13,780 --> 00:34:16,080 graphs that really showed anything, 950 00:34:16,400 --> 00:34:18,000 we were having to scale 951 00:34:18,000 --> 00:34:20,100 the string instantiation by a factor of 952 00:34:20,100 --> 00:34:20,800 about 50 here. 953 00:34:23,440 --> 00:34:24,100 Calls to 954 00:34:24,100 --> 00:34:25,700 eval are indicated here, 955 00:34:26,020 --> 00:34:27,900 element instance calls of the 956 00:34:27,900 --> 00:34:30,020 document object, and also object 957 00:34:30,020 --> 00:34:30,760 instantiation. 958 00:34:32,020 --> 00:34:34,020 To compare this visually 959 00:34:34,020 --> 00:34:35,240 with our 960 00:34:36,040 --> 00:34:37,060 samples from MySpace, 961 00:34:37,700 --> 00:34:40,200 we broke down all the JavaScripts from MySpace 962 00:34:40,200 --> 00:34:41,140 by domain name. 963 00:34:42,140 --> 00:34:43,620 We took the top ten 964 00:34:44,080 --> 00:34:45,920 by the number of unique JavaScripts that were 965 00:34:45,920 --> 00:34:47,920 returned. And on the far left, 966 00:34:48,120 --> 00:34:50,120 by far the most JavaScripts 967 00:34:50,120 --> 00:34:51,940 were hosted up at the MySpace 968 00:34:52,160 --> 00:34:53,920 .com domain. These could be people's 969 00:34:53,920 --> 00:34:56,040 profiles, these could be MySpace's own internal 970 00:34:56,040 --> 00:34:57,940 JavaScripts to manage login and 971 00:34:57,940 --> 00:34:59,220 cookie tracking, etc. 972 00:34:59,700 --> 00:35:02,040 All the way, rounding out the top 973 00:35:02,040 --> 00:35:03,760 nine, actually, because we had a tie, 974 00:35:03,960 --> 00:35:05,580 is Hillaryclinton.com. 975 00:35:06,120 --> 00:35:07,780 And she 976 00:35:07,780 --> 00:35:10,120 is very popular on MySpace, many links 977 00:35:10,120 --> 00:35:11,120 lead to her website. 978 00:35:11,480 --> 00:35:13,540 And she hosted several 979 00:35:14,160 --> 00:35:16,100 JavaScripts that we ran through our analysis engine. 980 00:35:16,740 --> 00:35:17,960 Of note also 981 00:35:17,960 --> 00:35:18,600 is 982 00:35:19,980 --> 00:35:21,080 photofile.ru. 983 00:35:22,160 --> 00:35:22,360 So apparently 984 00:35:23,720 --> 00:35:25,400 hosting photos in the 985 00:35:25,960 --> 00:35:27,820 Russian networks is quite popular on 986 00:35:27,820 --> 00:35:29,300 MySpace for whatever reason. 987 00:35:31,880 --> 00:35:33,980 And here you see that document write 988 00:35:33,980 --> 00:35:36,220 is relatively 989 00:35:36,220 --> 00:35:38,020 more common. Document write 990 00:35:38,020 --> 00:35:39,420 is being called a lot more in these scripts. 991 00:35:39,880 --> 00:35:41,740 String instantiations are less frequent. 992 00:35:42,960 --> 00:35:43,980 Calls to eval 993 00:35:43,980 --> 00:35:45,880 are of different 994 00:35:45,880 --> 00:35:48,020 magnitude. And to put these 995 00:35:48,020 --> 00:35:50,060 two next to each other, I think you can visually see 996 00:35:50,060 --> 00:35:51,400 some of the patterns we found here. 997 00:35:52,160 --> 00:35:53,980 The four stack 998 00:35:53,980 --> 00:35:55,860 bar graphs on your left are 999 00:35:55,860 --> 00:35:58,000 known malicious JavaScripts. 1000 00:35:58,000 --> 00:36:00,180 The rest of them are those top nine domains 1001 00:36:00,180 --> 00:36:01,880 by the JavaScript samples 1002 00:36:01,880 --> 00:36:03,420 in our MySpace spider run. 1003 00:36:03,880 --> 00:36:06,080 So immediately it jumps out at you that 1004 00:36:06,080 --> 00:36:07,320 wow, document write 1005 00:36:08,160 --> 00:36:10,180 is rarely called 1006 00:36:10,180 --> 00:36:11,940 in these malicious scripts, but it's called 1007 00:36:11,940 --> 00:36:14,200 all over the place in these benign 1008 00:36:14,200 --> 00:36:16,240 JavaScripts. Another thing that struck 1009 00:36:16,240 --> 00:36:17,700 us is that relatively 1010 00:36:17,700 --> 00:36:20,020 string instantiation is happening much 1011 00:36:20,020 --> 00:36:22,060 more in these malicious 1012 00:36:22,160 --> 00:36:22,940 JavaScripts. 1013 00:36:24,100 --> 00:36:26,120 To speculate on why that is, 1014 00:36:26,280 --> 00:36:27,960 like we spoke before, the 1015 00:36:27,960 --> 00:36:29,600 string splitting method of evasion 1016 00:36:30,040 --> 00:36:31,760 is used throughout these malicious scripts 1017 00:36:31,760 --> 00:36:34,040 and these 1018 00:36:34,040 --> 00:36:36,000 benign scripts don't seem to be splitting up their 1019 00:36:36,000 --> 00:36:37,920 strings or instantiating new strings with 1020 00:36:37,920 --> 00:36:39,420 string concatenation nearly as frequently. 1021 00:36:40,360 --> 00:36:41,380 Also you see 1022 00:36:42,820 --> 00:36:44,020 eval is 1023 00:36:44,020 --> 00:36:45,780 called relatively more frequently 1024 00:36:45,780 --> 00:36:47,660 in the benign samples than it is 1025 00:36:47,660 --> 00:36:50,100 in the malicious samples. And object 1026 00:36:50,100 --> 00:36:52,020 instantiation is happening much more 1027 00:36:52,160 --> 00:36:53,960 at being the top bar chart in pink 1028 00:36:53,960 --> 00:36:55,320 in these 1029 00:36:56,480 --> 00:36:57,800 monkey chow malicious 1030 00:36:57,800 --> 00:36:59,880 samples than in our MySpace spider 1031 00:36:59,880 --> 00:37:00,620 run over here. 1032 00:37:01,660 --> 00:37:04,020 And when you download our tool from the website 1033 00:37:04,020 --> 00:37:05,960 the data this is based on 1034 00:37:05,960 --> 00:37:08,040 is available in the form of 1035 00:37:08,040 --> 00:37:09,640 a spreadsheet and a CSV file. 1036 00:37:10,140 --> 00:37:12,020 If you email us I'll also provide you a 1037 00:37:12,020 --> 00:37:13,180 database dump if you're curious. 1038 00:37:17,420 --> 00:37:18,580 So what's the future 1039 00:37:18,580 --> 00:37:21,520 of CaffeineMonkey? 1040 00:37:22,160 --> 00:37:24,000 Well the code is being made 1041 00:37:24,000 --> 00:37:26,100 available on the research tool 1042 00:37:26,100 --> 00:37:27,800 slash blog section 1043 00:37:27,800 --> 00:37:29,880 of our corporate website because 1044 00:37:29,880 --> 00:37:31,900 like most people in here we're owned by 1045 00:37:31,900 --> 00:37:32,220 somebody. 1046 00:37:34,120 --> 00:37:34,640 So 1047 00:37:36,000 --> 00:37:38,020 there's a lot of directions this can move. 1048 00:37:38,320 --> 00:37:39,900 And it'd be great 1049 00:37:39,900 --> 00:37:42,040 if the community as a whole is going to take it up 1050 00:37:42,040 --> 00:37:44,160 expand on it and save everybody some time. 1051 00:37:44,320 --> 00:37:46,060 Because it takes analysts more 1052 00:37:46,060 --> 00:37:48,000 and more time to go through these. Especially 1053 00:37:48,000 --> 00:37:50,000 if you're working in IPS, IDS 1054 00:37:50,000 --> 00:37:51,960 or any sort of incident response 1055 00:37:52,160 --> 00:37:53,780 capacity to find out what really happened. 1056 00:37:55,960 --> 00:37:57,520 It's going to take a long time. 1057 00:37:58,340 --> 00:38:00,080 So potential things 1058 00:38:00,080 --> 00:38:01,880 that could happen are inclusion in a web 1059 00:38:01,880 --> 00:38:04,180 proxy of some sort, IDS, IPS 1060 00:38:05,040 --> 00:38:05,920 heuristics based 1061 00:38:05,920 --> 00:38:07,560 addition to signature based platforms 1062 00:38:08,020 --> 00:38:09,780 or yet another point of 1063 00:38:10,600 --> 00:38:11,720 logic for 1064 00:38:11,720 --> 00:38:13,140 heuristics based platforms 1065 00:38:13,140 --> 00:38:14,740 or anything else. 1066 00:38:15,340 --> 00:38:17,920 Another crazy interplatform thing that could happen 1067 00:38:17,920 --> 00:38:19,400 is a Firefox plugin 1068 00:38:20,020 --> 00:38:22,040 that would run your JavaScript before it ran 1069 00:38:22,160 --> 00:38:22,600 your JavaScript. 1070 00:38:23,740 --> 00:38:24,980 Crazier things have happened. 1071 00:38:25,440 --> 00:38:27,180 Not suggesting that one but 1072 00:38:27,180 --> 00:38:29,460 if anybody wants to do it, knock yourself out. 1073 00:38:29,600 --> 00:38:31,880 It might be very useful and you'll probably learn a lot 1074 00:38:31,880 --> 00:38:32,340 in the time. 1075 00:38:34,240 --> 00:38:35,540 So moving on from there 1076 00:38:35,540 --> 00:38:36,300 we got about 1077 00:38:37,640 --> 00:38:39,740 seven or eight minutes for a Q&A before 1078 00:38:39,740 --> 00:38:41,180 we move into the smaller room. 1079 00:38:41,500 --> 00:38:43,000 So if anybody has anything 1080 00:38:43,000 --> 00:38:44,700 please raise your hand. 1081 00:38:47,480 --> 00:38:47,960 Yes. 1082 00:38:48,320 --> 00:38:48,800 Right. 1083 00:38:53,420 --> 00:38:54,540 I'm sorry. 1084 00:38:56,500 --> 00:38:57,060 Yes. 1085 00:38:57,860 --> 00:38:59,260 The logging shows 1086 00:38:59,260 --> 00:39:01,300 command by command 1087 00:39:01,300 --> 00:39:02,180 that has been hooked 1088 00:39:02,180 --> 00:39:03,640 as it runs through the tool. 1089 00:39:03,760 --> 00:39:05,200 It shows everything that happens. 1090 00:39:05,420 --> 00:39:05,740 For every 1091 00:39:07,720 --> 00:39:08,280 Yeah. 1092 00:39:09,220 --> 00:39:10,360 Among other things. 1093 00:39:10,640 --> 00:39:10,720 On the graph. 1094 00:39:14,420 --> 00:39:15,300 So basically 1095 00:39:15,300 --> 00:39:16,220 the legend here. 1096 00:39:16,460 --> 00:39:17,020 Oh, here. 1097 00:39:17,080 --> 00:39:18,780 This is just a selection of the ones that we 1098 00:39:18,800 --> 00:39:20,920 believed would show the best output. 1099 00:39:21,580 --> 00:39:22,900 There are other ones 1100 00:39:22,900 --> 00:39:23,400 that are output. 1101 00:39:24,440 --> 00:39:25,900 We haven't fully 1102 00:39:26,760 --> 00:39:27,800 put together everything 1103 00:39:27,800 --> 00:39:29,240 in the Caffeine Monkey 1104 00:39:29,240 --> 00:39:31,940 because Mozilla and IE 1105 00:39:31,940 --> 00:39:33,940 both have extended JavaScript some 1106 00:39:33,940 --> 00:39:36,200 past the basic engine approach 1107 00:39:36,660 --> 00:39:37,940 but a lot of things are in there 1108 00:39:37,940 --> 00:39:39,540 that would be called. 1109 00:39:42,880 --> 00:39:43,680 Sparkly shirt. 1110 00:39:51,260 --> 00:39:52,360 The question was 1111 00:39:52,360 --> 00:39:53,660 the presentation on the CD. 1112 00:39:54,280 --> 00:39:55,100 Yes it is. 1113 00:39:55,820 --> 00:39:57,500 The skeleton version of it. 1114 00:39:57,680 --> 00:39:59,380 It's not full but it's pretty close. 1115 00:40:00,220 --> 00:40:00,700 Yes. 1116 00:40:00,840 --> 00:40:02,420 The white paper should also be on the CD. 1117 00:40:05,660 --> 00:40:06,680 You don't see the 1118 00:40:10,540 --> 00:40:11,500 We'll go 1119 00:40:11,500 --> 00:40:13,840 It should be downloadable 1120 00:40:13,840 --> 00:40:15,340 from the same location as the tool. 1121 00:40:17,240 --> 00:40:18,200 Which again 1122 00:40:18,800 --> 00:40:19,060 it's right there. 1123 00:40:20,820 --> 00:40:21,360 Okay. 1124 00:40:22,420 --> 00:40:23,200 Sound guy? 1125 00:40:25,500 --> 00:40:26,220 Or not. 1126 00:40:58,800 --> 00:40:59,280 Right. 1127 00:40:59,840 --> 00:41:00,840 So the question that was 1128 00:41:00,840 --> 00:41:02,080 asked is about 1129 00:41:02,660 --> 00:41:04,260 application security in this context. 1130 00:41:04,400 --> 00:41:06,160 It seems like you're going to have to have an application 1131 00:41:06,740 --> 00:41:07,920 that allows this to run 1132 00:41:07,920 --> 00:41:09,480 that scans it beforehand. 1133 00:41:09,840 --> 00:41:11,820 And that's exactly a lot of the problem we're seeing 1134 00:41:11,820 --> 00:41:13,580 is that these are just run straight out beforehand 1135 00:41:13,580 --> 00:41:16,260 and your AV might catch it, it might not. 1136 00:41:16,440 --> 00:41:18,000 With AV it all depends. 1137 00:41:18,800 --> 00:41:19,460 AV makes the first hit. 1138 00:41:19,760 --> 00:41:22,060 AV isn't based on preemptive detection 1139 00:41:22,060 --> 00:41:23,820 except with some of their heuristics models. 1140 00:41:31,080 --> 00:41:31,720 Correct. 1141 00:41:46,440 --> 00:41:47,940 That is correct. 1142 00:41:48,800 --> 00:41:49,720 The sandboxing technology 1143 00:41:49,720 --> 00:41:51,840 that the gentleman up here is mentioning 1144 00:41:51,840 --> 00:41:54,080 could be used and should be used 1145 00:41:54,080 --> 00:41:55,140 in a lot of web browsers 1146 00:41:55,140 --> 00:41:56,880 and it probably will continue 1147 00:41:56,880 --> 00:41:58,580 probably will be like that in the future. 1148 00:42:01,280 --> 00:42:01,840 Yeah. 1149 00:42:06,720 --> 00:42:07,280 Right. 1150 00:42:13,420 --> 00:42:15,940 Essentially our web crawler was set up 1151 00:42:15,940 --> 00:42:17,720 on one, you know, 1152 00:42:17,740 --> 00:42:18,900 mid-level 1153 00:42:18,900 --> 00:42:21,440 recent vintage Dell workstation. 1154 00:42:21,740 --> 00:42:23,480 It was hanging off a 1155 00:42:23,480 --> 00:42:25,160 residential broadband connection. 1156 00:42:26,560 --> 00:42:27,320 And 1157 00:42:27,600 --> 00:42:29,480 we gathered the eight gigabytes off 1158 00:42:29,480 --> 00:42:31,840 MySpace over approximately three and a half days. 1159 00:42:32,600 --> 00:42:33,680 I believe 1160 00:42:33,680 --> 00:42:36,000 we had, you know, say 120,000 1161 00:42:36,000 --> 00:42:36,760 HTML documents, 1162 00:42:37,320 --> 00:42:39,300 77,000 JPEGs, 1163 00:42:39,460 --> 00:42:41,720 500 JavaScripts in that 1164 00:42:41,720 --> 00:42:42,240 corpus. 1165 00:42:43,180 --> 00:42:45,280 And I'd be happy to 1166 00:42:45,940 --> 00:42:47,700 I don't have the numbers off the top of my head 1167 00:42:47,700 --> 00:42:49,400 for the other runs, but just to give you an idea 1168 00:42:49,400 --> 00:42:50,280 of how long that took. 1169 00:43:00,620 --> 00:43:05,340 What really concerns me 1170 00:43:06,000 --> 00:43:07,460 is the heap spray and 1171 00:43:07,460 --> 00:43:09,340 feng shui attacks. 1172 00:43:10,720 --> 00:43:11,940 Basically they yield directly 1173 00:43:11,940 --> 00:43:13,400 into remote code execution 1174 00:43:13,400 --> 00:43:15,920 through the browser. They're hard to detect. 1175 00:43:15,940 --> 00:43:18,100 And they're quite reliable. 1176 00:43:29,260 --> 00:43:31,680 Based on my understanding of heap spray, 1177 00:43:32,620 --> 00:43:33,840 and I'm not 1178 00:43:33,840 --> 00:43:35,400 the expert on this, essentially 1179 00:43:35,400 --> 00:43:38,180 the JavaScript, since it's running in the browser, 1180 00:43:38,540 --> 00:43:39,980 when you're doing things 1181 00:43:39,980 --> 00:43:42,040 it's allocating heap space in the browser's heap. 1182 00:43:42,320 --> 00:43:43,940 Okay. And so you could 1183 00:43:43,940 --> 00:43:45,540 spray a particular 1184 00:43:45,940 --> 00:43:47,540 nop-sled that is a valid heap address 1185 00:43:48,160 --> 00:43:49,600 followed by your shellcode. 1186 00:43:49,920 --> 00:43:51,740 And then you need to combine it with one more 1187 00:43:52,320 --> 00:43:53,920 the final punch and the one-two 1188 00:43:53,920 --> 00:43:55,960 setup to essentially overwrite 1189 00:43:55,960 --> 00:43:57,760 a virtual function pointer. It's going to 1190 00:43:57,760 --> 00:43:59,160 redirect you back into the heap. 1191 00:43:59,680 --> 00:44:01,800 And then it'll, when you overwrite 1192 00:44:01,800 --> 00:44:03,780 that function pointer, like I said, it's a 1193 00:44:03,780 --> 00:44:05,820 heap address, nop-sled, that's going to 1194 00:44:05,820 --> 00:44:07,900 jump you or trampoline you over to your 1195 00:44:07,900 --> 00:44:08,660 shellcode. 1196 00:44:09,920 --> 00:44:11,880 From what I can tell, the heap lib 1197 00:44:11,880 --> 00:44:14,180 tool that Alexander Sadarov 1198 00:44:14,180 --> 00:44:15,720 released, it's quite reliable. 1199 00:44:15,940 --> 00:44:17,700 And it's improving on the initial 1200 00:44:17,700 --> 00:44:18,860 heap spray attacks. 1201 00:44:23,940 --> 00:44:24,500 Right. 1202 00:44:25,840 --> 00:44:27,940 The basic SpiderMonkey you're going to download 1203 00:44:27,940 --> 00:44:29,380 doesn't have a document object. 1204 00:44:29,620 --> 00:44:31,480 It doesn't have a navigator object 1205 00:44:31,480 --> 00:44:33,540 or a location. So we implemented 1206 00:44:33,540 --> 00:44:35,140 the document object, we implemented 1207 00:44:35,760 --> 00:44:36,860 navigator, we implemented location, 1208 00:44:37,300 --> 00:44:38,560 the screen object, 1209 00:44:40,280 --> 00:44:41,440 can't recall the others. 1210 00:44:41,560 --> 00:44:43,380 So we were adding in functionality 1211 00:44:43,380 --> 00:44:45,540 and we were also hooking a lot of the existing 1212 00:44:45,940 --> 00:44:48,040 calls. We hooked the internal 1213 00:44:48,040 --> 00:44:49,660 function that does string instantiation. 1214 00:44:49,980 --> 00:44:51,780 We hooked the escape and unescape 1215 00:44:51,780 --> 00:44:53,800 functions. We hooked the internal function 1216 00:44:53,800 --> 00:44:55,900 that yields object instantiation. 1217 00:44:56,320 --> 00:44:58,140 And in that method 1218 00:44:58,140 --> 00:44:59,900 we didn't care about the syntax or the 1219 00:44:59,900 --> 00:45:01,820 semantics of the script as it's 1220 00:45:01,820 --> 00:45:03,860 presented. We're essentially hooked in the 1221 00:45:03,860 --> 00:45:05,780 interpreter and profiling the 1222 00:45:05,780 --> 00:45:06,480 dynamic execution. 1223 00:45:08,220 --> 00:45:08,740 . 1224 00:45:15,780 --> 00:45:18,300 We weren't the first to come up with this idea. 1225 00:45:18,600 --> 00:45:20,420 Didier Stevens had a blog post 1226 00:45:20,420 --> 00:45:22,360 where he was exploring this 1227 00:45:22,360 --> 00:45:22,640 idea. 1228 00:45:24,360 --> 00:45:26,340 There's a couple others that had mentioned it. 1229 00:45:26,660 --> 00:45:28,500 I think we may be the first 1230 00:45:28,500 --> 00:45:30,380 that added that much more 1231 00:45:30,380 --> 00:45:31,280 functionality to it. 1232 00:45:32,260 --> 00:45:34,320 I'd be happy if you guys checked out the 1233 00:45:34,320 --> 00:45:34,620 code. 1234 00:45:36,480 --> 00:45:38,300 If you got improvements, we'd like to see them. 1235 00:45:39,500 --> 00:45:40,480 So it's out there for 1236 00:45:40,480 --> 00:45:41,180 anybody to use. 1237 00:45:44,180 --> 00:45:45,280 If that's all the questions, 1238 00:45:45,920 --> 00:45:47,640 we may be moving over to the Q&A 1239 00:45:47,640 --> 00:45:49,500 track room across the hallway. 1240 00:45:49,700 --> 00:45:50,200 Thank you.