1 00:00:00,640 --> 00:00:03,900 Really quickly, we're going to blitz through a lot of the talk today. 2 00:00:04,560 --> 00:00:08,180 We had the same talk at Black Hat with about 20 minutes more 3 00:00:08,180 --> 00:00:11,800 and didn't get a chance to cover everything in depth, 4 00:00:11,920 --> 00:00:14,140 so we might talk a little bit quickly. 5 00:00:15,880 --> 00:00:18,260 Really quickly, to go through the agenda, 6 00:00:18,960 --> 00:00:22,220 we're going to do a who we are, what we do, 7 00:00:22,790 --> 00:00:25,020 what the talk's about, and why we actually care. 8 00:00:25,960 --> 00:00:29,480 We're going to touch on the background of timing attacks a little bit. 9 00:00:30,120 --> 00:00:34,220 Then we're going to start looking at timing more as we care about it, 10 00:00:34,600 --> 00:00:37,960 so as a channel for attacking networks. 11 00:00:38,560 --> 00:00:40,780 We'll look at timing as its own vector. 12 00:00:41,120 --> 00:00:44,440 We'll look at some of its privacy implications or privacy implications 13 00:00:45,880 --> 00:00:49,700 just so that we can introduce a new acronym or make it more popular 14 00:00:49,700 --> 00:00:51,540 because there aren't enough of those going around. 15 00:00:52,620 --> 00:00:54,640 We'll look at cross-site request timing. 16 00:00:55,560 --> 00:00:59,140 Then we'll add a D just to make it distributed cross-site request timing. 17 00:00:59,140 --> 00:01:02,880 programming, and then we'll go into questions and conclusion. 18 00:01:04,670 --> 00:01:10,840 So really quickly, SensePost is a small computer security company based out of South Africa. 19 00:01:11,180 --> 00:01:19,520 We were formed way back in 2000, so it's quite a bit in internet years. Our analysts have 20 00:01:19,520 --> 00:01:24,460 written a few papers, spoken at a few conferences, so we've done Black Hat DEF CON for about 21 00:01:24,460 --> 00:01:30,440 six years in a row now. Our guys have written in a few books, showing that the publishing 22 00:01:30,440 --> 00:01:37,100 industry is doomed, and we've done a little bit of training. Most of our time we spent 23 00:01:37,100 --> 00:01:43,200 preparing for this talk was just to pull these two Simpsonized Me characters, so that's Marco 24 00:01:43,200 --> 00:01:50,380 down there, and me next to him. Both of us just researchers at SensePost. And down here, 25 00:01:50,520 --> 00:01:52,140 we've got the mandatory blog. 26 00:01:53,000 --> 00:01:54,440 So if you've got nothing else to say, please feel free to leave a comment below. 27 00:01:54,440 --> 00:01:55,920 If you've got nothing to do, go visit us online. 28 00:01:58,240 --> 00:02:06,460 So really quickly, what this talk is about, other than timing, and why you should care, 29 00:02:06,560 --> 00:02:11,420 or who should care. If you're a developer, something that's interesting is that we've 30 00:02:11,420 --> 00:02:17,020 been protecting against info leakage for a long time, and we might not notice how timing 31 00:02:17,020 --> 00:02:22,140 is leaking information. If you're a pen tester, something that you'll pick up from all of 32 00:02:22,140 --> 00:02:24,420 the examples and demos is that you might not notice how timing is leaking information. 33 00:02:24,420 --> 00:02:29,480 But you could be missing huge attack targets, huge vectors, just because you're not paying 34 00:02:29,480 --> 00:02:34,540 attention to it. And we're hoping that'll change going forward. And if you like new 35 00:02:34,540 --> 00:02:40,380 acronyms, you can start using XSRT and DXSRT when you hand in your pen test reports. 36 00:02:42,400 --> 00:02:48,760 All right. So before we actually get into the nitty-gritty of our tool and the 37 00:02:48,760 --> 00:02:54,200 techniques that we've got, we thought we'd give a very brief background into timing attacks, 38 00:02:54,420 --> 00:03:00,660 and where they sit in terms of attacks against software and hardware. So basically, side 39 00:03:00,660 --> 00:03:04,200 channel attacks, if we step even further back, have got this long and illustrious history 40 00:03:04,200 --> 00:03:08,540 against computing systems. And two of the very common hardware-based attacks are, of 41 00:03:08,540 --> 00:03:14,040 course, power analysis and EM emission analysis. But those are very specifically against hardware. 42 00:03:14,600 --> 00:03:19,500 And if we're looking at side channel attacks against software, one of the attacks that 43 00:03:19,500 --> 00:03:24,340 crops up very often becomes timing attacks. Next slide. 44 00:03:25,020 --> 00:03:28,300 Thank you. So in the traditional sense, timing attacks 45 00:03:28,300 --> 00:03:33,540 are generally used in cryptanalysis, right? So the guys are trying to break algorithms. 46 00:03:33,560 --> 00:03:40,060 They're trying to expose weaknesses in various algorithms. And timing attacks are remarkably 47 00:03:40,060 --> 00:03:46,120 efficient at this, because they don't attack the math behind the crypto. They're attacking 48 00:03:46,120 --> 00:03:50,320 the implementation. So over the past couple of years, there have 49 00:03:50,320 --> 00:03:53,880 been a bunch of papers. We've listed four here. There's lots more. 50 00:03:54,420 --> 00:04:00,980 But these four are kind of the seminal papers for timing attacks against crypto. We started 51 00:04:00,980 --> 00:04:06,900 off with local attacks against RSA. That moved to attacks over the network, deriving RSA 52 00:04:06,900 --> 00:04:14,440 keys over the network. There were weaknesses that Daniel Bernstein showed in AES. And then 53 00:04:14,440 --> 00:04:20,240 finally, Clive Percival, just two years ago, showed timing attacks, again, local, but this 54 00:04:20,240 --> 00:04:21,760 time on hyper-threaded processes. 55 00:04:23,780 --> 00:04:24,100 So 56 00:04:24,420 --> 00:04:28,920 So if we move away from cryptanalysis, what we find on the Web is actually there's not 57 00:04:28,920 --> 00:04:35,600 a lot of stuff to be had in terms of timing attacks. As long ago as 2000, Felton and Schneider 58 00:04:35,600 --> 00:04:40,560 had a paper in which they showed that there were various timing attacks that could be 59 00:04:40,560 --> 00:04:48,380 conducted, but they focused mostly on privacy and users' privacy concerns. So two of the 60 00:04:48,380 --> 00:04:53,380 attacks of the four that they had, two of them are relatively interesting for us. The 61 00:04:53,380 --> 00:04:54,400 one was a browser control. 62 00:04:54,400 --> 00:04:59,220 The other was a cache snooping attack. So basically, the idea there was, through JavaScript, 63 00:04:59,460 --> 00:05:03,580 they could measure load times of pages. And based on that load time, they could determine 64 00:05:04,080 --> 00:05:08,180 whether you'd already visited that page in the past, given it was in your cache. 65 00:05:08,380 --> 00:05:13,260 So there was a privacy implication there. They also had another attack where they used 66 00:05:13,260 --> 00:05:17,840 a Java applet to make DNS requests. Based on the timing of those DNS requests, again, 67 00:05:18,040 --> 00:05:23,680 they could snoop on your DNS cache, determine if you had made that request somewhat previously. 68 00:05:24,520 --> 00:05:30,440 But if we move a little forward, we get to the slide that I titled in this entire presentation. 69 00:05:30,840 --> 00:05:38,460 I think it's fairly punny, so feel free to laugh. I call it Web Time Point O. You can 70 00:05:38,460 --> 00:05:44,980 groan as well, feel free. It is that bad. Last year we had two papers at Black Hat by 71 00:05:44,980 --> 00:05:50,540 Grossman and Nitzelkowski, and also by Spy Dynamics. And basically, those guys all released 72 00:05:51,360 --> 00:05:53,180 JavaScript-based port scanners. 73 00:05:53,680 --> 00:05:59,420 And although they weren't explicit timing attacks that they used, the tools used an 74 00:05:59,420 --> 00:06:06,340 implicit timing attack to gather information. So one of the legs of their tool was, basically, 75 00:06:06,960 --> 00:06:12,060 if you tried to make a connection to a site or to a host on a port, and that connection 76 00:06:12,060 --> 00:06:17,040 timed out, you could infer certain information about that host. And that implicitly is a 77 00:06:17,040 --> 00:06:21,260 timing attack, right? You don't know that that port is actually closed, but based on 78 00:06:21,260 --> 00:06:23,660 a timeout, you're saying, we're going to infer that. 79 00:06:23,680 --> 00:06:28,520 There's nothing there. And then a little earlier this year, a couple of guys from Stanford 80 00:06:28,520 --> 00:06:34,980 released a paper where they explicitly brought timing attacks to the Internet to the Web. 81 00:06:35,120 --> 00:06:39,320 So they were conducting timing attacks against websites to see what information they could 82 00:06:39,320 --> 00:06:43,200 derive. And it was quite interesting. What they found was that you could split them into 83 00:06:43,200 --> 00:06:49,300 two categories. The first was direct timing attacks. In a direct timing attack, the attacker 84 00:06:49,300 --> 00:06:53,580 would make a request to a site. Based on the time of the response, infer certain information. 85 00:06:53,680 --> 00:06:57,880 So one of the aspects they looked at was, for instance, you have these picture gallery 86 00:06:57,880 --> 00:07:03,260 software where users have galleries, and they can mark some of them as private, some of 87 00:07:03,260 --> 00:07:08,520 them as public. And based on the length of time that it took to build the response, when 88 00:07:08,520 --> 00:07:12,780 you tried to view a user's gallery, you could determine how many galleries that user had, 89 00:07:12,940 --> 00:07:17,360 even if they were marked private. So it's a basic timing attack, but it serves that purpose. 90 00:07:17,740 --> 00:07:22,980 One of the others that we'll get to a little later was inferring the validity of a user's 91 00:07:22,980 --> 00:07:23,660 name, based on the response to a user's gallery. So they got a feature that was called the 92 00:07:23,680 --> 00:07:26,760 based on the time that your request took to come back. 93 00:07:27,360 --> 00:07:33,260 And the second point that they had was cross-site timing, which we'll talk about a little. 94 00:07:33,600 --> 00:07:34,980 This is pretty interesting. 95 00:07:35,120 --> 00:07:40,140 What they found was you could send a browser or a victim JavaScript from your own malicious 96 00:07:40,140 --> 00:07:46,520 website and then based on the JavaScript would conduct or would issue requests against third 97 00:07:46,520 --> 00:07:51,860 party sites and based on the response of those, the timing of the response of those, you could 98 00:07:51,860 --> 00:07:56,980 infer whether that victim was logged into third party sites and so on. 99 00:07:57,400 --> 00:08:03,440 So that cross-site timing we believe is quite an interesting field to look at. 100 00:08:05,360 --> 00:08:05,840 Okay. 101 00:08:06,480 --> 00:08:11,780 So now that the background's done, we're going to take a look at when you're pen testing, 102 00:08:12,000 --> 00:08:16,840 one of the things that comes up is you quite clearly need to establish a good communication 103 00:08:16,840 --> 00:08:19,440 channel with the box that you're attacking. 104 00:08:20,140 --> 00:08:21,840 So we're going to take a quick look. 105 00:08:21,840 --> 00:08:25,880 A quick progression at some remote command execution attacks. 106 00:08:27,520 --> 00:08:32,300 You find in the old days there were tons of applications vulnerable. 107 00:08:32,700 --> 00:08:35,540 If we can bring this up on screen reasonably. 108 00:08:37,100 --> 00:08:43,600 And so if we take a look at this application, this is a pretty straightforward command injection 109 00:08:43,600 --> 00:08:44,120 attack. 110 00:08:44,500 --> 00:08:50,440 Allows you to put in an IP and instead we're going to tell it to also run our command. 111 00:08:50,880 --> 00:08:51,520 Okay. 112 00:08:51,840 --> 00:08:58,420 And in this case, what's clear is this application itself gives us the channel we need to get 113 00:08:58,420 --> 00:08:59,880 our data out of the network. 114 00:09:00,520 --> 00:09:00,760 Okay. 115 00:09:00,800 --> 00:09:04,940 So you'll notice whatever we do, the app comes back and the app gives us whatever it 116 00:09:04,940 --> 00:09:05,880 is we need to know. 117 00:09:06,880 --> 00:09:11,540 You don't see so much of that anymore, mainly because you don't see so many applications 118 00:09:11,540 --> 00:09:13,160 written by sysadmins anymore. 119 00:09:13,780 --> 00:09:14,300 Okay. 120 00:09:14,320 --> 00:09:19,580 Instead, what you find is lots of applications making trivial SQL injection mistakes. 121 00:09:20,720 --> 00:09:21,240 Okay. 122 00:09:21,840 --> 00:09:27,220 So if we take a really quick example of a SQL injection problem, you'll find that again 123 00:09:27,220 --> 00:09:34,180 with SQL injection, you sometimes find yourself lucky enough that you find a SQL query that 124 00:09:34,180 --> 00:09:36,040 actually returns results to you. 125 00:09:36,480 --> 00:09:36,940 Okay. 126 00:09:37,000 --> 00:09:43,140 If it's going to return results to you, then you're fully able to use the channel itself 127 00:09:44,160 --> 00:09:46,680 to start to get information back. 128 00:09:46,880 --> 00:09:51,820 So what I'm doing here is just union select name from sysobjects.com. 129 00:09:51,820 --> 00:09:56,220 And what you should find is that your SQL query should concatenate. 130 00:09:56,420 --> 00:10:01,720 And again, you're able to use the channel itself to start to get information back. 131 00:10:02,980 --> 00:10:03,520 Okay. 132 00:10:03,860 --> 00:10:10,280 This would be perfect, except it doesn't, occasionally that avenue isn't open to you. 133 00:10:10,700 --> 00:10:16,500 You often find that in the past, through completely poor firewalling, you could actually 134 00:10:16,500 --> 00:10:21,800 run your attack and then have the victim box send a shell all the way back to you. 135 00:10:21,820 --> 00:10:22,600 Okay. 136 00:10:22,660 --> 00:10:24,020 Again, it's a total pleasure. 137 00:10:24,400 --> 00:10:26,260 You don't need to do a lot of work. 138 00:10:26,340 --> 00:10:28,220 You've got your channel with the box. 139 00:10:29,300 --> 00:10:29,780 Okay. 140 00:10:29,820 --> 00:10:33,060 So the question is, what happens when things start getting a little harder? 141 00:10:33,700 --> 00:10:39,060 A little while back, we came up against a web application, or it was actually just the 142 00:10:39,060 --> 00:10:44,840 search box of a web application, that had code similar to the pseudocode sitting behind 143 00:10:44,840 --> 00:10:45,260 it. 144 00:10:45,740 --> 00:10:46,220 Okay. 145 00:10:46,240 --> 00:10:51,140 And what you'll find, if you look at the pseudocode, is that a regular expression search is being 146 00:10:51,140 --> 00:10:57,380 done with input that the user gives it, without the user input being saved at all. 147 00:10:58,160 --> 00:10:58,280 Okay. 148 00:10:58,360 --> 00:11:04,840 So it basically gives you a chance to use malicious input, which then gets passed to 149 00:11:04,840 --> 00:11:08,540 this backend regular expression. 150 00:11:09,220 --> 00:11:16,900 So it expects a moo, or it expects something else, and instead what we do, instead what 151 00:11:16,900 --> 00:11:21,120 we do is use a regular expression for email. 152 00:11:21,120 --> 00:11:25,360 And we throw that into our browser. 153 00:11:26,020 --> 00:11:26,540 Okay. 154 00:11:26,640 --> 00:11:29,920 So, what you'll notice here, we're just throwing in the uname command. 155 00:11:31,280 --> 00:11:36,860 And uname possibly ran, but there's no way for us to get feedback to know exactly what 156 00:11:36,860 --> 00:11:37,220 happened. 157 00:11:37,720 --> 00:11:38,240 Okay. 158 00:11:38,260 --> 00:11:43,540 In our example, that box was tightly firewalled, so we found ourselves with no channel at all. 159 00:11:44,500 --> 00:11:49,860 What you did find, though, is that you're able to, instead of just asking it for a name, 160 00:11:49,860 --> 00:11:52,780 tell it to sleep 10 seconds. 161 00:11:53,940 --> 00:11:54,580 Okay. 162 00:11:54,640 --> 00:11:59,440 And what you should see down here is that the browser now hangs as this thing sleeps 163 00:11:59,440 --> 00:12:00,420 10 seconds. 164 00:12:00,740 --> 00:12:01,380 Okay. 165 00:12:01,420 --> 00:12:03,560 Which puts us in an interesting position. 166 00:12:04,220 --> 00:12:09,720 We're now able to get feedback on our command as it executed on the server. 167 00:12:10,080 --> 00:12:16,000 So instead of just telling it to sleep 10 seconds, we actually figure out that we're 168 00:12:16,000 --> 00:12:19,320 able to make our embedded command longer. 169 00:12:19,320 --> 00:12:20,160 Okay. 170 00:12:20,360 --> 00:12:25,720 So exactly the same way we said sleep 10, we're now telling Perl to call system to call 171 00:12:25,720 --> 00:12:31,380 sleep 10, which seems a little contrived, but actually the reason we're doing it is 172 00:12:31,380 --> 00:12:37,860 because we want the output of our sleep to go inside of Perl so that we can start mangling 173 00:12:37,860 --> 00:12:39,260 it on the remote system. 174 00:12:40,280 --> 00:12:40,800 Okay. 175 00:12:40,880 --> 00:12:47,920 What you'll find is this quickly leads you to much, much more complex Perl, and what 176 00:12:47,920 --> 00:12:48,780 you see down here. 177 00:12:48,780 --> 00:12:56,100 Here is us saying run the command uname, then take the first character for uname, find 178 00:12:56,100 --> 00:13:01,480 out what it is or what its ordinal value is, and then sleep its ordinal value. 179 00:13:02,100 --> 00:13:02,580 Okay. 180 00:13:02,640 --> 00:13:06,620 So then we can say sleep the first character, sleep the second character, sleep the third 181 00:13:06,620 --> 00:13:11,800 character, and we should be able to get the results of our input, should be able to get 182 00:13:11,800 --> 00:13:12,820 the results of our command. 183 00:13:13,660 --> 00:13:14,140 Okay. 184 00:13:14,200 --> 00:13:16,800 So if I could get control of my presentation again. 185 00:13:17,540 --> 00:13:18,020 Okay. 186 00:13:18,780 --> 00:13:24,400 So this leaves us with something like this, okay, a script that we run, and you can see 187 00:13:24,400 --> 00:13:31,380 it slept 83 seconds, which gives us the S, 117 seconds for the U, 110 seconds for the 188 00:13:31,380 --> 00:13:37,800 N. It's painful, but you will find that you get the result, Sanos, coming back eventually. 189 00:13:38,400 --> 00:13:40,880 Now clearly this has problems. 190 00:13:41,600 --> 00:13:43,880 Does anyone know the biggest problem with it? 191 00:13:47,560 --> 00:13:48,080 Sorry. 192 00:13:48,160 --> 00:13:48,680 Okay. 193 00:13:49,680 --> 00:13:55,520 Network delays, for sure, and the second one, which is a lot more important, our analysts 194 00:13:55,520 --> 00:13:57,580 kept falling asleep while using this attack. 195 00:13:59,260 --> 00:13:59,780 Okay. 196 00:13:59,860 --> 00:14:05,260 So the results of that uname would have taken about eight minutes, and if there were network 197 00:14:05,260 --> 00:14:06,460 delays, we were screwed. 198 00:14:06,800 --> 00:14:07,320 Okay. 199 00:14:07,340 --> 00:14:09,060 And that's because we were a little bit stupid. 200 00:14:09,660 --> 00:14:16,260 So we were sleeping the ordinal, we were sleeping 65 seconds to get the A, where with slightly 201 00:14:16,260 --> 00:14:17,860 more complex Perl. 202 00:14:17,860 --> 00:14:24,600 We could break that A down into a string of bits, and then if it was a zero, sleep zero, 203 00:14:24,840 --> 00:14:30,080 and if it's a one, sleep one, and that way, at the most, you're going to take eight seconds 204 00:14:30,080 --> 00:14:32,400 to get back a single byte. 205 00:14:33,200 --> 00:14:42,080 So at the time, we threw it into a quick script that we cunningly called one time. 206 00:14:42,440 --> 00:14:43,000 Okay. 207 00:14:43,060 --> 00:14:44,760 We're not really good at naming stuff. 208 00:14:45,520 --> 00:14:46,080 Okay. 209 00:14:46,080 --> 00:14:52,220 And basically, you told one time, run this command, and the two says, every time you 210 00:14:52,220 --> 00:14:57,480 see a one, sleep for two seconds, and every time you see a zero, sleep for zero seconds. 211 00:14:57,940 --> 00:15:02,660 And what you should find is using this, you can send whichever command you want to your 212 00:15:02,660 --> 00:15:07,820 target server, and you should get your results coming back purely via timing. 213 00:15:09,100 --> 00:15:09,580 Okay. 214 00:15:09,600 --> 00:15:14,840 We could wait for this thing to spell out Linux, but at this point, we're tight on time, so 215 00:15:14,840 --> 00:15:16,240 you're going to have to take my word for it. 216 00:15:16,840 --> 00:15:18,540 It's going all the way for Linux. 217 00:15:19,140 --> 00:15:19,600 Okay. 218 00:15:19,660 --> 00:15:20,800 I'll leave it after the end. 219 00:15:23,640 --> 00:15:24,100 Okay. 220 00:15:24,180 --> 00:15:26,480 But the concept should be pretty straightforward. 221 00:15:26,600 --> 00:15:32,300 At this point, we're making requests, timing how long it comes back, and able to infer 222 00:15:32,300 --> 00:15:34,740 whatever we need to from there. 223 00:15:35,960 --> 00:15:36,420 Okay. 224 00:15:36,440 --> 00:15:41,500 SQL injection, there was a presentation earlier today, and we're going to touch on some of 225 00:15:41,500 --> 00:15:41,940 that stuff. 226 00:15:42,300 --> 00:15:44,460 But you'll find that with SQL injection... 227 00:15:44,460 --> 00:15:44,820 Okay. 228 00:15:44,840 --> 00:15:50,160 In the past, there was the possibility that actually you'd have, you'd be able to use 229 00:15:50,160 --> 00:15:51,860 the same channel also. 230 00:15:52,260 --> 00:16:03,720 So for example, we could have done exec master dot dot xp command shell echo defcon greater 231 00:16:03,720 --> 00:16:12,060 than c inet pub wo wo wo root backslash dc dot html. 232 00:16:12,600 --> 00:16:13,380 Okay. 233 00:16:13,380 --> 00:16:18,040 And if that goes through, we should be able to go to the box. 234 00:16:18,700 --> 00:16:23,920 If my spelling was correct, we should be able to go dc dot html, and we should be able 235 00:16:23,920 --> 00:16:26,280 to use the box as our channel again. 236 00:16:27,000 --> 00:16:27,440 Okay. 237 00:16:27,500 --> 00:16:31,620 But like we said, you don't get that happening much anymore. 238 00:16:32,480 --> 00:16:32,920 Okay. 239 00:16:32,960 --> 00:16:37,840 And oftentimes, you'll find that your SQL server doesn't necessarily come back to you. 240 00:16:38,760 --> 00:16:42,780 So one of the problems you have when you're pen testing or when you're breaking into boxes, 241 00:16:43,380 --> 00:16:46,500 is you need to know whether your command executed or not. 242 00:16:47,000 --> 00:16:47,280 Okay. 243 00:16:47,300 --> 00:16:51,780 And so often what people will do is they'll try to get their target to come back and touch 244 00:16:51,780 --> 00:16:54,140 them somehow, as kinky as that sounds. 245 00:16:54,340 --> 00:16:54,860 Okay. 246 00:16:54,920 --> 00:17:01,100 So either via ping or SMB or netcat, you're going to try to elicit a response that you 247 00:17:01,100 --> 00:17:01,700 can measure. 248 00:17:02,480 --> 00:17:08,340 So what people figured out was that here again, you are in the position to use some sort 249 00:17:08,340 --> 00:17:10,260 of rudimentary timing. 250 00:17:10,660 --> 00:17:13,320 So instead of telling it to create... 251 00:17:13,320 --> 00:17:18,380 Create a file, we could have told it to ping itself 20 times. 252 00:17:19,360 --> 00:17:19,880 Okay. 253 00:17:19,920 --> 00:17:24,100 If I could type, I would tell it to ping itself 20 times. 254 00:17:24,400 --> 00:17:30,320 And then again, based on how long it took, we'd be able to say something that we did 255 00:17:30,320 --> 00:17:33,300 definitely had an effect on the server. 256 00:17:34,600 --> 00:17:35,120 Okay. 257 00:17:35,320 --> 00:17:40,180 Something else that's interesting is that you could tell it to nslookup something. 258 00:17:40,840 --> 00:17:41,360 Okay. 259 00:17:41,420 --> 00:17:41,780 Because... 260 00:17:41,780 --> 00:17:47,460 Because if you tell it to nslookup, one of the interesting properties is that with nslookup, 261 00:17:47,600 --> 00:17:54,820 even if you don't directly talk to its DNS server, its DNS server will ask its parent, 262 00:17:55,120 --> 00:18:00,440 it'll follow its DNS tree, and at some point, something will come to your name server. 263 00:18:00,820 --> 00:18:01,420 Okay. 264 00:18:01,460 --> 00:18:08,260 So you XP on it, you ask for moo-moo-moo.sensepost.com, and then you watch your name server to see 265 00:18:08,260 --> 00:18:11,300 if someone requested moo-moo-moo.sensepost.com. 266 00:18:11,300 --> 00:18:12,040 Okay. 267 00:18:12,180 --> 00:18:17,580 And this obviously becomes an interesting attack possibility for us, so it's something 268 00:18:17,580 --> 00:18:19,680 that we figured would be worth chasing. 269 00:18:25,080 --> 00:18:29,980 So when we've come across this particular problem in past assessments, typically what 270 00:18:29,980 --> 00:18:37,340 we did was someone hauled out a cmd.exe reference manual, and we'd start digging through it 271 00:18:37,340 --> 00:18:39,380 for appropriate commands that we could use. 272 00:18:39,540 --> 00:18:41,160 And the one that always comes up... 273 00:18:41,300 --> 00:18:41,400 Okay. 274 00:18:41,400 --> 00:18:42,160 ...is the for loop. 275 00:18:42,320 --> 00:18:47,820 So for instance, what we can do is construct a really bad attempt at a DNS tunnel simply 276 00:18:47,820 --> 00:18:49,240 through cmd.exe. 277 00:18:49,740 --> 00:18:58,220 So what we've got is our, again, our vulnerable website, and this line that I'm going to 278 00:18:58,220 --> 00:19:02,960 cut and paste here is, give me that. 279 00:19:03,960 --> 00:19:10,180 So this line that I'm going to cut and paste here is basically a piece of cmd.exe script. 280 00:19:10,180 --> 00:19:16,620 It's going to execute the DIR, so you'll see the DIR on your right-hand side. 281 00:19:17,800 --> 00:19:22,760 And for each token, or for each line in that directory listing, it breaks it up into tokens 282 00:19:22,760 --> 00:19:30,100 based on spaces, and then it conducts an NSLOOKUP on basically the first token to 283 00:19:30,100 --> 00:19:31,740 our domain, which is sensepost.com. 284 00:19:32,120 --> 00:19:34,500 So let's attempt that. 285 00:19:34,560 --> 00:19:38,800 What I've got to show you that everything is actually, in fact, sending DNS requests, 286 00:19:38,800 --> 00:19:40,980 is a terminal here. 287 00:19:41,420 --> 00:19:46,200 We've got tcpdump running, so you will see the request coming through. 288 00:19:54,080 --> 00:19:54,600 Okay. 289 00:19:55,600 --> 00:19:56,300 All right. 290 00:19:56,360 --> 00:19:57,240 All going well. 291 00:19:58,780 --> 00:20:06,020 What we'll see on this side are blah.text.sensepost.com, and basically we'll get that file listing, 292 00:20:06,100 --> 00:20:07,360 boot.ini and so on. 293 00:20:07,840 --> 00:20:08,360 Okay. 294 00:20:08,800 --> 00:20:10,480 And this is a little bit effective. 295 00:20:10,640 --> 00:20:14,500 We can get a basic idea of what's happening, but there are clearly problems with this approach. 296 00:20:14,780 --> 00:20:15,980 So we'll let that thing run. 297 00:20:17,640 --> 00:20:22,440 And what this process works for is for small pieces of data, so file names. 298 00:20:22,580 --> 00:20:24,660 But where it breaks are on other things. 299 00:20:24,780 --> 00:20:28,720 So if your file names contain spaces, the script will break. 300 00:20:29,080 --> 00:20:31,760 If you've got anything binary, that script's going to break. 301 00:20:31,940 --> 00:20:35,820 And also, if there's anything that you're trying to extract that's over 255 characters, 302 00:20:36,160 --> 00:20:37,080 it's going to break. 303 00:20:37,140 --> 00:20:37,800 The reason for that? 304 00:20:38,440 --> 00:20:41,160 Domain names can't be longer than 255 characters. 305 00:20:41,560 --> 00:20:44,740 So clearly, we needed to think of a better way to do this. 306 00:20:45,160 --> 00:20:49,220 And just to rehash that, what we've got is a SQL injection point. 307 00:20:49,340 --> 00:20:51,120 So we're executing code within a database. 308 00:20:51,360 --> 00:20:54,620 And we've got a method of extracting DNS queries. 309 00:20:54,980 --> 00:20:58,880 So this naturally led us to a tool we call Squeezer. 310 00:20:59,740 --> 00:21:02,800 It's inspired by the Sec1 SQL injector. 311 00:21:02,900 --> 00:21:07,720 And what it gives you is basically a very simple shell that allows you to pull server-side 312 00:21:07,800 --> 00:21:09,260 data into tables. 313 00:21:09,500 --> 00:21:15,260 So you could, for instance, execute commands, copy files, or execute SQL queries on the 314 00:21:15,260 --> 00:21:18,760 SQL server itself and dump that stuff into an intermediate table. 315 00:21:19,380 --> 00:21:24,340 And then what it also provides you with is, in this case, a DNS channel to extract that 316 00:21:24,340 --> 00:21:24,600 information. 317 00:21:25,100 --> 00:21:29,220 So SQL gives you a bunch of ways to get data into an intermediate table. 318 00:21:29,320 --> 00:21:33,760 And it also can extract it via DNS and one important other. 319 00:21:35,520 --> 00:21:37,460 Squeezer gives us binary-safe transport. 320 00:21:37,800 --> 00:21:40,180 You could do conversions of stuff to hex. 321 00:21:40,320 --> 00:21:44,020 So basically, if you want to copy out binary files, that's all possible. 322 00:21:44,220 --> 00:21:49,580 If you want to copy out or if you want to do a command execution and the output of those 323 00:21:49,580 --> 00:21:55,100 commands contains characters that are not part of DNS domain names, that's also fine. 324 00:21:55,680 --> 00:21:58,480 It also gives us a reliable transport mechanism. 325 00:21:58,620 --> 00:22:01,000 So we can implement file copy over DNS. 326 00:22:01,320 --> 00:22:03,220 DNS typically is UDP, right? 327 00:22:03,560 --> 00:22:04,920 And that's best effort. 328 00:22:05,080 --> 00:22:07,180 But Squeezer does a layer on top of that. 329 00:22:07,180 --> 00:22:08,700 That's to give us reliability. 330 00:22:09,460 --> 00:22:13,180 The requirements for Squeezer, if you want to run it, you're going to need Ruby. 331 00:22:14,060 --> 00:22:16,100 You just need a standard Ruby 1.84. 332 00:22:16,480 --> 00:22:17,480 Install should be good. 333 00:22:17,580 --> 00:22:18,720 No extra modules required. 334 00:22:19,500 --> 00:22:22,620 We use TCP dump as a quick hack to get hold of those DNS queries. 335 00:22:23,560 --> 00:22:27,440 You need access possibly to DNS server on which to run Squeezer. 336 00:22:28,160 --> 00:22:33,080 And the last point there is that you need a fairly large injection point in a vulnerable 337 00:22:33,080 --> 00:22:33,560 application. 338 00:22:34,460 --> 00:22:36,060 You're going to be asking me how large. 339 00:22:37,080 --> 00:22:41,360 We've got various injection strings, but they typically range up to about 600 bytes. 340 00:22:41,880 --> 00:22:46,500 So you're trying to do a lot of stuff in T-SQL, and this is one of the drawbacks. 341 00:22:48,040 --> 00:22:50,340 So very quickly, this is how we do things. 342 00:22:50,440 --> 00:22:52,460 We send an initial HTTP request. 343 00:22:52,580 --> 00:22:54,940 What that does is it builds that intermediate table somehow. 344 00:22:55,180 --> 00:22:58,740 And in the case I'll show you, that table's built with command execution. 345 00:22:59,340 --> 00:23:04,720 And then for each row, we've got a piece of T-SQL that takes each row in that database. 346 00:23:04,800 --> 00:23:06,040 It breaks it up into fields. 347 00:23:06,040 --> 00:23:08,920 We fixize blocks, which will fit into a domain name. 348 00:23:09,400 --> 00:23:11,180 They are the requisite length. 349 00:23:11,440 --> 00:23:12,820 It converts that to hex. 350 00:23:12,940 --> 00:23:15,920 We add a header to that, and we initiate a DNS lookup. 351 00:23:16,760 --> 00:23:21,220 And then on the client side with Squeezer, we've just got TCP dump running where we 352 00:23:21,220 --> 00:23:25,220 capture that, decode it, and store it in our reliability layer. 353 00:23:26,260 --> 00:23:29,740 And then basically, the last point there is if blocks are missing, we just re-request 354 00:23:29,740 --> 00:23:29,980 them. 355 00:23:30,120 --> 00:23:32,080 And in that way, we get our reliability. 356 00:23:34,240 --> 00:23:35,580 There's a couple of things to... 357 00:23:36,040 --> 00:23:41,320 Just keep in your mind as you think about Squeezer, the way that we get data into the 358 00:23:41,320 --> 00:23:43,520 tables is not related to the way that we get it out. 359 00:23:43,940 --> 00:23:45,320 So I can use... 360 00:23:45,320 --> 00:23:50,200 We'll talk about other channels, but DNS is one channel to extract information. 361 00:23:50,600 --> 00:23:53,000 We'll also see timing as a channel there. 362 00:23:53,180 --> 00:23:56,840 But those are not related to putting data into the intermediate table. 363 00:23:56,960 --> 00:24:00,460 So I can combine my command execution with whatever channel I want. 364 00:24:01,520 --> 00:24:06,020 The second point is that by default, we use xbcmd-shell plus nsql. 365 00:24:06,020 --> 00:24:08,940 And we can use that to do our DNS lookup to implement our DNS lookups. 366 00:24:10,580 --> 00:24:14,840 But often that stored proc isn't available or you don't have permissions and so on. 367 00:24:15,200 --> 00:24:19,980 And so the rhetorical question that I pose here, can we cause DNS requests to be initiated 368 00:24:19,980 --> 00:24:20,340 otherwise? 369 00:24:20,900 --> 00:24:23,180 I'm asking the question, so I guess there's an answer. 370 00:24:24,060 --> 00:24:25,280 The answer is of course. 371 00:24:25,620 --> 00:24:29,520 And there are a bunch of stored procs that'll happily do this for us. 372 00:24:29,640 --> 00:24:33,740 The one that we decided on was one called xbgetfiledetails. 373 00:24:34,440 --> 00:24:35,420 This is... 374 00:24:36,020 --> 00:24:37,700 A stored proc that'll take a UNC path. 375 00:24:38,380 --> 00:24:40,720 And based on that, we can initiate lookups. 376 00:24:40,960 --> 00:24:45,280 So to show you, this is the permissions on that particular stored proc. 377 00:24:45,380 --> 00:24:48,560 As you can see, all that's required is execute permissions. 378 00:24:48,760 --> 00:24:51,100 You don't have to be SA at all. 379 00:24:52,040 --> 00:24:57,300 This is an example of a path that we might pass into getfiledetails. 380 00:24:57,500 --> 00:24:58,820 You'll see it's a UNC path. 381 00:24:58,960 --> 00:25:00,940 At the beginning, we've got this header. 382 00:25:01,240 --> 00:25:04,500 And then there's this fairly long hex string, .sanspost.com. 383 00:25:04,500 --> 00:25:06,440 And a share. 384 00:25:06,640 --> 00:25:12,200 And what that does is it forces getfiledetails to attempt to first look up this particular 385 00:25:12,200 --> 00:25:12,620 machine. 386 00:25:12,940 --> 00:25:18,780 And because of the way DNS works, of course, this request will eventually wind up with 387 00:25:18,780 --> 00:25:19,120 us. 388 00:25:20,280 --> 00:25:26,100 So we're gonna do a very small demo of Squeezer to give you an idea of the test setup before 389 00:25:26,100 --> 00:25:26,740 we carry on. 390 00:25:26,960 --> 00:25:28,520 Basically, what we've got is an attacker. 391 00:25:29,180 --> 00:25:33,680 He's gonna be sending inbound TCP on port 80 to a vulnerable web server. 392 00:25:33,680 --> 00:25:37,420 Which passes SQL queries to a back-end database. 393 00:25:37,740 --> 00:25:41,560 But nothing can come out from that firewall. 394 00:25:41,820 --> 00:25:47,200 So we can't get, well, for the sake of this example, assume you can't get error messages, 395 00:25:47,380 --> 00:25:49,820 you can't get netcat tunnels, and all of that stuff. 396 00:25:50,000 --> 00:25:52,040 All we've got are DNS requests. 397 00:25:56,640 --> 00:25:57,600 Ooh, demo. 398 00:25:57,920 --> 00:25:58,480 Come here. 399 00:25:59,080 --> 00:25:59,600 Okay. 400 00:26:02,940 --> 00:26:03,660 Did you all hear that? 401 00:26:03,660 --> 00:26:04,000 Did you all see that? 402 00:26:04,640 --> 00:26:05,500 I'll try it again. 403 00:26:05,740 --> 00:26:09,800 In case you're sleeping, what we've got is some very silly ASCII art animation. 404 00:26:10,240 --> 00:26:12,000 I figure that's about the coolest thing. 405 00:26:12,000 --> 00:26:13,700 That took us the other half of our time. 406 00:26:13,960 --> 00:26:14,040 Yeah. 407 00:26:15,080 --> 00:26:15,560 Okay. 408 00:26:15,740 --> 00:26:21,120 So what we've got here with Squeezer is a simple config file. 409 00:26:23,840 --> 00:26:27,200 On the config, or in the config file, it's the typical injection type stuff. 410 00:26:27,320 --> 00:26:29,740 So it would specify a target host. 411 00:26:29,940 --> 00:26:31,780 It would specify a target URL. 412 00:26:32,440 --> 00:26:32,920 HTTP. 413 00:26:33,660 --> 00:26:34,660 HTTP methods to use. 414 00:26:35,000 --> 00:26:36,800 Vulnerable parameters and all of that stuff. 415 00:26:37,200 --> 00:26:43,960 And based on this config file, Squeezer will construct the injection requests and send 416 00:26:43,960 --> 00:26:44,840 them off for us. 417 00:26:47,640 --> 00:26:48,080 Okay. 418 00:26:50,040 --> 00:26:51,320 We are a Ruby file. 419 00:26:53,000 --> 00:26:56,700 So as I said, Squeezer's got a couple of modes that it supports. 420 00:26:56,900 --> 00:26:59,780 The one is command execution mode, and that's what we're in at the moment. 421 00:26:59,960 --> 00:27:03,640 To give you an idea, again, we've got tcpdata.com. 422 00:27:03,660 --> 00:27:04,240 tcpdump running here. 423 00:27:04,860 --> 00:27:05,880 tcpdump running here. 424 00:27:08,300 --> 00:27:09,260 That's just all good. 425 00:27:10,220 --> 00:27:11,140 We'll switch back. 426 00:27:11,480 --> 00:27:15,940 So what I'm going to do is execute a simple directory listing in C drive. 427 00:27:17,020 --> 00:27:21,540 And you'll see our tcpdump that those requests are starting to come through. 428 00:27:22,380 --> 00:27:26,040 Again, these are all hexified, so it's kind of hard to interpret. 429 00:27:26,860 --> 00:27:31,940 But Squeezer will obviously decode all of that stuff for you and provide you with the 430 00:27:31,940 --> 00:27:32,160 output. 431 00:27:34,340 --> 00:27:36,640 So we can also break this up into blocks. 432 00:27:36,760 --> 00:27:40,760 By default, Squeezer's only requesting a line at a time, but we can request five lines 433 00:27:40,760 --> 00:27:42,060 at a time and so on. 434 00:27:42,660 --> 00:27:45,380 And it supports lots of other funkiness. 435 00:27:45,500 --> 00:27:50,660 The one thing that I want to show you before we move on is it's also got a SQL extraction 436 00:27:50,660 --> 00:27:51,080 mode. 437 00:27:51,300 --> 00:27:54,540 So we've got a command mode where we can execute commands on the server. 438 00:27:54,700 --> 00:28:01,040 We've got a SQL extraction mode, which will pull out various information from the SQL 439 00:28:01,040 --> 00:28:01,360 database. 440 00:28:01,360 --> 00:28:05,660 So the one is we've got a pre-built query that will extract table names. 441 00:28:06,480 --> 00:28:14,520 The interesting thing about this particular mode, the SQL mode, is that it uses the get 442 00:28:14,520 --> 00:28:15,580 file detail stored proc. 443 00:28:15,680 --> 00:28:22,400 And you'll see that with the get file detail stored proc, we've got five requests come 444 00:28:22,400 --> 00:28:25,940 through for each domain name instead of the single one with nslookup. 445 00:28:26,080 --> 00:28:26,920 So it's slower. 446 00:28:27,040 --> 00:28:31,340 And because UNC pods are shorter than domain names, we can also extract less than one domain name. 447 00:28:31,340 --> 00:28:33,480 So we get less information at a time. 448 00:28:33,640 --> 00:28:34,520 But it is effective. 449 00:28:36,240 --> 00:28:39,180 And what we've got here are a list of the tables in the database. 450 00:28:39,440 --> 00:28:42,720 It's somewhat similar to Patrick Carlson's talk earlier. 451 00:28:42,840 --> 00:28:44,100 I don't know how many of you guys saw that. 452 00:28:44,780 --> 00:28:49,320 He's also got a similar kind of idea for extracting database schema. 453 00:28:49,680 --> 00:28:55,180 What Squeezer does support is it allows you to also execute arbitrary queries against 454 00:28:55,180 --> 00:28:55,720 the database. 455 00:28:56,020 --> 00:29:01,320 So if you find out that, you know, there's a user's table with a password and a user's 456 00:29:01,340 --> 00:29:05,400 username column, you can construct your own query quite easily. 457 00:29:05,760 --> 00:29:14,120 So the toy example I'll give here is here's a query that'll extract all of the columns 458 00:29:14,120 --> 00:29:17,340 in a particular table, the table sqcmd. 459 00:29:19,840 --> 00:29:27,080 So basically the format of your arbitrary query is a column name, table names, and a 460 00:29:27,080 --> 00:29:27,560 where clause. 461 00:29:27,900 --> 00:29:28,440 All right. 462 00:29:28,460 --> 00:29:29,640 So it's fairly rudimentary. 463 00:29:29,640 --> 00:29:32,620 But what we'll see is that it does work. 464 00:29:33,540 --> 00:29:36,980 There's the first arbitrary data that we can extract. 465 00:29:37,060 --> 00:29:40,200 It's a column name of data and so on. 466 00:29:41,900 --> 00:29:45,120 So that's basically what Squeezer gives us at this point. 467 00:29:45,260 --> 00:29:50,020 We'll talk a little bit now about the other stuff. 468 00:29:50,420 --> 00:29:50,940 Okay. 469 00:29:50,960 --> 00:29:55,440 So at this point, you should be saying, what's all this DNS stuff? 470 00:29:56,380 --> 00:29:58,780 You were told that the stuff's about timing. 471 00:29:58,980 --> 00:29:59,500 Okay. 472 00:29:59,640 --> 00:30:01,560 So the SQL, the DNS stuff is cool. 473 00:30:01,680 --> 00:30:06,380 It gives us a channel of getting stuff out using DNS, but there is a reason we bring 474 00:30:06,380 --> 00:30:06,700 it up. 475 00:30:07,180 --> 00:30:07,700 Okay. 476 00:30:07,740 --> 00:30:12,960 And that's because SQL Server also supports this wait for delay function. 477 00:30:13,520 --> 00:30:14,040 Okay. 478 00:30:14,120 --> 00:30:20,780 And there's a few injection tools out there, SQL Injector, PowerShell, SQL Ninja, SQL 479 00:30:20,780 --> 00:30:27,280 Brute, that try to use wait for delay, but most of them use them as a sort of Boolean 480 00:30:27,280 --> 00:30:27,680 operator. 481 00:30:28,000 --> 00:30:28,220 Okay. 482 00:30:28,220 --> 00:30:34,320 So they do a MISA, if I am, wait for delay 10, if I'm not, wait for zero. 483 00:30:34,940 --> 00:30:35,500 Okay. 484 00:30:35,540 --> 00:30:42,620 But if you consider that what we've learned from Squeezer 1 and consider what we figured 485 00:30:42,620 --> 00:30:49,320 out from onetime.py, you can pretty quickly put two and two together and say, we can do 486 00:30:49,320 --> 00:30:50,880 the same thing on SQL Server. 487 00:30:51,080 --> 00:30:53,020 So let's execute our commands. 488 00:30:53,440 --> 00:30:57,060 Let's dump it into a table on the database. 489 00:30:57,420 --> 00:30:57,980 Okay. 490 00:30:58,220 --> 00:31:03,860 And let's use the same sleep commands to decide how we read our output. 491 00:31:04,460 --> 00:31:04,980 Okay. 492 00:31:05,040 --> 00:31:10,320 So this gives us another chance to check a little bit of how lamely I was doing this. 493 00:31:10,900 --> 00:31:11,420 Okay. 494 00:31:11,500 --> 00:31:18,740 So the first thing we came up with was something else cunningly named another time.py. 495 00:31:19,340 --> 00:31:24,460 And what another time did was you gave it all of your details for the SQL injection 496 00:31:24,460 --> 00:31:25,020 point. 497 00:31:25,320 --> 00:31:27,860 And then you just told it the command. 498 00:31:27,860 --> 00:31:30,380 And then you told it the command that you actually wanted to get back. 499 00:31:30,840 --> 00:31:31,360 Okay. 500 00:31:31,400 --> 00:31:34,020 And pretty simply, this is doing what we discussed. 501 00:31:34,380 --> 00:31:40,560 It's going to run your command on the target server and then sleep for two seconds for 502 00:31:40,560 --> 00:31:42,460 one, sleep zero seconds for zero. 503 00:31:42,680 --> 00:31:46,860 And at this point, you're going to start to get your information back from SQL Server, 504 00:31:47,020 --> 00:31:50,400 but purely using timing as your vector. 505 00:31:50,660 --> 00:31:51,180 Okay. 506 00:31:51,260 --> 00:31:56,540 So where the previous one used DNS, in this case, you assume even DNS can't come back 507 00:31:56,540 --> 00:31:56,920 to you. 508 00:31:56,920 --> 00:32:00,200 You're just going to get your data out using timing. 509 00:32:00,840 --> 00:32:01,360 Okay. 510 00:32:01,440 --> 00:32:02,960 I'm going to kill this really quickly. 511 00:32:03,600 --> 00:32:05,980 Does anyone know where this is going to go wrong? 512 00:32:06,500 --> 00:32:07,680 It's not our guy sleeping. 513 00:32:08,160 --> 00:32:08,600 Okay. 514 00:32:08,700 --> 00:32:12,380 Again, the problem is going to be potential latency on the line. 515 00:32:15,400 --> 00:32:17,880 Which brings you to Marco's cleverness. 516 00:32:21,680 --> 00:32:22,200 Okay. 517 00:32:22,360 --> 00:32:24,780 So when we implemented this in Squeezer. 518 00:32:24,780 --> 00:32:30,500 What we figured was actually we need to think about that timing issue a little bit more. 519 00:32:30,780 --> 00:32:35,380 So I'm going to give you a brief demo of the way timing works in Squeezer. 520 00:32:35,680 --> 00:32:41,340 So what I simply do is I switch my channel from DNS to time and I can execute or we switch 521 00:32:41,340 --> 00:32:42,320 back into command mode. 522 00:32:45,300 --> 00:32:48,280 And then we can simply execute a host name. 523 00:32:49,680 --> 00:32:50,160 Now. 524 00:32:51,160 --> 00:32:52,380 As Haroon said. 525 00:32:52,380 --> 00:32:59,380 The problem with sort of specifying static values for, say, a threshold value. 526 00:32:59,480 --> 00:33:04,780 So a typical way to approach this would be to say, well, we'll ask the request to pause 527 00:33:04,780 --> 00:33:05,760 for two seconds. 528 00:33:05,900 --> 00:33:10,800 And anything that comes back over two seconds will take as a one bit. 529 00:33:10,920 --> 00:33:13,020 And anything under that will take as a zero bit. 530 00:33:13,220 --> 00:33:17,160 But the problem arises if you get a request that takes 70 seconds. 531 00:33:17,340 --> 00:33:22,100 At that point, you're not in any position to actually say if that was a zero bit or 532 00:33:22,100 --> 00:33:22,560 a one bit. 533 00:33:22,680 --> 00:33:25,980 Because there's too much, there's too big a differential there. 534 00:33:26,220 --> 00:33:27,560 Clearly something went wrong. 535 00:33:27,800 --> 00:33:32,620 So the approach that we took here was to introduce a calibration mode for the timing channel. 536 00:33:33,260 --> 00:33:37,840 And basically within the calibration mode, what we do is send out a bunch of samples. 537 00:33:38,240 --> 00:33:40,260 Sample requests for zero bits and one bits. 538 00:33:40,600 --> 00:33:42,020 And their appropriate delays. 539 00:33:42,340 --> 00:33:44,680 And we do a bit of simple stats on that. 540 00:33:44,900 --> 00:33:47,180 And what we derive are two landing pads. 541 00:33:47,600 --> 00:33:51,100 Now you'll see that over there my host name has come back. 542 00:33:51,240 --> 00:33:51,980 It's intranet-ma. 543 00:33:52,920 --> 00:33:54,920 So the timing channel clearly works. 544 00:33:55,000 --> 00:33:56,960 I can simply switch between that and DNS. 545 00:33:59,560 --> 00:34:05,180 So to get back to what I was talking about, this thing, this is in the slides if you want. 546 00:34:05,280 --> 00:34:06,020 Go and check this. 547 00:34:06,840 --> 00:34:08,880 It's basically a summary of what I said. 548 00:34:09,080 --> 00:34:11,200 But essentially what we get is this thing. 549 00:34:11,260 --> 00:34:14,760 A histogram with timings for one bits and zero bits. 550 00:34:15,420 --> 00:34:19,380 And so with a bit of simple stats, what we can do is derive two landing pads. 551 00:34:19,640 --> 00:34:20,480 One for the zero bit. 552 00:34:20,560 --> 00:34:21,200 One for the one bit. 553 00:34:21,200 --> 00:34:26,260 And then all we do is if a request lands or if a request timing lands in one of these 554 00:34:26,260 --> 00:34:29,480 landing pads, we'll treat it as either a zero bit or a one bit. 555 00:34:29,660 --> 00:34:32,940 If it does not land there, then we can simply discard it. 556 00:34:33,440 --> 00:34:38,500 And so by doing that, what we introduce is a measure of control over the timing values 557 00:34:39,060 --> 00:34:40,140 that we get back. 558 00:34:41,800 --> 00:34:43,880 A couple more things with Squeezer. 559 00:34:43,940 --> 00:34:49,700 So just very briefly, we also support the original SQL injector HTTP error message channel. 560 00:34:49,700 --> 00:34:52,040 So that means Squeezer's got three channels. 561 00:34:52,140 --> 00:34:57,140 You can get info out via DNS, via timing, and via HTTP error messages, dependent on 562 00:34:57,140 --> 00:34:57,840 your circumstances. 563 00:34:58,320 --> 00:35:04,340 It also supports file transfer, so you can copy files from a server to your local client. 564 00:35:04,720 --> 00:35:09,200 And the third point is H's word, modularitynessity. 565 00:35:10,120 --> 00:35:12,560 You can just basically keep adding on there. 566 00:35:13,200 --> 00:35:18,560 But Squeezer's hopefully written in a way that it's fairly easy to add other modules 567 00:35:18,560 --> 00:35:18,920 to it. 568 00:35:19,700 --> 00:35:22,320 So if you have multiple channels and so on, or other modes you'd like to add, it should 569 00:35:22,320 --> 00:35:23,020 be pretty simple. 570 00:35:23,200 --> 00:35:29,360 Something I'd like to point out at this stage is that clearly Squeezer is MS SQL Server 571 00:35:29,360 --> 00:35:29,700 specific. 572 00:35:30,460 --> 00:35:35,520 And that turned out because that's what we conduct our assessments against for the most 573 00:35:35,520 --> 00:35:35,740 part. 574 00:35:36,040 --> 00:35:40,140 But we believe that most of these techniques should carry over to other databases if they 575 00:35:40,140 --> 00:35:42,740 have support for most of those. 576 00:35:42,880 --> 00:35:48,120 So DNS requests and a pause, literally you just need a pause function. 577 00:35:49,000 --> 00:35:49,460 So. 578 00:35:49,700 --> 00:35:52,160 So you can find out a little more about Squeezer at that website. 579 00:35:52,480 --> 00:35:53,700 The stuff's not up there yet. 580 00:35:53,820 --> 00:35:56,900 When we get back to South Africa, we'll stick it up. 581 00:35:57,080 --> 00:36:01,380 But what you can find out, or where you will find Squeezer, currently is on our blog. 582 00:36:01,560 --> 00:36:02,480 It's posted there. 583 00:36:04,880 --> 00:36:05,360 Okay. 584 00:36:06,860 --> 00:36:09,460 So I'm going to start talking even faster. 585 00:36:11,360 --> 00:36:17,340 Timing as its own vector starts to become interesting when you application pen testing. 586 00:36:17,340 --> 00:36:23,640 And it's not just because pen testers want to write down used genetic error messages 587 00:36:23,640 --> 00:36:24,560 in their report. 588 00:36:25,040 --> 00:36:25,640 Okay. 589 00:36:25,700 --> 00:36:31,440 You'll notice that any app that betrays or tells you whether you're a valid user or not 590 00:36:31,800 --> 00:36:34,660 is giving away information that's useful as an attacker. 591 00:36:35,440 --> 00:36:36,040 Okay. 592 00:36:36,780 --> 00:36:40,260 We have, however, been saying this for a really long time. 593 00:36:40,400 --> 00:36:45,840 So it's not that common for you to find an application that'll tell you you have an incorrect 594 00:36:45,840 --> 00:36:46,580 user name. 595 00:36:46,580 --> 00:36:48,420 Or you have an incorrect password. 596 00:36:48,760 --> 00:36:54,620 Because if we were able to trivially mine usernames on your system, that would be a 597 00:36:54,620 --> 00:36:55,340 pretty big deal. 598 00:36:56,240 --> 00:37:03,160 It turns out, though, that there's often subtle timing differences for valid user 599 00:37:03,160 --> 00:37:06,780 logins when the user exists and when the user doesn't. 600 00:37:06,840 --> 00:37:09,680 We just haven't been timing them that often. 601 00:37:10,000 --> 00:37:10,600 Okay. 602 00:37:10,700 --> 00:37:16,560 You find it particularly prevalent when some sort of hardware token is being used. 603 00:37:16,560 --> 00:37:22,140 If there's a round trip time that's needed for a valid user as opposed to an invalid 604 00:37:22,140 --> 00:37:27,880 user, it's pretty easy as a remote attacker to say, when I put in this name, it took longer 605 00:37:27,880 --> 00:37:31,320 because it was going all the way to the hardware security device. 606 00:37:32,440 --> 00:37:32,720 Okay. 607 00:37:32,800 --> 00:37:36,080 So we spotted this example a little while back during testing. 608 00:37:36,740 --> 00:37:39,180 We're obviously not hitting the live site right now. 609 00:37:39,480 --> 00:37:45,460 But if you pay really careful attention, you should see that for user Bob Bob, that happens. 610 00:37:45,460 --> 00:37:51,580 And for user Marco, whatever, that took a millisecond longer. 611 00:37:52,180 --> 00:37:52,780 Okay. 612 00:37:52,840 --> 00:37:57,640 So in the example that we were looking at, you basically found yourself in a situation 613 00:37:57,640 --> 00:38:06,320 where if you threw a big enough user name, if you threw a big enough, sorry, if you threw 614 00:38:06,320 --> 00:38:14,440 a big enough user name at the target, you were actually in a position to time whether 615 00:38:14,440 --> 00:38:15,440 a user exists or not. 616 00:38:15,440 --> 00:38:18,160 I can't actually see what I called it. 617 00:38:18,880 --> 00:38:22,200 Turns out this was called yet another time. 618 00:38:22,720 --> 00:38:23,040 Okay. 619 00:38:23,100 --> 00:38:24,780 So you take yet another time. 620 00:38:24,860 --> 00:38:26,960 You pass it a huge user list. 621 00:38:27,300 --> 00:38:34,760 And basically what it does is times how long the login took to come back. 622 00:38:35,100 --> 00:38:39,660 And you can see there for user Marco, it figures that took a millisecond longer. 623 00:38:40,000 --> 00:38:41,320 It's doing some rounding. 624 00:38:41,520 --> 00:38:44,620 But basically it comes back and says that's a valid user. 625 00:38:44,620 --> 00:38:47,020 While the others were not. 626 00:38:47,940 --> 00:38:48,540 Okay. 627 00:38:48,840 --> 00:38:53,160 This becomes interesting to us and scary at the same time. 628 00:38:53,400 --> 00:38:57,580 Because we took a look at a whole bunch of popular web application scanners. 629 00:38:57,820 --> 00:39:03,540 And from the little reading that we did, none of them make any mention of ever checking 630 00:39:03,540 --> 00:39:04,540 for timing stuff. 631 00:39:04,920 --> 00:39:09,700 So they'd happily tell you that you've got a different error message for valid and invalid 632 00:39:09,700 --> 00:39:10,300 logins. 633 00:39:10,460 --> 00:39:13,540 But if that difference was coming through on a timing channel. 634 00:39:13,540 --> 00:39:15,960 Most of those scanners would be blind. 635 00:39:17,120 --> 00:39:19,100 We've got a web app scanner called Suru. 636 00:39:19,320 --> 00:39:21,860 Some of you would know we put it into Suru. 637 00:39:22,000 --> 00:39:25,540 But we've actually only put it in after we discovered this. 638 00:39:25,860 --> 00:39:29,900 So if you've got another app vendor, you should probably speak to them and have it 639 00:39:29,900 --> 00:39:31,900 built into the tool. 640 00:39:34,240 --> 00:39:38,920 Which brings us to another place where timing gets interesting. 641 00:39:39,100 --> 00:39:41,980 And that's with privacy or privacy. 642 00:39:42,600 --> 00:39:43,160 Okay. 643 00:39:43,540 --> 00:39:48,580 So for those of you who know the same origin policy, or have heard of the same origin policy, 644 00:39:49,320 --> 00:39:52,140 basically it was there to protect you online. 645 00:39:52,300 --> 00:39:57,420 It said, if you get script from my page, my script shouldn't be able to figure out 646 00:39:57,420 --> 00:40:00,560 stuff about what you're doing on some other page. 647 00:40:01,200 --> 00:40:01,580 Okay. 648 00:40:01,580 --> 00:40:06,320 So the question is, how did Jeremiah and those other clever guys figure out how to do the 649 00:40:06,320 --> 00:40:07,580 port scanning coolness? 650 00:40:07,840 --> 00:40:11,760 And Marco already told you they used some sort of timing. 651 00:40:11,920 --> 00:40:12,440 Okay. 652 00:40:12,440 --> 00:40:18,020 They said, go fetch this resource, and we'll time it, and based on time, we'll figure some 653 00:40:18,020 --> 00:40:18,600 stuff out. 654 00:40:18,940 --> 00:40:25,120 Because it turns out that the same origin policy doesn't really work for timing stuff. 655 00:40:25,440 --> 00:40:32,520 So it does allow me to time what's going on on another page, even though the same origin 656 00:40:32,520 --> 00:40:33,580 policy is in place. 657 00:40:34,640 --> 00:40:35,060 Okay. 658 00:40:35,120 --> 00:40:41,360 So after Jeremiah and them came out with port scanning, there was the history hacks where 659 00:40:41,360 --> 00:40:46,360 they basically tried to figure out using CSS, if you had visited another page or not. 660 00:40:47,000 --> 00:40:53,180 In honesty, like Marco said, way back in 2000, Felton had figured some of that stuff out. 661 00:40:53,580 --> 00:40:59,800 And basically what he did was, he tried to make a request to Scientology.org, logo.gif, 662 00:40:59,960 --> 00:41:06,420 figured it took 80 milliseconds, sent you a Java applet, and if you got it in 10 milliseconds, 663 00:41:06,980 --> 00:41:08,780 he said you got it from your cache. 664 00:41:09,000 --> 00:41:11,340 So clearly you visited Scientology.org. 665 00:41:12,300 --> 00:41:12,620 Okay. 666 00:41:15,400 --> 00:41:19,280 At this point during our testing, we were actually really excited. 667 00:41:19,480 --> 00:41:21,240 We thought we invented a new acronym. 668 00:41:21,620 --> 00:41:24,560 So we thought we invented cross-site request timing. 669 00:41:25,340 --> 00:41:31,280 Unfortunately, Andrew Bortz, earlier this year, at a conference, published it and discussed 670 00:41:31,280 --> 00:41:31,680 it. 671 00:41:32,020 --> 00:41:38,940 And we did pretty much the same vector as he did, which basically says, if you visited 672 00:41:38,940 --> 00:41:41,100 LinkedIn, or in this case... 673 00:41:41,360 --> 00:41:41,820 Facebook. 674 00:41:42,620 --> 00:41:48,060 And if you made a request for friends.php, if you were logged in, you would get this 675 00:41:48,060 --> 00:41:50,860 page, which is a whole bunch of HTML. 676 00:41:51,220 --> 00:41:55,700 And if you weren't, you'd get this page, which is a very terse, you are not logged 677 00:41:55,700 --> 00:41:56,240 in message. 678 00:41:56,760 --> 00:41:57,240 Okay. 679 00:41:57,280 --> 00:42:02,160 So obviously if I was timing stuff, I'd be able to figure out whether you were logged 680 00:42:02,160 --> 00:42:06,240 in or not based on how long that page took to load in your browser. 681 00:42:07,160 --> 00:42:07,640 Okay. 682 00:42:07,760 --> 00:42:08,800 So really simple. 683 00:42:08,880 --> 00:42:10,140 You visit my page. 684 00:42:10,320 --> 00:42:10,640 Okay. 685 00:42:11,360 --> 00:42:12,020 You make a request there. 686 00:42:12,220 --> 00:42:14,800 And I figure out if you logged in to Facebook or not. 687 00:42:15,840 --> 00:42:19,680 There's a small problem that needs overcoming, and that's line latency. 688 00:42:20,900 --> 00:42:24,960 In South Africa, it takes us about a minute anyway to surf to anything. 689 00:42:25,420 --> 00:42:28,260 And so we needed something to normalize that. 690 00:42:29,080 --> 00:42:33,760 So what we do basically is introduce the concept of a base page. 691 00:42:34,200 --> 00:42:35,500 So you come to us. 692 00:42:35,600 --> 00:42:38,540 We tell you fetch friends.php. 693 00:42:38,660 --> 00:42:39,660 But also... 694 00:42:39,660 --> 00:42:40,040 Okay. 695 00:42:40,040 --> 00:42:44,060 We also fetch login.php, for example. 696 00:42:44,300 --> 00:42:51,520 And based on the ratio of those two pages, we get a latency-neutral way of determining 697 00:42:51,520 --> 00:42:54,000 whether you are logged in or whether you aren't. 698 00:42:54,740 --> 00:42:57,280 The question down there is what about cached pages? 699 00:42:57,900 --> 00:42:59,560 We get to handle it simply. 700 00:42:59,620 --> 00:43:04,840 So we have you load the pages twice so that we're always getting your timing off your 701 00:43:04,840 --> 00:43:05,540 cached page. 702 00:43:05,740 --> 00:43:08,700 And whether you cache it or not doesn't make a difference to us. 703 00:43:09,380 --> 00:43:09,920 Okay. 704 00:43:10,040 --> 00:43:15,980 So the quick example we're going to look at here is a webmail system. 705 00:43:17,480 --> 00:43:19,360 I'm going to quickly log into it. 706 00:43:19,440 --> 00:43:20,940 And actually, this is the trickiest part. 707 00:43:21,140 --> 00:43:22,320 Webmail sometimes breaks. 708 00:43:23,260 --> 00:43:23,740 Okay. 709 00:43:23,800 --> 00:43:26,120 So what you've got here is pretty straightforward. 710 00:43:26,280 --> 00:43:27,660 A guy logged in to webmail. 711 00:43:28,260 --> 00:43:29,760 He visits my page. 712 00:43:30,300 --> 00:43:33,760 And my JavaScript basically loads two frames. 713 00:43:34,100 --> 00:43:37,440 One is the base page, and the other is his inbox. 714 00:43:37,860 --> 00:43:39,520 And based on that, I say... 715 00:43:39,520 --> 00:43:39,960 Yep. 716 00:43:40,140 --> 00:43:41,660 You are logged in to webmail. 717 00:43:42,080 --> 00:43:42,600 Okay. 718 00:43:42,660 --> 00:43:45,780 And so we can test that and sign him out. 719 00:43:46,600 --> 00:43:53,160 And hopefully, reloading this page should come back and say, sorry, you're not logged 720 00:43:53,160 --> 00:43:54,340 in to webmail anymore. 721 00:43:55,260 --> 00:43:55,780 Okay. 722 00:43:55,820 --> 00:44:03,320 So like the slide says, this is entirely underwhelming because we're now able to tell someone on 723 00:44:03,320 --> 00:44:06,060 a web page whether he is or isn't logged in to webmail. 724 00:44:06,460 --> 00:44:06,980 Okay. 725 00:44:07,040 --> 00:44:08,500 But why this is interesting? 726 00:44:08,600 --> 00:44:09,120 Okay. 727 00:44:09,520 --> 00:44:16,920 Because we can actually export this information so that an attacker sitting out there on the 728 00:44:16,920 --> 00:44:23,140 Internet is able to now figure out if the user is or isn't logged in. 729 00:44:23,680 --> 00:44:23,960 Okay. 730 00:44:24,020 --> 00:44:28,820 So what you're seeing is the request going to a complete stranger saying, yes, this guy 731 00:44:28,820 --> 00:44:30,800 is logged in, or no, he isn't. 732 00:44:33,620 --> 00:44:34,180 Okay. 733 00:44:34,280 --> 00:44:38,500 So if we summarize all of the things that we've spotted really quickly... 734 00:44:38,500 --> 00:44:41,560 You'll see a whole bunch of things starting to converge. 735 00:44:42,340 --> 00:44:48,200 Firstly, you have sites on the Internet that'll tell you whether a user does exist or not 736 00:44:48,680 --> 00:44:49,680 based on timing. 737 00:44:50,380 --> 00:44:55,860 Then you've got something worse, is that you can figure out whether a session is valid 738 00:44:55,860 --> 00:44:58,260 or not effectively based on timing. 739 00:44:58,680 --> 00:45:04,520 And then you get the last bit, which says instead of using my timing, I can use your 740 00:45:04,520 --> 00:45:08,400 browser to figure out whether someone's logged in or not. 741 00:45:13,100 --> 00:45:13,740 Okay. 742 00:45:15,700 --> 00:45:22,460 So really quickly, this allows us to introduce the last part of our acronym, which is distributed 743 00:45:22,460 --> 00:45:24,020 cross-site request timing. 744 00:45:24,500 --> 00:45:30,840 So basically, if you remember with timing.py, I could determine if a user existed or not. 745 00:45:31,120 --> 00:45:37,280 But now with JavaScript, instead of running the Python on my box, I can run it in JavaScript 746 00:45:37,280 --> 00:45:40,560 on your box when you visit my web page. 747 00:45:41,220 --> 00:45:41,440 Okay. 748 00:45:41,520 --> 00:45:45,920 The small problem you have is JavaScript's timer is not granular enough. 749 00:45:46,900 --> 00:45:54,080 Fortunately, a little while back, Lars Kinderman found that you could call Java applets directly, 750 00:45:54,360 --> 00:45:59,140 and it's the trick that Jeremiah and PDP and guys use to get your IP address. 751 00:45:59,560 --> 00:46:06,860 So we use the same trick to import java.lang.net system's nano timer, so we get a much higher 752 00:46:06,860 --> 00:46:09,180 res timer inside our script. 753 00:46:10,700 --> 00:46:13,400 Proof is that's a small number and that's a bigger number. 754 00:46:14,500 --> 00:46:15,060 Okay. 755 00:46:15,280 --> 00:46:21,640 But effectively, what it allows us to do is have you visit us, we send you JavaScript, 756 00:46:22,660 --> 00:46:29,060 you run JavaScript trying to run a whole bunch of brute force attacks based on timing, and 757 00:46:29,060 --> 00:46:32,980 once you get a success, you come back and tell us whether it succeeds or not. 758 00:46:33,740 --> 00:46:34,300 Okay. 759 00:46:34,380 --> 00:46:36,840 Which brings us to this last script. 760 00:46:36,860 --> 00:46:44,180 This is a screen which, if you look at what's going on down here, we basically load, so 761 00:46:44,180 --> 00:46:51,120 some guy visits us, we send down this JavaScript, and basically all this JavaScript is doing 762 00:46:51,590 --> 00:46:57,700 is trying a whole bunch of usernames in that user's browser, and as soon as it actually 763 00:46:57,700 --> 00:47:03,420 finds valid usernames, it then comes back to us and says, hey, okay, this is going to 764 00:47:03,420 --> 00:47:04,320 go horribly . 765 00:47:04,320 --> 00:47:04,500 Okay. 766 00:47:04,500 --> 00:47:10,940 It's going to come back and say, when I found, when I tried user Haroon, I actually found 767 00:47:10,940 --> 00:47:13,460 that user Haroon existed on the system. 768 00:47:14,100 --> 00:47:14,620 Okay. 769 00:47:14,660 --> 00:47:19,340 So there's username Marco and there's username Haroon coming through. 770 00:47:20,380 --> 00:47:21,000 Okay. 771 00:47:21,060 --> 00:47:25,300 So effectively, we're looking at this video here. 772 00:47:26,020 --> 00:47:32,080 We either inject our cross-site scripting onto some popular page, get ourselves upvoted 773 00:47:32,080 --> 00:47:33,440 on Reddit or Slashdot. 774 00:47:33,440 --> 00:47:36,260 A post like Microsoft sucks should go a long way. 775 00:47:37,920 --> 00:47:39,460 Guys browse our site. 776 00:47:39,600 --> 00:47:42,700 As they get to us, we send them user lists. 777 00:47:43,020 --> 00:47:43,440 Okay. 778 00:47:43,700 --> 00:47:50,560 And everyone who visits our site becomes our zombie, trying to log into this victim application. 779 00:47:51,120 --> 00:47:57,380 As soon as they find a user that exists based on timing, they send the success back to us. 780 00:47:58,220 --> 00:47:59,680 Effectively, we've done nothing. 781 00:47:59,900 --> 00:48:01,460 You can't shut them down. 782 00:48:01,540 --> 00:48:02,840 You're trying to shut down the Internet. 783 00:48:02,840 --> 00:48:07,220 They come back to us with valid users or valid sessions. 784 00:48:08,220 --> 00:48:08,760 Okay. 785 00:48:08,860 --> 00:48:14,360 So really quickly, in conclusion, if you're developing, you need to make sure that you're 786 00:48:14,360 --> 00:48:18,120 not throwing information away via silly timing channels. 787 00:48:18,700 --> 00:48:24,200 You need to look at cross-site request forgery because lots of this uses the same sort of 788 00:48:24,200 --> 00:48:24,500 thinking. 789 00:48:25,660 --> 00:48:32,000 Network admins, you need to re-look at least privilege, figure out whether your SQL server 790 00:48:32,000 --> 00:48:32,820 really needs it. 791 00:48:32,840 --> 00:48:37,380 You need to make DNS requests at all to stop the DNS channel. 792 00:48:37,760 --> 00:48:43,640 You need to be watching your network to look for timing stuff going through. 793 00:48:44,400 --> 00:48:50,080 If you're pen testing, if you're a researcher, some interesting area for research is going 794 00:48:50,080 --> 00:48:56,020 to be injecting fake headers into XSS because if you can do that, this whole attack goes 795 00:48:56,020 --> 00:48:57,440 into a whole different space. 796 00:48:57,700 --> 00:49:00,080 You can basically brute session IDs. 797 00:49:00,560 --> 00:49:01,980 The world's your oyster. 798 00:49:02,180 --> 00:49:02,820 Okay. 799 00:49:02,840 --> 00:49:03,660 So we're going to keep it this way. 800 00:49:03,660 --> 00:49:05,740 Grab a copy of Squeezer from our blog. 801 00:49:06,180 --> 00:49:07,280 Send us feedback. 802 00:49:07,580 --> 00:49:09,680 We'll make sure we make Marco work on it. 803 00:49:09,780 --> 00:49:11,480 He doesn't have a social life anyway. 804 00:49:13,060 --> 00:49:13,540 It's true. 805 00:49:15,160 --> 00:49:17,060 Ad modules, drop us feedback. 806 00:49:17,820 --> 00:49:19,080 Visit us on the blog. 807 00:49:19,300 --> 00:49:21,360 We don't get enough mail, so spam us anytime. 808 00:49:22,480 --> 00:49:26,360 And if you've got questions, we'll be down in the question room.