start	end	text
990	7170	Hello, my name is Michael Schrenk. I live in Las Vegas, Nevada, where I write botnets for a living.
7170	13230	And I'm here to talk about malware. Thanks for coming to my talk. So I said I write botnets,
13230	18310	and what that basically means is that I write distributed systems that do data extraction,
18630	27070	we do automation, we do analytics. But one thing that we get to do a lot more than probably most
27070	33410	people is look at other people's code. It's because we download webpages and we have to
33410	40630	write parsers for them. So we get to look at a lot of source code. And one of the things that
40630	45510	I've noticed, I've been doing this now since the mid-90s, and I've noticed that people are
45510	51970	using JavaScript differently than they did even 10 years ago. So that's what this is about. And
51970	57330	I believe that JavaScript is being used in a dangerous way that can be used as an attack
57330	64590	vector. So one of the things I did to get a better idea of how people are using JavaScript,
64590	70030	you know, if I'm just looking at files randomly, that means one thing. But to go off and look at
70030	76110	1,000 of the top websites and see how they use JavaScript would be a really useful thing.
76110	82650	So I did that. I wrote a bot that goes out and looks at a list of 1,000 websites,
82650	88650	analyzes their homepage for how they are using JavaScript. And that's part of this talk.
89390	94030	But here's really what we're going to discuss. We are going to discuss this thing that I'm
94030	101350	calling third-party JavaScript, which is... there we go, get my... it's like this stuff
101350	105590	that we're talking about right here. It's these little scripts that people include
105590	114710	in their HTML that brings in external JavaScript libraries like jQuery, Google Charts, you name it.
114710	121890	There are a lot of these that people are using. And I believe that these third-party JavaScript
121890	127850	files are an attack vector, and I'm going to show you why. I'm going to give you examples,
128390	132030	and I'm also going to teach you ways that you can use these third-party
132030	135900	files in a much, much more secure environment.
137070	144350	So one of the things that I want to make very clear here is that I do not believe that JavaScript
144350	150250	itself is a threat. I believe that the way people use JavaScript is a threat,
150250	154560	and the way they're using it creates opportunities for attack vectors.
155960	162900	So, before we look at the threat, we need to figure out what exactly JavaScript is capable of doing.
162980	169240	Well, it's basically capable of doing two things. As you probably know, if you're a developer,
169240	176340	you know that JavaScript operates on the DOM. So anything on a web page, JavaScript pretty much has
176340	181520	access to it, with a few exceptions. But basically, it can not only have access to it, but it can also
181520	188200	change things on the website. The other thing it can do is JavaScript can communicate with other
188200	196360	servers, right, using Ajax-y kind of technologies. Also, if you are downloading the library from an
196360	203120	external server, you're also leaving server logs, right? So my guess is that if you went to any of
203120	210240	these big framework suppliers, like jQuery or Angular, if you looked in their log files,
210240	216660	you could learn a lot about the people who are using their libraries, just from the metadata
216660	222640	that becomes created. The other thing you might say is that JavaScript, that's not dangerous,
222640	230920	that's just like HTML, right? No, it is actually dangerous. There have been over 40,000 known
230920	236780	examples of JavaScript malware that have not only been documented, but they're available for you at
236780	243980	this website, at GitHub, the address is in the URL. And you can go there and you can download
243980	247880	them, you can play with them, you can study them, you can do whatever you want to with them.
247960	257340	But they do exist. So what exactly am I talking about when I refer to a third-party JavaScript
257340	263940	file? Well, there's two different things that I'm referring to. One are files that are truly
263940	270540	third-party and truly remote. That would include examples like the one over here. I got to get this
270540	278180	down. Right over here. You're just making a JavaScript request to bring in or to include
278180	285660	another JavaScript file that you will reference later. The other example would be a file that's
285660	290560	running off of your own server, but it's one that you didn't write. So in other words, you went
290560	295280	and you downloaded somebody's library, threw it on your server, referenced that,
295280	300080	and that's the file that you're using. As far as I'm concerned, if you don't do anything else,
300080	305320	these are both third-party JavaScript files, and they can both cause some trouble.
307380	313720	The other problem is that when you're using somebody else's code like this,
313720	320360	you are doing it without any kind of source control whatsoever. Now, I think to some degree,
320360	328220	the whole notion of source control is a little bit generational. And I'm going to say that because
329040	338560	I did a very similar talk a few years ago in Sofia, Bulgaria, and I was at the Code Monsters
338560	346860	Java 2 Days conference. And I was talking to a room of probably, I don't know, 1,500 people or so,
346860	355300	and I asked for a rising of hands. How many people were developers who have developed code
356100	362860	not for the internet, not for a web application? Of all the people in that room, I maybe saw
362860	369520	five or six hands come up. And they were mostly older people like myself who had worked in other
369520	378780	areas. Web development is a little different apparently. A lot of what we would consider
379560	385120	traditional DevOps don't seem to apply anymore. One of them is source control.
385440	393280	So what is source control? Well, source control is a number of things, but it assumes that you
393280	400520	validate your production software. That's kind of basic in source control. The other
400520	405620	thing is that it assumes that you freeze your code before you do your validation.
407720	413480	You also need to prove that your code hasn't changed while you're validating it. So in other
413480	418140	words, somebody makes a quick fix that may affect other things. So you probably want to look at
418140	424700	other things too. The other thing is that you only want to release production quality software.
427420	432900	And you only make changes to known good code. Those are the things that happen with source
432900	440000	control. Now when you're kind of importing somebody else's code into your software,
440920	445040	not a whole lot of this happens. Not a whole lot of this happens.
445980	451920	The other part of source control is version control. And version control basically says that you're able to
451920	458120	go back to a prior version if you need to, or several versions back. But you're able to keep
458120	464840	track of changes in an orderly fashion. Again, this is not something that happens when you're just
465520	469840	loading in other people's files that basically they're maintaining.
470900	472020	Okay.
476180	482900	So why are third-party libraries a problem? Well, the other problem is that they're used without any
482900	489520	kind of validation, generally. And there are reasons for this. You ever look at the code you
489520	494720	import? A lot of the code that you download is machine-readable only, and it's not meant for
494720	501700	human eyes. So it's very difficult to validate. I also hear a lot of people say, and I mentioned
501700	508000	this a little bit earlier, people say, web apps are hard to validate because, well, they're just
508000	515680	different. They're just different. For example, you don't control the choice of browser. Okay?
515680	520900	Unless you only allow one browser, you really don't control what browser they're using.
520900	527520	So if you are writing a bunch of server-side code, you are running your code in an environment
527520	532640	that you don't know a whole lot about. So it's really hard to validate your code in situations
532640	537440	like that. Also, you don't control the hardware. You don't know if they're running on a phone.
537480	541360	You don't know if it's a phone from the 90s. You don't know if they're running it on a big
541940	544580	gaming console. You have no idea what they're running it on.
545280	549340	The other thing is that you don't know what they're doing with their browser,
549340	555720	again. You know, your code might run differently if they have 40 tabs open, all running very
555720	562480	complex Google charts or something. You really don't have control over that kind of stuff.
563640	572240	So to a real extent, web development is different than other kinds of development,
572240	577740	but we shouldn't lose sight of what we're doing. And then some people might say,
577740	583420	source control? We're an Agile shop. We don't do source control. Well, you might have even more
583420	589000	need to do source control if you're in an Agile shop, especially version control, because things
589000	594220	are going to be changing more often. And you definitely can do source control with Agile.
595480	599700	The other thing people might say is that, well, there's nothing mission-critical
600280	607280	on our website. So we really don't care. I mean, there's not much that could happen. It's like,
607280	614260	yeah, that's probably true. I just want to show you an example of a JavaScript trojan
614960	626140	called, you are an idiot. So this is a short example of what this trojan does.
626340	632880	It's completely harmless outside of the fact that it creates this big visual thing on your display,
632880	639000	which is not something that you would probably want on a corporate website or for your
639000	644360	organization in general. Not only do these little boxes appear, but they grow in number
644920	650420	and they also sing to you too. They also say you are an idiot and they all say this in chorus.
650520	656260	So it's quite the thing. You don't really want this. And again, this is a JavaScript exploit.
658880	666260	So web development is unique, but you always want to be able to release stable code, right?
666260	670740	And you want to make sure that the code you're releasing stays stable and not
670740	676120	subject to change. You also want to be able to revert to other stable versions.
676720	683860	But regardless of the nature of web development, source control is quite, quite important.
685140	692280	And the more important your software is, the more important validation and source control become.
694520	700120	Now, one of the problems with all this is that the libraries that people are importing are just
700120	707020	so attractive that people just want to use them. And these are things that you probably would not
707020	712380	want to write on your own. For example, frameworks, jQuery in particularly. I mean,
712380	721960	it's incredibly useful. It just needs to be used with proper DevOps. Again, other libraries,
721960	727440	Google Analytics, Chart, AdSense. Chart is my favorite, by the way. I use that all the time.
729260	736400	These are not JavaScript apps that you really want to write your own. You really don't. You
736400	741520	want to use somebody else's. And these are very capable libraries. And that's why people use them.
741520	748240	They're just so attractive. But when you use these libraries, the assumption is that they come
748240	756300	fully debugged and that the admins use proper source and version control, and also that they're
756300	763500	free of exploits. We assume that they are free of exploits. And that's something we probably wouldn't
763500	769980	do with the rest of our code. But for some reason, that happens with JavaScript. In many cases,
769980	776680	the code that people import is very significant. And let's just look at my survey here to find out
776680	786700	what exactly people really do with JavaScript. So how was the survey done? Well, I looked at the
786700	796840	home pages of a Google list that I found, Google's top 1,000 websites. How effective that is in
796840	802660	identifying the top 1,000 websites, I really don't know. I'm really not even that concerned
802660	807000	because the list itself is pretty arbitrary. I just wanted to have a list that people could
807000	813640	reference. And again, I just looked at the home pages for this study. I did not include looking
813640	818060	at scripts that the JavaScript also imports, because that's another thing that happens.
818060	824340	You import one JavaScript file from some server, and it imports five others. You really have no
824340	832540	control over that. So again, the survey came from a list that I found from Google. It's an
832540	839220	international list, which is good. And like I said, this list is probably pretty arbitrary.
839240	843140	It's probably not that much different than what you would find from something from Alexa or
843140	851280	somebody like that. From those 10,000 web pages that I looked at, just the home pages from those,
851280	861000	I found over 4,100 unique imported JavaScript files. I also found that almost 75% of those
861000	868880	websites use JavaScript. And my number is pretty consistent with other people's. This is another
868880	873860	person's study. And again, I don't know what websites they looked at, but they got a number
873860	879440	that was slightly higher than mine. So I think 75 to 90 is probably a pretty close percentage
879900	886400	of how many websites are using JavaScript. Of the websites that I looked at, those 1,000,
887320	899460	they averaged 6.5 JavaScript files, imported JavaScript files per home page. Two of the sites
899460	905500	that I looked at imported over 100 separate JavaScript files just on their home page. Can
905500	911700	you imagine that? That's the most I've ever seen. Now this is the number that should probably stick
911700	917920	with us, and that is 60% of the websites that we looked at imported third-party JavaScript
917920	923280	from another domain. And those are the ones that I think are probably the most dangerous.
923300	930260	What are people using? To nobody's surprise, a lot of people are using jQuery. I'm surprised that
930260	936600	React and Angular aren't a little more popular. I thought they were. But again, this is primarily
936600	941760	corporate websites. Other people may be doing other things. Again, like I said, my list is
941760	948420	pretty arbitrary. A lot of people are using Google AdSense. That makes sense. My favorite, Google
948420	957200	Chart, wasn't terribly popular. So to understand what we're really talking about here, let's take
957360	965400	a history lesson. Let's go back to 1995, the static web, and look at how things were done then.
965400	971120	Well, then you'd sit in front of a terminal. You'd request a web page through your browser.
971120	977980	It would bring back HTML. Your browser would parse the HTML, look for other media,
977980	985680	go get that media, bring it back, and render the web page. Well, we still do all those things today.
987380	994700	But today, we also, in addition to images, we also go out and we download JavaScript.
995260	1000220	From anywhere on the internet. It could be all kinds of domains from all over the place.
1000220	1006900	Most people don't really pay that much attention. But this stuff is coming from an external source,
1006900	1011520	and that's why we should be taking this very seriously. Because these libraries that are
1011520	1019960	imported are seldom validated by the developer who is importing them. They generally have no
1019960	1023980	source control. Well, you have no source control because you're relying on somebody else to do it,
1023980	1030540	and they may or may not be doing it. And you also don't have control over their server
1030540	1035640	configurations. Now, this probably isn't a big deal if you're talking about Google or Amazon,
1035640	1040240	one of the big players. But some of the smaller ones, do you know that they're patching their
1040240	1045160	server? Do you know what kind of server they're using? You don't know any of this stuff. You're
1045160	1050540	basically trusting that their server configurations are good. They're always going to be up.
1050540	1056240	And again, these are not things you do when you control your source. You don't do any of those
1056240	1061700	things. So what, what kind of threats are we really looking at here? Definitely bandwidth
1061700	1068540	stealing. I'm going to give you an example that's actually not a JavaScript example, but it makes a
1068540	1074740	really good point about how JavaScript is, or how bandwidth is stolen in this kind of a context.
1075620	1080900	There was a developer who came up with a URL shortener. Okay. And if you know what URL
1080900	1086100	shorteners are, if you want to send a link to a friend, either in social media or through email
1086100	1091080	or something, and it's a really long link, sometimes you use a shortener that'll give
1091080	1097160	you a short little link that you can use that will be expanded into your full link once they
1097160	1102900	click on it and go to the site and are redirected and whatnot. Well, somebody wrote one of these
1102900	1109660	that worked beautifully and became very popular. But in addition to doing the expansion of the link
1110360	1116020	and redirecting them to the correct webpage, it would also do insert a little bit of JavaScript
1116660	1122840	that would do a denial of service attack on some target. Okay. Clever, clever exploit,
1122840	1126740	but these are the kinds of things that can happen with bandwidth stealing.
1127760	1131260	JavaScript is also used, by the way, in that case.
1132620	1138360	The other threats are privacy violations, because JavaScript can look at DOM
1139640	1145680	and it can create analytics. And like I said earlier, just downloading these libraries from
1145680	1154650	another server provides a lot of metadata that really creates opportunities for security violations.
1156780	1160600	The other thing are phishing attacks, and phishing attempts are probably
1161300	1168520	the most dominant forms of attacks at this point. And they can also be done through JavaScript.
1169960	1173080	All right. Now here's another example I wanted to give you.
1174200	1180800	This is a case where somebody developed a tutorial for Google Analytics, and they also gave you a
1180800	1188880	link to the code. How convenient. The only problem is the URL they gave was the wrong URL.
1188940	1195500	It looked very much like the real URL, but it wasn't. So basically, this person just taught
1195500	1200700	you how to use Analytics, and now you're using that person's version of Analytics,
1201040	1208640	and they basically have all of your web traffic data. Plus, they could also modify the code and
1208640	1214780	inject some other stuff in there, too, if they'd want. So you don't, again, it's important to do
1214780	1224280	source control. Well, the other threat is that since server-side code runs on your machine,
1224280	1228360	it doesn't run on the server, it runs on somebody else's machine, you are essentially
1228950	1235530	giving people the opportunity to run arbitrary JavaScript code on a lot of users' machines.
1237850	1244830	There can also be bugs and stuff, and bugs and exploits. It wasn't that long ago there was a
1244830	1252450	zero-day in jQuery, and apparently this thing had been out there for about three years. So, again,
1252450	1260630	this is what happens when you don't control your own source code. So what are some other
1260630	1265510	possible attack vectors if you're using third-party JavaScript? Well, things that can happen are
1265510	1271790	after your site is running nicely and everything looks good, the owner of the library that you're
1271790	1278090	using could decide to change the code. And it might be a bug fix, it might be an update,
1278090	1284230	or maybe it's something more deviant. That possibility exists. And if that possibility
1284230	1292010	exists, it will at some point happen. Here's another possibility. The owner of the repository
1292010	1298290	that you're using gets hacked, and somebody either changes the code, or maybe the server
1298290	1305410	just goes down, right? Part of security is availability. If these remote servers go down,
1305410	1312250	again, to no fault of your own, that creates an issue. Those are other attack vectors.
1312370	1317350	Other things that can happen, you can have things happening with DNS. Somebody can poison DNS,
1317350	1322190	send you off to a different library. There can be DNS spoofing. There can also be some
1322190	1326470	social engineering that happens that could get people to use the wrong libraries.
1326890	1332770	Some other things that you open yourself up to are poor source control used by the person who
1332770	1338290	maintains the repository that you're using. You can run into cross-site scripting issues.
1338710	1344450	All the common exploit types happen here, too. You can have man-in-the-middle attacks.
1344450	1352270	You can have API credentials sent out in clear text. I've seen that happen even on pretty legit
1353270	1358650	JavaScript apps. Anyway, I don't want to discourage people from using JavaScript,
1358650	1363550	or even discourage people from using some of these nice frameworks and stuff that people use,
1363550	1367110	but I really would like to encourage people to use them safely.
1367110	1376290	How do you safely use JavaScript? Well, one way to do it is you can download these libraries
1376290	1382570	and store them locally. That at least gives you control of the source. You know it's not
1382570	1388030	going to be changing, and you know the environment that it's in. Now, if you do this, you might
1388030	1393870	violate some license agreements that you have. Check with that first. Sometimes this isn't even
1394030	1400950	a possibility, because the files need to be remote. They might need to access some resource
1400950	1408030	that is only available remotely, and not available on your server. And also, doing this removes any
1408030	1414690	DNS issues that you might be concerned about. Another thing you might try to do is to sandbox
1414690	1419850	your script in an iframe, or a frame of some type. That might be useful for you.
1419850	1427070	Another thing you might want to look at is using SRI, which is a method to validate that the
1427850	1434670	source and the host and everything is correct. I really haven't seen many people do this,
1434670	1439120	and I'm actually not sure how common this is, to be absolutely honest.
1440870	1447810	The one thing I recommend all organizations doing is never, ever, ever host your website
1447810	1453750	on your own network. Always get it provided by a hosting company. The reason there is if
1453750	1460490	your website does get broken into, they don't have a path to your network. It's all sitting
1460490	1467090	someplace remotely, and that's where it should be. Keep private things private. Let public things be
1467090	1474670	public. Don't mix the two. The other thing that would be a good thing for you to do is to track
1474670	1479910	changes in the libraries. And I don't know how often people do this. So in other words,
1479910	1488570	if you're using a specific version of a library, make sure they don't do the updates for you.
1488790	1491590	In other words, they might make changes and not tell you about it.
1492410	1495890	You need to be able to track changes on any of these libraries that you're using.
1497070	1503230	And finally, I would ask for you to ask yourself if you really need the functionality
1503790	1512290	that this JavaScript library is providing. Do you need that submit button with the rounded edges?
1512610	1516930	Maybe you don't. Maybe you could write what you need to write in pure JavaScript
1517470	1521710	and not have to import those things. That would be wonderful, and it probably would be a lot more
1521710	1530330	secure. Also, keep in mind that JavaScript is not alone here, and that there are other threats
1530330	1537750	around other third-party things like Flash. Some people still use Flash. PDFs, videos,
1537750	1543990	and yes, even images can cause issues. And if you're curious about the kinds of issues that
1543990	1550650	images can create, check out my DEF CON 15 talk. It should be on the server.
1550750	1556390	The fabulous executable image exploit, where I talk about how you can have images running
1556390	1564390	arbitrary code on people's servers. So in conclusion, what have we learned?
1564430	1572730	We have learned that JavaScript is awesome. It's not going away. These libraries are just
1572730	1577370	too functional and too hard to ignore. People are going to use them. We just need to find
1577370	1587610	more safe ways of using them. We've learned that source control is a vital part of DevOps,
1587610	1593410	and if you're not doing source control on your entire project, you're not doing software or
1593410	1598370	you're not doing source control really for your project at all. A lot of developers are using
1598370	1603950	JavaScript that they really don't control, and we've also learned that most developers don't
1603950	1609890	validate imported libraries. They just use them. You know, you get that jQuery calendar working,
1609890	1615070	that's usually good enough for people, right? They don't do boundary testing and all the other
1615070	1620670	kind of classic stuff that is involved in software testing. These scripts that people
1620670	1626850	are importing can be used as attack vectors. I've demonstrated that. And we've learned that
1626850	1631930	there are ways to minimize your risk when using imported JavaScript libraries.
1634630	1638250	So, thank you, and I just want to leave you with one final message, which is
1638250	1644710	good DevOps can solve a lot of security issues. Thank you very much. I really enjoyed this. Thank you.
