1 00:00:00,000 --> 00:00:03,360 So this is the discovery and execution of entirely new classes of web attacks 2 00:00:03,360 --> 00:00:05,020 in order to meet your girlfriend. 3 00:00:05,420 --> 00:00:07,780 So before we begin, a little bit about me. 4 00:00:08,520 --> 00:00:09,660 I'm a security researcher. 5 00:00:10,100 --> 00:00:12,780 Narcissistic vulnerability pimp is what they're calling them these days, right? 6 00:00:14,300 --> 00:00:16,040 I do not do security professionally. 7 00:00:16,240 --> 00:00:19,060 I do it for fun, like most of you guys, or some of you guys. 8 00:00:20,040 --> 00:00:24,160 I'm known for the Sammy worm, the worm on MySpace, a couple of years ago. 9 00:00:25,040 --> 00:00:27,720 I co-founded Phonality, an IPPBX company. 10 00:00:28,240 --> 00:00:31,280 If you're familiar with the Trixbox, we developed that. 11 00:00:31,520 --> 00:00:32,940 And I love Lady Gaga. 12 00:00:34,080 --> 00:00:36,780 I love Kesha, too. It's kind of in between. I'm not sure. 13 00:00:38,000 --> 00:00:40,460 You're probably wondering, like, why haven't I heard of this guy? 14 00:00:40,600 --> 00:00:43,220 Or hasn't this guy done nothing for a couple of years? 15 00:00:43,380 --> 00:00:44,060 Why is that? 16 00:00:44,580 --> 00:00:46,220 They didn't let me touch computers. 17 00:00:49,020 --> 00:00:50,580 It's true. It's true. 18 00:00:50,940 --> 00:00:53,300 A few years ago, I was raided by the Secret Service, 19 00:00:53,420 --> 00:00:54,740 the Electronics Crimes Task Force. 20 00:00:54,900 --> 00:00:57,280 They came into my home. They took all of my computers. 21 00:00:57,720 --> 00:00:58,800 Well, my laptop. 22 00:00:59,600 --> 00:01:03,140 They took my phone. They took any CDs, DVDs. 23 00:01:03,700 --> 00:01:04,740 They took my Xbox. 24 00:01:06,520 --> 00:01:07,480 Yeah. Yeah. 25 00:01:09,020 --> 00:01:12,220 Dealt with court. Literally could not touch computers. 26 00:01:12,400 --> 00:01:13,280 I was banned for life. 27 00:01:13,660 --> 00:01:15,660 A couple years later, I fought and I fought. 28 00:01:16,060 --> 00:01:18,200 And I am now back. 29 00:01:18,820 --> 00:01:20,540 I'm allowed to touch computers. All right! 30 00:01:20,700 --> 00:01:20,940 Thanks! 31 00:01:25,520 --> 00:01:26,980 But I'm not allowed on MySpace. 32 00:01:31,300 --> 00:01:33,040 All right. So, what are we going to talk about today? 33 00:01:34,860 --> 00:01:36,720 Talk about the web. Why the web? 34 00:01:37,400 --> 00:01:40,600 Honestly, you know, I got bored of the web a couple of years ago. 35 00:01:40,700 --> 00:01:42,700 You know, it's really cool. There's so much you can do with it. 36 00:01:43,280 --> 00:01:45,200 But security is so much broader, right? 37 00:01:45,280 --> 00:01:47,520 There's so much cool stuff going on here at DEF CON, 38 00:01:48,100 --> 00:01:49,660 just in security in general, right? 39 00:01:49,740 --> 00:01:51,720 You have reverse engineering. You have network security. 40 00:01:52,060 --> 00:01:53,720 You do have web application security. 41 00:01:54,480 --> 00:01:56,580 There's hardware hacking. All this cool stuff. 42 00:01:57,340 --> 00:01:57,700 All right. So, I'm going to talk a little bit about security. 43 00:01:57,720 --> 00:02:00,120 Some people have even made ATMs dispense cash. 44 00:02:00,280 --> 00:02:01,320 You probably haven't heard about that. 45 00:02:01,440 --> 00:02:04,940 It's a really cool new thing that they're talking about. 46 00:02:05,600 --> 00:02:08,660 But the web is actually really cool in another way. 47 00:02:09,540 --> 00:02:11,060 Everyone has a web browser. 48 00:02:11,260 --> 00:02:13,520 If you've got a computer and you have an operating system, 49 00:02:13,680 --> 00:02:14,820 you have a web browser. 50 00:02:15,920 --> 00:02:19,100 So, it's like the one piece of software that allows me 51 00:02:19,100 --> 00:02:22,520 to deliver code to you and for you to execute it. 52 00:02:22,640 --> 00:02:27,460 It is basically code delivery mechanism that I can attack anyone. 53 00:02:28,040 --> 00:02:29,600 Anyone. Everyone has the internet today. 54 00:02:30,440 --> 00:02:32,980 It's kind of like when the App Store came out for the iPhone, right? 55 00:02:33,040 --> 00:02:36,340 At that point, you could deliver any sort of content that you wanted. 56 00:02:36,460 --> 00:02:39,280 Of course, Apple bans malicious content. 57 00:02:39,900 --> 00:02:42,620 And fortunately, they give us freedom from porn. 58 00:02:45,500 --> 00:02:49,040 So, the web browser is just like that except no one's guarding it. 59 00:02:49,100 --> 00:02:51,640 There's no one checking to make sure that your site's not malicious. 60 00:02:51,920 --> 00:02:54,140 I mean, obviously, there are companies that are doing this in software 61 00:02:54,140 --> 00:02:55,200 that's working on this. 62 00:02:55,420 --> 00:02:56,980 But for a long time, there hasn't been. 63 00:02:59,640 --> 00:03:01,580 So, this is my home page. 64 00:03:02,540 --> 00:03:03,680 It's probably for many of you. 65 00:03:04,460 --> 00:03:05,840 Anna Faris, she's amazing. 66 00:03:06,280 --> 00:03:07,080 I'm in love with her. 67 00:03:07,760 --> 00:03:11,520 So, I was checking out, you know, just pictures of girls on a social network 68 00:03:11,520 --> 00:03:13,400 as I typically do before I get in a lot of trouble. 69 00:03:14,120 --> 00:03:15,600 And I found her. 70 00:03:16,040 --> 00:03:17,900 I think, man, she's amazing, you know. 71 00:03:18,600 --> 00:03:20,380 She's the kind of girl I want to get to know. 72 00:03:22,280 --> 00:03:24,500 So, I'm looking at her profile, looking through her pictures. 73 00:03:24,760 --> 00:03:26,240 I can't really see too much. 74 00:03:26,260 --> 00:03:27,600 She's not my friend. 75 00:03:30,140 --> 00:03:31,800 I thought about that for a second. 76 00:03:32,060 --> 00:03:34,520 And then I saw, oh, man, you know, I should message her. 77 00:03:34,560 --> 00:03:37,100 But then I saw she's in a relationship, not an open relationship. 78 00:03:37,960 --> 00:03:38,880 It's not complicated. 79 00:03:39,300 --> 00:03:40,300 She's in a relationship. 80 00:03:43,620 --> 00:03:46,400 So, I'm like, who is this guy, and how am I going to best him? 81 00:03:46,640 --> 00:03:48,160 So, I look into him a little bit. 82 00:03:50,820 --> 00:03:55,460 All right, so this guy, he's a certified information security specialist professional. 83 00:03:56,440 --> 00:03:56,800 Yeah. 84 00:03:56,960 --> 00:03:57,320 Chief. 85 00:03:57,600 --> 00:03:59,780 Executive officer of Sec Theory. 86 00:04:00,100 --> 00:04:00,260 Ooh. 87 00:04:00,660 --> 00:04:03,020 Co-author of XSS Exploits. 88 00:04:03,380 --> 00:04:04,240 Oh, no. 89 00:04:04,340 --> 00:04:05,720 Author of Detecting Malice. 90 00:04:05,940 --> 00:04:11,460 Co-developer of Clickjacking, a really cool technology with the really awesome Jeremiah 91 00:04:11,460 --> 00:04:11,980 Grossman. 92 00:04:12,360 --> 00:04:15,420 Runs hackers.org and slackers.org, if you guys have ever been there. 93 00:04:15,900 --> 00:04:20,340 And he's a certified ass, which is an application security specialist. 94 00:04:24,680 --> 00:04:26,440 It's a pretty impressive resume. 95 00:04:26,640 --> 00:04:27,040 Yeah. 96 00:04:27,640 --> 00:04:31,380 So, a man who needs no introduction, Robert R. Snake Hansen. 97 00:04:31,680 --> 00:04:32,440 This guy. 98 00:04:33,180 --> 00:04:34,440 So, here's the problem. 99 00:04:34,600 --> 00:04:36,020 I want to attack this guy. 100 00:04:36,720 --> 00:04:39,200 We all know we can attack random people on the web. 101 00:04:39,440 --> 00:04:43,560 You have a little bit of malicious content on there, and you'll get some sort of hit 102 00:04:43,560 --> 00:04:43,800 rate. 103 00:04:43,980 --> 00:04:48,000 And if you get enough visitors, you will be attacking random people. 104 00:04:48,260 --> 00:04:51,260 But I want to do a targeted attack to someone who is secure. 105 00:04:51,880 --> 00:04:57,580 Someone like you people who understand security, who are probably running with a lot of technology, 106 00:04:57,580 --> 00:04:59,100 to help secure yourself. 107 00:05:00,760 --> 00:05:02,100 So, how do we do it? 108 00:05:03,660 --> 00:05:04,760 How do I attack him? 109 00:05:05,320 --> 00:05:06,100 You don't. 110 00:05:06,220 --> 00:05:08,080 You do not attack that person. 111 00:05:08,280 --> 00:05:09,280 You attack him directly. 112 00:05:10,800 --> 00:05:11,240 Ooh. 113 00:05:12,120 --> 00:05:13,240 That's what I'm trying to attack. 114 00:05:15,340 --> 00:05:16,160 Come on, guys. 115 00:05:16,360 --> 00:05:16,800 Come on. 116 00:05:18,000 --> 00:05:19,320 So, he's on Facebook. 117 00:05:19,980 --> 00:05:21,620 Facebook's an awesome website. 118 00:05:21,720 --> 00:05:22,700 It's a social network. 119 00:05:22,960 --> 00:05:24,080 It's the cool one these days. 120 00:05:24,660 --> 00:05:27,560 Now, if we go to Facebook, we'll see something in the URL, but we're not going to do it. 121 00:05:27,560 --> 00:05:27,720 It's a toolbar. 122 00:05:27,920 --> 00:05:29,160 Index.php. 123 00:05:29,800 --> 00:05:30,680 I know what you're thinking. 124 00:05:31,700 --> 00:05:32,380 It's FIP. 125 00:05:32,480 --> 00:05:32,960 It's not. 126 00:05:33,080 --> 00:05:33,520 It's PHP. 127 00:05:33,720 --> 00:05:34,180 I looked it up. 128 00:05:35,680 --> 00:05:38,060 It's a computer language, right? 129 00:05:38,140 --> 00:05:39,580 Typically used for the web. 130 00:05:39,760 --> 00:05:41,660 It's an extremely common web language. 131 00:05:41,760 --> 00:05:43,100 I'm sure all of you have at least heard of it. 132 00:05:43,460 --> 00:05:44,900 Many of you, I'm sure, program in it. 133 00:05:45,620 --> 00:05:47,460 It's great because it's extremely common. 134 00:05:47,660 --> 00:05:49,460 So, it's well understood. 135 00:05:49,980 --> 00:05:51,440 The code is open source. 136 00:05:51,760 --> 00:05:54,220 You can all go and look at it and see what's going on in there. 137 00:05:54,220 --> 00:06:01,580 It basically has very good session management that everyone uses. 138 00:06:01,860 --> 00:06:07,500 Every single person who does PHP and uses sessions typically uses the built-in session management. 139 00:06:08,620 --> 00:06:17,580 If you're using frameworks like CakePHP or Kohana or CodeIgniter or any of those other things, they're also using this session management. 140 00:06:22,280 --> 00:06:25,740 So, PHP sessions, what are they? 141 00:06:25,860 --> 00:06:27,980 They're basically a random string that's generated. 142 00:06:28,200 --> 00:06:32,200 It's passed either in the URL or cookies. 143 00:06:34,380 --> 00:06:35,920 So, what are cookies? 144 00:06:39,260 --> 00:06:39,860 Yeah. 145 00:06:40,660 --> 00:06:41,860 It's my second favorite. 146 00:06:42,700 --> 00:06:47,400 A cookie is basically a persistent piece of text that remains with your browser. 147 00:06:47,580 --> 00:06:48,960 I'm sure all of you are familiar with it. 148 00:06:49,080 --> 00:06:50,260 It just contains data. 149 00:06:50,460 --> 00:06:52,420 Typically, it will contain session data. 150 00:06:52,660 --> 00:07:01,180 Session data is basically a random string so that when you go to any page on that website, it can identify you with other information the server has stored locally. 151 00:07:02,160 --> 00:07:09,400 So, when you go to Facebook and you log in with a username and password, they provide you a random string that is assigned to that username. 152 00:07:09,600 --> 00:07:14,600 If you ever go to any other pages later on, they look at that random string that you're sending them and they say, 153 00:07:14,660 --> 00:07:16,120 Oh, I know this guy. This is Sammy. 154 00:07:16,620 --> 00:07:17,060 So, 155 00:07:17,940 --> 00:07:18,980 it authenticates you. 156 00:07:20,800 --> 00:07:21,240 So, 157 00:07:22,260 --> 00:07:23,880 let's try to attack a session. 158 00:07:24,240 --> 00:07:25,740 Let's look at PHP session code. 159 00:07:25,920 --> 00:07:26,560 So, open source. 160 00:07:26,720 --> 00:07:27,800 So, we pull up session.c. 161 00:07:28,380 --> 00:07:30,320 This is the function session start. 162 00:07:30,480 --> 00:07:32,320 This is what creates a session in PHP. 163 00:07:33,620 --> 00:07:39,460 Basically, what happens is it creates your random string right here in the snippet of code in this SP prunef. 164 00:07:39,840 --> 00:07:41,160 It's looking at a couple of things. 165 00:07:41,360 --> 00:07:46,320 It's looking at the IP address of the person authenticating or getting this session. 166 00:07:46,320 --> 00:07:52,020 It looks at the epoch, which is basically a time from January 1st, 1970, the number of seconds. 167 00:07:52,680 --> 00:07:56,160 It's looking at the microseconds that that person acquired the cookie. 168 00:07:56,820 --> 00:08:00,000 And it's looking at just a random number that's created. 169 00:08:01,200 --> 00:08:05,020 So, if we take all of that, that's 160 bits of entropy. 170 00:08:05,500 --> 00:08:08,080 We're going to get a little deep here, just for a little bit. 171 00:08:08,660 --> 00:08:12,460 So, 160 bits is a lot if I were to brute force it. 172 00:08:12,540 --> 00:08:15,020 Let's say I wanted to become our snake on Facebook. 173 00:08:15,020 --> 00:08:18,300 What I would do is I would brute force this session, that random string. 174 00:08:18,680 --> 00:08:20,660 But 160 bits, that's a lot. 175 00:08:21,560 --> 00:08:23,200 Now, bits can be a little confusing. 176 00:08:23,340 --> 00:08:24,600 We'll just do a really quick primer. 177 00:08:25,220 --> 00:08:28,280 You know, 64 bits is not double 32 bits. 178 00:08:28,500 --> 00:08:29,960 Every time you add a bit, you're doubling. 179 00:08:31,020 --> 00:08:32,580 So, just a quick primer. 180 00:08:32,640 --> 00:08:34,040 What we can do is a little trick. 181 00:08:34,160 --> 00:08:35,880 For every 10 bits, you can add three zeros. 182 00:08:36,320 --> 00:08:38,000 So, 10 bits is 1,000. 183 00:08:38,280 --> 00:08:39,400 20 bits, a million. 184 00:08:39,980 --> 00:08:41,000 30 bits, a billion. 185 00:08:42,040 --> 00:08:44,240 Also, if you can just remember the 10 bits. 186 00:08:45,360 --> 00:08:50,160 0 through 9 equals 1, 2, 4, 8, 16, 32, 64, 128, 256, 512. 187 00:08:50,400 --> 00:08:53,580 You can take that number to figure out what you want. 188 00:08:53,720 --> 00:08:55,540 So, 25 bits, we know 5 is 32. 189 00:08:56,000 --> 00:08:58,700 And the 20 bits, right, is six zeros. 190 00:08:58,900 --> 00:09:00,940 So, 32 million in that scenario. 191 00:09:02,880 --> 00:09:06,280 So, 160 bits is essentially 10 to the 48. 192 00:09:07,260 --> 00:09:11,540 If we could brute force at 100 trillion values per second, 193 00:09:11,620 --> 00:09:14,340 it would take 900 quadrillion eons. 194 00:09:15,020 --> 00:09:15,500 To brute force. 195 00:09:16,920 --> 00:09:18,540 I didn't even know what an eon was. 196 00:09:18,820 --> 00:09:19,540 I had to look it up. 197 00:09:19,780 --> 00:09:20,800 It's 500 million years. 198 00:09:21,020 --> 00:09:21,520 It's a lot. 199 00:09:22,460 --> 00:09:23,080 Brittany knows. 200 00:09:32,140 --> 00:09:33,960 So, again, 160 bits. 201 00:09:34,180 --> 00:09:35,420 We're not going to brute force this. 202 00:09:35,800 --> 00:09:37,780 It doesn't matter how fast of a computer you have. 203 00:09:38,580 --> 00:09:40,880 So, let's take a look at this a little bit closer. 204 00:09:42,640 --> 00:09:45,000 Well, microseconds isn't really 32 bits. 205 00:09:45,020 --> 00:09:47,680 Microseconds, there are only a million microseconds per second. 206 00:09:47,940 --> 00:09:51,600 Well, a million, if we remember, is only 20 bits. 207 00:09:52,040 --> 00:09:52,520 Right? 208 00:09:52,620 --> 00:09:53,620 Because there are six zeros. 209 00:09:53,920 --> 00:09:57,720 So, we actually just reduced, without doing anything, the 160 bits, 210 00:09:57,820 --> 00:10:01,580 and we reduced 12 bits and got it down to 148 bits, 211 00:10:01,820 --> 00:10:03,200 which doesn't help us. 212 00:10:03,380 --> 00:10:04,260 That's a lot. 213 00:10:04,920 --> 00:10:07,460 So, let's take a little closer look. 214 00:10:09,120 --> 00:10:11,180 If you're familiar with Facebook, it has chat. 215 00:10:11,480 --> 00:10:14,600 When you go online, or when someone logs in, 216 00:10:15,020 --> 00:10:15,620 and you look in the chat window, 217 00:10:15,800 --> 00:10:17,220 you actually see that person come online. 218 00:10:17,460 --> 00:10:18,120 How is that happening? 219 00:10:18,380 --> 00:10:19,840 That's happening with Ajax. 220 00:10:20,220 --> 00:10:22,920 Your client is continuously checking with Facebook 221 00:10:22,920 --> 00:10:24,900 to see, is someone else logging in? 222 00:10:25,020 --> 00:10:25,860 Is someone going offline? 223 00:10:26,280 --> 00:10:28,880 Just to understand, get an updated status. 224 00:10:29,640 --> 00:10:31,840 Well, if you use something like live HTTP headers 225 00:10:31,840 --> 00:10:33,160 or a packet sniffer or something, 226 00:10:33,380 --> 00:10:36,060 you can see the HTTP requests going back and forth, 227 00:10:36,200 --> 00:10:38,160 and you can recreate those if you'd like. 228 00:10:38,800 --> 00:10:41,440 And what you can do is you can just send that request, 229 00:10:41,740 --> 00:10:44,440 is there anyone new online, every single second. 230 00:10:44,440 --> 00:10:47,460 As you're sending it every second, one of these times, 231 00:10:47,680 --> 00:10:49,180 our snake is going to go on, 232 00:10:49,260 --> 00:10:51,620 because he wants to check if anyone poked him. 233 00:10:53,340 --> 00:10:56,500 The cool thing about this is that if you see here in the red, 234 00:10:57,040 --> 00:11:02,340 the date in red is sent from the server. 235 00:11:02,560 --> 00:11:04,580 The server sends us their local time. 236 00:11:05,320 --> 00:11:07,080 Our local time doesn't help us too much, 237 00:11:07,140 --> 00:11:08,560 because we don't really know the difference 238 00:11:08,560 --> 00:11:10,440 between our local time and the server's local time. 239 00:11:10,820 --> 00:11:13,680 That local time helped create that cookie, if you recall. 240 00:11:14,440 --> 00:11:17,860 So that 32 bits, if we are checking every second, 241 00:11:18,320 --> 00:11:21,640 we can now reduce that 32 bits as soon as our snake comes online. 242 00:11:22,020 --> 00:11:23,820 Just by watching that every second. 243 00:11:24,080 --> 00:11:25,320 We write a program to do that. 244 00:11:25,460 --> 00:11:28,260 We see him come online, we take that date, convert it to epoch, 245 00:11:28,300 --> 00:11:29,560 we just reduce 32 bits. 246 00:11:29,800 --> 00:11:34,140 We've now reduced the 160 bits by 44 bits down to 116 bits. 247 00:11:34,580 --> 00:11:35,400 That's awesome. 248 00:11:36,020 --> 00:11:36,800 Still a lot. 249 00:11:37,480 --> 00:11:38,280 Let's go further. 250 00:11:40,220 --> 00:11:42,480 So he comes online, we can send him a message. 251 00:11:42,740 --> 00:11:44,420 Well, why not send him to my blog? 252 00:11:45,020 --> 00:11:46,560 N-A-M-B dot L-A. 253 00:11:47,220 --> 00:11:47,620 NAMBLA. 254 00:11:51,420 --> 00:11:52,540 So you send him there, 255 00:11:52,680 --> 00:11:55,240 and then what you do is you just track the IP address. 256 00:11:55,600 --> 00:11:57,740 Don't worry, there's no XSS, there's nothing on there. 257 00:11:57,780 --> 00:11:59,920 If he's running NoScript or something that's protecting him, 258 00:12:00,020 --> 00:12:01,440 there's nothing malicious on my website. 259 00:12:02,500 --> 00:12:05,360 So he goes there, nothing happens to his browser. 260 00:12:05,480 --> 00:12:11,040 He sees a really cool blog post about how I did a DEF CON talk 261 00:12:11,040 --> 00:12:11,860 and everyone loved it. 262 00:12:12,820 --> 00:12:14,120 And what we do is, 263 00:12:14,440 --> 00:12:16,360 we track the Apache logs and we see his IP address. 264 00:12:16,660 --> 00:12:19,980 Well, there's another 32 bits of that cookie. 265 00:12:20,580 --> 00:12:23,560 So we're now down to 84 bits from 160. 266 00:12:24,240 --> 00:12:26,280 We're basically half, well, it's not really half. 267 00:12:27,660 --> 00:12:29,580 Okay, bits, ugh, so confusing. 268 00:12:30,220 --> 00:12:32,640 Alright, so the only thing left here that we don't know, 269 00:12:32,740 --> 00:12:34,800 we don't know 20 bits of the microseconds, 270 00:12:34,900 --> 00:12:35,820 and we're not going to guess that. 271 00:12:35,920 --> 00:12:37,740 There's no way we're accurately going to guess 272 00:12:38,300 --> 00:12:41,300 the microsecond that someone logged in on a remote system. 273 00:12:41,740 --> 00:12:43,500 You might be able to if you tried really hard, 274 00:12:43,500 --> 00:12:44,680 if you got a system really close 275 00:12:44,680 --> 00:12:46,860 and you timed things really accurately, 276 00:12:47,000 --> 00:12:47,740 but it's not worth it. 277 00:12:48,140 --> 00:12:51,100 So the only other thing left here is this random LCG value, 278 00:12:51,380 --> 00:12:52,280 64 bits. 279 00:12:52,600 --> 00:12:53,460 What is this? 280 00:12:53,860 --> 00:12:56,340 An LCG is a linear congruential generator. 281 00:12:56,620 --> 00:12:58,020 It's a pseudo-random number generator. 282 00:12:58,480 --> 00:12:59,660 They've been studied for years. 283 00:12:59,840 --> 00:13:02,280 It came out like, I don't know, 25 years ago or something. 284 00:13:02,360 --> 00:13:03,340 It's older than I am. 285 00:13:05,380 --> 00:13:07,680 They're really well studied and they're really well understood. 286 00:13:08,220 --> 00:13:10,840 You can actually look up information on how to reverse them. 287 00:13:10,840 --> 00:13:14,740 The LCG used here is actually two LCGs that are combined, 288 00:13:14,960 --> 00:13:17,340 so it's a little bit harder, and I'm not that good at math. 289 00:13:17,880 --> 00:13:19,900 So I didn't understand it too well, 290 00:13:20,020 --> 00:13:21,300 but I looked over the code anyway. 291 00:13:22,880 --> 00:13:25,820 Now, as soon as the LCG, or the random number generator, 292 00:13:25,920 --> 00:13:27,300 is called, it's seeded. 293 00:13:27,360 --> 00:13:30,580 The seed basically provides the actual random data 294 00:13:30,580 --> 00:13:33,800 that provides every single random number from here on out. 295 00:13:34,420 --> 00:13:39,040 Now, the seed is critical to the randomness of the PRNG. 296 00:13:39,820 --> 00:13:41,840 So let's take a look at the seed function here, 297 00:13:41,880 --> 00:13:43,980 this LCG seed at the bottom side of the screen. 298 00:13:44,280 --> 00:13:46,940 What you'll see is, we do a get time of, 299 00:13:47,020 --> 00:13:49,840 there's two parts of the seed, and it's 64 bits. 300 00:13:50,060 --> 00:13:54,040 It's 64 bits of entropy, and every random number is also 64 bits. 301 00:13:55,140 --> 00:13:57,840 It's split into two, called S1 and S2. 302 00:13:58,120 --> 00:13:59,700 They're both each 32 bits long. 303 00:14:00,720 --> 00:14:04,300 Now, S1, if you can see, is this thing called TV seconds 304 00:14:04,300 --> 00:14:07,100 XORed by the ones complement of TBU seconds. 305 00:14:07,280 --> 00:14:09,020 What that is, is that's the epoch, 306 00:14:09,040 --> 00:14:10,340 as soon as it's seeded, 307 00:14:11,000 --> 00:14:14,240 XORed with the ones complement of the microseconds 308 00:14:14,240 --> 00:14:17,040 that the PRNG was seeded. 309 00:14:18,000 --> 00:14:19,560 S2 is the process ID. 310 00:14:20,100 --> 00:14:21,800 So let's just take a look at S1 a little bit more. 311 00:14:21,880 --> 00:14:23,780 That's 32 bits of entropy we're looking at right now. 312 00:14:24,300 --> 00:14:25,960 The interesting thing about this is, 313 00:14:26,040 --> 00:14:28,140 the microseconds, I'm sorry, 314 00:14:28,220 --> 00:14:30,580 the seconds that the PHP was seeded 315 00:14:30,580 --> 00:14:32,680 was probably when the web server started. 316 00:14:33,160 --> 00:14:35,320 We don't necessarily know when that happened, 317 00:14:35,400 --> 00:14:37,860 but we can potentially make an estimate. 318 00:14:37,860 --> 00:14:40,900 We could also send thousands and thousands of requests 319 00:14:40,900 --> 00:14:42,920 to a web server to get it to reset, 320 00:14:43,200 --> 00:14:45,260 and to figure out when it started. 321 00:14:45,680 --> 00:14:48,440 One of the issues is we won't know which requests caused that restart, 322 00:14:48,660 --> 00:14:51,480 but we can make an assumption that it happened in the last hour 323 00:14:51,480 --> 00:14:52,640 if we send enough requests. 324 00:14:53,740 --> 00:14:56,920 Now, what they do to make this harder to guess 325 00:14:56,920 --> 00:14:58,380 is they XOR it with the microseconds. 326 00:14:58,540 --> 00:15:00,620 There's no way we're going to know the microsecond 327 00:15:00,620 --> 00:15:01,960 that the web server started. 328 00:15:02,740 --> 00:15:07,140 But they're XORing the most variable data of the epoch 329 00:15:07,140 --> 00:15:09,260 with the most variable data microseconds. 330 00:15:09,300 --> 00:15:10,840 The fixed data, like what year, 331 00:15:11,020 --> 00:15:13,380 what month, what week it started, 332 00:15:13,580 --> 00:15:14,460 remains the same. 333 00:15:14,820 --> 00:15:15,920 Basically, it's being XORed. 334 00:15:16,440 --> 00:15:17,960 The fixed data remains fixed. 335 00:15:18,220 --> 00:15:21,460 So, we end up with 12 bits that we can guess 336 00:15:21,460 --> 00:15:23,720 if we know within a 12-day period 337 00:15:23,720 --> 00:15:25,220 of when PHP started. 338 00:15:25,620 --> 00:15:26,920 And again, if we don't, 339 00:15:26,920 --> 00:15:29,020 we can send enough requests to get that. 340 00:15:29,320 --> 00:15:31,560 The other 20 bits is just microseconds 341 00:15:31,560 --> 00:15:33,720 XORed with the other variable data of epoch. 342 00:15:33,740 --> 00:15:35,820 We don't know that. Whatever. That's 20 bits. 343 00:15:35,820 --> 00:15:38,580 We've just reduced 12 bits of entropy 344 00:15:38,580 --> 00:15:40,500 in the random number generator. 345 00:15:41,100 --> 00:15:42,340 So, let's look at S2. 346 00:15:43,440 --> 00:15:45,720 Process ID. Get process ID. 347 00:15:46,060 --> 00:15:47,600 That's 32 bits of entropy. 348 00:15:48,160 --> 00:15:50,920 Well, process IDs on Linux are only 15 bits long. 349 00:15:51,140 --> 00:15:53,320 So, immediately, you reduce 17 bits. 350 00:15:53,760 --> 00:15:56,820 And if you can execute PHP through any function, 351 00:15:57,020 --> 00:16:00,040 if you can execute a program like PS, 352 00:16:00,320 --> 00:16:03,380 if you can hit an Apache server info page 353 00:16:03,380 --> 00:16:04,240 or something like that, 354 00:16:04,240 --> 00:16:06,140 you get the entire 32 bits. 355 00:16:06,420 --> 00:16:08,620 We've now reduced the 64 bits 356 00:16:08,620 --> 00:16:11,180 down to 20 bits in the PRNG. 357 00:16:12,460 --> 00:16:15,600 We are now at a total of 40 bits of entropy 358 00:16:15,600 --> 00:16:17,080 from a 160-bit seed. 359 00:16:17,960 --> 00:16:19,780 I'm sorry, from a 160-bit cookie 360 00:16:19,780 --> 00:16:21,860 for every cookie in PHP. 361 00:16:22,940 --> 00:16:23,920 That's awesome. 362 00:16:25,020 --> 00:16:26,720 But wait! There's more. 363 00:16:30,200 --> 00:16:31,680 We can take... 364 00:16:32,240 --> 00:16:34,160 Normally, you think, alright, well, 20 bits and 20 bits, 365 00:16:34,240 --> 00:16:34,860 that's 40 bits. 366 00:16:35,080 --> 00:16:37,600 Well, we can actually calculate the PRNG, 367 00:16:37,680 --> 00:16:38,340 the LCG value, 368 00:16:38,620 --> 00:16:40,660 the 20 bits that we didn't know, separately. 369 00:16:41,600 --> 00:16:44,220 Separately means we calculate that 20 bits, 370 00:16:44,320 --> 00:16:45,600 and then the other 20 bits, 371 00:16:45,720 --> 00:16:47,040 that's only 21 bits. 372 00:16:48,420 --> 00:16:50,900 We can calculate with a time memory trade-off 373 00:16:50,900 --> 00:16:52,820 and code I created on your DEF CON CDs, 374 00:16:53,680 --> 00:16:56,420 we can calculate that 20 bits in a matter of seconds. 375 00:16:57,140 --> 00:16:57,580 Seconds. 376 00:16:58,380 --> 00:17:00,340 That reduces the other 20 bits, 377 00:17:00,440 --> 00:17:03,080 and now we're at exactly 20 bits. 378 00:17:03,180 --> 00:17:04,100 The 20 bits of entropy, 379 00:17:04,100 --> 00:17:07,260 from the microseconds that the user authenticated, 380 00:17:07,340 --> 00:17:07,720 their cookie. 381 00:17:08,540 --> 00:17:09,660 That's a million cookies. 382 00:17:10,100 --> 00:17:12,540 On average, we'll be able to log in as in... 383 00:17:13,400 --> 00:17:14,880 with 500,000 requests, 384 00:17:15,120 --> 00:17:16,360 which we can easily do in a day. 385 00:17:17,460 --> 00:17:18,340 500,000. 386 00:17:18,960 --> 00:17:19,800 So I've done it. 387 00:17:20,340 --> 00:17:21,320 I've become our snake. 388 00:17:23,680 --> 00:17:25,480 So what can we do at this point? 389 00:17:25,760 --> 00:17:27,820 Well, first let's understand, how do we fix this? 390 00:17:28,900 --> 00:17:31,160 Make sure you're running a later version of PHP. 391 00:17:31,460 --> 00:17:32,360 Entropy is... 392 00:17:32,360 --> 00:17:34,080 I sent this over to PHP, 393 00:17:34,080 --> 00:17:35,800 and they quickly released a patch. 394 00:17:35,880 --> 00:17:36,800 They added some more entropy. 395 00:17:37,480 --> 00:17:38,940 Or create your own session values. 396 00:17:39,240 --> 00:17:40,320 Use your own randomness. 397 00:17:40,480 --> 00:17:42,420 One of the great things about PHP is that 398 00:17:42,420 --> 00:17:43,380 it's very fast. 399 00:17:43,560 --> 00:17:44,300 It's meant to be fast. 400 00:17:44,740 --> 00:17:46,120 So they don't want to... 401 00:17:46,120 --> 00:17:49,680 It's also OS, basically cross-compatible. 402 00:17:49,920 --> 00:17:53,060 So they don't do too much that's very system-level. 403 00:17:53,180 --> 00:17:54,860 Like, they're not going to access DEVU random, 404 00:17:55,060 --> 00:17:56,960 because that's not on Windows, for example. 405 00:17:57,520 --> 00:17:58,980 Create your own session values. 406 00:17:59,260 --> 00:18:01,200 Or seed your own random number generator. 407 00:18:01,520 --> 00:18:03,100 You don't need to understand crypto. 408 00:18:04,080 --> 00:18:06,860 Just use a strong seed that your system comes with. 409 00:18:06,940 --> 00:18:09,160 If you're running on Linux or BSD or something like that, 410 00:18:09,280 --> 00:18:10,860 use DEVU random for your seed. 411 00:18:11,020 --> 00:18:12,100 Don't use the process ID. 412 00:18:12,900 --> 00:18:14,620 The attack is difficult to execute. 413 00:18:14,920 --> 00:18:16,460 It's much easier on social networks, 414 00:18:16,580 --> 00:18:17,920 where I spend most of my time, unfortunately. 415 00:18:19,520 --> 00:18:20,460 One thing to note, 416 00:18:20,520 --> 00:18:21,700 Facebook is actually not vulnerable. 417 00:18:21,900 --> 00:18:23,020 This is not an attack on Facebook. 418 00:18:23,440 --> 00:18:24,540 If you're familiar, 419 00:18:24,700 --> 00:18:27,020 Facebook has created their own version of PHP 420 00:18:27,020 --> 00:18:27,860 called HipHop. 421 00:18:28,620 --> 00:18:30,660 Some sort of mash of PHP 422 00:18:30,660 --> 00:18:32,620 turns into compiled C++. 423 00:18:33,160 --> 00:18:34,280 It's supposed to be much faster. 424 00:18:34,600 --> 00:18:35,380 I love Facebook. 425 00:18:36,020 --> 00:18:36,740 If you go on there, 426 00:18:36,800 --> 00:18:38,780 if you could just plant some crops for me 427 00:18:38,780 --> 00:18:40,000 in my farm, Bill, I'd appreciate it. 428 00:18:41,180 --> 00:18:42,820 So at this point, what do we do? 429 00:18:42,860 --> 00:18:43,980 I'm logged in as rsnake. 430 00:18:44,100 --> 00:18:45,460 How am I going to meet this girl? 431 00:18:46,540 --> 00:18:47,180 She's happily... 432 00:18:49,280 --> 00:18:49,600 boyfriended? 433 00:18:49,760 --> 00:18:50,840 I don't know what the word is. 434 00:18:52,300 --> 00:18:53,520 So using his cookie, 435 00:18:53,680 --> 00:18:55,120 I can now message her as him. 436 00:18:55,400 --> 00:18:56,180 So what do I say? 437 00:18:56,700 --> 00:18:57,500 Well, here's the thing. 438 00:18:57,840 --> 00:18:59,900 Why don't I send her to a malicious URL? 439 00:19:01,060 --> 00:19:01,380 Nambla. 440 00:19:05,820 --> 00:19:07,300 We're going to attack her network now. 441 00:19:08,960 --> 00:19:10,460 So this is your network. 442 00:19:11,880 --> 00:19:13,260 This is your network on drugs. 443 00:19:17,400 --> 00:19:19,500 We're going to learn a little bit about a network 444 00:19:19,500 --> 00:19:20,200 and a NAT here. 445 00:19:21,160 --> 00:19:22,020 This is a NAT. 446 00:19:23,620 --> 00:19:25,280 So a NAT, what it is, 447 00:19:25,300 --> 00:19:27,400 is basically a system that allows you to 448 00:19:27,400 --> 00:19:29,860 run multiple systems behind one public IP 449 00:19:29,860 --> 00:19:30,820 in a nutshell. 450 00:19:30,820 --> 00:19:34,220 All of your computers behind the NAT 451 00:19:34,220 --> 00:19:35,940 will typically run in private IP space. 452 00:19:36,640 --> 00:19:38,460 This allows you to, you know, 453 00:19:38,460 --> 00:19:40,800 typically your cable modem will only provide one IP address, 454 00:19:40,840 --> 00:19:42,740 so use a router which contains NAT software. 455 00:19:43,100 --> 00:19:44,740 And that will allow all of your system, 456 00:19:44,840 --> 00:19:46,760 all your network devices to run behind the NAT. 457 00:19:47,300 --> 00:19:49,780 It also is somewhat of a firewall. 458 00:19:49,980 --> 00:19:52,600 It prevents people from accessing services and ports 459 00:19:52,600 --> 00:19:54,020 that you have running on your computer, 460 00:19:54,200 --> 00:19:55,280 whether you know it or not. 461 00:19:55,580 --> 00:19:57,040 So when you go behind a NAT 462 00:19:57,040 --> 00:19:58,780 and you're running, say, Apache on port 80, 463 00:19:58,900 --> 00:20:00,120 no one can connect to you 464 00:20:00,120 --> 00:20:01,400 except internally on your network, 465 00:20:02,020 --> 00:20:03,020 unless you go to the NAT 466 00:20:03,020 --> 00:20:04,960 and you enable port forwarding or DMZ 467 00:20:04,960 --> 00:20:05,600 or something else. 468 00:20:06,940 --> 00:20:08,020 Well, let's talk about something 469 00:20:08,020 --> 00:20:09,660 that some of you may have heard recently 470 00:20:09,660 --> 00:20:11,840 called cross protocol scripting, XPS. 471 00:20:12,540 --> 00:20:14,200 The cool thing about this is 472 00:20:14,200 --> 00:20:16,080 HTTP servers can run on any port. 473 00:20:16,320 --> 00:20:19,440 This means the browser will allow you to communicate 474 00:20:20,120 --> 00:20:22,540 to other HTTP servers on any port. 475 00:20:23,800 --> 00:20:26,120 But HTTP is a new line-based protocol. 476 00:20:26,460 --> 00:20:29,440 What that means is each line has some data. 477 00:20:29,580 --> 00:20:30,100 Right? 478 00:20:30,120 --> 00:20:30,880 Rather than some weird, 479 00:20:30,980 --> 00:20:32,380 let's say, XML formatted data 480 00:20:32,380 --> 00:20:35,200 or a binary stream of some sort. 481 00:20:35,500 --> 00:20:37,060 But there are other protocols 482 00:20:37,060 --> 00:20:38,420 that are also new line-based. 483 00:20:40,240 --> 00:20:42,720 So what we can do is we can actually communicate 484 00:20:42,720 --> 00:20:45,380 with a different new line-based protocol, 485 00:20:45,680 --> 00:20:46,580 like IRC. 486 00:20:51,000 --> 00:20:52,120 IRC is a great place. 487 00:20:52,180 --> 00:20:52,700 It's good people. 488 00:20:54,800 --> 00:20:57,420 So this is what an IRC connection looks like, 489 00:20:57,480 --> 00:20:58,480 just so you can tell really quickly. 490 00:20:58,480 --> 00:21:02,320 I tell that to a reputable server like Fnet. 491 00:21:03,180 --> 00:21:04,140 I log in. 492 00:21:04,220 --> 00:21:05,260 I basically say my name's Sammy. 493 00:21:05,620 --> 00:21:08,320 I respond to a ping request if they have one. 494 00:21:08,460 --> 00:21:09,540 And then I join a channel. 495 00:21:09,960 --> 00:21:12,340 And I find out where I can get WinNuke. 496 00:21:14,020 --> 00:21:15,160 It doesn't work anymore. 497 00:21:15,620 --> 00:21:18,000 So if anyone has a version that works, 498 00:21:18,120 --> 00:21:18,720 please send it to me. 499 00:21:19,580 --> 00:21:22,540 This is how we do an IRC client on the web. 500 00:21:23,440 --> 00:21:25,200 What's interesting about this is 501 00:21:25,880 --> 00:21:27,420 I create a malicious page 502 00:21:27,420 --> 00:21:30,480 that has this code running on the page. 503 00:21:30,800 --> 00:21:32,600 You visit my malicious web page. 504 00:21:32,780 --> 00:21:35,420 Now your client connects to the IRC server. 505 00:21:35,800 --> 00:21:37,820 Your web browser thinks it's an HTTP server. 506 00:21:38,060 --> 00:21:40,100 And what it does is it sends the HTTP request 507 00:21:40,920 --> 00:21:43,320 with the post data of my IRC data. 508 00:21:43,640 --> 00:21:44,940 Now the IRC server says, 509 00:21:45,200 --> 00:21:47,620 well, I don't understand this HTTP request. 510 00:21:47,720 --> 00:21:49,260 I don't understand this line, line, line, line. 511 00:21:49,440 --> 00:21:50,320 Oh, I understand this. 512 00:21:50,480 --> 00:21:52,660 I understand join pound hackers. 513 00:21:52,820 --> 00:21:53,400 I know what that means. 514 00:21:53,560 --> 00:21:54,460 I'll interpret that. 515 00:21:54,580 --> 00:21:55,900 I'll just ignore all your other stuff. 516 00:21:55,900 --> 00:21:59,540 And at this point, I'm making your IP address 517 00:21:59,540 --> 00:22:00,700 connect to the IRC server. 518 00:22:01,640 --> 00:22:05,740 Now this can be used for SMTP, for example. 519 00:22:06,660 --> 00:22:08,120 Spammers have actually been using this 520 00:22:08,120 --> 00:22:08,820 for years and years. 521 00:22:09,020 --> 00:22:10,900 And it hasn't been really well known. 522 00:22:11,140 --> 00:22:15,940 But they've been basically making people's browsers 523 00:22:15,940 --> 00:22:17,300 become spam servers. 524 00:22:17,600 --> 00:22:20,020 You visit a page, and without you ever seeing, 525 00:22:20,160 --> 00:22:23,200 on the back end there's a form 526 00:22:23,200 --> 00:22:25,880 that's connecting to an HTTP server on your IP. 527 00:22:25,900 --> 00:22:28,580 You're on port 25 and auto-submitting that form. 528 00:22:29,340 --> 00:22:32,040 And then basically you're now sending Viagra spam. 529 00:22:34,120 --> 00:22:35,920 Why you're going to Viagra site, I don't know. 530 00:22:36,060 --> 00:22:37,860 But that's what they have on the back. 531 00:22:38,460 --> 00:22:41,820 So this is what an HTTP post looks like. 532 00:22:42,200 --> 00:22:44,300 You see basically all the HTTP headers 533 00:22:44,300 --> 00:22:45,400 that your browser is sending. 534 00:22:45,800 --> 00:22:47,200 And then you see the IRC data. 535 00:22:47,420 --> 00:22:49,800 Again, the IRC server ignores the data it doesn't understand 536 00:22:49,800 --> 00:22:52,580 until it hits the data it understands. 537 00:22:53,300 --> 00:22:54,420 So why am I bringing this up? 538 00:22:54,900 --> 00:22:57,780 I'm going to talk about something called NAT pinning. 539 00:23:09,060 --> 00:23:10,020 NAT pinning. 540 00:23:13,380 --> 00:23:16,160 It's like XPS over times 9000. 541 00:23:18,060 --> 00:23:19,380 So what is NAT pinning? 542 00:23:19,700 --> 00:23:20,780 Well, here's the thing. 543 00:23:20,860 --> 00:23:22,000 Your web browser was confused. 544 00:23:22,140 --> 00:23:24,240 It thought it was communicating with an HTTP server. 545 00:23:24,420 --> 00:23:26,400 But it was communicating with an IRC server. 546 00:23:26,700 --> 00:23:28,900 So NAT pinning takes this one step further. 547 00:23:29,100 --> 00:23:34,040 And basically it makes the router also confused 548 00:23:34,040 --> 00:23:36,660 and thinks that it's communicating with a different protocol. 549 00:23:37,120 --> 00:23:40,060 So now your router thinks it's communicating with IRC. 550 00:23:40,160 --> 00:23:41,940 Your browser thinks it's communicating with HTTP. 551 00:23:42,240 --> 00:23:43,620 And they start doing different things. 552 00:23:44,580 --> 00:23:45,700 What can we do with this? 553 00:23:46,340 --> 00:23:48,360 Well, let's take a look at a malicious server. 554 00:23:50,160 --> 00:23:51,620 That was supposed to say HP. 555 00:23:52,400 --> 00:23:53,500 I don't know what happened. 556 00:23:55,640 --> 00:23:58,040 So you have your network devices behind your NAT. 557 00:23:58,180 --> 00:24:00,280 You have a malicious server that you're going to hit a website. 558 00:24:00,540 --> 00:24:03,200 You're hitting a web URL on that malicious server. 559 00:24:04,420 --> 00:24:07,340 Now, if you're familiar with IRC, there's something called a DCC. 560 00:24:07,660 --> 00:24:09,820 It's basically how porn is sent over IRC. 561 00:24:09,920 --> 00:24:10,460 It's great. 562 00:24:11,140 --> 00:24:11,900 It's a great protocol. 563 00:24:12,500 --> 00:24:15,380 Basically what a DCC is, it's a direct client connection. 564 00:24:15,840 --> 00:24:18,260 So when you're communicating with an IRC server 565 00:24:18,260 --> 00:24:20,700 and you're chatting with all the other really cool people, 566 00:24:20,880 --> 00:24:22,820 and you say, you know what, I want to send you this file. 567 00:24:22,820 --> 00:24:24,540 So connect directly to me. 568 00:24:25,720 --> 00:24:28,260 There's no point of the server bridging this file or this chat. 569 00:24:28,520 --> 00:24:29,320 So we'll connect directly. 570 00:24:29,820 --> 00:24:32,640 The way that works is you send a message to the person and you say, 571 00:24:32,820 --> 00:24:36,600 hey, I want you to connect back to me on this IP address on this port. 572 00:24:37,560 --> 00:24:40,320 Now, years ago, routers didn't understand this message. 573 00:24:40,420 --> 00:24:42,300 It was just TCP traffic. 574 00:24:42,700 --> 00:24:45,900 And what would happen is if you didn't have that port opened or forwarded to yourself, 575 00:24:46,320 --> 00:24:47,960 then the connection would never establish. 576 00:24:48,800 --> 00:24:49,600 People complained. 577 00:24:49,760 --> 00:24:51,020 You know, this broke all sorts of things. 578 00:24:51,080 --> 00:24:52,640 It broke IRC, DCC. 579 00:24:52,640 --> 00:24:53,600 It broke FTP. 580 00:24:53,780 --> 00:24:54,560 It broke SIP. 581 00:24:54,880 --> 00:24:56,460 So routers got smart. 582 00:24:56,680 --> 00:25:00,080 They started developing software that would actually watch the traffic, 583 00:25:00,280 --> 00:25:04,520 look for messages like this, the private message, Sammy, you know, DCC chat me. 584 00:25:04,880 --> 00:25:07,140 And if they saw that message, then they would say, 585 00:25:07,240 --> 00:25:10,480 oh, a client on my network is trying to get a file sent. 586 00:25:12,080 --> 00:25:14,320 So I'll port forward that port back to them. 587 00:25:14,840 --> 00:25:19,220 Well, if you recall, they're assuming that you're a valid client that said, 588 00:25:19,260 --> 00:25:20,180 I want to do this. 589 00:25:20,480 --> 00:25:22,560 I actually want this person to connect back to me. 590 00:25:22,640 --> 00:25:27,860 But you can visit my malicious website, and your browser sent this data. 591 00:25:28,520 --> 00:25:32,460 Well, what if I put that DCC message in the browser in the JavaScript submit? 592 00:25:32,960 --> 00:25:34,660 Now you visit my website. 593 00:25:35,400 --> 00:25:39,560 The website submits that malicious form to just some random server, 594 00:25:39,680 --> 00:25:46,400 and it says, I want you to connect to me on port 22 and port 80 and port 443 and 25 and 21 and 23. 595 00:25:47,740 --> 00:25:51,660 I've now just port forwarded every port I want to attack you on. 596 00:25:52,760 --> 00:25:54,000 Just by you visiting my website. 597 00:25:55,200 --> 00:25:55,700 That's it. 598 00:25:55,780 --> 00:25:57,140 The browser has no idea what's going on. 599 00:25:57,200 --> 00:25:59,160 It's just filling out its request. 600 00:25:59,560 --> 00:26:02,260 And I am attacking you on every single port. 601 00:26:03,380 --> 00:26:04,000 Here's the code. 602 00:26:04,640 --> 00:26:05,600 It's also on your CD. 603 00:26:05,800 --> 00:26:06,240 Have fun. 604 00:26:07,860 --> 00:26:09,100 So this is really cool. 605 00:26:09,460 --> 00:26:12,860 Now, once the XPS stuff basically became big, 606 00:26:13,480 --> 00:26:15,800 the browser started working on blocking certain ports. 607 00:26:15,960 --> 00:26:16,500 They said, you know what? 608 00:26:16,620 --> 00:26:19,820 You shouldn't be communicating on port 6667. 609 00:26:20,020 --> 00:26:22,480 If you're running a web server on there, you're stupid. 610 00:26:23,120 --> 00:26:24,200 Choose a different port. 611 00:26:24,380 --> 00:26:25,860 So they started blocking ports. 612 00:26:26,920 --> 00:26:28,620 Now, the interesting thing about ports is 613 00:26:28,620 --> 00:26:33,480 they're 16 bits is the size of a TCP or UDP port. 614 00:26:35,440 --> 00:26:40,080 Now, if the browser says, you know, I'm not going to allow connections on port 6667, 615 00:26:40,540 --> 00:26:41,980 does this port match 6667? 616 00:26:42,200 --> 00:26:42,680 No. 617 00:26:42,960 --> 00:26:44,180 Just overflow it. 618 00:26:44,740 --> 00:26:46,340 So if you add another bit, 619 00:26:46,480 --> 00:26:49,460 and you add 65,536 to it, 620 00:26:50,520 --> 00:26:51,080 you... 621 00:26:51,080 --> 00:26:53,680 you get this bigger number, right? 622 00:26:53,720 --> 00:26:55,000 72,203. 623 00:26:55,140 --> 00:26:57,340 Your browser says, oh, that's not 6667. 624 00:26:57,380 --> 00:26:58,000 This will go fine. 625 00:26:58,340 --> 00:26:59,960 It gets sent to the TCP stack, 626 00:27:00,160 --> 00:27:01,100 which then shortens it. 627 00:27:01,860 --> 00:27:03,540 And now you have 6667. 628 00:27:04,200 --> 00:27:05,940 I did not think of this. 629 00:27:06,040 --> 00:27:09,300 It was actually the respectable security group, 630 00:27:09,540 --> 00:27:10,380 Goatsea Security, 631 00:27:10,680 --> 00:27:11,680 that came up with this. 632 00:27:13,120 --> 00:27:13,960 Very good people. 633 00:27:14,660 --> 00:27:15,380 Very awesome. 634 00:27:15,540 --> 00:27:16,180 Very awesome. 635 00:27:21,460 --> 00:27:24,800 So at this point, Anna has clicked on my link. 636 00:27:25,660 --> 00:27:26,180 Wow. 637 00:27:26,920 --> 00:27:28,600 And now I've attacked her ports. 638 00:27:31,100 --> 00:27:32,740 So what did she have open? 639 00:27:32,860 --> 00:27:36,580 Well, a lot of OSX systems have a web server running by default. 640 00:27:37,540 --> 00:27:38,880 She was working on her website. 641 00:27:39,640 --> 00:27:40,380 So cute. 642 00:27:40,920 --> 00:27:43,340 So I connected back to her port 80 643 00:27:43,340 --> 00:27:46,100 and saw she was making her own website 644 00:27:46,100 --> 00:27:47,980 about Team Jacob from Twilight. 645 00:27:48,380 --> 00:27:49,400 I love Twilight. 646 00:27:51,080 --> 00:27:52,440 Now I know how to get her. 647 00:27:53,020 --> 00:27:54,040 I'm just going to win her over. 648 00:27:54,160 --> 00:27:54,580 Here's the thing. 649 00:27:54,680 --> 00:27:55,880 I'm actually on Team Edward, 650 00:27:56,280 --> 00:27:57,420 but I'm not going to tell her that. 651 00:27:58,200 --> 00:27:59,500 So when I see her, I'm going to say, 652 00:27:59,540 --> 00:28:00,200 I'm on Team Jacob. 653 00:28:02,840 --> 00:28:04,400 So how do you stop NAT pinning? 654 00:28:06,820 --> 00:28:08,980 Well, there are so many ways that you want to... 655 00:28:08,980 --> 00:28:10,220 You want to have multiple layers. 656 00:28:10,340 --> 00:28:11,380 So you want a strict firewall. 657 00:28:12,440 --> 00:28:13,080 Don't allow... 658 00:28:13,080 --> 00:28:15,020 Try to make it as strict as possible if you can. 659 00:28:15,180 --> 00:28:17,240 If you don't expect people using IRC on your network, 660 00:28:17,560 --> 00:28:18,380 block it off entirely. 661 00:28:18,840 --> 00:28:21,000 If you don't expect people 662 00:28:21,080 --> 00:28:22,540 being able to send stuff, 663 00:28:22,720 --> 00:28:23,860 block off... 664 00:28:23,860 --> 00:28:26,220 You can actually turn off UPnP 665 00:28:26,220 --> 00:28:29,500 and other protocols that allow this type of thing to happen. 666 00:28:30,100 --> 00:28:31,420 Client-side, run up-to-date browsers. 667 00:28:32,260 --> 00:28:35,220 WebKit was vulnerable to the port overflow. 668 00:28:35,480 --> 00:28:36,800 I believe they're resolved now. 669 00:28:36,880 --> 00:28:38,100 Other browsers might still be vulnerable. 670 00:28:38,300 --> 00:28:38,620 I'm not sure. 671 00:28:38,820 --> 00:28:40,520 Make sure you're running up-to-date browsers. 672 00:28:41,000 --> 00:28:42,460 Use NoScript if you're using Firefox. 673 00:28:42,660 --> 00:28:44,020 That'll block all sorts of types of things. 674 00:28:44,420 --> 00:28:46,000 When I released NAT pinning, 675 00:28:46,760 --> 00:28:48,960 NoScript a day later added this... 676 00:28:48,960 --> 00:28:50,040 added protection in. 677 00:28:51,080 --> 00:28:52,440 Run a local firewall if you can, 678 00:28:52,460 --> 00:28:54,100 like Little Snitch. 679 00:28:54,720 --> 00:28:56,200 I mean, really, we all understand 680 00:28:56,200 --> 00:28:58,040 security's not just one level of security. 681 00:28:58,200 --> 00:29:00,040 You basically have to use multiple layers of protection. 682 00:29:00,820 --> 00:29:01,740 Like I would with Anna. 683 00:29:06,240 --> 00:29:07,140 So at this point, 684 00:29:07,740 --> 00:29:08,720 I know what she's into. 685 00:29:09,200 --> 00:29:10,680 I know how to win her over, I think. 686 00:29:10,980 --> 00:29:12,080 So I'm going to send her a message 687 00:29:12,960 --> 00:29:14,200 to go to another malicious website. 688 00:29:15,080 --> 00:29:15,940 I'm going to say, you know what? 689 00:29:16,060 --> 00:29:17,860 This guy, Sammy, he's a really good friend of mine. 690 00:29:17,900 --> 00:29:18,500 He's going to come over. 691 00:29:18,940 --> 00:29:19,780 He'll take care of you. 692 00:29:19,780 --> 00:29:22,980 Check out his Twitter on Nambla slash Twitter. 693 00:29:25,460 --> 00:29:28,960 So now, the moment you've all been waiting for. 694 00:29:31,160 --> 00:29:31,680 XXXSS. 695 00:29:34,700 --> 00:29:36,020 This is awesome. 696 00:29:36,440 --> 00:29:37,920 This is actually really awesome. 697 00:29:38,460 --> 00:29:40,580 We're going to be talking about geolocation 698 00:29:40,580 --> 00:29:42,720 via XXXSS. 699 00:29:44,380 --> 00:29:45,540 So how does this work? 700 00:29:46,500 --> 00:29:48,120 Anna visits my malicious site. 701 00:29:49,780 --> 00:29:54,500 She then, the XXXSS scans her local network 702 00:29:54,500 --> 00:29:56,440 to figure out what kind of router she's running. 703 00:29:56,880 --> 00:29:57,760 This is very simple. 704 00:29:58,140 --> 00:29:59,160 Here's one example. 705 00:29:59,320 --> 00:30:00,340 There's a million ways to do it. 706 00:30:00,740 --> 00:30:03,480 Basically, I have iframes on a bunch of different URLs 707 00:30:03,480 --> 00:30:06,560 that are known router locations on your local network. 708 00:30:06,820 --> 00:30:07,940 I can't access that. 709 00:30:08,100 --> 00:30:10,740 But because her browser is on my site, 710 00:30:10,920 --> 00:30:13,300 it's now her network that's accessing it. 711 00:30:13,400 --> 00:30:15,440 So she's accessing 192.168 addresses. 712 00:30:16,040 --> 00:30:17,720 If any of those addresses work, 713 00:30:17,960 --> 00:30:19,200 an onload occurs. 714 00:30:19,200 --> 00:30:21,700 Which says, oh, I've detected a Vulkan router. 715 00:30:21,860 --> 00:30:23,800 Or, oh, I've detected a Verizon Fios router. 716 00:30:24,000 --> 00:30:25,540 And now we know what kind of router she's on. 717 00:30:27,140 --> 00:30:29,580 After that, we could log in with default credentials. 718 00:30:30,000 --> 00:30:31,720 No one changes their credentials on the router. 719 00:30:31,860 --> 00:30:32,880 They're like, who's going to connect? 720 00:30:33,400 --> 00:30:35,120 A, you need to have a really strong, 721 00:30:35,320 --> 00:30:36,920 let's assume you're running WPA. 722 00:30:37,880 --> 00:30:40,720 And the only way to connect is either knowing the WPA password 723 00:30:41,140 --> 00:30:42,660 or by getting physical access. 724 00:30:42,980 --> 00:30:45,820 So who's going to be able to access those internal IP addresses? 725 00:30:46,360 --> 00:30:47,200 Well, I can. 726 00:30:47,200 --> 00:30:48,380 So can you. 727 00:30:49,160 --> 00:30:51,100 So make sure you change your credentials 728 00:30:51,100 --> 00:30:52,320 when you have a router at home 729 00:30:52,320 --> 00:30:54,620 that has an HTTP-based authentication system. 730 00:30:55,640 --> 00:30:58,880 This is not necessary for this attack in many cases. 731 00:30:59,100 --> 00:31:00,860 But here's a way to log in to, 732 00:31:01,000 --> 00:31:02,240 I believe this is a Vulkan router. 733 00:31:02,540 --> 00:31:06,200 There's actually a nice list of XSS, CSRF, 734 00:31:06,340 --> 00:31:09,200 and default passwords for every major router 735 00:31:09,200 --> 00:31:09,900 that you can find online. 736 00:31:12,500 --> 00:31:14,080 So in a visit to the site, 737 00:31:14,180 --> 00:31:15,520 we figure out the router type. 738 00:31:15,520 --> 00:31:17,160 We log in if we have to, 739 00:31:17,260 --> 00:31:18,620 which in many cases we don't. 740 00:31:18,680 --> 00:31:20,200 And then we XSS the router. 741 00:31:20,820 --> 00:31:23,040 And we load remote JavaScript. 742 00:31:23,660 --> 00:31:25,360 All right, so what's the JavaScript do? 743 00:31:26,920 --> 00:31:28,960 The JavaScript then uses Ajax 744 00:31:28,960 --> 00:31:32,780 and connects to another page on the router 745 00:31:32,780 --> 00:31:34,800 and acquires the MAC address of the router. 746 00:31:35,520 --> 00:31:37,460 All right, well, who cares? 747 00:31:37,580 --> 00:31:38,280 It's a MAC address. 748 00:31:39,380 --> 00:31:40,240 What's the big deal? 749 00:31:41,780 --> 00:31:44,360 So briefly, what is a MAC address? 750 00:31:44,360 --> 00:31:47,040 It's basically every network device on your network 751 00:31:47,040 --> 00:31:47,980 has a MAC address, 752 00:31:48,240 --> 00:31:49,260 kind of like an IP address. 753 00:31:50,340 --> 00:31:51,520 It's in hardware. 754 00:31:51,720 --> 00:31:53,120 It can't change unless you're spoofing it. 755 00:31:53,360 --> 00:31:55,600 And it's how everything communicates 756 00:31:55,600 --> 00:31:56,560 with each other on your LAN. 757 00:31:58,940 --> 00:32:00,320 So why the MAC address? 758 00:32:00,580 --> 00:32:01,740 Why do we want to acquire it? 759 00:32:01,840 --> 00:32:03,020 What's so interesting about it? 760 00:32:03,800 --> 00:32:04,820 I'll take you through the steps. 761 00:32:06,300 --> 00:32:07,000 Just Bing it. 762 00:32:07,720 --> 00:32:08,620 Open your browser. 763 00:32:09,760 --> 00:32:12,860 Type www.bing.com in the URL bar. 764 00:32:13,580 --> 00:32:15,760 When the search box comes up, 765 00:32:16,960 --> 00:32:17,880 type in Google. 766 00:32:26,320 --> 00:32:27,560 And hit Enter. 767 00:32:30,400 --> 00:32:31,020 I'll wait. 768 00:32:35,980 --> 00:32:36,860 So why Google? 769 00:32:38,280 --> 00:32:40,180 Oh, yeah, because they know everything. 770 00:32:41,840 --> 00:32:42,320 Really. 771 00:32:45,400 --> 00:32:47,380 So some of you may be familiar with this. 772 00:32:48,080 --> 00:32:49,640 If you remember Aaron Andrews, 773 00:32:49,640 --> 00:32:51,040 the peephole video that came out. 774 00:32:52,060 --> 00:32:52,480 Google. 775 00:32:53,780 --> 00:32:54,660 Google Street View. 776 00:32:54,960 --> 00:32:56,720 Actually, peephole.google.com, I think. 777 00:32:57,200 --> 00:32:58,640 So this is a Street View car. 778 00:32:59,460 --> 00:33:00,760 Some of you may have seen it. 779 00:33:01,140 --> 00:33:03,260 Lots of you probably know what it is. 780 00:33:03,480 --> 00:33:04,200 It's the car. 781 00:33:04,400 --> 00:33:06,420 It's the one guy who drives around America 782 00:33:06,420 --> 00:33:07,440 taking pictures. 783 00:33:07,880 --> 00:33:09,320 Drives down every single street. 784 00:33:09,440 --> 00:33:10,400 This would be the worst job. 785 00:33:12,860 --> 00:33:14,640 Now, we understand Street View is really cool. 786 00:33:14,900 --> 00:33:16,960 You can go onto Google Maps 787 00:33:16,960 --> 00:33:19,680 and you can see all the different streets, 788 00:33:19,780 --> 00:33:20,940 the people flashing the cameras, 789 00:33:21,060 --> 00:33:21,800 marriage proposals, 790 00:33:22,180 --> 00:33:23,320 all sorts of awesome stuff. 791 00:33:24,300 --> 00:33:25,840 What you may have not known 792 00:33:25,840 --> 00:33:27,560 is that they're collecting data. 793 00:33:28,140 --> 00:33:29,920 Now, recently there was this big thing 794 00:33:30,480 --> 00:33:33,020 about Google collecting unencrypted Wi-Fi data. 795 00:33:33,260 --> 00:33:35,180 Well, this has nothing to do with that. 796 00:33:35,500 --> 00:33:37,280 Assume they don't have any of that Wi-Fi data, 797 00:33:37,380 --> 00:33:38,980 which they've already deleted in a lot of places. 798 00:33:40,220 --> 00:33:41,740 They're still collecting other... 799 00:33:41,740 --> 00:33:42,480 Right. 800 00:33:42,720 --> 00:33:44,440 They're still collecting other Wi-Fi data. 801 00:33:44,700 --> 00:33:46,000 So what are they collecting? 802 00:33:46,300 --> 00:33:48,140 Well, as they're driving around, 803 00:33:49,060 --> 00:33:50,460 not only are they taking pictures, 804 00:33:50,960 --> 00:33:53,240 not only are they mapping GPS coordinates, 805 00:33:53,480 --> 00:33:56,080 but they're also looking at just Wi-Fi packets in general. 806 00:33:56,220 --> 00:33:57,320 Not the data portion. 807 00:33:57,860 --> 00:33:58,980 They're looking at the headers. 808 00:33:59,260 --> 00:34:00,620 Now, what's interesting about the headers? 809 00:34:00,820 --> 00:34:02,100 It contains MAC addresses. 810 00:34:02,520 --> 00:34:04,600 The hardware MAC address of your router. 811 00:34:05,260 --> 00:34:07,400 The same device that we acquired, 812 00:34:07,460 --> 00:34:09,100 the MAC address that we acquired 813 00:34:09,100 --> 00:34:11,160 just with our triple XSS. 814 00:34:13,120 --> 00:34:14,680 All right, so why is that interesting? 815 00:34:15,120 --> 00:34:16,660 Well, Wi-Fi, you can detect strength. 816 00:34:17,260 --> 00:34:18,560 As they're driving down, 817 00:34:19,000 --> 00:34:21,520 they're actually detecting my network at home, 818 00:34:22,120 --> 00:34:24,140 Mojito's Mo Problems, if you ever see it. 819 00:34:26,060 --> 00:34:27,460 They're driving down the street and they say, 820 00:34:27,500 --> 00:34:29,980 oh, I detect a network. 821 00:34:30,520 --> 00:34:33,000 It's about 10 out of 100 strength-wise. 822 00:34:33,220 --> 00:34:34,160 It must be close. 823 00:34:34,680 --> 00:34:36,640 Driving a little further, taking their pictures, 824 00:34:37,400 --> 00:34:38,980 like, oh, it's stronger now. 825 00:34:39,000 --> 00:34:39,860 It's 50 out of 100. 826 00:34:40,440 --> 00:34:42,800 Gets to its maximum, say, 85 out of 100. 827 00:34:42,940 --> 00:34:45,480 And then it starts to basically go down. 828 00:34:46,020 --> 00:34:48,220 Well, they've just triangulated my position. 829 00:34:48,940 --> 00:34:51,080 They're actually, not only are they going on that street, 830 00:34:51,200 --> 00:34:52,740 but they're going on every other street around it. 831 00:34:52,940 --> 00:34:54,600 And now they're getting even more accurate data. 832 00:34:54,720 --> 00:34:56,920 They may see it actually goes up to strength 95 833 00:34:56,920 --> 00:34:58,380 on the street parallel to mine. 834 00:34:59,040 --> 00:35:01,480 Now they know that I'm actually closer to that street 835 00:35:01,480 --> 00:35:03,560 than I am the other one that was at 85 strength. 836 00:35:04,400 --> 00:35:07,600 They are literally triangulating your network. 837 00:35:07,920 --> 00:35:09,060 Doesn't matter if you're encrypted. 838 00:35:09,060 --> 00:35:12,060 Doesn't matter if you're using WEP, WPA, WPA2. 839 00:35:13,960 --> 00:35:17,260 The packets are flying and the MAC address is in there, unencrypted. 840 00:35:19,280 --> 00:35:21,100 So, how do we use this to our advantage? 841 00:35:22,500 --> 00:35:25,820 Well, Firefox has this cool feature that very few people know about 842 00:35:25,820 --> 00:35:26,760 called Location Services. 843 00:35:27,720 --> 00:35:28,540 It's really cool. 844 00:35:29,380 --> 00:35:31,460 What happens is JavaScript will execute. 845 00:35:31,800 --> 00:35:34,440 You can go to a website and JavaScript will execute 846 00:35:34,440 --> 00:35:37,400 and it will say, Firefox understands this and says, 847 00:35:37,400 --> 00:35:40,040 oh, I better collect the MAC address of my gateway 848 00:35:40,040 --> 00:35:42,440 and send it to Google and find out where I am. 849 00:35:43,000 --> 00:35:43,780 Well, they're smart. 850 00:35:44,120 --> 00:35:44,860 They said, you know what? 851 00:35:44,960 --> 00:35:46,800 We probably shouldn't do that by default, 852 00:35:47,480 --> 00:35:48,460 even though we'd like to. 853 00:35:49,340 --> 00:35:51,180 So, what we're going to do is we're going to ask the user. 854 00:35:51,320 --> 00:35:52,960 We're going to have a little box come up that says, 855 00:35:53,080 --> 00:35:54,940 do you want to share your location with this website? 856 00:35:55,120 --> 00:35:55,700 They want to do it. 857 00:35:56,100 --> 00:35:58,020 You can't take it over with click jacking. 858 00:35:59,260 --> 00:36:02,120 I haven't really found any way to basically hack it in Firefox. 859 00:36:02,500 --> 00:36:04,320 Other browsers don't have support for it yet. 860 00:36:04,580 --> 00:36:06,580 I believe a developer build of Chrome does. 861 00:36:07,400 --> 00:36:08,420 So, how is this interesting? 862 00:36:08,680 --> 00:36:10,100 You know, we can't really access it. 863 00:36:10,180 --> 00:36:13,040 They visit our website, but we don't want them to see that 864 00:36:13,040 --> 00:36:14,040 and they're not going to click it. 865 00:36:14,820 --> 00:36:18,000 Well, Firefox is making an HTTPS connection to Google 866 00:36:18,000 --> 00:36:19,600 and asking them for this information. 867 00:36:20,380 --> 00:36:22,040 Well, why don't we make that connection? 868 00:36:22,540 --> 00:36:24,240 I can write a program on the back end, 869 00:36:24,320 --> 00:36:25,780 so when you visit my website, 870 00:36:26,000 --> 00:36:29,780 I use triple XSS to acquire your MAC address 871 00:36:29,780 --> 00:36:32,700 and then I send it back to my little program 872 00:36:32,700 --> 00:36:33,420 running in the background 873 00:36:33,420 --> 00:36:35,600 that's not running on your browser anymore. 874 00:36:35,600 --> 00:36:37,360 I then connect to Google. 875 00:36:37,480 --> 00:36:39,800 I send your MAC address and this post request 876 00:36:39,800 --> 00:36:43,080 and it sends back your location, your coordinates. 877 00:36:44,860 --> 00:36:47,020 Jack Bauer level triangulation. 878 00:36:54,720 --> 00:36:58,040 Now, just to understand how accurate is this, 879 00:36:58,220 --> 00:37:00,640 this is an actual router I've exploited 880 00:37:00,640 --> 00:37:02,440 and I knew the address beforehand 881 00:37:02,440 --> 00:37:03,860 because Anna was there. 882 00:37:04,460 --> 00:37:05,140 So... 883 00:37:05,600 --> 00:37:08,540 I went over there and I did a Google Maps request 884 00:37:08,540 --> 00:37:10,500 and I said, you know, take these coordinates 885 00:37:10,500 --> 00:37:14,300 and drive me to the location, the address. 886 00:37:14,500 --> 00:37:15,800 Let's see how far it was. 887 00:37:18,900 --> 00:37:20,800 Driving directions, 30 feet. 888 00:37:22,180 --> 00:37:23,300 I looked over the router. 889 00:37:23,440 --> 00:37:24,640 It was 30 feet away. 890 00:37:27,720 --> 00:37:29,520 Seriously, that's what it said, 30 feet. 891 00:37:29,620 --> 00:37:30,940 That's how accurate the coordinates are. 892 00:37:31,080 --> 00:37:34,220 I mean, it's on that router that I was exploiting. 893 00:37:35,600 --> 00:37:36,860 I think Zuckerberg said it best. 894 00:37:38,880 --> 00:37:39,600 Privacy is dead. 895 00:37:40,960 --> 00:37:41,500 Thank you.