1 00:00:00,990 --> 00:00:02,810 Hello, my name is Michael Schrenk. 2 00:00:02,810 --> 00:00:07,170 I live in Las Vegas, Nevada, where I write botnets for a living. 3 00:00:07,170 --> 00:00:09,250 And I'm here to talk about malware. 4 00:00:09,250 --> 00:00:10,770 Thanks for coming to my talk. 5 00:00:10,850 --> 00:00:23,430 So I said I write botnets, and what that basically means is that I write distributed systems that do data extraction, we do automation, we do analytics. 6 00:00:23,430 --> 00:00:30,910 But one thing that we get to do a lot more than probably most people is look at other people's code. 7 00:00:30,910 --> 00:00:34,830 It's because we download webpages and we have to write parsers for them. 8 00:00:34,830 --> 00:00:39,450 So we get to look at a lot of source code. 9 00:00:39,450 --> 00:00:50,310 And one of the things that I've noticed, I've been doing this now since the mid-90s, and I've noticed that people are using JavaScript differently than they did even 10 years ago. 10 00:00:50,430 --> 00:00:51,930 So that's what this is about. 11 00:00:51,930 --> 00:00:58,170 And I believe that JavaScript is being used in a dangerous way that can be used as an attack vector. 12 00:00:59,530 --> 00:01:08,470 So one of the things I did to get a better idea of how people are using JavaScript, you know, if I'm just looking at files randomly, that means one thing. 13 00:01:08,470 --> 00:01:16,110 But to go off and look at 1,000 of the top websites and see how they use JavaScript would be a really useful thing. 14 00:01:16,110 --> 00:01:17,130 So I did that. 15 00:01:17,130 --> 00:01:26,690 I wrote a bot that goes out and looks at a list of 1,000 websites, analyzes their homepage for how they are using JavaScript. 16 00:01:26,690 --> 00:01:28,650 And that's part of this talk. 17 00:01:29,390 --> 00:01:31,990 But here's really what we're going to discuss. 18 00:01:31,990 --> 00:01:43,090 We are going to discuss this thing that I'm calling third-party JavaScript, which is... there we go, get my... it's like this stuff that we're talking about right here. 19 00:01:43,110 --> 00:01:54,710 It's these little scripts that people include in their HTML that brings in external JavaScript libraries like jQuery, Google Charts, you name it. 20 00:01:54,710 --> 00:01:57,010 There are a lot of these that people are using. 21 00:01:58,550 --> 00:02:05,810 And I believe that these third-party JavaScript files are an attack vector, and I'm going to show you why. 22 00:02:05,950 --> 00:02:15,900 I'm going to give you examples, and I'm also going to teach you ways that you can use these third-party files in a much, much more secure environment. 23 00:02:17,070 --> 00:02:26,590 So one of the things that I want to make very clear here is that I do not believe that JavaScript itself is a threat. 24 00:02:26,590 --> 00:02:34,560 I believe that the way people use JavaScript is a threat, and the way they're using it creates opportunities for attack vectors. 25 00:02:35,960 --> 00:02:42,900 So, before we look at the threat, we need to figure out what exactly JavaScript is capable of doing. 26 00:02:42,980 --> 00:02:46,920 Well, it's basically capable of doing two things. 27 00:02:46,980 --> 00:02:52,460 As you probably know, if you're a developer, you know that JavaScript operates on the DOM. 28 00:02:52,660 --> 00:02:58,720 So anything on a web page, JavaScript pretty much has access to it, with a few exceptions. 29 00:02:58,900 --> 00:03:04,140 But basically, it can not only have access to it, but it can also change things on the website. 30 00:03:04,220 --> 00:03:11,780 The other thing it can do is JavaScript can communicate with other servers, right, using Ajax-y kind of technologies. 31 00:03:11,980 --> 00:03:20,300 Also, if you are downloading the library from an external server, you're also leaving server logs, right? 32 00:03:20,300 --> 00:03:38,440 So my guess is that if you went to any of these big framework suppliers, like jQuery or Angular, if you looked in their log files, you could learn a lot about the people who are using their libraries, just from the metadata that becomes created. 33 00:03:38,500 --> 00:03:45,280 The other thing you might say is that JavaScript, that's not dangerous, that's just like HTML, right? 34 00:03:45,280 --> 00:03:47,100 No, it is actually dangerous. 35 00:03:47,100 --> 00:04:02,140 There have been over 40,000 known examples of JavaScript malware that have not only been documented, but they're available for you at this website, at GitHub, the address is in the URL. 36 00:04:02,500 --> 00:04:07,880 And you can go there and you can download them, you can play with them, you can study them, you can do whatever you want to with them. 37 00:04:07,960 --> 00:04:09,760 But they do exist. 38 00:04:10,320 --> 00:04:17,880 So what exactly am I talking about when I refer to a third-party JavaScript file? 39 00:04:17,880 --> 00:04:20,540 Well, there's two different things that I'm referring to. 40 00:04:20,540 --> 00:04:26,920 One are files that are truly third-party and truly remote. 41 00:04:26,920 --> 00:04:29,820 That would include examples like the one over here. 42 00:04:29,820 --> 00:04:31,020 I got to get this down. 43 00:04:31,020 --> 00:04:32,020 Right over here. 44 00:04:32,860 --> 00:04:41,660 You're just making a JavaScript request to bring in or to include another JavaScript file that you will reference later. 45 00:04:41,800 --> 00:04:49,720 The other example would be a file that's running off of your own server, but it's one that you didn't write. 46 00:04:49,720 --> 00:04:56,820 So in other words, you went and you downloaded somebody's library, threw it on your server, referenced that, and that's the file that you're using. 47 00:04:56,820 --> 00:05:05,320 As far as I'm concerned, if you don't do anything else, these are both third-party JavaScript files, and they can both cause some trouble. 48 00:05:07,380 --> 00:05:18,680 The other problem is that when you're using somebody else's code like this, you are doing it without any kind of source control whatsoever. 49 00:05:18,680 --> 00:05:26,580 Now, I think to some degree, the whole notion of source control is a little bit generational. 50 00:05:26,680 --> 00:05:40,200 And I'm going to say that because I did a very similar talk a few years ago in Sofia, Bulgaria, and I was at the Code Monsters Java 2 Days conference. 51 00:05:41,140 --> 00:05:50,240 And I was talking to a room of probably, I don't know, 1,500 people or so, and I asked for a rising of hands. 52 00:05:50,240 --> 00:06:00,420 How many people were developers who have developed code not for the internet, not for a web application? 53 00:06:00,560 --> 00:06:05,560 Of all the people in that room, I maybe saw five or six hands come up. 54 00:06:05,560 --> 00:06:10,740 And they were mostly older people like myself who had worked in other areas. 55 00:06:12,880 --> 00:06:15,640 Web development is a little different apparently. 56 00:06:15,760 --> 00:06:23,560 A lot of what we would consider traditional DevOps don't seem to apply anymore. 57 00:06:23,560 --> 00:06:25,120 One of them is source control. 58 00:06:25,440 --> 00:06:27,940 So what is source control? 59 00:06:28,340 --> 00:06:36,200 Well, source control is a number of things, but it assumes that you validate your production software. 60 00:06:36,240 --> 00:06:40,000 That's kind of basic in source control. 61 00:06:40,000 --> 00:06:45,620 The other thing is that it assumes that you freeze your code before you do your validation. 62 00:06:47,720 --> 00:06:53,060 You also need to prove that your code hasn't changed while you're validating it. 63 00:06:53,060 --> 00:06:57,020 So in other words, somebody makes a quick fix that may affect other things. 64 00:06:57,020 --> 00:06:59,360 So you probably want to look at other things too. 65 00:07:00,540 --> 00:07:04,700 The other thing is that you only want to release production quality software. 66 00:07:07,420 --> 00:07:10,900 And you only make changes to known good code. 67 00:07:10,900 --> 00:07:13,880 Those are the things that happen with source control. 68 00:07:13,940 --> 00:07:22,900 Now when you're kind of importing somebody else's code into your software, not a whole lot of this happens. 69 00:07:22,940 --> 00:07:25,040 Not a whole lot of this happens. 70 00:07:25,980 --> 00:07:29,560 The other part of source control is version control. 71 00:07:29,560 --> 00:07:36,640 And version control basically says that you're able to go back to a prior version if you need to, or several versions back. 72 00:07:36,640 --> 00:07:42,120 But you're able to keep track of changes in an orderly fashion. 73 00:07:42,180 --> 00:07:49,840 Again, this is not something that happens when you're just loading in other people's files that basically they're maintaining. 74 00:07:50,900 --> 00:07:52,020 Okay. 75 00:07:56,180 --> 00:07:59,160 So why are third-party libraries a problem? 76 00:07:59,640 --> 00:08:04,760 Well, the other problem is that they're used without any kind of validation, generally. 77 00:08:05,520 --> 00:08:08,260 And there are reasons for this. 78 00:08:08,280 --> 00:08:10,360 You ever look at the code you import? 79 00:08:10,480 --> 00:08:15,840 A lot of the code that you download is machine-readable only, and it's not meant for human eyes. 80 00:08:15,840 --> 00:08:19,080 So it's very difficult to validate. 81 00:08:19,600 --> 00:08:29,200 I also hear a lot of people say, and I mentioned this a little bit earlier, people say, web apps are hard to validate because, well, they're just different. 82 00:08:29,380 --> 00:08:30,420 They're just different. 83 00:08:30,420 --> 00:08:35,300 For example, you don't control the choice of browser. 84 00:08:35,380 --> 00:08:35,680 Okay? 85 00:08:35,680 --> 00:08:40,900 Unless you only allow one browser, you really don't control what browser they're using. 86 00:08:40,900 --> 00:08:50,020 So if you are writing a bunch of server-side code, you are running your code in an environment that you don't know a whole lot about. 87 00:08:50,020 --> 00:08:53,620 So it's really hard to validate your code in situations like that. 88 00:08:53,800 --> 00:08:55,540 Also, you don't control the hardware. 89 00:08:55,540 --> 00:08:57,440 You don't know if they're running on a phone. 90 00:08:57,480 --> 00:08:59,660 You don't know if it's a phone from the 90s. 91 00:08:59,660 --> 00:09:02,920 You don't know if they're running it on a big gaming console. 92 00:09:02,920 --> 00:09:04,580 You have no idea what they're running it on. 93 00:09:05,280 --> 00:09:10,200 The other thing is that you don't know what they're doing with their browser, again. 94 00:09:10,320 --> 00:09:18,220 You know, your code might run differently if they have 40 tabs open, all running very complex Google charts or something. 95 00:09:19,440 --> 00:09:22,480 You really don't have control over that kind of stuff. 96 00:09:23,640 --> 00:09:35,600 So to a real extent, web development is different than other kinds of development, but we shouldn't lose sight of what we're doing. 97 00:09:36,240 --> 00:09:38,680 And then some people might say, source control? 98 00:09:38,780 --> 00:09:40,300 We're an Agile shop. 99 00:09:40,300 --> 00:09:41,840 We don't do source control. 100 00:09:41,900 --> 00:09:50,420 Well, you might have even more need to do source control if you're in an Agile shop, especially version control, because things are going to be changing more often. 101 00:09:50,420 --> 00:09:54,220 And you definitely can do source control with Agile. 102 00:09:55,480 --> 00:10:01,480 The other thing people might say is that, well, there's nothing mission-critical on our website. 103 00:10:01,480 --> 00:10:02,860 So we really don't care. 104 00:10:02,860 --> 00:10:06,960 I mean, there's not much that could happen. 105 00:10:06,960 --> 00:10:09,240 It's like, yeah, that's probably true. 106 00:10:10,540 --> 00:10:16,780 I just want to show you an example of a JavaScript trojan called, you are an idiot. 107 00:10:20,780 --> 00:10:26,140 So this is a short example of what this trojan does. 108 00:10:26,340 --> 00:10:40,640 It's completely harmless outside of the fact that it creates this big visual thing on your display, which is not something that you would probably want on a corporate website or for your organization in general. 109 00:10:41,060 --> 00:10:46,740 Not only do these little boxes appear, but they grow in number and they also sing to you too. 110 00:10:46,740 --> 00:10:50,420 They also say you are an idiot and they all say this in chorus. 111 00:10:50,520 --> 00:10:52,580 So it's quite the thing. 112 00:10:52,580 --> 00:10:53,880 You don't really want this. 113 00:10:53,880 --> 00:10:56,260 And again, this is a JavaScript exploit. 114 00:10:58,880 --> 00:11:06,260 So web development is unique, but you always want to be able to release stable code, right? 115 00:11:06,260 --> 00:11:12,100 And you want to make sure that the code you're releasing stays stable and not subject to change. 116 00:11:12,100 --> 00:11:16,120 You also want to be able to revert to other stable versions. 117 00:11:16,720 --> 00:11:23,860 But regardless of the nature of web development, source control is quite, quite important. 118 00:11:25,140 --> 00:11:32,280 And the more important your software is, the more important validation and source control become. 119 00:11:34,520 --> 00:11:44,340 Now, one of the problems with all this is that the libraries that people are importing are just so attractive that people just want to use them. 120 00:11:44,600 --> 00:11:48,400 And these are things that you probably would not want to write on your own. 121 00:11:48,400 --> 00:11:51,980 For example, frameworks, jQuery in particularly. 122 00:11:52,140 --> 00:11:54,420 I mean, it's incredibly useful. 123 00:11:54,860 --> 00:12:00,080 It just needs to be used with proper DevOps. 124 00:12:00,360 --> 00:12:04,820 Again, other libraries, Google Analytics, Chart, AdSense. 125 00:12:04,820 --> 00:12:06,100 Chart is my favorite, by the way. 126 00:12:06,100 --> 00:12:07,440 I use that all the time. 127 00:12:09,260 --> 00:12:14,520 These are not JavaScript apps that you really want to write your own. 128 00:12:15,260 --> 00:12:16,300 You really don't. 129 00:12:16,300 --> 00:12:18,000 You want to use somebody else's. 130 00:12:18,000 --> 00:12:20,360 And these are very capable libraries. 131 00:12:20,360 --> 00:12:21,520 And that's why people use them. 132 00:12:21,520 --> 00:12:23,420 They're just so attractive. 133 00:12:23,680 --> 00:12:37,280 But when you use these libraries, the assumption is that they come fully debugged and that the admins use proper source and version control, and also that they're free of exploits. 134 00:12:37,280 --> 00:12:40,780 We assume that they are free of exploits. 135 00:12:41,040 --> 00:12:45,920 And that's something we probably wouldn't do with the rest of our code. 136 00:12:45,920 --> 00:12:48,420 But for some reason, that happens with JavaScript. 137 00:12:48,420 --> 00:12:52,580 In many cases, the code that people import is very significant. 138 00:12:52,580 --> 00:13:02,560 And let's just look at my survey here to find out what exactly people really do with JavaScript. 139 00:13:02,820 --> 00:13:04,720 So how was the survey done? 140 00:13:04,920 --> 00:13:12,900 Well, I looked at the home pages of a Google list that I found, Google's top 1,000 websites. 141 00:13:13,840 --> 00:13:20,200 How effective that is in identifying the top 1,000 websites, I really don't know. 142 00:13:20,780 --> 00:13:25,400 I'm really not even that concerned because the list itself is pretty arbitrary. 143 00:13:25,400 --> 00:13:27,880 I just wanted to have a list that people could reference. 144 00:13:28,120 --> 00:13:31,520 And again, I just looked at the home pages for this study. 145 00:13:31,600 --> 00:13:38,060 I did not include looking at scripts that the JavaScript also imports, because that's another thing that happens. 146 00:13:38,060 --> 00:13:43,460 You import one JavaScript file from some server, and it imports five others. 147 00:13:43,460 --> 00:13:45,640 You really have no control over that. 148 00:13:47,240 --> 00:13:51,720 So again, the survey came from a list that I found from Google. 149 00:13:52,100 --> 00:13:54,720 It's an international list, which is good. 150 00:13:55,400 --> 00:13:59,220 And like I said, this list is probably pretty arbitrary. 151 00:13:59,240 --> 00:14:04,480 It's probably not that much different than what you would find from something from Alexa or somebody like that. 152 00:14:05,220 --> 00:14:17,400 From those 10,000 web pages that I looked at, just the home pages from those, I found over 4,100 unique imported JavaScript files. 153 00:14:17,420 --> 00:14:23,700 I also found that almost 75% of those websites use JavaScript. 154 00:14:25,520 --> 00:14:28,300 And my number is pretty consistent with other people's. 155 00:14:28,300 --> 00:14:30,220 This is another person's study. 156 00:14:30,400 --> 00:14:35,460 And again, I don't know what websites they looked at, but they got a number that was slightly higher than mine. 157 00:14:35,460 --> 00:14:42,740 So I think 75 to 90 is probably a pretty close percentage of how many websites are using JavaScript. 158 00:14:42,860 --> 00:14:55,760 Of the websites that I looked at, those 1,000, they averaged 6.5 JavaScript files, imported JavaScript files per home page. 159 00:14:57,620 --> 00:15:05,420 Two of the sites that I looked at imported over 100 separate JavaScript files just on their home page. 160 00:15:05,420 --> 00:15:06,740 Can you imagine that? 161 00:15:07,200 --> 00:15:09,460 That's the most I've ever seen. 162 00:15:09,740 --> 00:15:19,760 Now this is the number that should probably stick with us, and that is 60% of the websites that we looked at imported third-party JavaScript from another domain. 163 00:15:19,760 --> 00:15:23,280 And those are the ones that I think are probably the most dangerous. 164 00:15:23,300 --> 00:15:24,760 What are people using? 165 00:15:24,760 --> 00:15:29,160 To nobody's surprise, a lot of people are using jQuery. 166 00:15:29,360 --> 00:15:32,840 I'm surprised that React and Angular aren't a little more popular. 167 00:15:32,840 --> 00:15:34,000 I thought they were. 168 00:15:34,220 --> 00:15:37,980 But again, this is primarily corporate websites. 169 00:15:37,980 --> 00:15:40,160 Other people may be doing other things. 170 00:15:40,260 --> 00:15:42,920 Again, like I said, my list is pretty arbitrary. 171 00:15:43,500 --> 00:15:45,920 A lot of people are using Google AdSense. 172 00:15:45,920 --> 00:15:47,160 That makes sense. 173 00:15:47,220 --> 00:15:50,920 My favorite, Google Chart, wasn't terribly popular. 174 00:15:52,680 --> 00:15:58,140 So to understand what we're really talking about here, let's take a history lesson. 175 00:15:58,140 --> 00:16:05,400 Let's go back to 1995, the static web, and look at how things were done then. 176 00:16:05,400 --> 00:16:08,920 Well, then you'd sit in front of a terminal. 177 00:16:08,920 --> 00:16:11,120 You'd request a web page through your browser. 178 00:16:11,120 --> 00:16:13,800 It would bring back HTML. 179 00:16:13,880 --> 00:16:21,520 Your browser would parse the HTML, look for other media, go get that media, bring it back, and render the web page. 180 00:16:21,520 --> 00:16:25,680 Well, we still do all those things today. 181 00:16:27,380 --> 00:16:34,700 But today, we also, in addition to images, we also go out and we download JavaScript. 182 00:16:35,260 --> 00:16:37,340 From anywhere on the internet. 183 00:16:37,340 --> 00:16:40,220 It could be all kinds of domains from all over the place. 184 00:16:40,220 --> 00:16:43,180 Most people don't really pay that much attention. 185 00:16:43,520 --> 00:16:49,300 But this stuff is coming from an external source, and that's why we should be taking this very seriously. 186 00:16:49,760 --> 00:16:57,240 Because these libraries that are imported are seldom validated by the developer who is importing them. 187 00:16:58,620 --> 00:17:00,600 They generally have no source control. 188 00:17:00,600 --> 00:17:06,160 Well, you have no source control because you're relying on somebody else to do it, and they may or may not be doing it. 189 00:17:07,880 --> 00:17:11,700 And you also don't have control over their server configurations. 190 00:17:11,740 --> 00:17:16,880 Now, this probably isn't a big deal if you're talking about Google or Amazon, one of the big players. 191 00:17:16,960 --> 00:17:21,020 But some of the smaller ones, do you know that they're patching their server? 192 00:17:21,120 --> 00:17:23,060 Do you know what kind of server they're using? 193 00:17:23,500 --> 00:17:25,020 You don't know any of this stuff. 194 00:17:25,020 --> 00:17:29,060 You're basically trusting that their server configurations are good. 195 00:17:29,060 --> 00:17:30,540 They're always going to be up. 196 00:17:30,540 --> 00:17:34,900 And again, these are not things you do when you control your source. 197 00:17:34,900 --> 00:17:37,040 You don't do any of those things. 198 00:17:37,180 --> 00:17:40,240 So what, what kind of threats are we really looking at here? 199 00:17:40,620 --> 00:17:42,600 Definitely bandwidth stealing. 200 00:17:42,980 --> 00:17:54,740 I'm going to give you an example that's actually not a JavaScript example, but it makes a really good point about how JavaScript is, or how bandwidth is stolen in this kind of a context. 201 00:17:55,620 --> 00:17:59,200 There was a developer who came up with a URL shortener. 202 00:17:59,200 --> 00:17:59,620 Okay. 203 00:17:59,720 --> 00:18:21,320 And if you know what URL shorteners are, if you want to send a link to a friend, either in social media or through email or something, and it's a really long link, sometimes you use a shortener that'll give you a short little link that you can use that will be expanded into your full link once they click on it and go to the site and are redirected and whatnot. 204 00:18:21,480 --> 00:18:25,960 Well, somebody wrote one of these that worked beautifully and became very popular. 205 00:18:26,100 --> 00:18:39,600 But in addition to doing the expansion of the link and redirecting them to the correct webpage, it would also do insert a little bit of JavaScript that would do a denial of service attack on some target. 206 00:18:39,600 --> 00:18:40,160 Okay. 207 00:18:40,980 --> 00:18:46,740 Clever, clever exploit, but these are the kinds of things that can happen with bandwidth stealing. 208 00:18:47,760 --> 00:18:51,260 JavaScript is also used, by the way, in that case. 209 00:18:52,620 --> 00:19:02,300 The other threats are privacy violations, because JavaScript can look at DOM and it can create analytics. 210 00:19:02,740 --> 00:19:14,650 And like I said earlier, just downloading these libraries from another server provides a lot of metadata that really creates opportunities for security violations. 211 00:19:16,780 --> 00:19:26,520 The other thing are phishing attacks, and phishing attempts are probably the most dominant forms of attacks at this point. 212 00:19:26,520 --> 00:19:28,520 And they can also be done through JavaScript. 213 00:19:29,960 --> 00:19:30,680 All right. 214 00:19:30,680 --> 00:19:33,080 Now here's another example I wanted to give you. 215 00:19:34,200 --> 00:19:42,160 This is a case where somebody developed a tutorial for Google Analytics, and they also gave you a link to the code. 216 00:19:42,160 --> 00:19:43,220 How convenient. 217 00:19:43,340 --> 00:19:48,880 The only problem is the URL they gave was the wrong URL. 218 00:19:48,940 --> 00:19:52,900 It looked very much like the real URL, but it wasn't. 219 00:19:52,980 --> 00:20:06,020 So basically, this person just taught you how to use Analytics, and now you're using that person's version of Analytics, and they basically have all of your web traffic data. 220 00:20:06,500 --> 00:20:10,900 Plus, they could also modify the code and inject some other stuff in there, too, if they'd want. 221 00:20:12,080 --> 00:20:16,060 So you don't, again, it's important to do source control. 222 00:20:18,300 --> 00:20:35,530 Well, the other threat is that since server-side code runs on your machine, it doesn't run on the server, it runs on somebody else's machine, you are essentially giving people the opportunity to run arbitrary JavaScript code on a lot of users' machines. 223 00:20:37,850 --> 00:20:41,910 There can also be bugs and stuff, and bugs and exploits. 224 00:20:41,910 --> 00:20:50,590 It wasn't that long ago there was a zero -day in jQuery, and apparently this thing had been out there for about three years. 225 00:20:50,790 --> 00:20:57,870 So, again, this is what happens when you don't control your own source code. 226 00:20:58,570 --> 00:21:03,710 So what are some other possible attack vectors if you're using third-party JavaScript? 227 00:21:04,210 --> 00:21:14,110 Well, things that can happen are after your site is running nicely and everything looks good, the owner of the library that you're using could decide to change the code. 228 00:21:14,150 --> 00:21:20,310 And it might be a bug fix, it might be an update, or maybe it's something more deviant. 229 00:21:20,750 --> 00:21:23,210 That possibility exists. 230 00:21:23,210 --> 00:21:26,890 And if that possibility exists, it will at some point happen. 231 00:21:26,890 --> 00:21:28,590 Here's another possibility. 232 00:21:29,290 --> 00:21:40,330 The owner of the repository that you're using gets hacked, and somebody either changes the code, or maybe the server just goes down, right? 233 00:21:40,330 --> 00:21:42,790 Part of security is availability. 234 00:21:42,810 --> 00:21:49,310 If these remote servers go down, again, to no fault of your own, that creates an issue. 235 00:21:49,730 --> 00:21:52,250 Those are other attack vectors. 236 00:21:52,370 --> 00:21:55,610 Other things that can happen, you can have things happening with DNS. 237 00:21:55,630 --> 00:21:59,710 Somebody can poison DNS, send you off to a different library. 238 00:21:59,750 --> 00:22:01,370 There can be DNS spoofing. 239 00:22:01,370 --> 00:22:06,470 There can also be some social engineering that happens that could get people to use the wrong libraries. 240 00:22:06,890 --> 00:22:15,250 Some other things that you open yourself up to are poor source control used by the person who maintains the repository that you're using. 241 00:22:15,370 --> 00:22:18,290 You can run into cross-site scripting issues. 242 00:22:18,710 --> 00:22:22,670 All the common exploit types happen here, too. 243 00:22:22,670 --> 00:22:24,450 You can have man-in-the-middle attacks. 244 00:22:24,450 --> 00:22:29,470 You can have API credentials sent out in clear text. 245 00:22:29,590 --> 00:22:34,830 I've seen that happen even on pretty legit JavaScript apps. 246 00:22:35,570 --> 00:22:47,110 Anyway, I don't want to discourage people from using JavaScript, or even discourage people from using some of these nice frameworks and stuff that people use, but I really would like to encourage people to use them safely. 247 00:22:47,110 --> 00:22:51,590 How do you safely use JavaScript? 248 00:22:52,610 --> 00:22:58,230 Well, one way to do it is you can download these libraries and store them locally. 249 00:22:58,310 --> 00:23:01,890 That at least gives you control of the source. 250 00:23:01,890 --> 00:23:06,130 You know it's not going to be changing, and you know the environment that it's in. 251 00:23:06,690 --> 00:23:10,970 Now, if you do this, you might violate some license agreements that you have. 252 00:23:10,970 --> 00:23:12,330 Check with that first. 253 00:23:12,630 --> 00:23:18,990 Sometimes this isn't even a possibility, because the files need to be remote. 254 00:23:18,990 --> 00:23:25,050 They might need to access some resource that is only available remotely, and not available on your server. 255 00:23:26,030 --> 00:23:30,650 And also, doing this removes any DNS issues that you might be concerned about. 256 00:23:31,750 --> 00:23:37,810 Another thing you might try to do is to sandbox your script in an iframe, or a frame of some type. 257 00:23:37,810 --> 00:23:39,850 That might be useful for you. 258 00:23:39,850 --> 00:23:50,470 Another thing you might want to look at is using SRI, which is a method to validate that the source and the host and everything is correct. 259 00:23:50,830 --> 00:23:59,120 I really haven't seen many people do this, and I'm actually not sure how common this is, to be absolutely honest. 260 00:24:00,870 --> 00:24:09,070 The one thing I recommend all organizations doing is never, ever, ever host your website on your own network. 261 00:24:09,230 --> 00:24:12,250 Always get it provided by a hosting company. 262 00:24:12,490 --> 00:24:18,990 The reason there is if your website does get broken into, they don't have a path to your network. 263 00:24:19,630 --> 00:24:22,970 It's all sitting someplace remotely, and that's where it should be. 264 00:24:23,230 --> 00:24:25,330 Keep private things private. 265 00:24:25,870 --> 00:24:27,810 Let public things be public. 266 00:24:27,810 --> 00:24:29,170 Don't mix the two. 267 00:24:32,010 --> 00:24:36,110 The other thing that would be a good thing for you to do is to track changes in the libraries. 268 00:24:37,250 --> 00:24:39,370 And I don't know how often people do this. 269 00:24:39,370 --> 00:24:48,570 So in other words, if you're using a specific version of a library, make sure they don't do the updates for you. 270 00:24:48,790 --> 00:24:51,590 In other words, they might make changes and not tell you about it. 271 00:24:52,410 --> 00:24:55,890 You need to be able to track changes on any of these libraries that you're using. 272 00:24:57,070 --> 00:25:06,670 And finally, I would ask for you to ask yourself if you really need the functionality that this JavaScript library is providing. 273 00:25:07,550 --> 00:25:12,290 Do you need that submit button with the rounded edges? 274 00:25:12,610 --> 00:25:13,930 Maybe you don't. 275 00:25:13,930 --> 00:25:19,110 Maybe you could write what you need to write in pure JavaScript and not have to import those things. 276 00:25:19,110 --> 00:25:22,550 That would be wonderful, and it probably would be a lot more secure. 277 00:25:24,630 --> 00:25:34,010 Also, keep in mind that JavaScript is not alone here, and that there are other threats around other third-party things like Flash. 278 00:25:34,010 --> 00:25:35,590 Some people still use Flash. 279 00:25:35,590 --> 00:25:41,170 PDFs, videos, and yes, even images can cause issues. 280 00:25:41,170 --> 00:25:48,970 And if you're curious about the kinds of issues that images can create, check out my DEF CON 15 talk. 281 00:25:48,970 --> 00:25:50,650 It should be on the server. 282 00:25:50,750 --> 00:25:58,890 The fabulous executable image exploit, where I talk about how you can have images running arbitrary code on people's servers. 283 00:25:59,990 --> 00:26:04,390 So in conclusion, what have we learned? 284 00:26:04,430 --> 00:26:07,950 We have learned that JavaScript is awesome. 285 00:26:07,950 --> 00:26:09,410 It's not going away. 286 00:26:09,430 --> 00:26:14,850 These libraries are just too functional and too hard to ignore. 287 00:26:14,850 --> 00:26:16,230 People are going to use them. 288 00:26:16,230 --> 00:26:20,350 We just need to find more safe ways of using them. 289 00:26:21,330 --> 00:26:36,730 We've learned that source control is a vital part of DevOps, and if you're not doing source control on your entire project, you're not doing software or you're not doing source control really for your project at all. 290 00:26:36,730 --> 00:26:45,730 A lot of developers are using JavaScript that they really don't control, and we've also learned that most developers don't validate imported libraries. 291 00:26:45,730 --> 00:26:47,030 They just use them. 292 00:26:47,230 --> 00:26:52,090 You know, you get that jQuery calendar working, that's usually good enough for people, right? 293 00:26:52,890 --> 00:26:58,790 They don't do boundary testing and all the other kind of classic stuff that is involved in software testing. 294 00:26:59,170 --> 00:27:03,250 These scripts that people are importing can be used as attack vectors. 295 00:27:03,250 --> 00:27:04,810 I've demonstrated that. 296 00:27:05,370 --> 00:27:11,930 And we've learned that there are ways to minimize your risk when using imported JavaScript libraries. 297 00:27:14,630 --> 00:27:21,930 So, thank you, and I just want to leave you with one final message, which is good DevOps can solve a lot of security issues. 298 00:27:21,930 --> 00:27:22,870 Thank you very much. 299 00:27:22,870 --> 00:27:23,990 I really enjoyed this. 300 00:27:23,990 --> 00:27:24,710 Thank you.