1 00:00:00,000 --> 00:00:02,100 Hey, guys. Welcome to DEF CON 20. 2 00:00:09,860 --> 00:00:13,440 So what are we here to talk about? I got some good news, I 3 00:00:13,440 --> 00:00:19,260 got some bad news. Good news is we are actually going to fix 4 00:00:19,260 --> 00:00:24,780 this thing. Who here focuses on blowing stuff up? Who here is 5 00:00:24,780 --> 00:00:29,340 offense, hack some stuff? Yeah. You're awesome. We need you. 6 00:00:30,860 --> 00:00:32,940 Defense doesn't have offense. You know what happens? Defense 7 00:00:32,940 --> 00:00:40,940 gets stupid. We call that compliance. The bad news is 8 00:00:40,940 --> 00:00:43,840 we're not going to fix it by doing things the way we've been 9 00:00:43,840 --> 00:00:47,900 doing them for 20 years because look where that got us. There's 10 00:00:47,900 --> 00:00:51,780 a lot of dogma insecurity and the dogma is useful because 11 00:00:51,780 --> 00:00:54,500 there's a lot of really, really crappy stuff that we shouldn't 12 00:00:54,500 --> 00:00:54,760 be doing. There's a lot of really, really crappy stuff that 13 00:00:54,760 --> 00:00:57,240 we shouldn't be doing. But that doesn't mean what we're doing 14 00:00:57,240 --> 00:01:02,800 today is entirely correct. Got a riddle for you. What is the 15 00:01:02,800 --> 00:01:06,720 fundamental difference between offense and defense? Between an 16 00:01:06,720 --> 00:01:12,340 attack and a defense? You can tell when an attack doesn't 17 00:01:12,340 --> 00:01:19,560 work. Offense has a quality filter. Put up or shut up. 18 00:01:19,620 --> 00:01:23,940 Either it works or it doesn't. That doesn't mean we don't get 19 00:01:23,940 --> 00:01:24,740 crappy attacks. That doesn't mean we don't get crappy 20 00:01:24,740 --> 00:01:25,120 attacks. That doesn't mean we don't get crappy attacks. We 21 00:01:25,120 --> 00:01:26,340 attacks. We have hacks floating around out there. I don't know 22 00:01:26,340 --> 00:01:28,620 if you noticed. There's a bunch of them. But it's not the 23 00:01:28,620 --> 00:01:31,120 same. It's not like it isn't defense. Defense has a lot 24 00:01:31,120 --> 00:01:33,980 about dogma. It's not much science. We've kind of 25 00:01:33,980 --> 00:01:38,240 transmuted the, well, you can't defend against everything into 26 00:01:38,240 --> 00:01:42,300 I don't need to show what I do and don't defend against. And 27 00:01:42,300 --> 00:01:46,460 critiques against defenses don't need to show how useless they 28 00:01:46,460 --> 00:01:50,060 actually are. So we have this really random discussion with 29 00:01:50,060 --> 00:01:53,800 insufficient skepticism. So that's really what this talk is 30 00:01:53,800 --> 00:01:54,720 about. This talk is about how we can use the argument that we've 31 00:01:54,740 --> 00:02:00,220 is about doubt. This talk is about calling bullshit. If you walk out of this talk believing 32 00:02:00,220 --> 00:02:08,060 everything even I have to say, you're doing it wrong. Guys, my goal is to show you some 33 00:02:08,060 --> 00:02:14,340 new ideas. And they're out there. They're by normal theory wrong. If they are wrong, 34 00:02:14,460 --> 00:02:19,260 let's find out. Let's prove it. But let's not just assume because it violates dogma 35 00:02:19,260 --> 00:02:23,460 that it might not actually be a better path to protecting these networks. 36 00:02:24,900 --> 00:02:30,560 So just to talk concrete, here's a fundamental test. You take 2,000 machines with a given 37 00:02:30,560 --> 00:02:36,740 defense. You take 2,000 machines without. You come back in six months. You see, is there 38 00:02:36,740 --> 00:02:43,100 a statistically significant difference in the infection rate? Now, I'm not saying that 39 00:02:43,100 --> 00:02:46,560 everything, even in the near future, is going to be tested like this. But let's at least 40 00:02:46,560 --> 00:02:48,480 recognize a gold standard. 41 00:02:49,260 --> 00:02:54,020 When we see one. One of these days, we're going to be spending as much time and money 42 00:02:54,020 --> 00:02:59,240 on security research as we are on medical research. Now, I don't know if you realize 43 00:02:59,240 --> 00:03:05,480 this, it took hundreds of years for medicine to get its scientific act together, and they 44 00:03:05,480 --> 00:03:12,480 had dead bodies. We got just like, you know, an economy of a world or something at stake 45 00:03:12,480 --> 00:03:19,080 here. Which, you know, kind of matters. We got to fix this stuff. We don't have hundreds 46 00:03:19,080 --> 00:03:24,540 of years. We got to start fixing it fast. So we got three heads in the security hydra. 47 00:03:24,640 --> 00:03:28,800 Three reasons why we're in this place. One, we can't authenticate. Two, we can't write 48 00:03:28,800 --> 00:03:32,960 secure code. Three, we can't bust the bad guys. We're not going to talk authentication 49 00:03:32,960 --> 00:03:37,400 today because that's DNSSEC. And, well, if you want to talk to me in private, you can 50 00:03:37,400 --> 00:03:41,580 do that. We're not going to talk about busting the bad guys. I don't know if you noticed, 51 00:03:41,780 --> 00:03:46,720 but there seems to be some lack of consensus on who the bad guys are. 52 00:03:48,860 --> 00:03:56,020 Me, I tend to worry about that time the entire Fortune 500 got owned. Aurora was really bad. 53 00:03:56,360 --> 00:03:59,840 People seem to forget about it. They're like, sucks that, sucks that, sucks that. I'm like, 54 00:03:59,880 --> 00:04:06,580 how about the entire stock market? And I'm kind of worried about these small businesses 55 00:04:06,580 --> 00:04:12,780 that are getting their payrolls stolen and their banks saying, sorry, your fault. That's 56 00:04:12,780 --> 00:04:16,700 what makes me worry. But other people are worried about, I don't know, death. I don't 57 00:04:16,720 --> 00:04:22,100 know. Dark night rises. So what are we here to worry about? We're here to talk about 58 00:04:22,100 --> 00:04:27,260 the inability to write secure code. Now, just inability, let me clarify, it's not that 59 00:04:27,260 --> 00:04:33,400 it's impossible to write secure code. It's not impossible to make an authentication system 60 00:04:33,400 --> 00:04:39,320 with certificates using the X509 protocol. It's not impossible to go out and bust criminals 61 00:04:39,320 --> 00:04:46,700 and bad guys. It's just not going to frigging happen. It's totally improbable. Probably 62 00:04:46,720 --> 00:04:50,780 impossible is not enough. Not if you want to actually say you fixed the problem. I wish 63 00:04:50,780 --> 00:04:55,560 I could just blow stuff up. It's a lot of fun. I do it from time to time. But I'd like to 64 00:04:55,560 --> 00:04:59,360 be working on different stuff 20 years from now. You know, new bugs instead of the same 65 00:04:59,360 --> 00:05:03,980 existing ones. So what are we going to do today? We've got five different things to 66 00:05:03,980 --> 00:05:08,620 talk about for DC20. We're going to talk about addressing timing attacks. We're going 67 00:05:08,620 --> 00:05:12,180 to talk about generating random numbers. We're going to talk about suppressing SQL 68 00:05:12,180 --> 00:05:16,700 injection attacks. We are going to detect network manipulation. A little bit of a 69 00:05:16,720 --> 00:05:21,100 follow-up to Nooter from last year. And just for fun, we're going to go scan the Internet 70 00:05:21,100 --> 00:05:26,980 really fast. These are all things that are totally possible today. How do we make them 71 00:05:26,980 --> 00:05:33,920 more deployable, less expensive, more probable? Let's talk about timing attacks. Timing attacks 72 00:05:33,920 --> 00:05:39,900 are a lot of fun. Basically, generally when we model the security of a system, we look 73 00:05:39,900 --> 00:05:46,700 at who says what to who. And we never look at when. Sometimes, when a message is sent, 74 00:05:46,720 --> 00:05:53,500 it leaks internal information that allows you to break the security of a system. Now, 75 00:05:53,540 --> 00:05:58,000 the timing differences we have on computers tend to be small, except for databases. They'll 76 00:05:58,000 --> 00:06:03,200 have, like, second-level deviations. But it doesn't matter. According to a really interesting 77 00:06:03,200 --> 00:06:10,840 paper, we can distinguish 15 to 100 microseconds of latency over the Internet. All the way 78 00:06:10,840 --> 00:06:16,260 down to 100 nanoseconds of latency over a LAN. You know, just like 1,000 probes. I mean, 79 00:06:16,260 --> 00:06:23,500 this is a really small thing of saying, did that take one second? Or did that take 1.00001 80 00:06:23,500 --> 00:06:27,300 seconds? And you can tell reliably. It's kind of cool. 81 00:06:27,800 --> 00:06:32,800 So Nate Lawson and Taylor Nelson did, I think, the best talk on this subject, where they 82 00:06:32,800 --> 00:06:38,300 looked at string comparison functions and broke a bunch of they broke open ID and open 83 00:06:38,300 --> 00:06:44,180 auth, a couple of authentication protocols, really nicely. So the canonical correct fix 84 00:06:44,180 --> 00:06:46,240 to timing attacks is you make everything look like it's going to be the same thing over 85 00:06:46,240 --> 00:06:50,660 time. Everything take the same amount of time. The maximum amount of time any individual 86 00:06:50,660 --> 00:06:56,020 comparison would take. This is a neat little trick. It involves using XOR. And if when 87 00:06:56,020 --> 00:07:01,560 you compare values, you go through the entire string and you XOR everything around, you'll 88 00:07:01,560 --> 00:07:06,720 find out if there's a difference or not. And the time will not vary. Job done. Move 89 00:07:06,720 --> 00:07:12,600 on to the next bug, right? I have never met anyone in my life who has ever implemented 90 00:07:12,600 --> 00:07:16,080 this. The problem is, is that you have to ‑‑ if 91 00:07:16,240 --> 00:07:20,740 you want any security advantage, you have to do it every time there's a security critical 92 00:07:20,740 --> 00:07:26,680 comparison. That means you need to identify the security critical comparisons. You don't 93 00:07:26,680 --> 00:07:32,340 get to do this all the time because it is by definition quite a bit slower. And the 94 00:07:32,340 --> 00:07:36,800 difficulty of identifying all the circumstances where you need to do this stuff is enough 95 00:07:36,800 --> 00:07:45,020 to make this fix possible but not probable. So what can we do instead? I seem to note 96 00:07:45,020 --> 00:07:49,780 that when we're up against Internet‑level latency, you know, the Internet is slow, 97 00:07:50,060 --> 00:07:56,060 sometimes packets take longer to arrive than others, I note that now we can only distinguish 98 00:07:56,060 --> 00:08:04,200 15,000 to 100,000 nanoseconds instead of 100 nanoseconds. That's three to four orders 99 00:08:04,200 --> 00:08:11,320 of magnitude. And Internet noise is not random. It turns out you can just tell Linux on your 100 00:08:11,320 --> 00:08:14,900 network interface, be as slow as the rest of the Internet. 101 00:08:15,020 --> 00:08:23,220 And it'll do it. It's a one‑line command. Now, here's the deal. This is a lot easier 102 00:08:23,220 --> 00:08:29,040 to deploy. And it turns out that matters. I could probably get someone to go ahead and 103 00:08:29,040 --> 00:08:34,060 say make things take a million to three million nanoseconds longer. I can't say make it take 104 00:08:34,060 --> 00:08:38,860 another second, but another hundredth of a second, I might be able to ask for that. 105 00:08:40,500 --> 00:08:44,940 Now who here thinks they know about this enough to say, bullshit, this is never going to work? 106 00:08:46,340 --> 00:08:52,820 Maybe someone. Here's the deal. Let's say this didn't work. I have some code to show 107 00:08:52,820 --> 00:09:00,400 you. This code right here is from the middle of OpenSSH. And what OpenSSH is doing is 108 00:09:00,400 --> 00:09:05,200 it's going ahead and it's comparing the password provided by the user through an encryption 109 00:09:05,200 --> 00:09:10,640 function to the password stored on the hard drive. And it's doing it in non‑constant 110 00:09:10,640 --> 00:09:14,800 time. If the first character is right versus the eighth character is right, it's going 111 00:09:15,020 --> 00:09:20,760 a different amount of time. Now, the difference is going to be like a nanosecond. It's going 112 00:09:20,760 --> 00:09:28,780 to be like one motion of the CPU. If you can find every single timing attack, if you just 113 00:09:28,780 --> 00:09:34,340 get enough samples, then I just dropped me some open SSH, oh, dang. Either my attack 114 00:09:34,340 --> 00:09:41,760 works, which it doesn't, or I'm on to something with this defense. Now, what we're actually 115 00:09:41,760 --> 00:09:46,220 looking for, what the actual equation we would want to have is how much timing noise 116 00:09:46,220 --> 00:09:52,440 of what nature will permanently obscure how much timing signal beyond the point of infeasible 117 00:09:52,440 --> 00:09:58,440 return. Look, if I delay it a day, you're not going to find a nanosecond. So somewhere 118 00:09:58,440 --> 00:10:04,640 between a day and one nanosecond is an amount of noise that you can insert on a network 119 00:10:04,640 --> 00:10:10,820 interface that is going to destroy an entire class of security vulnerability with a single 120 00:10:10,820 --> 00:10:11,340 command. 121 00:10:11,760 --> 00:10:18,020 That is kind of cool. I like that. Now, there are things that can go wrong with this particular 122 00:10:18,020 --> 00:10:23,560 implementation using the single line to Linux. It was not really designed to implement a 123 00:10:23,560 --> 00:10:30,520 random value precisely between 1 million nanoseconds and 3 million nanoseconds. So maybe there's 124 00:10:30,520 --> 00:10:35,720 quantization. Maybe it's chunky and it's delay. Maybe the noise pattern is wrong. It's 125 00:10:35,720 --> 00:10:41,200 Gaussian, which should be uniform or uniform when it's Gaussian. Maybe the fact that other 126 00:10:41,200 --> 00:10:41,740 protocols are going to be the same. Maybe it's going to be the same. Maybe it's going to be the 127 00:10:41,740 --> 00:10:47,040 same. There are protocols like TCP. It has its own timestamps. So every message that's sent out of a 128 00:10:47,040 --> 00:10:53,860 network interface actually has a thing that says, I was sent at this time. So even though the 129 00:10:53,860 --> 00:10:59,800 interface is delaying it, there's actually bits in there that say when it was sent. Maybe that's a 130 00:10:59,800 --> 00:11:09,000 problem. These are all things that can be fixed. The question is, is it worth investigating? And 131 00:11:09,000 --> 00:11:11,720 the deal is, our perfect fix can be fixed. It can be fixed. It can be fixed. It can be fixed. It can be 132 00:11:11,740 --> 00:11:18,000 fixed. Constantine comparisons is the enemy of the good. As long as we think we have a fix and we're 133 00:11:18,000 --> 00:11:24,100 done, there's no reason to look for something we can actually deploy. This pattern shows up 134 00:11:24,100 --> 00:11:31,760 elsewhere. Let's talk about that time RSA was broken. Not the time RSA was broken where the 135 00:11:31,760 --> 00:11:37,240 smart cards leaked our private key or the time RSA was broken where the secure IDs were stolen by 136 00:11:37,240 --> 00:11:41,720 China. No. What is this? Like, I don't know. I don't know. I don't know. I don't know. I don't 137 00:11:42,760 --> 00:11:46,600 know. I don't know. I don't know. I don't know. I don't know. But this time I'm talking about 138 00:11:46,600 --> 00:11:53,000 some work by Arjen Landstra and James Hughes and also by Nadia Henninger where they found that one 139 00:11:53,000 --> 00:12:02,340 out of 200 cryptographic keys on the Internet were actually badly generated. And this is a 140 00:12:02,340 --> 00:12:08,180 tremendous number. I mean, you got to think of this in terms of nines of reliability. Something 141 00:12:08,180 --> 00:12:11,720 went wrong and all crypto on the Internet went down to 2000 cryptos. I'm going to check it out. 142 00:12:11,720 --> 00:12:19,660 unines of reliability. That's failing. So the question is, who failed? Now, Lenstra and Hughes 143 00:12:19,660 --> 00:12:25,560 thought that RSA had screwed up here. Like, oh, my God, RSA has this thing that allowed us to go 144 00:12:25,560 --> 00:12:31,540 ahead and recover things when the keys were badly generated. No, no, no. Everything breaks when the 145 00:12:31,540 --> 00:12:37,920 keys are badly generated. The problem is, is that the keys were badly generated. Bad random number 146 00:12:37,920 --> 00:12:45,160 generations create trap doors in all crypto systems. If instead of breaking RSA or ECC or AES 147 00:12:45,160 --> 00:12:51,040 or whatever, instead of breaking the thing and figuring out what key was used, you can just guess 148 00:12:51,040 --> 00:12:56,760 what key was used. Well, that's a lot easier. And it turns out one out of 200 times you had the basis 149 00:12:56,760 --> 00:13:01,660 in order to be able to do that. So they thought that RSA was bad. They'd actually shown that 150 00:13:01,660 --> 00:13:07,820 still in 2012, random number generators are a problem. This is stuff that we've been fretting 151 00:13:07,820 --> 00:13:11,900 about for 20 years. 20 years ago, someone was saying, I hope I'm not worrying about this 20 years 152 00:13:11,900 --> 00:13:19,880 from now. And they're screwed. So when we found that the Debian random number generator was 153 00:13:19,880 --> 00:13:24,900 busted, Debian is a Linux distribution. It had some issues generating random numbers. It made a 154 00:13:24,900 --> 00:13:32,060 bunch of bad keys. We spent, like, years making fun of Debian. And it turns out it won't just 155 00:13:32,060 --> 00:13:37,040 Debian. A bunch of things are broken. Debian was just the tip of the iceberg. 156 00:13:37,820 --> 00:13:41,840 Now, weren't operating systems supposed to fix this? Wasn't the OS supposed to do all this magic 157 00:13:41,840 --> 00:13:46,800 work? Well, it gave us some things that we could talk to, a thing called the random device, which 158 00:13:46,800 --> 00:13:51,400 would always give us bits if it had it and would freeze up if it didn't. And then Urandom, which 159 00:13:51,400 --> 00:13:58,140 would do whatever it could, you know, give it something. Where would the actual randomness come 160 00:13:58,140 --> 00:14:05,060 from? So there's really only four sources of randomness that we right now really allow 161 00:14:05,060 --> 00:14:07,800 computers to use. We say, oh, we're going to do this. We're going to do this. We're going to do this. 162 00:14:07,820 --> 00:14:12,640 Okay. There should be a little thing in the CPU, a hardware function that just says give me random 163 00:14:12,640 --> 00:14:17,220 bits. And it runs off of, I don't know, like a little radio or like bad diode, you know, buggy 164 00:14:17,220 --> 00:14:25,240 hardware made a feature. Next thing is keyboard, mouse, and maybe, okay, the speed at which the 165 00:14:25,240 --> 00:14:31,020 disk goes around in a hard drive because that's impacted by air. Here's the problem. Most 166 00:14:31,020 --> 00:14:37,520 computers on the Internet don't have a single one of these random sources. Not one. 167 00:14:38,140 --> 00:14:44,880 Desktops are okay. They got a human with keyboard and mouse and often some disks. Servers, less and 168 00:14:44,880 --> 00:14:49,780 less do they have disks. They don't have any of the rest. Virtual machines, nothing. Embedded 169 00:14:49,780 --> 00:14:58,580 devices, nothing. Like not a single one of those is present. Now, people say, oh, but Intel's top of 170 00:14:58,580 --> 00:15:07,800 the line to be out soon CPU has a random number generator. Yes, top of the line in 2012 has a 171 00:15:07,800 --> 00:15:13,100 random number generator. The rest of all hardware in the world that developers have to build for 172 00:15:13,100 --> 00:15:19,280 have nothing and will continue to have nothing. There's a rule called the high end keeps getting 173 00:15:19,280 --> 00:15:27,040 higher, but the low end never goes away. Now, there's these things called TPMs that are, you 174 00:15:27,040 --> 00:15:30,940 know, supposed to be for trusted computers and PCs. They got into a whole bunch of things in, like, 175 00:15:30,940 --> 00:15:36,800 the mid-2000s. I tell you, everything I've ever seen treats these things like radioactive. 176 00:15:37,800 --> 00:15:41,140 I don't know if it's because they break stuff. I don't know if it's because they're unstable. I don't 177 00:15:41,140 --> 00:15:45,680 know if it's because they may or may not be present. But they're treated like radioactive gunk and 178 00:15:45,680 --> 00:15:49,720 they're almost never an embedded gear anyway. You know what I mean by embedded? Like, you know, 179 00:15:49,720 --> 00:15:55,340 stuff in a rack, your little Linksys box, things like that. So what's kind of happening here, 180 00:15:55,440 --> 00:16:00,240 because there's no sources of entropy, let me give you an analogy. You go on the Internet. 181 00:16:00,860 --> 00:16:06,640 Always a bad idea. Carbohydrates cause cancer. That's a real link. 182 00:16:08,360 --> 00:16:13,060 Proteins cause cancer. Fats cause cancer. Alcohol causes cancer. Uh-oh. 183 00:16:15,440 --> 00:16:19,540 Oh. Man, I didn't realize that would be a hot button subject here at DEF CON. 184 00:16:22,260 --> 00:16:25,180 Now, so you don't consume proteins, carbohydrates, 185 00:16:25,680 --> 00:16:31,760 fats or booze, you know what happens? You starve to death. This is a thing that happens 186 00:16:31,760 --> 00:16:37,540 in technology all the time. You get too good at one solution and another failure mode 187 00:16:37,800 --> 00:16:43,640 crops up. We are starving for entropy. And the way I know this is because I actually asked some 188 00:16:43,640 --> 00:16:48,300 developers. I'm like, dude, what the hell? They're like, look, I got some code. It depends 189 00:16:48,300 --> 00:16:52,620 on the random device. I turn on my little embedded thing. It needs to generate a key. 190 00:16:52,900 --> 00:16:58,840 It's just born. And guess what? There's no hard drive. There's no keyboard, mouse, human, 191 00:16:58,960 --> 00:17:06,300 anything. It just locks up. And this is actually found during tests. And it goes back to the 192 00:17:06,300 --> 00:17:07,780 developer. And the developer says, you know what? I don't know. I don't know. I don't know. I don't 193 00:17:07,800 --> 00:17:13,200 know. Oh, well, let me go ahead and go to one of these not so good sources instead. 194 00:17:15,820 --> 00:17:20,200 The perfectionists think this isn't what's going to happen. They think the developer will protest, 195 00:17:20,360 --> 00:17:25,400 will march into management's office and say, buy us hardware with Ivy Bridge. We need that 196 00:17:25,400 --> 00:17:31,140 random number generator, damn it. No, actually, they say freaking security people failed us once 197 00:17:31,140 --> 00:17:37,080 more. Let's try some crap that actually appears to work. This is reality. 198 00:17:37,800 --> 00:17:43,020 You can secure theory. You can secure homework. You can secure your final exam. 199 00:17:43,880 --> 00:17:48,860 Or you can secure the freaking Internet. I'm playing the ladder game here. 200 00:17:49,760 --> 00:17:54,200 Perfectionism caused one out of 200 RSA keys on the net to be easily broken. 201 00:17:54,440 --> 00:18:00,500 We have seen the enemy and it's us. This was our fault. This was our failure. Because we 202 00:18:00,500 --> 00:18:07,160 were terrified that someone somewhere might have a bad key generated on a machine, one out of 200 203 00:18:07,160 --> 00:18:07,780 things. And that's why we're here. We're here. We're here. We're here. We're here. We're here. We're here. 204 00:18:09,020 --> 00:18:14,200 And by the way, it's worse than one out of 200. It's one out of 200 easily detectable. 205 00:18:14,860 --> 00:18:21,720 Way higher. Slightly difficult to detect. But we can do better, and what we can do is we can bring 206 00:18:21,720 --> 00:18:29,720 back an old hack called true rant. Humans and computers are not synchronized. That's why we 207 00:18:29,720 --> 00:18:37,780 like measuring keyboard and mice. See, the deal is, even if you were trying, you could not hit that key on a keyboard. 208 00:18:37,780 --> 00:18:41,560 with nanosecond accuracy the same way every time. 209 00:18:41,780 --> 00:18:43,180 It's like one millionth of a second 210 00:18:43,180 --> 00:18:44,240 and one billionth of a second. 211 00:18:45,540 --> 00:18:46,400 I don't know. 212 00:18:46,400 --> 00:18:47,740 Whichever one it is, you ain't doing it. 213 00:18:48,880 --> 00:18:50,600 Any system with two clocks 214 00:18:50,600 --> 00:18:52,860 has a hardware random number generator. 215 00:18:53,120 --> 00:18:56,760 And it turns out the biggest lie about your computer 216 00:18:56,760 --> 00:18:59,200 is that it is simply one computer. 217 00:19:00,060 --> 00:19:03,480 Computers are small networks of interconnected devices 218 00:19:03,480 --> 00:19:06,800 on asynchronous networks that communicate with each other 219 00:19:06,800 --> 00:19:08,640 at their own time and pace. 220 00:19:08,920 --> 00:19:10,120 That's how they work. 221 00:19:10,440 --> 00:19:13,280 Every single computer has different devices 222 00:19:13,280 --> 00:19:14,800 talking to each other from different clocks. 223 00:19:15,060 --> 00:19:17,100 These clocks are not synchronized. 224 00:19:17,240 --> 00:19:19,940 Even if they had an error of one part per million, 225 00:19:20,180 --> 00:19:22,220 that's a bit per second per megahertz. 226 00:19:22,280 --> 00:19:24,740 We have way more than that actually going on. 227 00:19:25,840 --> 00:19:30,160 So there's an old hack from 96 by Matt Blaze and D.P. Mitchell. 228 00:19:30,420 --> 00:19:32,660 What they do is they run the CPU in a tight loop. 229 00:19:33,660 --> 00:19:35,640 Every 16, so they basically say, 230 00:19:35,780 --> 00:19:36,680 increment by 1. 231 00:19:36,800 --> 00:19:38,500 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. 232 00:19:38,860 --> 00:19:40,580 Every 16 milliseconds they say, 233 00:19:40,700 --> 00:19:42,900 wait, how far did it get? 234 00:19:43,260 --> 00:19:45,180 On that interrupt they do some shuffling. 235 00:19:45,480 --> 00:19:47,040 Now here's where the entropy happens. 236 00:19:47,300 --> 00:19:48,640 You have a slow clock. 237 00:19:49,260 --> 00:19:53,240 It's 16 milliseconds plus minus some number of nanoseconds. 238 00:19:53,660 --> 00:19:55,660 And then that some number of nanoseconds 239 00:19:55,660 --> 00:19:58,480 determines how far the CPU spun in a circle. 240 00:19:59,180 --> 00:20:00,620 That's where the entropy comes from. 241 00:20:00,760 --> 00:20:02,680 Then they do a bunch of stuff to mix it up. 242 00:20:03,000 --> 00:20:05,360 Shuffle it around, hash it around, and so on. 243 00:20:06,260 --> 00:20:06,780 The interesting thing is, 244 00:20:06,780 --> 00:20:07,900 this is not a bad approach. 245 00:20:08,360 --> 00:20:10,200 It is totally disowned. 246 00:20:10,380 --> 00:20:11,260 And it's too bad. 247 00:20:11,580 --> 00:20:12,880 Because if it had been used, 248 00:20:13,180 --> 00:20:14,520 and it had been part of the Linux kernel, 249 00:20:14,800 --> 00:20:17,360 those keys all would have been good. 250 00:20:18,340 --> 00:20:19,680 Now why was it disowned? 251 00:20:20,540 --> 00:20:21,440 And I mean seriously, 252 00:20:21,580 --> 00:20:24,100 Matt Blaze is horrified that I'm pushing this stuff. 253 00:20:26,700 --> 00:20:29,540 I have a tremendous amount of respect for Matt Blaze. 254 00:20:29,700 --> 00:20:30,420 So let me tell you, 255 00:20:30,520 --> 00:20:33,200 I'm at least honoring his discontent. 256 00:20:35,700 --> 00:20:36,640 His approach, 257 00:20:36,640 --> 00:20:39,340 his approach is we can't model its behavior. 258 00:20:39,700 --> 00:20:41,040 And if we can't model it, 259 00:20:41,080 --> 00:20:42,500 we don't know how good or bad it is. 260 00:20:42,560 --> 00:20:44,040 So we shouldn't do it at all. 261 00:20:45,800 --> 00:20:47,680 I understand this attitude. 262 00:20:48,000 --> 00:20:49,300 It's a respectable attitude. 263 00:20:49,600 --> 00:20:51,460 You should know how good your system is. 264 00:20:51,660 --> 00:20:53,800 But what it's done is it's led to a reduction 265 00:20:53,800 --> 00:20:55,700 of the available entropy in the Linux kernel. 266 00:20:56,020 --> 00:20:57,880 We used to look at interrupt counts to go ahead 267 00:20:57,880 --> 00:20:58,580 and get some entropy. 268 00:20:58,880 --> 00:21:00,200 Someone said, oh my God, 269 00:21:00,340 --> 00:21:02,360 you might be able to remotely do something weird 270 00:21:02,360 --> 00:21:04,620 that would cause this interrupt to fire three times more. 271 00:21:04,740 --> 00:21:06,040 And then we'll get all the keys. 272 00:21:06,140 --> 00:21:06,540 Ha ha ha. 273 00:21:06,640 --> 00:21:10,380 Um, no, it's just not true. 274 00:21:11,660 --> 00:21:13,740 So I've been writing a thing called Dacorand. 275 00:21:13,940 --> 00:21:14,900 It'll be out next week. 276 00:21:16,400 --> 00:21:17,800 It's an update to the old model. 277 00:21:18,140 --> 00:21:20,380 We have various modes of generators. 278 00:21:21,080 --> 00:21:23,140 So we'll go ahead and we'll do a sleep 279 00:21:23,140 --> 00:21:24,120 with the use sleep command. 280 00:21:24,420 --> 00:21:27,280 And then we'll see how long did that sleep actually last 281 00:21:27,280 --> 00:21:28,400 with various clocks. 282 00:21:28,680 --> 00:21:30,240 You know, we have a thing called the monotonic clock, 283 00:21:30,400 --> 00:21:31,200 the real time clock. 284 00:21:31,380 --> 00:21:32,760 We can actually ask the CPU, 285 00:21:33,000 --> 00:21:34,920 how many cycles did you run? 286 00:21:35,120 --> 00:21:36,320 You know, like a 1.5, 287 00:21:36,620 --> 00:21:37,540 gigahertz processor. 288 00:21:37,820 --> 00:21:41,440 So the cycle count goes up 1.5 billion times a second. 289 00:21:41,540 --> 00:21:42,680 So how many did we go through? 290 00:21:43,200 --> 00:21:44,400 There's an incrementer. 291 00:21:44,400 --> 00:21:46,980 See how many times we can increment an integer 292 00:21:46,980 --> 00:21:47,920 within a time period. 293 00:21:48,160 --> 00:21:50,980 So we say, hey, and just keep trying to go 294 00:21:50,980 --> 00:21:54,420 and wait until we've passed 50 milliseconds. 295 00:21:54,740 --> 00:21:55,520 What's your number at? 296 00:21:56,360 --> 00:21:59,740 Um, there's the real time clock on PC hardware. 297 00:21:59,800 --> 00:22:00,180 There's that. 298 00:22:00,240 --> 00:22:01,820 Anyone remember IRQs? 299 00:22:03,200 --> 00:22:05,000 Yo, there's still one in use. 300 00:22:05,060 --> 00:22:06,140 It's like IRQ8. 301 00:22:06,140 --> 00:22:08,900 It's like hooked up to this thing on the motherboard. 302 00:22:09,260 --> 00:22:11,200 And it just fires whenever you want it to. 303 00:22:11,240 --> 00:22:13,380 And you just say, yeah, 8,000 times a second. 304 00:22:13,520 --> 00:22:13,880 Ping me. 305 00:22:14,420 --> 00:22:18,080 8,000 times a second plus minus some number of nanoseconds. 306 00:22:18,220 --> 00:22:19,460 So there you go. 307 00:22:19,640 --> 00:22:21,060 You got one clock against another. 308 00:22:21,700 --> 00:22:23,240 Then there's my favorite of these, 309 00:22:23,400 --> 00:22:24,820 two threads, one int. 310 00:22:30,460 --> 00:22:32,460 All right, look, it sounds crappy. 311 00:22:32,600 --> 00:22:33,220 Well played. 312 00:22:35,580 --> 00:22:36,020 Okay. 313 00:22:36,140 --> 00:22:40,120 Look, anyone who thinks computers are completely deterministic devices 314 00:22:40,120 --> 00:22:42,800 has clearly never written threaded code. 315 00:22:46,620 --> 00:22:48,320 Seriously, it's really true. 316 00:22:50,400 --> 00:22:54,120 Guys, it's hard to make a computer do things 317 00:22:54,120 --> 00:22:55,800 at the right time constantly. 318 00:22:56,080 --> 00:22:58,100 Time is the one factor of computers 319 00:22:58,100 --> 00:23:00,480 we never pay any attention to. 320 00:23:00,700 --> 00:23:03,240 We have these things called real time operating systems 321 00:23:03,240 --> 00:23:05,120 that are really difficult to write 322 00:23:05,120 --> 00:23:05,860 because, 323 00:23:06,140 --> 00:23:07,100 at small time scales, 324 00:23:07,240 --> 00:23:09,060 computers do whatever the hell they want. 325 00:23:10,760 --> 00:23:12,320 Nothing a computer likes to do more 326 00:23:12,320 --> 00:23:13,720 than screw around for 10 milliseconds. 327 00:23:14,020 --> 00:23:14,440 Where'd you go? 328 00:23:14,520 --> 00:23:14,780 I don't know. 329 00:23:18,840 --> 00:23:20,840 So, you know, it's not a bug. 330 00:23:20,940 --> 00:23:21,380 It's a feature. 331 00:23:21,480 --> 00:23:22,480 We're using those properties. 332 00:23:22,640 --> 00:23:25,440 We're exacerbating them as much as possible. 333 00:23:25,680 --> 00:23:27,880 And we're forcing them to compete, 334 00:23:28,100 --> 00:23:29,680 thus hopefully giving us some noise. 335 00:23:30,800 --> 00:23:32,600 So the flow of how all this works, 336 00:23:34,240 --> 00:23:36,060 we take whatever bits we get. 337 00:23:36,140 --> 00:23:38,540 It doesn't matter how they're good, bad, whatever. 338 00:23:39,440 --> 00:23:40,980 We throw them into a hash. 339 00:23:41,200 --> 00:23:42,720 So you have SHA-256. 340 00:23:42,920 --> 00:23:44,540 You can just keep throwing data into it. 341 00:23:44,920 --> 00:23:45,900 Whatever they are, 342 00:23:45,940 --> 00:23:47,360 whatever the nanosecond clock was, 343 00:23:47,480 --> 00:23:48,640 you throw it in raw. 344 00:23:48,940 --> 00:23:50,060 Why do you throw it in raw? 345 00:23:50,180 --> 00:23:51,140 It might be good. 346 00:23:51,660 --> 00:23:54,420 Maybe it's bad, but it might be good. 347 00:23:54,560 --> 00:23:56,460 Let's not undercount our entropy. 348 00:23:57,860 --> 00:23:59,980 However, we only count it 349 00:23:59,980 --> 00:24:02,640 if it passes what's called von Neumann de-biasing. 350 00:24:02,900 --> 00:24:04,580 Von Neumann de-biasing means 351 00:24:04,580 --> 00:24:06,120 you take a stream of data, 352 00:24:06,120 --> 00:24:08,580 of either zeros and ones, 353 00:24:09,020 --> 00:24:11,200 and we get whatever comes out of the generator. 354 00:24:11,480 --> 00:24:13,100 We count the number of ones in there. 355 00:24:13,240 --> 00:24:14,440 If it's even, we make it a zero. 356 00:24:14,540 --> 00:24:15,460 If it's odd, we make it a one. 357 00:24:16,040 --> 00:24:18,320 Zero zeros and one ones, we throw that away. 358 00:24:19,060 --> 00:24:20,360 Zero one is a zero. 359 00:24:20,460 --> 00:24:21,500 One zero is a one. 360 00:24:21,640 --> 00:24:24,180 So we're basically capturing the transitions only. 361 00:24:26,720 --> 00:24:29,180 Now, we've been putting lots of data into the hash, 362 00:24:29,420 --> 00:24:31,540 but we count that we got a bit 363 00:24:31,540 --> 00:24:33,020 every time von Neumann is happy. 364 00:24:33,240 --> 00:24:35,000 We also throw a zero one in there 365 00:24:35,000 --> 00:24:36,600 just for correctness' sake. 366 00:24:37,560 --> 00:24:40,620 Once we have 256 bits, we finalize the hash. 367 00:24:40,800 --> 00:24:42,320 We have a 256-bit hash now. 368 00:24:42,560 --> 00:24:44,980 Now, we can go ahead and we run something called sCrypt. 369 00:24:45,500 --> 00:24:47,260 sCrypt is a time-memory-hard function. 370 00:24:47,460 --> 00:24:49,260 What it means is you've got some value. 371 00:24:49,380 --> 00:24:51,300 You're going to spend a second churning on it 372 00:24:51,300 --> 00:24:52,280 until you get another value. 373 00:24:52,480 --> 00:24:54,940 It's just that when the bad guy tries to go ahead and do this, 374 00:24:55,040 --> 00:24:57,720 they've got to spend a second on every single attempt. 375 00:24:59,060 --> 00:25:00,540 Finally, once we have this thing, 376 00:25:00,680 --> 00:25:04,420 we put it into encryption function AES-256 encounter mode. 377 00:25:04,420 --> 00:25:09,500 We get a stream, and that's our entropy that we're looking for. 378 00:25:10,480 --> 00:25:11,880 So you want to mess with this. 379 00:25:12,000 --> 00:25:13,320 Actually, anyone here want to mess with this? 380 00:25:13,520 --> 00:25:14,700 Think they can break this approach? 381 00:25:15,700 --> 00:25:16,860 Good. Try. 382 00:25:17,620 --> 00:25:19,060 You pick the hardware. 383 00:25:19,240 --> 00:25:20,340 You pick the platform. 384 00:25:20,640 --> 00:25:21,480 You pick the generator. 385 00:25:21,700 --> 00:25:22,540 There's seven of them. 386 00:25:22,600 --> 00:25:24,340 They can't all work. 387 00:25:25,600 --> 00:25:27,920 Something here must fail in some environment. 388 00:25:28,580 --> 00:25:29,720 Here's where you can look. 389 00:25:30,160 --> 00:25:32,060 User space and hypervisor scheduling. 390 00:25:32,400 --> 00:25:34,400 So it turns out all this stuff is not right. 391 00:25:34,400 --> 00:25:35,260 It's not running in the kernel yet. 392 00:25:35,320 --> 00:25:36,420 It's running as a program. 393 00:25:37,000 --> 00:25:40,200 Program is only visited some number of times a second, 394 00:25:40,300 --> 00:25:41,980 not at random intervals. 395 00:25:42,280 --> 00:25:44,540 So that might screw up my clocks. 396 00:25:45,140 --> 00:25:47,440 The bigger issue is what's called auto-clocking. 397 00:25:47,540 --> 00:25:49,980 If you time something against itself, 398 00:25:50,220 --> 00:25:51,420 you're going to have a bad time. 399 00:25:54,000 --> 00:25:57,340 Clocks tend to be highly correlated against themselves. 400 00:25:59,880 --> 00:26:01,500 So let's say you're in a VM, 401 00:26:01,660 --> 00:26:03,940 and the real-time clock is being emulated, 402 00:26:04,400 --> 00:26:07,600 and it's the same emulator that's running the clock monotonic clock 403 00:26:07,600 --> 00:26:09,640 that Linux is ultimately depending on. 404 00:26:09,800 --> 00:26:13,180 Then you might have a entropy problem here as well. 405 00:26:13,760 --> 00:26:16,060 Virtual machines, more than anything else, 406 00:26:16,080 --> 00:26:18,040 should not have to directly use this stuff. 407 00:26:18,180 --> 00:26:19,840 They should be able to ask their host, 408 00:26:20,060 --> 00:26:21,360 give me random bits. 409 00:26:21,560 --> 00:26:23,160 And maybe it does this stuff, 410 00:26:23,280 --> 00:26:24,860 but it's the host that's doing it. 411 00:26:26,620 --> 00:26:28,180 So that being said, 412 00:26:28,320 --> 00:26:30,360 I've run this on every VM I can find, 413 00:26:30,500 --> 00:26:32,100 and it survives just fine, 414 00:26:32,240 --> 00:26:33,500 which is kind of crazy. 415 00:26:34,540 --> 00:26:36,100 What about VM cloning? 416 00:26:36,240 --> 00:26:38,800 Everyone worries about virtual machines being copied. 417 00:26:39,020 --> 00:26:40,460 See, here's the deal. 418 00:26:40,960 --> 00:26:43,920 Normally, you only get bits for your random source 419 00:26:43,920 --> 00:26:45,960 in the operating system really slowly. 420 00:26:46,320 --> 00:26:48,720 So you make a copy of this virtual machine. 421 00:26:49,060 --> 00:26:51,440 The pool of bits is exactly the same. 422 00:26:51,620 --> 00:26:54,080 You go to pull some out, you get the same bits. 423 00:26:54,600 --> 00:26:55,960 My approach says, 424 00:26:56,120 --> 00:27:01,620 look, you get different bits every time you go to the well. 425 00:27:01,920 --> 00:27:04,380 So each time you begin a unique, 426 00:27:04,400 --> 00:27:07,400 read to my version of randomness, 427 00:27:07,520 --> 00:27:08,580 then you're okay. 428 00:27:09,520 --> 00:27:11,920 Now, if your virtual machine goes ahead 429 00:27:11,920 --> 00:27:17,120 and is cloned before I can't, 430 00:27:17,140 --> 00:27:18,420 or after I can't help you, 431 00:27:18,480 --> 00:27:21,520 but before, you can be like right before the instruction 432 00:27:21,520 --> 00:27:22,960 that you say, give me some random bits, 433 00:27:23,160 --> 00:27:24,360 and you'll still be fine. 434 00:27:25,980 --> 00:27:27,480 Okay, what else could go on? 435 00:27:27,720 --> 00:27:29,900 Is the underlying use of cryptography safe? 436 00:27:30,300 --> 00:27:33,700 Well, we have this thing called, 437 00:27:33,700 --> 00:27:35,200 I'm called modified von Neumann. 438 00:27:36,220 --> 00:27:40,120 We absorb a tremendous amount of low quality data into our hash. 439 00:27:40,240 --> 00:27:41,600 We are throwing crap in there. 440 00:27:42,120 --> 00:27:43,020 But here's the deal. 441 00:27:43,700 --> 00:27:45,180 I hate you so much right now. 442 00:27:51,060 --> 00:27:52,300 You didn't realize you had one in your hand. 443 00:27:53,260 --> 00:27:53,820 Good man. 444 00:27:54,400 --> 00:27:55,720 You're supposed to do it with us. 445 00:27:56,400 --> 00:27:57,420 I'm sorry, by the way. 446 00:28:04,080 --> 00:28:06,240 This was supposed to be a two hour talk. 447 00:28:07,560 --> 00:28:08,120 Oops. 448 00:28:11,840 --> 00:28:12,820 Yeah, yeah, yeah. 449 00:28:13,060 --> 00:28:13,860 You started early. 450 00:28:14,960 --> 00:28:16,340 Less yapping, more talking. 451 00:28:16,980 --> 00:28:17,700 All right. 452 00:28:17,740 --> 00:28:18,640 Check it out, guys. 453 00:28:19,800 --> 00:28:22,680 You got 100 gigabytes of zeros. 454 00:28:23,160 --> 00:28:27,660 You got 128 bits of good high quality data. 455 00:28:27,900 --> 00:28:29,220 And you hash all that. 456 00:28:30,300 --> 00:28:33,680 Generally, we consider the entropy of the resulting hash 457 00:28:33,700 --> 00:28:36,180 to have 128 bits. 458 00:28:36,440 --> 00:28:40,680 Meaning you can't get worse, but you might get better. 459 00:28:40,880 --> 00:28:43,360 So I think modified von Neumann is going to be okay. 460 00:28:45,100 --> 00:28:49,660 The fact that I'm emitting the result of a pseudo random stream 461 00:28:49,660 --> 00:28:52,400 instead of the raw output of a random number generator, 462 00:28:52,620 --> 00:28:55,760 I seem to note that every attack against random number generators 463 00:28:55,760 --> 00:28:58,380 involve looking at large amounts of output from them. 464 00:28:58,540 --> 00:28:59,680 So you know what I want to do? 465 00:28:59,800 --> 00:29:00,800 Not that. 466 00:29:01,880 --> 00:29:03,680 It seems to be the way 467 00:29:03,680 --> 00:29:04,840 you break these things. 468 00:29:04,940 --> 00:29:08,000 Maybe we shouldn't expose the raw data from our generator. 469 00:29:08,240 --> 00:29:09,380 It gets us busted. 470 00:29:10,020 --> 00:29:12,600 In fact, I wanted to see just how true that was. 471 00:29:13,320 --> 00:29:19,560 So normally, random number generators don't use cryptographic functions. 472 00:29:19,840 --> 00:29:21,960 This is a mistake because they're just as fast. 473 00:29:22,100 --> 00:29:23,220 We keep having security bugs. 474 00:29:23,640 --> 00:29:26,500 Someone found at Black Hat that, you know, all those, like, 475 00:29:26,500 --> 00:29:29,080 forget my password tokens, the URLs or whatnot. 476 00:29:30,200 --> 00:29:33,560 So generally, those tokens are generated by one of the random functions. 477 00:29:33,680 --> 00:29:34,100 It's in PHP. 478 00:29:38,320 --> 00:29:38,960 Really? 479 00:29:40,360 --> 00:29:46,060 Millions of sites have bad forgot my password token generators 480 00:29:46,060 --> 00:29:48,580 because they're using any generator but the open SSL one. 481 00:29:49,340 --> 00:29:51,460 So the question I had was, 482 00:29:52,100 --> 00:29:56,140 can you actually trust a output from a cryptographic stream 483 00:29:56,400 --> 00:29:58,740 to survive random number tests? 484 00:29:59,080 --> 00:30:02,180 I mean, I assumed so, but let's find out. 485 00:30:02,180 --> 00:30:05,120 So I went ahead, thanks to Jamie Schwettman, 486 00:30:05,240 --> 00:30:09,840 she actually said about 16,000 CPU hours with a die-harder entropy test 487 00:30:09,840 --> 00:30:13,660 run across 21 ciphers with inputs of either 16 megs of zeros 488 00:30:14,120 --> 00:30:16,040 or 16 megs of devu random. 489 00:30:16,900 --> 00:30:19,780 At first, it looked like there was actually the ability 490 00:30:19,780 --> 00:30:22,600 to differentiate ciphers and so on. 491 00:30:23,480 --> 00:30:26,160 Yeah, data lies a lot. 492 00:30:26,840 --> 00:30:28,140 We eventually found the bug. 493 00:30:28,360 --> 00:30:31,020 There's different padding and different cryptographic functions. 494 00:30:32,180 --> 00:30:34,160 In short, the files were of different sizes. 495 00:30:35,380 --> 00:30:40,500 16,000 CPU hours and I was detecting these two files are differently sized. 496 00:30:44,020 --> 00:30:47,460 This is the less embarrassing way of finding out about that. 497 00:30:49,420 --> 00:30:51,740 That being said, we're going to release the data anyway. 498 00:30:51,900 --> 00:30:54,020 We're still trying to do some machine learning against it. 499 00:30:54,880 --> 00:30:56,440 I actually have a neat little tool. 500 00:30:56,600 --> 00:30:57,980 Mail me if you think it's useful. 501 00:30:58,440 --> 00:31:01,060 It lets you take a comma-separated file, a CSV, 502 00:31:02,180 --> 00:31:03,440 and run SQL statements on it. 503 00:31:03,600 --> 00:31:05,460 It dynamically generates the database, 504 00:31:05,640 --> 00:31:07,400 executes your query, and gives you statistics. 505 00:31:07,840 --> 00:31:09,420 It's called C-SQL. It's kind of nice. 506 00:31:10,480 --> 00:31:12,880 This didn't work and find anything, but we did it anyway. 507 00:31:14,300 --> 00:31:15,520 Some kernel recommendations. 508 00:31:16,220 --> 00:31:18,420 These are things I'm going to tell the Linux guys to do. 509 00:31:18,880 --> 00:31:20,360 Dev random needs to stop blocking. 510 00:31:20,800 --> 00:31:22,100 It just, no, no. 511 00:31:22,300 --> 00:31:25,520 Crypt dev random doesn't block, or crypt gen random on Windows does not block. 512 00:31:26,720 --> 00:31:29,580 When I actually go ahead and get all the certificates for RDP, 513 00:31:29,780 --> 00:31:30,620 you know what I'm going to find? 514 00:31:30,620 --> 00:31:33,060 One out of 200 of them are not bad. 515 00:31:33,240 --> 00:31:34,180 They're going to be fine. 516 00:31:36,100 --> 00:31:38,520 Don't be so shy about interrupt sources. 517 00:31:38,960 --> 00:31:40,700 I don't care that much about interrupt counts. 518 00:31:42,360 --> 00:31:45,860 But when your network card is talking to your PC, 519 00:31:46,040 --> 00:31:46,960 it's talking to your CPU, 520 00:31:47,320 --> 00:31:51,940 it is not going to be nanosecond accurate to where the CPU is. 521 00:31:52,120 --> 00:31:53,800 That's just not how it works. 522 00:31:54,120 --> 00:31:57,260 So you actually have this thing in Linux called Ftrace, 523 00:31:57,460 --> 00:31:59,600 a really nice framework for tracing 524 00:31:59,600 --> 00:32:01,260 when events happen in the kernel. 525 00:32:01,760 --> 00:32:03,980 Right now, it's microsecond accurate. 526 00:32:04,260 --> 00:32:05,800 Make it nanosecond accurate, 527 00:32:06,040 --> 00:32:07,900 and then occasionally, randomly, 528 00:32:08,160 --> 00:32:11,000 use values from there to seed randomness. 529 00:32:11,420 --> 00:32:13,840 This is the appropriate approach. 530 00:32:14,080 --> 00:32:16,420 Maybe consider modified Von Neumann, 531 00:32:16,480 --> 00:32:19,320 but really, the time is over 532 00:32:19,320 --> 00:32:22,580 for these classes of entropy starvation vulnerabilities. 533 00:32:23,140 --> 00:32:24,460 It has to stop now. 534 00:32:25,780 --> 00:32:29,500 So, that being said, our biggest problems in security 535 00:32:29,600 --> 00:32:31,780 do not revolve around random number generators, 536 00:32:32,060 --> 00:32:33,920 just some of our more annoying ones. 537 00:32:36,420 --> 00:32:37,880 They revolve around languages. 538 00:32:38,540 --> 00:32:40,900 So we got this thing called language theoretic security, 539 00:32:41,240 --> 00:32:42,980 which is the idea that security vulnerabilities 540 00:32:43,240 --> 00:32:46,520 are the consequences of the languages that we're writing stuff in. 541 00:32:46,960 --> 00:32:49,280 Coined by Len Sassman and Meredith Patterson, 542 00:32:49,900 --> 00:32:52,940 has a corollary, if language got us into this mess, 543 00:32:53,120 --> 00:32:55,420 perhaps it can get us out. 544 00:32:56,900 --> 00:32:59,480 One way of looking at language theoretic security 545 00:32:59,600 --> 00:33:00,800 is through the lens of computability. 546 00:33:01,100 --> 00:33:05,300 It's saying, you know, you just want to be able to declare some information, 547 00:33:05,540 --> 00:33:08,540 but something bad happens, and now you're running these big programs 548 00:33:08,540 --> 00:33:11,120 of a complexity called Turing completeness. 549 00:33:12,140 --> 00:33:14,680 This is a valid lens to think about. 550 00:33:14,940 --> 00:33:16,220 But I'm going to give you another one. 551 00:33:17,500 --> 00:33:21,120 Who remembers diagramming sentences? 552 00:33:24,320 --> 00:33:27,520 Who would have thought failure to understand this 553 00:33:27,520 --> 00:33:28,640 would cause 554 00:33:28,640 --> 00:33:31,680 the majority of all security vulnerabilities 555 00:33:32,300 --> 00:33:34,200 ever found and ever written? 556 00:33:35,280 --> 00:33:38,580 Turns out diagramming sentences is serious business. 557 00:33:39,240 --> 00:33:42,560 See, when you have injection attacks, 558 00:33:42,940 --> 00:33:46,300 that means SQL injection, that means cross-site scripting, 559 00:33:46,340 --> 00:33:49,520 that means pretty much every web vulnerability out there, 560 00:33:50,480 --> 00:33:54,780 what these attacks actually are when you get down to it 561 00:33:54,780 --> 00:33:58,280 is that one piece of the system thinks it's sending 562 00:33:58,640 --> 00:34:01,580 data, the other piece thinks it's receiving code. 563 00:34:01,940 --> 00:34:06,560 One piece of the system thinks code is coming from another program. 564 00:34:06,680 --> 00:34:08,860 The other thinks it's coming from the user. 565 00:34:09,180 --> 00:34:13,520 So everything is about tree differences. 566 00:34:14,020 --> 00:34:15,340 This is what's going on. 567 00:34:15,440 --> 00:34:18,380 You have two different trees for all injection types. 568 00:34:19,000 --> 00:34:21,540 Now, so why am I bringing this up now? 569 00:34:21,780 --> 00:34:23,440 You know, why another theory? 570 00:34:23,680 --> 00:34:27,260 Well, this simple stuff is kicking our ass. 571 00:34:27,260 --> 00:34:29,300 This is the majority of vulnerabilities. 572 00:34:29,640 --> 00:34:30,940 We haven't fixed them. 573 00:34:31,040 --> 00:34:34,180 If we did fix them, they wouldn't still be costing us billions of dollars. 574 00:34:35,240 --> 00:34:38,200 So this gives us the rules of the game. 575 00:34:38,800 --> 00:34:41,480 If we wish to fix injection vulnerabilities, 576 00:34:41,920 --> 00:34:44,080 we want to synchronize parse trees. 577 00:34:44,280 --> 00:34:47,240 That crap of mess that you saw earlier needs to be the same 578 00:34:47,240 --> 00:34:50,460 on the front-end web server and the back-end database server. 579 00:34:50,900 --> 00:34:52,940 They need to see the same thing. 580 00:34:53,260 --> 00:34:57,160 And more importantly, we want developers to actually 581 00:34:57,260 --> 00:35:00,080 use what we write, okay? 582 00:35:00,240 --> 00:35:02,580 A language unspoken has a term. 583 00:35:02,700 --> 00:35:03,940 It's called a dead language. 584 00:35:04,960 --> 00:35:08,880 So what's neat is that this approach explains what's not really well understood. 585 00:35:09,400 --> 00:35:12,140 Why did XML become popular? 586 00:35:12,360 --> 00:35:15,440 I mean, it was like this big, huge, oh, my God, XML is going to save the world. 587 00:35:15,640 --> 00:35:16,340 You know why? 588 00:35:17,120 --> 00:35:20,600 Because developers looked at it and said, wow, if I use this, 589 00:35:20,760 --> 00:35:25,240 I don't need to spend four months finding out if the third bit of the fourth byte 590 00:35:25,640 --> 00:35:26,520 needs me to change. 591 00:35:26,520 --> 00:35:27,540 I'm going to change my parser entirely. 592 00:35:28,340 --> 00:35:34,040 That was life in the early 90s and is life in a couple regions of the market. 593 00:35:35,500 --> 00:35:37,340 Why did JSON become popular? 594 00:35:37,640 --> 00:35:40,800 XML figured out its own ways to get fiddly, to be honest. 595 00:35:41,240 --> 00:35:42,160 JSON just worked. 596 00:35:42,240 --> 00:35:43,640 You eval didn't move on with your life. 597 00:35:45,100 --> 00:35:47,120 The hard truth is that developers are in charge. 598 00:35:47,600 --> 00:35:49,200 Not me, I'll tell you that much. 599 00:35:49,500 --> 00:35:50,440 It's not architects. 600 00:35:50,760 --> 00:35:53,440 They love ASN1 and XML and web services. 601 00:35:53,900 --> 00:35:54,920 Not academics. 602 00:35:54,920 --> 00:35:56,720 They love Haskell. 603 00:35:59,540 --> 00:36:00,380 Not management. 604 00:36:00,520 --> 00:36:01,020 They love money. 605 00:36:02,200 --> 00:36:05,120 Performance, reliability, maintainability, features, rapid developments, 606 00:36:05,300 --> 00:36:06,460 these are the things that make you money. 607 00:36:07,320 --> 00:36:09,780 Security may lose you money later. 608 00:36:09,940 --> 00:36:11,220 So management doesn't give a crap. 609 00:36:11,400 --> 00:36:15,120 They just say do what works fastest and best by these metrics, 610 00:36:15,260 --> 00:36:17,240 which oddly and notably don't include security. 611 00:36:18,200 --> 00:36:20,840 So what is the number one thing that developers like? 612 00:36:21,440 --> 00:36:22,900 Code needs to work. 613 00:36:23,680 --> 00:36:27,260 And that's why PHP is so damn popular. 614 00:36:28,880 --> 00:36:32,780 Anyone here not think PHP is the most popular language on the planet? 615 00:36:33,560 --> 00:36:36,560 Because there's like a river right there and I encourage you to figure out which one. 616 00:36:38,940 --> 00:36:42,980 PHP is really good at copying and pasting code, which is a thing, of course, 617 00:36:43,000 --> 00:36:45,540 no one would ever do, but everyone always does. 618 00:36:45,840 --> 00:36:49,120 You know, you go to the documentation, you have some tasks, like, okay, 619 00:36:49,160 --> 00:36:51,100 I got to read out of the database. 620 00:36:51,520 --> 00:36:52,360 How do I do that? 621 00:36:52,360 --> 00:36:53,860 Copy, paste, done. 622 00:36:54,780 --> 00:36:57,320 People say, oh, that's the wrong way to do it. 623 00:36:57,440 --> 00:36:58,320 I'm going to do it in Java. 624 00:36:58,580 --> 00:37:01,680 I'm going to do it in my IDE, my integrated development environment, 625 00:37:02,220 --> 00:37:08,340 which is short for a thing that moved copy and paste from the edit menu to the file menu. 626 00:37:16,080 --> 00:37:20,520 There is a metric of quality for languages that no one measures, 627 00:37:20,520 --> 00:37:27,060 which is when I try something, how often does it actually work? 628 00:37:27,720 --> 00:37:30,940 See, normally it's does it fail fast? 629 00:37:31,480 --> 00:37:33,620 Does the compiler find it quickly? 630 00:37:33,920 --> 00:37:35,380 Is it discovered in test? 631 00:37:35,780 --> 00:37:39,000 No, devs aren't looking for code that fails fast. 632 00:37:39,240 --> 00:37:41,960 They want it to work the first time. 633 00:37:42,320 --> 00:37:45,940 And it turns out PHP is an amazing language for that. 634 00:37:46,040 --> 00:37:47,080 It just goes. 635 00:37:47,860 --> 00:37:50,460 Almost no one tracks this metric of whether 636 00:37:50,520 --> 00:37:51,200 it works or not. 637 00:37:51,780 --> 00:37:54,780 Processing does, and it's an amazing language for it. 638 00:37:54,880 --> 00:37:59,920 But this is why all the successful languages are the brainstorm of one guy. 639 00:38:00,240 --> 00:38:03,220 Like, it's Guido for Python. 640 00:38:03,540 --> 00:38:05,380 It's Larry for Pearl. 641 00:38:05,560 --> 00:38:07,760 Like, there's one guy who has it in his head. 642 00:38:08,260 --> 00:38:11,840 Art is science before we know what we're doing. 643 00:38:12,320 --> 00:38:15,720 Our languages that are popular are artistic endeavors, 644 00:38:15,860 --> 00:38:18,700 generally by one person, supported by others. 645 00:38:18,740 --> 00:38:20,180 But one guy has got the vision. 646 00:38:21,080 --> 00:38:25,540 PHP beats your favorite language, which means if you want to fix security, 647 00:38:25,800 --> 00:38:28,320 which you may not, you may enjoy the status quo, 648 00:38:28,760 --> 00:38:33,100 but if you do, PHP is the most important language in the world to repair. 649 00:38:35,100 --> 00:38:36,580 So, what's wrong with it? 650 00:38:37,040 --> 00:38:39,680 Well, we've got these things called object relational models 651 00:38:40,220 --> 00:38:42,500 where you don't even go out to a database. 652 00:38:42,700 --> 00:38:44,520 You never write database queries with SQL. 653 00:38:44,740 --> 00:38:49,680 You just, like, use normal methods from PHP or whatever language you're in, 654 00:38:49,680 --> 00:38:51,960 and it just makes it work on the back end. 655 00:38:52,520 --> 00:38:55,520 This is amazing and wonderful, and I love seeing it. 656 00:38:55,840 --> 00:38:59,000 The stuff works right up until the moment where you need to ask a question. 657 00:39:00,240 --> 00:39:01,520 Anyone familiar with that? 658 00:39:03,360 --> 00:39:04,860 Who knows what language this is? 659 00:39:06,120 --> 00:39:06,880 Brain fuck! 660 00:39:07,440 --> 00:39:08,540 Check it out, guys. 661 00:39:08,620 --> 00:39:10,000 Brain fuck has a rejoinder. 662 00:39:10,240 --> 00:39:15,460 There are more things in this world broken by punctuation than just brain fuck. 663 00:39:16,140 --> 00:39:17,280 It not alone. 664 00:39:18,360 --> 00:39:19,160 Look at this. 665 00:39:19,780 --> 00:39:26,560 Result from $name-arrow in $names-arrow, 666 00:39:26,660 --> 00:39:29,420 32 characters of punctuation, 667 00:39:29,580 --> 00:39:31,980 and it's, like, nested in, like, for insult. 668 00:39:32,840 --> 00:39:34,280 Compare that to this thing. 669 00:39:34,380 --> 00:39:37,700 Result equals query select name from names more length than name less than 5. 670 00:39:37,940 --> 00:39:41,680 I had 12 characters of punctuation there and huge gaps. 671 00:39:42,280 --> 00:39:43,940 Which would you rather write? 672 00:39:44,220 --> 00:39:46,860 It turns out this really matters. 673 00:39:46,860 --> 00:39:52,740 It turns out that SQL is a language that's really good at structured queries. 674 00:39:59,640 --> 00:40:00,660 This matters. 675 00:40:02,160 --> 00:40:05,220 Now, we got some classic things that are supposed to fix this. 676 00:40:05,500 --> 00:40:06,560 We got, like, escaping. 677 00:40:07,560 --> 00:40:11,500 Does anything say we don't give a shit like a 25-character command? 678 00:40:12,580 --> 00:40:13,220 . 679 00:40:15,800 --> 00:40:17,020 We got bigger problems. 680 00:40:17,260 --> 00:40:18,120 Escapes fail open. 681 00:40:18,380 --> 00:40:20,180 If you just don't write it, it doesn't matter. 682 00:40:21,780 --> 00:40:22,800 It's a blacklist. 683 00:40:22,900 --> 00:40:24,940 When's the last time a blacklist actually worked? 684 00:40:26,380 --> 00:40:28,460 Supposedly, we can do this thing called parameterization, 685 00:40:28,840 --> 00:40:30,600 where what you do is you write a template. 686 00:40:30,920 --> 00:40:32,560 You say, I'm going to put these little holes here, 687 00:40:32,680 --> 00:40:34,540 and later I'm going to fill in the holes. 688 00:40:34,740 --> 00:40:36,380 And this is what I put in for the first hole, 689 00:40:36,440 --> 00:40:38,100 and this is what I put in for the second hole, and so on. 690 00:40:38,680 --> 00:40:40,600 Maybe if you're lucky, you get to have alias. 691 00:40:40,660 --> 00:40:42,300 You're going to say, I'm going to have a hole, 692 00:40:42,300 --> 00:40:43,440 but I'm going to name the hole. 693 00:40:43,520 --> 00:40:44,800 I'll tell you what the hole's name is. 694 00:40:45,360 --> 00:40:47,440 So you got, like, this big batch of code, 695 00:40:47,500 --> 00:40:48,760 where before you had a single line. 696 00:40:49,680 --> 00:40:51,100 How popular is this? 697 00:40:52,340 --> 00:40:55,680 Well, nobody has ever written a parameterized query in their life 698 00:40:55,680 --> 00:40:56,740 without a gun to their head. 699 00:40:56,880 --> 00:40:58,860 We know. We hold the gun. 700 00:41:01,940 --> 00:41:05,680 Even secure code, when audited, tends to be 701 00:41:05,680 --> 00:41:08,680 safe things are written quickly and unsafe things. 702 00:41:08,920 --> 00:41:11,080 Then we'll go ahead and go through all this work. 703 00:41:11,080 --> 00:41:15,280 We threaten to fire people if they don't write it right. 704 00:41:15,600 --> 00:41:17,260 That's a data point, guys. 705 00:41:17,640 --> 00:41:19,220 If you need to, like, threaten people, 706 00:41:19,360 --> 00:41:22,280 maybe you can make a language you don't have to threaten people. 707 00:41:23,260 --> 00:41:25,120 Not to mention, for some reason, 708 00:41:25,200 --> 00:41:27,940 databases don't particularly enforce too hard right here. 709 00:41:29,180 --> 00:41:31,840 There's a lot of stuff that you just can't parameterize. 710 00:41:31,900 --> 00:41:34,300 Go ahead and try to have a hole where select is. 711 00:41:34,440 --> 00:41:35,520 It's not going to work. 712 00:41:37,640 --> 00:41:41,020 SQL, for all of its elegance, builds this really complicated 713 00:41:41,020 --> 00:41:45,300 parse tree, and sometimes you get to go ahead and do stuff 714 00:41:45,300 --> 00:41:49,540 to make it safe against injection, and a lot of times you just don't. 715 00:41:50,840 --> 00:41:53,860 So I released this thing in 2010 called Interpolink. 716 00:41:54,480 --> 00:41:56,980 And it was basically a way of saying, 717 00:41:57,180 --> 00:42:00,820 we're going to let devs write code the way they want to write it, 718 00:42:00,880 --> 00:42:03,760 and then we're going to figure out how they should have written it, 719 00:42:03,780 --> 00:42:05,620 and we'll actually fix it compiler side. 720 00:42:06,300 --> 00:42:09,180 What we're going to do is we're looking at the fact that you say you see a string, 721 00:42:09,380 --> 00:42:11,000 select star from foo or x from foo, 722 00:42:11,020 --> 00:42:14,340 x equals dollar sign x, and y equals dollar sign y. 723 00:42:14,700 --> 00:42:18,720 Well, humans can see the separation between data and code. 724 00:42:19,020 --> 00:42:21,760 Code is everything that doesn't have a dollar sign in front of it. 725 00:42:21,900 --> 00:42:23,640 Data is everything that does. 726 00:42:24,720 --> 00:42:27,080 But languages were throwing this out. 727 00:42:27,220 --> 00:42:29,780 They were just taking the value of the variable x, 728 00:42:29,880 --> 00:42:31,800 putting it in, making a single string, done. 729 00:42:32,140 --> 00:42:34,160 Information separation has been lost forever. 730 00:42:34,420 --> 00:42:35,760 What if it wasn't? 731 00:42:35,860 --> 00:42:38,160 What if we kept this data around? 732 00:42:38,920 --> 00:42:40,920 And so what I would do is I'd have 733 00:42:41,020 --> 00:42:46,420 this alternate syntax where you use the caret instead of the dollar sign, 734 00:42:46,580 --> 00:42:48,340 so caret caret x and caret caret y. 735 00:42:48,920 --> 00:42:50,960 Then I had a function that was a code generator, 736 00:42:51,240 --> 00:42:53,560 and it would go ahead and it would look at that stuff 737 00:42:53,560 --> 00:42:57,760 and say anything that began with a caret, that's a parameter. 738 00:42:57,860 --> 00:43:00,100 I'll put a hole there, and I'll fill the hole. 739 00:43:00,560 --> 00:43:02,480 And then you have to go ahead and evaluate, 740 00:43:02,800 --> 00:43:05,300 meaning run the code inline that's text, 741 00:43:05,500 --> 00:43:07,640 evaluate this new safe function. 742 00:43:08,560 --> 00:43:09,520 This works. 743 00:43:09,520 --> 00:43:11,740 This works really well. 744 00:43:12,600 --> 00:43:15,060 Among other things that are scary about it, 745 00:43:15,220 --> 00:43:18,240 what if the developer goes ahead and puts a variable 746 00:43:18,240 --> 00:43:21,760 into the statement that's going into the b function? 747 00:43:22,080 --> 00:43:25,200 Say do x equals dollar sign x instead of my funky x. 748 00:43:25,820 --> 00:43:29,700 Now the attacker is one step away 749 00:43:30,160 --> 00:43:33,360 between an evaluation and attacker controlled code. 750 00:43:34,020 --> 00:43:35,640 That b function in the middle, 751 00:43:35,720 --> 00:43:39,000 the text that it returns is going to be run as arbitrary code. 752 00:43:39,520 --> 00:43:41,840 It could look at what came through and say, 753 00:43:42,000 --> 00:43:47,380 maybe I can predict what PHP is going to do when it runs this code. 754 00:43:48,340 --> 00:43:50,020 Yeah, that's a bad idea. 755 00:43:50,220 --> 00:43:51,440 That's not going to work. 756 00:43:51,960 --> 00:43:53,960 Predicting what some other language is going to do 757 00:43:53,960 --> 00:43:57,300 given arbitrary input is a fool's errand. 758 00:43:58,920 --> 00:44:02,240 So this is what we're actually doing. 759 00:44:02,500 --> 00:44:06,500 And Daniel Zula, who has an amazing talk coming up on Sunday, by the way, 760 00:44:06,600 --> 00:44:08,440 has actually implemented this. 761 00:44:10,720 --> 00:44:13,580 It's a thing that does what's called a self-scoped function. 762 00:44:14,840 --> 00:44:19,840 Self-scoped functions actually run and have access to all the variables 763 00:44:20,400 --> 00:44:21,500 from where they were called. 764 00:44:21,700 --> 00:44:24,120 This is heresy in language development. 765 00:44:24,480 --> 00:44:25,800 It's also a really good idea. 766 00:44:26,280 --> 00:44:29,340 So the idea is that we have this function, 767 00:44:31,600 --> 00:44:33,980 mysqlsafequery, and it says select star from foo 768 00:44:33,980 --> 00:44:36,900 where x equals caret caret x and y equals caret caret y. 769 00:44:37,420 --> 00:44:38,900 Inside that function, 770 00:44:38,900 --> 00:44:44,040 it can get the variable for x and it can get the variable for y 771 00:44:44,040 --> 00:44:47,060 and now it can go ahead and pull that out, make them holes, 772 00:44:47,320 --> 00:44:50,080 make it a parameterized query and run it just like. 773 00:44:50,240 --> 00:44:53,920 So the dev runs this and the code does what it's supposed to. 774 00:44:54,640 --> 00:44:55,880 That's kind of cool. 775 00:44:56,280 --> 00:44:57,720 What other things could we do? 776 00:44:58,140 --> 00:45:00,200 Well, there's some arguments for code rewriting. 777 00:45:00,340 --> 00:45:04,020 If we know what devs should write, why don't we rewrite it once and be done with it? 778 00:45:04,260 --> 00:45:07,240 Has anyone here ever audited auto-generated code? 779 00:45:09,260 --> 00:45:10,660 I'm just not a fan. 780 00:45:12,500 --> 00:45:15,740 There's a tainting approach that Zula's been thinking about. 781 00:45:15,900 --> 00:45:16,760 I kind of like it. 782 00:45:16,920 --> 00:45:22,000 The idea is when characters come in from the web, 783 00:45:22,200 --> 00:45:24,480 you mark them as these are web characters. 784 00:45:25,020 --> 00:45:26,980 So as they flow through the application, 785 00:45:27,380 --> 00:45:29,520 they're always marked as having come from the web. 786 00:45:29,700 --> 00:45:32,840 And then your mysqlsafe function says, 787 00:45:33,000 --> 00:45:35,980 wait, anything that came from the web is data. 788 00:45:36,100 --> 00:45:37,540 That's what I'll parameterize. 789 00:45:37,540 --> 00:45:39,680 It's kind of a variant on tainting. 790 00:45:39,960 --> 00:45:41,940 So this is kind of a neat thing that can work. 791 00:45:43,640 --> 00:45:45,880 I've been working with the guys over at Etsy 792 00:45:45,880 --> 00:45:47,940 who have a hilariously good security team. 793 00:45:50,320 --> 00:45:54,040 What we've been talking about is based on a variant of what they're already doing. 794 00:45:54,400 --> 00:45:59,020 Where instead of doing magic underlying stuff underneath the character set, 795 00:45:59,180 --> 00:46:01,760 you know, expanding the object of what a string is, 796 00:46:02,380 --> 00:46:04,140 we just hex encode the stuff. 797 00:46:04,420 --> 00:46:05,860 Like, just like we would in HTML, 798 00:46:05,860 --> 00:46:09,240 and whatever, 41 for an A. 799 00:46:10,060 --> 00:46:12,500 And now you go all the way through the application. 800 00:46:12,780 --> 00:46:14,520 You get to the mysql query. 801 00:46:14,820 --> 00:46:16,100 It goes to execute. 802 00:46:16,260 --> 00:46:18,600 It says, aha, here are some hex bytes. 803 00:46:18,920 --> 00:46:21,760 These bytes, these are parameters that came from the web. 804 00:46:21,960 --> 00:46:24,880 We'll go ahead and parameterize those. 805 00:46:25,280 --> 00:46:28,280 This work could also even be done in mysql itself. 806 00:46:28,580 --> 00:46:34,400 We can modify the parser in mysql when it got bytes that were marked in such a way 807 00:46:34,400 --> 00:46:35,840 they can only be treated as text. 808 00:46:35,860 --> 00:46:37,920 As a string and could never be understood as code. 809 00:46:38,680 --> 00:46:41,480 The final alternative is actually kind of interesting. 810 00:46:41,660 --> 00:46:43,280 And this is really a last minute add. 811 00:46:43,560 --> 00:46:47,580 Instead of marking the dangerous stuff as dangerous, 812 00:46:47,740 --> 00:46:49,380 we mark the safe stuff as safe. 813 00:46:49,640 --> 00:46:54,160 So you actually mark all SQL code using some sort of a marking. 814 00:46:54,340 --> 00:46:55,660 Even if it's just hex encoding. 815 00:46:56,420 --> 00:47:00,380 Now, the reason you do this is because the bytes from the network 816 00:47:00,380 --> 00:47:04,160 flow through a web application 83 ways from Sunday. 817 00:47:04,260 --> 00:47:05,340 They're transformed. 818 00:47:05,340 --> 00:47:07,520 They're moved from function to function to function. 819 00:47:07,760 --> 00:47:10,300 This is why we have these things called static analyzers. 820 00:47:10,400 --> 00:47:11,640 They got to track all this crap. 821 00:47:12,040 --> 00:47:18,440 But the actual code, the SQL, that tends to be like right before the actual execution. 822 00:47:18,920 --> 00:47:20,860 So that is a thing that we could do. 823 00:47:20,940 --> 00:47:24,540 We could mark the actual SQL and then let the other stuff go raw. 824 00:47:24,820 --> 00:47:26,180 This is not a bad thing. 825 00:47:27,480 --> 00:47:28,840 That's what LANGSEC means. 826 00:47:29,220 --> 00:47:31,220 What are people trying to express? 827 00:47:31,520 --> 00:47:33,400 How can we make it easier to say this? 828 00:47:33,540 --> 00:47:35,320 What errors will be made? 829 00:47:35,320 --> 00:47:37,520 What will people do when they try to use our stuff? 830 00:47:37,860 --> 00:47:42,040 If you don't care about the crap that you're putting developers through, 831 00:47:42,520 --> 00:47:44,620 why the hell should they care about you? 832 00:47:47,460 --> 00:47:49,180 So we got two more things to talk about. 833 00:47:49,300 --> 00:47:51,080 I think 20 minutes left to do it. 834 00:47:52,800 --> 00:47:54,840 20 minutes left to do it. 835 00:47:55,580 --> 00:47:56,840 Suck it. 20. 836 00:48:00,200 --> 00:48:02,300 It doesn't matter what code you write, 837 00:48:02,340 --> 00:48:04,440 if there are parties in the middle that are blocking what you send. 838 00:48:05,320 --> 00:48:08,540 Content alteration and blocking is actually becoming a bit of a thing. 839 00:48:08,800 --> 00:48:14,320 Like Verizon's claiming the First Amendment right to edit your First Amendment rights. 840 00:48:16,300 --> 00:48:18,600 Entire countries are blocking webpages. 841 00:48:18,820 --> 00:48:20,780 It would be nice if we could figure out what's going on here. 842 00:48:21,600 --> 00:48:26,640 So last year I wrote a really, really fun piece of code called Neuter. 843 00:48:26,800 --> 00:48:33,820 It did some crazy under the surface mad packet tricks to impersonate a stream between some client 844 00:48:33,820 --> 00:48:35,980 and some test node out there on the internet. 845 00:48:36,360 --> 00:48:39,280 I could go ahead and impersonate any protocol, any host. 846 00:48:39,460 --> 00:48:40,460 It was brutal. 847 00:48:40,620 --> 00:48:41,660 It would find everything. 848 00:48:42,420 --> 00:48:46,960 Unfortunately, it required because of its low level packet nature. 849 00:48:47,140 --> 00:48:54,440 I basically needed to ship hardware like an actual physical box that would sit at some customer site. 850 00:48:54,640 --> 00:48:56,840 Has anyone here ever shipped hardware? 851 00:48:58,520 --> 00:49:00,760 You guys are smarter than I am. 852 00:49:01,260 --> 00:49:03,000 That is a miserable experience. 853 00:49:03,820 --> 00:49:05,740 You know what's way easier than shipping hardware? 854 00:49:06,120 --> 00:49:07,540 Shipping webpages. 855 00:49:07,740 --> 00:49:08,700 That's pretty cool. 856 00:49:09,860 --> 00:49:12,340 So what else could we do? 857 00:49:12,820 --> 00:49:16,040 We could ship executable code, you know, set up that XE install. 858 00:49:16,840 --> 00:49:18,200 Uniprobe takes that approach. 859 00:49:18,740 --> 00:49:21,360 There's a web page approach using iframes. 860 00:49:21,420 --> 00:49:24,920 You get a little window and it says, in this window, do you see this website? 861 00:49:25,920 --> 00:49:27,200 Herdict does that. 862 00:49:27,420 --> 00:49:30,560 It either needs user cooperation or a Chrome extension. 863 00:49:32,800 --> 00:49:33,800 Is it possible? 864 00:49:33,820 --> 00:49:39,420 It's possible to determine whether content is up or down based on nothing but a web page. 865 00:49:39,840 --> 00:49:42,860 So can we crowdsource censorship data? 866 00:49:43,280 --> 00:49:47,780 If we wish to do this, that means we want to maximize the data we get per user. 867 00:49:47,920 --> 00:49:51,080 We want to minimize the installation load per user. 868 00:49:51,700 --> 00:49:52,820 Okay, what can we do? 869 00:49:53,740 --> 00:49:59,740 Well, the browser same origin policy usually prevents web pages from doing much to read one another. 870 00:50:00,320 --> 00:50:03,080 You wouldn't want Yahoo able to read your Gmail. 871 00:50:03,080 --> 00:50:06,100 Just because, like, the two windows were open at the same time. 872 00:50:07,020 --> 00:50:10,260 But there is one exception to this same origin policy. 873 00:50:10,600 --> 00:50:12,440 And the exception is images. 874 00:50:13,500 --> 00:50:16,360 Domains are allowed to load images from one another. 875 00:50:16,680 --> 00:50:20,220 Beyond that, they're allowed to know that a load was successful. 876 00:50:20,780 --> 00:50:27,740 Not merely that there was a particular file at a location, but that it was an image, the image rendered, and here's its dimensions. 877 00:50:28,300 --> 00:50:29,580 You can actually learn quite a bit. 878 00:50:30,000 --> 00:50:30,880 Now, here's the thing. 879 00:50:30,980 --> 00:50:32,860 If a website is being censored, 880 00:50:33,080 --> 00:50:35,420 images from it are not going to load. 881 00:50:36,140 --> 00:50:40,560 Now, what one image is on, like, every domain on the Internet? 882 00:50:43,140 --> 00:50:44,020 favicon.ico. 883 00:50:45,360 --> 00:50:48,580 This is this little icon in the upper left-hand corner of your tab. 884 00:50:48,740 --> 00:50:49,700 It used to be for bookmarks. 885 00:50:49,760 --> 00:50:50,800 That's why it was called favicon. 886 00:50:51,780 --> 00:50:54,140 Pretty much everyone's got one of these. 887 00:50:54,540 --> 00:50:57,920 So what we do is we try to load the thing. 888 00:50:58,080 --> 00:50:59,400 And if it's there, great. 889 00:50:59,680 --> 00:51:01,860 And if it's not, we say the site is blocked. 890 00:51:01,860 --> 00:51:03,160 So we got this site. 891 00:51:03,280 --> 00:51:04,140 It's actually up today. 892 00:51:04,400 --> 00:51:10,800 I wrote it with Joseph Van Geffen and Michael Tiffany with the Wall Street Journal Data Transparency Hackathon. 893 00:51:11,420 --> 00:51:13,480 And it is themed like Minesweeper. 894 00:51:13,700 --> 00:51:17,580 If you hit play, if the image loads, it will drop the favicon. 895 00:51:17,860 --> 00:51:19,620 If not, it will drop a bomb. 896 00:51:20,720 --> 00:51:21,760 Works kind of nicely. 897 00:51:22,960 --> 00:51:25,100 So what's going on behind the scenes? 898 00:51:25,420 --> 00:51:27,260 You create an image object in JavaScript. 899 00:51:27,640 --> 00:51:28,700 Image equals new image. 900 00:51:28,900 --> 00:51:30,360 You create an onload handler. 901 00:51:30,440 --> 00:51:31,840 You create an onerror handler. 902 00:51:31,860 --> 00:51:34,620 You do this a bunch in parallel. 903 00:51:34,900 --> 00:51:39,540 Reading from a list of sites that have been validated to have favicon.ico files. 904 00:51:40,180 --> 00:51:43,920 Six failures are required before a bomb is dropped on the map. 905 00:51:44,380 --> 00:51:45,400 Is this enough? 906 00:51:45,880 --> 00:51:46,440 No. 907 00:51:46,540 --> 00:51:47,700 No, it's actually not. 908 00:51:48,340 --> 00:51:54,240 Web browsers provide really crappy feedback into what's actually going on on their network stack. 909 00:51:54,800 --> 00:51:56,960 It's like flow control really doesn't exist. 910 00:51:57,180 --> 00:51:59,420 They just assume they have infinite bandwidth. 911 00:51:59,760 --> 00:52:01,280 My friends told me this was true. 912 00:52:01,280 --> 00:52:04,020 When they were doing stuff still on modems, I didn't believe them. 913 00:52:04,140 --> 00:52:04,800 They were right. 914 00:52:05,940 --> 00:52:12,480 For actual reliability to the point where we could have genuine worldwide monitoring and trust the data we're getting back, 915 00:52:12,720 --> 00:52:18,940 we basically need to shut down all other probes while doing final validation 916 00:52:19,460 --> 00:52:23,340 and then do a probe just for something that is known to be up and might be down. 917 00:52:23,640 --> 00:52:27,940 And even then, we're going to have a few tenths of a percent that are going to be wrong anyway. 918 00:52:28,760 --> 00:52:29,740 That being said, 919 00:52:29,740 --> 00:52:32,180 sensor sweeper does work pretty well. 920 00:52:32,840 --> 00:52:34,480 Can we do better? 921 00:52:35,280 --> 00:52:35,760 All right. 922 00:52:35,920 --> 00:52:38,700 Well, let's talk about Flash and its sockets. 923 00:52:39,200 --> 00:52:49,360 Once upon a time, 2007, you could go ahead and you could turn any web browser you wanted basically into an open proxy to the internet. 924 00:52:49,620 --> 00:52:55,040 You could just basically say, hey, web browser, go to this site, get me this content, speak this protocol. 925 00:52:55,280 --> 00:52:56,460 It would do it for you. 926 00:52:56,540 --> 00:52:57,400 It was a bug. 927 00:52:57,540 --> 00:52:58,760 We got it fixed. 928 00:53:00,140 --> 00:53:03,600 However, networks are more complicated than they may appear at first. 929 00:53:03,980 --> 00:53:10,380 We fixed the browsers, we fixed the plug-ins so they can only speak back to our own IP. 930 00:53:11,140 --> 00:53:16,660 However, there are boxes in between the web browser and our own IP. 931 00:53:16,820 --> 00:53:18,360 They're called transparent proxies. 932 00:53:19,660 --> 00:53:24,460 Coincidentally, censoring systems are often implemented with transparent proxies. 933 00:53:25,300 --> 00:53:28,100 So what this means is that we actually have a thing that is 934 00:53:29,180 --> 00:53:31,300 nicely placed for us to start probing. 935 00:53:31,560 --> 00:53:36,800 Because what we can do is we can use Flash or Haxi, which is the better language to code Flash in. 936 00:53:38,780 --> 00:53:41,260 We create a connection back to ourselves on port 80. 937 00:53:41,900 --> 00:53:45,360 And then we tell ourselves, hey, I'm looking for Facebook. 938 00:53:45,520 --> 00:53:46,340 I'm looking for YouTube. 939 00:53:46,580 --> 00:53:47,600 I'm looking for BitTorrent. 940 00:53:47,680 --> 00:53:49,000 I'm looking for all this stuff. 941 00:53:49,560 --> 00:53:54,640 And it's coming back to our IP address, but it's intercepted by the transparent proxy. 942 00:53:54,900 --> 00:53:58,000 The transparent proxy decides to host whatever the heck it wants. 943 00:53:58,000 --> 00:54:00,540 It sends it back to our Flash application. 944 00:54:01,560 --> 00:54:04,160 And then we can see the content and go from there. 945 00:54:04,960 --> 00:54:05,260 Cool. 946 00:54:06,220 --> 00:54:09,880 So going beyond that, and I have 13 minutes. 947 00:54:09,960 --> 00:54:10,960 I'm watching this clock. 948 00:54:11,100 --> 00:54:12,000 You're not taking it from me. 949 00:54:15,120 --> 00:54:21,780 So just as HTTP traffic on port 80 is hijacked, so may HTTPS traffic on 443. 950 00:54:21,960 --> 00:54:27,940 So it turns out not only can you get web content, you can go 951 00:54:28,000 --> 00:54:30,340 ahead and see what certificates are being changed. 952 00:54:30,940 --> 00:54:36,160 Turns out when you make an SSL request, you can actually name the site that you would like. 953 00:54:39,040 --> 00:54:42,880 The IP at your side can actually decide based on what you said. 954 00:54:43,000 --> 00:54:47,620 It can either pretend to have that certificate or it can even proxy to the real Facebook, 955 00:54:47,740 --> 00:54:48,860 the real Yahoo or whatever. 956 00:54:51,260 --> 00:54:54,960 The transparent box in the middle that may or may not be replacing certificates, 957 00:54:55,480 --> 00:54:57,760 it doesn't know that it's not actually 958 00:54:58,000 --> 00:55:01,020 talking to the browser, so it goes ahead and provides the certificate. 959 00:55:01,340 --> 00:55:04,580 And that goes to the Flash applet and the Flash applet can go ahead and bust you. 960 00:55:04,740 --> 00:55:05,740 So it's kind of cool. 961 00:55:07,180 --> 00:55:10,040 Normally, the browser DOM, when you ask the browser, 962 00:55:10,200 --> 00:55:14,260 it can't tell you what certificate was at a given site. 963 00:55:14,460 --> 00:55:20,140 This is actually the first mechanism that will tell you for this site what cert is there. 964 00:55:20,940 --> 00:55:21,820 There's a limitation. 965 00:55:22,260 --> 00:55:26,940 If the hijacking is at the DNS layer and not at the IP, 966 00:55:29,200 --> 00:55:34,080 then you won't go to the correct IP address to get the interspersed certificate. 967 00:55:34,560 --> 00:55:38,320 So I am not going to be running the big certificate databases, 968 00:55:38,560 --> 00:55:43,700 but unnamed parties who are will be getting this code and I'm sure LOLs will be had. 969 00:55:46,260 --> 00:55:48,160 Full proxying is also possible. 970 00:55:48,300 --> 00:55:52,080 I'll kind of skip past this, but you can basically route every single protocol, 971 00:55:52,320 --> 00:55:56,080 have like a full HTTP proxy bouncing from a server, 972 00:55:56,080 --> 00:55:58,940 through a client, back to a server. 973 00:55:59,200 --> 00:56:00,440 Why would you do this? 974 00:56:00,580 --> 00:56:05,240 Because while I could try to emulate all the weirdness to play a YouTube video stream 975 00:56:05,240 --> 00:56:12,240 over a Flash application, it's a lot easier to just have a real browser 976 00:56:12,240 --> 00:56:15,760 really play through the Flash side. 977 00:56:16,000 --> 00:56:16,820 So that's kind of neat. 978 00:56:17,460 --> 00:56:21,920 So the last thing I want to talk to you guys about is scanning networks quickly. 979 00:56:22,520 --> 00:56:24,260 There's a thing that everyone should know. 980 00:56:24,320 --> 00:56:26,060 It's my definition of actionable intelligence. 981 00:56:26,080 --> 00:56:32,100 What can an attacker do today that he couldn't do yesterday for what class attacker 982 00:56:32,100 --> 00:56:33,380 to what class victim? 983 00:56:33,640 --> 00:56:38,240 If you write an advisory that does not answer this question, it's a bad advisory. 984 00:56:39,140 --> 00:56:40,260 What changed? 985 00:56:40,860 --> 00:56:45,080 And a big part of determining how big deal a bug is is, 986 00:56:45,180 --> 00:56:50,280 well, how many systems actually have this bug in the first place? 987 00:56:50,660 --> 00:56:54,520 I've run two major scans for two major press-announced bugs this year. 988 00:56:54,660 --> 00:56:56,020 One was the Telnet. 989 00:56:56,080 --> 00:56:56,740 I had an encryption bug. 990 00:56:57,080 --> 00:56:58,520 One was the RDP attack. 991 00:56:58,840 --> 00:57:01,180 And the question was, were either of them widespread? 992 00:57:02,760 --> 00:57:03,720 Telnet, nowhere. 993 00:57:03,940 --> 00:57:06,120 There was a tiny, tiny number of hosts that were running it. 994 00:57:06,420 --> 00:57:09,440 RDP, yeah, like 5 million hosts were running that. 995 00:57:09,600 --> 00:57:11,060 That was actually a big deal. 996 00:57:11,680 --> 00:57:13,100 So this is important. 997 00:57:13,340 --> 00:57:15,880 If we're going to actually rationally respond to bugs, 998 00:57:16,080 --> 00:57:19,080 we should know, does anyone actually have them? 999 00:57:20,180 --> 00:57:22,400 So how do you actually do these scans? 1000 00:57:24,260 --> 00:57:26,060 Once upon a time, I wrote a network 1001 00:57:26,060 --> 00:57:27,220 scanner called ScanRand. 1002 00:57:27,500 --> 00:57:30,980 It was fast because at the time, I didn't actually know how to slow down. 1003 00:57:31,200 --> 00:57:33,320 I just kept running in a loop and it worked. 1004 00:57:35,300 --> 00:57:38,220 So I sent a bunch of connection requests called TCP SYNs. 1005 00:57:38,900 --> 00:57:40,620 This is now not enough. 1006 00:57:40,960 --> 00:57:44,580 There are a whole bunch of things that will respond to the SYNs with a proper SYN 1007 00:57:44,580 --> 00:57:46,420 hack, but nothing is there. 1008 00:57:46,640 --> 00:57:48,740 They answer the door, but nobody's home. 1009 00:57:49,360 --> 00:57:51,460 So you basically have to split your process. 1010 00:57:51,720 --> 00:57:55,180 You get a bunch of candidates through the old method where you see if the three-way 1011 00:57:55,180 --> 00:57:56,300 stuff actually works. 1012 00:57:56,620 --> 00:58:01,560 And then, only then, you go ahead and you do real connections and connect to the IP. 1013 00:58:02,100 --> 00:58:03,540 So a little bit more detail. 1014 00:58:03,820 --> 00:58:04,620 You send the SYNs. 1015 00:58:04,700 --> 00:58:06,140 You increment the first byte first. 1016 00:58:06,440 --> 00:58:10,660 The reason you do this, so 1.1.1, 2.1.1.1, and so on. 1017 00:58:10,760 --> 00:58:14,900 This means the larger the network you're scanning or the larger internet you're 1018 00:58:14,900 --> 00:58:18,720 scanning, the slower you're scanning each individual network because you're 1019 00:58:18,720 --> 00:58:20,480 spending your time somewhere else. 1020 00:58:21,380 --> 00:58:23,180 So it increases your success rate. 1021 00:58:23,400 --> 00:58:24,660 Then a separate window. 1022 00:58:24,660 --> 00:58:26,920 I don't even use ScanRan to go ahead and capture the data. 1023 00:58:26,980 --> 00:58:31,460 I actually have tcpdump capturing SYNX, the little command that will do that. 1024 00:58:32,020 --> 00:58:37,680 And then once I have my candidates in the telnet encryption case, the Nmap guys 1025 00:58:37,680 --> 00:58:40,940 were so kind, they went ahead and whipped up a quick check for me. 1026 00:58:41,100 --> 00:58:43,940 I just fed my IP list to it and very few were found. 1027 00:58:45,640 --> 00:58:49,420 When I was getting RDP, there's an excellent framework called Black Mamba. 1028 00:58:49,560 --> 00:58:50,900 It's at rootfoo.org. 1029 00:58:51,840 --> 00:58:54,120 You basically just write really simple, 1030 00:58:54,120 --> 00:58:58,480 straightforward code and every time you're going to stop in the middle, you yield. 1031 00:58:58,720 --> 00:59:00,500 So you say yield connect. 1032 00:59:00,780 --> 00:59:02,200 So come back after you get a connection. 1033 00:59:02,480 --> 00:59:04,740 Then come back after you're able to write these bytes. 1034 00:59:04,920 --> 00:59:06,960 Come back after there's a response. 1035 00:59:07,440 --> 00:59:09,760 And Black Mamba makes it work very, very nice. 1036 00:59:10,040 --> 00:59:13,100 This gives you about 3,000 IPs a second. 1037 00:59:13,520 --> 00:59:14,660 I want more. 1038 00:59:15,200 --> 00:59:19,380 So I've always wanted to write a user space network stack. 1039 00:59:19,560 --> 00:59:23,940 This is a program that directly talks to the network and retrieves 1040 00:59:24,120 --> 00:59:24,280 content. 1041 00:59:25,340 --> 00:59:27,960 HD Moore kind of kicked me into high gear on it. 1042 00:59:28,100 --> 00:59:31,620 He's got some mysterious new scanning project called Critical I.O. 1043 00:59:32,440 --> 00:59:37,360 I am not at all beyond supporting any crazy project by HD Moore. 1044 00:59:37,560 --> 00:59:38,160 Heck yeah. 1045 00:59:38,880 --> 00:59:41,420 So ScanRand 3 will be out shortly. 1046 00:59:42,200 --> 00:59:43,900 ScanRand 3 is a new scanner. 1047 00:59:44,000 --> 00:59:45,300 It doesn't just flood SINs. 1048 00:59:45,340 --> 00:59:48,580 It actually connects to nodes and extracts data. 1049 00:59:49,000 --> 00:59:53,560 The original plan was to have there be a database inside of ScanRand. 1050 00:59:53,560 --> 00:59:55,140 I was going to use SQLite. 1051 00:59:55,380 --> 00:59:55,800 Why? 1052 00:59:55,900 --> 00:59:59,160 Because I thought it would be funny, just humorous to have a network stack 1053 00:59:59,160 --> 01:00:02,620 where I'm like select star from sockets where data sent not equal data 1054 01:00:02,620 --> 01:00:05,660 acknowledged and data sent time minus now is greater than three. 1055 01:00:05,900 --> 01:00:08,920 So it would be like a database lookup to figure out where you needed to send 1056 01:00:08,920 --> 01:00:09,640 a retransmit. 1057 01:00:09,840 --> 01:00:10,880 That would be cool. 1058 01:00:12,040 --> 01:00:18,800 This was useful for SQLite because that's really, really fast if there's no index. 1059 01:00:19,140 --> 01:00:22,020 That speed disappears if you add indexes. 1060 01:00:22,060 --> 01:00:23,480 So if you actually want to be able to query 1061 01:00:23,560 --> 01:00:25,380 the database, SQLite is no longer fast. 1062 01:00:26,160 --> 01:00:27,580 So let's just not do that. 1063 01:00:28,380 --> 01:00:30,220 Can't someone else do it? 1064 01:00:34,320 --> 01:00:35,900 So check this out. 1065 01:00:36,040 --> 01:00:37,960 I didn't think this was possible, but it actually works. 1066 01:00:39,640 --> 01:00:45,040 ScanRand did not get its speed by keeping track of all these machines it was speaking to. 1067 01:00:45,400 --> 01:00:47,100 So why should ScanRand 3? 1068 01:00:47,500 --> 01:00:50,400 We're going to build a stateless TCP stack. 1069 01:00:50,660 --> 01:00:52,120 It just sends data. 1070 01:00:52,120 --> 01:00:53,600 It doesn't remember to who. 1071 01:00:53,940 --> 01:00:56,760 And the other guy remembers that he's talking to me. 1072 01:01:01,380 --> 01:01:01,900 Thanks. 1073 01:01:02,660 --> 01:01:09,200 The way you do this, you send a SYN and you set the maximum segment size and window size to 1460. 1074 01:01:10,240 --> 01:01:16,660 What this means is at any given point, there's only going to be one packet outstanding at a time. 1075 01:01:16,980 --> 01:01:21,140 So now whenever you receive a SYNACK, okay, you got to talk, you send your payload, 1076 01:01:21,140 --> 01:01:21,920 you send the acknowledgement. 1077 01:01:22,520 --> 01:01:27,320 Every time you get another acknowledgement with a payload, you acknowledge that. 1078 01:01:27,460 --> 01:01:28,700 You ignore if there's no payload. 1079 01:01:29,060 --> 01:01:31,060 And when you get a SYNACK, you send a reset. 1080 01:01:31,200 --> 01:01:32,060 You say, I'm done with you. 1081 01:01:32,080 --> 01:01:32,940 Don't remember me anymore. 1082 01:01:34,660 --> 01:01:39,040 In every situation, except for if the original SYN is dropped, 1083 01:01:39,360 --> 01:01:44,220 every time the other side sends a packet, if there's a drop, well, whatever. 1084 01:01:44,760 --> 01:01:46,040 He'll clean it up for you. 1085 01:01:47,340 --> 01:01:51,040 I can take 3.25 million IP addresses. 1086 01:01:51,140 --> 01:01:55,660 I can sweep them from my little $200 Optron box on a really nice pipe. 1087 01:01:57,740 --> 01:02:03,440 I can get 800 megs of HTTP data. 1088 01:02:03,900 --> 01:02:05,760 The scan takes 75 seconds. 1089 01:02:15,800 --> 01:02:19,860 And of course, this is not even optimized code, right? 1090 01:02:19,860 --> 01:02:25,160 The goal, this will get out to about 200,000 IPs a second. 1091 01:02:25,380 --> 01:02:29,960 You end up doing stream reconstruction with a SQL query, which is kind of fun. 1092 01:02:32,060 --> 01:02:35,660 Security, right now I've implemented none of it, just like your average developer. 1093 01:02:39,380 --> 01:02:45,100 For security, you basically put cookies into the sequence number and source port 1094 01:02:45,100 --> 01:02:47,380 and maybe the TCP timestamp. 1095 01:02:47,600 --> 01:02:49,100 So the idea is, 1096 01:02:49,100 --> 01:02:52,600 you can put little secret data so you know when someone's responding to you, 1097 01:02:52,640 --> 01:02:56,060 they're actually responding to you and they're not faking responses. 1098 01:02:56,200 --> 01:02:58,560 You know, saying that Google's got a bunch of spicy stuff. 1099 01:03:00,340 --> 01:03:01,020 Some notes. 1100 01:03:01,280 --> 01:03:02,720 This may not be necessary. 1101 01:03:03,000 --> 01:03:04,760 Kernels have gotten kind of fast. 1102 01:03:05,500 --> 01:03:10,660 Non-blocking connect plus EPOL should probably be able to do at least tens 1103 01:03:10,660 --> 01:03:15,400 of thousands of sockets per second, and it'll certainly be easier to code for. 1104 01:03:15,620 --> 01:03:18,580 But my approach eventually becomes the fastest, 1105 01:03:18,580 --> 01:03:20,660 because I'm just really lazy. 1106 01:03:21,100 --> 01:03:22,440 I'm not doing anything. 1107 01:03:22,720 --> 01:03:23,680 The other guys are. 1108 01:03:24,440 --> 01:03:27,660 The biggest performance advantage that I'm going to get is when I get what's called 1109 01:03:27,660 --> 01:03:32,120 a right V for right vector, where I can give the kernel a whole bunch of packets 1110 01:03:32,120 --> 01:03:34,060 to send instead of just one. 1111 01:03:34,500 --> 01:03:35,860 A couple more notes. 1112 01:03:35,960 --> 01:03:38,300 I can try more efficient stores in SQLite. 1113 01:03:38,480 --> 01:03:42,280 I can do a giant allocation of RAM and just have fixed offsets per IP. 1114 01:03:42,660 --> 01:03:48,200 There's a cool project called MemSQL from these old Facebook guys, and they're basically converting 1115 01:03:48,200 --> 01:03:50,380 SQL to C++. 1116 01:03:50,920 --> 01:03:52,920 So that might actually work. 1117 01:03:53,260 --> 01:03:54,120 We'll find out. 1118 01:03:54,660 --> 01:03:59,300 And there are merged approaches, too, where I only keep state if I get a certain distance into a session. 1119 01:04:00,640 --> 01:04:07,400 Now, there are a few servers on the Internet that do not actually have a state, either. 1120 01:04:07,500 --> 01:04:09,860 They'll say, well, the client will keep track, and I'm almost done. 1121 01:04:10,480 --> 01:04:12,220 These servers tend to be run by Google. 1122 01:04:13,800 --> 01:04:18,000 And, yeah, if a client thinks the other guy's going to do it and the server thinks the other guy's going to do it, 1123 01:04:18,200 --> 01:04:18,800 it's a bad day. 1124 01:04:20,580 --> 01:04:25,600 The most important feature to write that isn't written yet, I need to implement blacklist support. 1125 01:04:25,980 --> 01:04:28,400 Most networks don't complain when you scan them. 1126 01:04:28,640 --> 01:04:31,180 Those that do, you've got to honor their request. 1127 01:04:31,520 --> 01:04:38,140 And it actually does require a fairly efficient data structure not to go ahead and have that take all your speed. 1128 01:04:39,440 --> 01:04:41,480 Oh, don't mess with the firewall. 1129 01:04:41,720 --> 01:04:43,080 Just have your code get its own IP. 1130 01:04:43,400 --> 01:04:44,860 Your little program arps for itself. 1131 01:04:45,920 --> 01:04:46,960 That's lots of stuff. 1132 01:04:47,140 --> 01:04:48,180 I hope you like it. 1133 01:04:48,200 --> 01:04:48,980 I'm out.