1 00:00:00,600 --> 00:00:02,160 Okay, good afternoon everyone. 2 00:00:03,880 --> 00:00:06,380 I'd like to apologize for the quality of the audio. 3 00:00:06,620 --> 00:00:09,180 It's not actually the mic, it's me that's lost my voice. 4 00:00:10,280 --> 00:00:13,820 We don't have a lot of time, so we'll blitz through lots of this. 5 00:00:14,220 --> 00:00:19,940 SensePost is a small security company based primarily out of South Africa. 6 00:00:20,460 --> 00:00:23,380 We've been speaking at DEF CON for about the last seven years, 7 00:00:24,340 --> 00:00:26,640 which kind of explains why my voice is gone. 8 00:00:27,680 --> 00:00:32,440 So, on my left is Marco, Senior SensePost Associate. 9 00:00:32,720 --> 00:00:33,120 Hello. 10 00:00:34,740 --> 00:00:35,620 I'm Harun. 11 00:00:35,660 --> 00:00:39,940 For those guys down there, the scratchy voice, the tuft of hair you see over the podium is me. 12 00:00:41,320 --> 00:00:46,840 What the talk's about is, chiefly, some new tools that we've released, 13 00:00:47,100 --> 00:00:49,180 some new ways of getting in and out of your network. 14 00:00:49,960 --> 00:00:54,740 Once we've got a small foothold, how to effectively drive a bus through it. 15 00:01:00,300 --> 00:01:05,100 Okay, so we're going to be doing this chair-switching thing just because we're driving off one notebook. 16 00:01:05,420 --> 00:01:07,820 So give us three seconds in between that. 17 00:01:08,300 --> 00:01:15,100 What we're going to start off very quickly is with a brief history of how you've traditionally got network traffic 18 00:01:15,100 --> 00:01:17,360 into and out of target networks. 19 00:01:17,600 --> 00:01:21,400 And in the pre-firewall days, if anyone can still remember those, 20 00:01:21,980 --> 00:01:26,420 most machines had publicly addressable IPs, or at least they were rootable. 21 00:01:27,080 --> 00:01:29,480 And we could send our traffic directly there. 22 00:01:29,940 --> 00:01:32,900 And that also gave us unfirewalled access to the rest of the network. 23 00:01:32,980 --> 00:01:33,540 Happy days. 24 00:01:34,300 --> 00:01:38,180 Of course, people realized pretty quickly that that was a gaping flaw. 25 00:01:38,340 --> 00:01:44,540 And so we found firewalls were deployed, and that would have prevented inbound traffic. 26 00:01:44,760 --> 00:01:48,480 But for a long time, outbound traffic was still allowed. 27 00:01:48,640 --> 00:01:55,200 So we saw a plethora of tools being developed, mostly supporting command execution through websites. 28 00:01:55,260 --> 00:01:56,620 So the upload of... 29 00:01:56,640 --> 00:01:57,720 Some kind of web shell. 30 00:01:58,380 --> 00:02:04,080 And if you had an outbound channel, or if outbound traffic was allowed through the firewall, 31 00:02:04,320 --> 00:02:08,980 you could easily set up your Netcat and once again get to a pretty comfortable place. 32 00:02:10,780 --> 00:02:14,460 That continued with the creation of binaries on the machine. 33 00:02:14,640 --> 00:02:19,280 So where you would need to upload Netcat, there were a bunch of tricks to upload. 34 00:02:19,760 --> 00:02:23,500 One was to use debug.exe on the Windows platform. 35 00:02:23,760 --> 00:02:25,440 Use that to write out binaries. 36 00:02:25,480 --> 00:02:26,620 Others were to upload... 37 00:02:27,400 --> 00:02:28,900 Specific upload pages. 38 00:02:29,400 --> 00:02:37,580 We also saw the notion of binding in front of open ports around 98. 39 00:02:37,780 --> 00:02:42,660 So these were all sort of traditional ways of passing your traffic into and out of networks. 40 00:02:44,420 --> 00:02:46,720 But none of these things really work today. 41 00:02:48,860 --> 00:02:52,140 At some point, this thing got classified as a Web 2.0 talk. 42 00:02:52,840 --> 00:02:56,140 And we figured it's because we had the words AJAX somewhere. 43 00:02:56,640 --> 00:02:57,300 We had the words in our slide deck. 44 00:02:57,480 --> 00:02:59,540 This is the one slide where you'll see AJAX. 45 00:02:59,640 --> 00:03:00,360 You won't see it again. 46 00:03:01,700 --> 00:03:04,660 What this slide introduces is just... 47 00:03:04,660 --> 00:03:06,820 Again, it's another web shell. 48 00:03:07,020 --> 00:03:14,520 In this case, though, what we've got is a JSP that uses XML HTTP request object 49 00:03:14,520 --> 00:03:18,340 to actually execute the shell that you need. 50 00:03:19,440 --> 00:03:20,300 Same screen. 51 00:03:21,540 --> 00:03:23,100 So let's figure this. 52 00:03:25,280 --> 00:03:26,620 I'm going to WebKit. 53 00:03:26,640 --> 00:03:27,400 Yep. 54 00:03:27,460 --> 00:03:27,780 Okay. 55 00:03:27,880 --> 00:03:29,980 So this is our web shell. 56 00:03:30,820 --> 00:03:35,120 It's a JSP file that we've uploaded to a target web server. 57 00:03:35,380 --> 00:03:39,140 Harun's going to speak a little bit about how you can actually get the JSP on the web server. 58 00:03:39,280 --> 00:03:47,900 But in this case, we can run our regular commands as if it were... 59 00:03:48,980 --> 00:03:53,260 If I could type, we'd see this is a regular Unix shell. 60 00:03:53,320 --> 00:03:54,900 It just gives you that web interface. 61 00:03:55,160 --> 00:03:56,260 So again, nothing new. 62 00:03:56,640 --> 00:03:58,660 But in that case, it's got a bit of AJAX. 63 00:03:58,780 --> 00:04:01,580 So it's a Web 2.0 talk, apparently. 64 00:04:02,760 --> 00:04:08,720 So we saw those traditional ways of getting data into networks and out of networks. 65 00:04:09,700 --> 00:04:13,700 We also saw a while back sort of the notion of pivot machines, 66 00:04:13,980 --> 00:04:18,560 whereby you compromised a particular machine that you had access to and had a channel to 67 00:04:18,560 --> 00:04:22,400 and used that to pivot traffic around the networks. 68 00:04:22,460 --> 00:04:26,240 In other words, TCP port redirectors for the most part. 69 00:04:27,180 --> 00:04:29,840 And so this was possible in a number of ways. 70 00:04:29,980 --> 00:04:32,940 SensePost had an early tool called QuickKill. 71 00:04:33,260 --> 00:04:39,760 It was also possible through a bunch of NetCat instances for the really ghetto attempt. 72 00:04:41,140 --> 00:04:42,880 SensePost had another tool called TCPR. 73 00:04:43,120 --> 00:04:44,140 FoundStone had Fpipe. 74 00:04:44,680 --> 00:04:48,080 And Harun specifically asked me to mention the word Circa. 75 00:04:48,160 --> 00:04:53,640 So I say that the tools were Circa 2000, and I should still have a job when we get back. 76 00:04:55,040 --> 00:04:56,620 So how do these tools work? 77 00:04:56,620 --> 00:04:57,940 Well, pretty simple. 78 00:04:58,080 --> 00:04:59,420 You have a client on the left. 79 00:04:59,720 --> 00:05:01,000 That's the attacker. 80 00:05:01,160 --> 00:05:02,580 On the right-hand side, you have a target. 81 00:05:02,780 --> 00:05:06,320 The client doesn't have a direct route to the target. 82 00:05:06,620 --> 00:05:10,300 The target's listening on a specific port, though, that the client wants to speak to. 83 00:05:10,560 --> 00:05:13,540 What the client does have is access to a pivot in the middle. 84 00:05:13,720 --> 00:05:16,820 So he uploads and runs his tool, TCPR. 85 00:05:17,160 --> 00:05:19,340 That tool listens on a given TCP port. 86 00:05:19,840 --> 00:05:22,360 The client makes a connection to that TCP port. 87 00:05:22,660 --> 00:05:26,440 And the pivot on the other side makes a socket connection. 88 00:05:26,620 --> 00:05:29,420 And then in the middle, you have this pivot. 89 00:05:29,560 --> 00:05:31,240 It acts as basically a proxy. 90 00:05:31,900 --> 00:05:34,680 And it can pass traffic between client and target. 91 00:05:34,820 --> 00:05:35,560 Nothing new. 92 00:05:36,440 --> 00:05:45,160 One point to mention at this stage is that today, people are still looking for Fpipe, TCPR, and those kind of tools. 93 00:05:45,340 --> 00:05:51,840 If the machine you're attacking is XP or Win2K3, look into NetSH and PortProxy. 94 00:05:52,040 --> 00:05:56,100 When you install IPv6 on Windows, those particular versions, 95 00:05:56,620 --> 00:06:00,600 you get a TCP port redirector by default on the OS. 96 00:06:00,820 --> 00:06:01,960 So look into it. 97 00:06:03,120 --> 00:06:08,620 The next option for these pivot techniques is through the use of SSH. 98 00:06:08,640 --> 00:06:14,100 And we're mostly all familiar with SSH and its ability to tunnel traffic. 99 00:06:15,840 --> 00:06:19,400 So, again, with the same situation, we have a client pivot and target. 100 00:06:20,260 --> 00:06:24,840 In this case, the pivot, which is the machine that the attacker has access to, 101 00:06:25,000 --> 00:06:26,600 it runs a secure shell. 102 00:06:26,600 --> 00:06:29,440 And it listens by default, of course, on port 22. 103 00:06:30,060 --> 00:06:33,680 The pivot has access to a target that's inside the network. 104 00:06:34,320 --> 00:06:36,600 And in this case, it's listening on port 25. 105 00:06:37,700 --> 00:06:45,080 So if the client has credentials for the SSH server, the client can log in with the minus L flag. 106 00:06:45,480 --> 00:06:48,260 He sets up a local listener on the client. 107 00:06:49,900 --> 00:06:55,040 And once the SSH connection is made through the pivot, the pivot makes a socket connection on the other side. 108 00:06:55,040 --> 00:07:01,300 And SSH will carry your traffic from the client all the way through to the target quite nicely. 109 00:07:02,600 --> 00:07:07,960 So it gives you an encrypted tunnel onto your target network, but it's not particularly useful. 110 00:07:08,120 --> 00:07:16,960 And the reason for that is it requires that the target runs or the pivot machine runs a secure shell daemon that you also have credentials for. 111 00:07:18,200 --> 00:07:20,140 So that can raise a number of barriers. 112 00:07:20,540 --> 00:07:23,240 So the second option is to flip that around. 113 00:07:23,420 --> 00:07:24,380 Not use minus L. 114 00:07:24,440 --> 00:07:25,020 Use minus L. 115 00:07:25,560 --> 00:07:28,940 Minus R creates a remote listener instead of a local listener. 116 00:07:29,300 --> 00:07:36,900 So in this case, what we do is we run the secure shell daemon at the attacker side in the middle, which is the pivot machine. 117 00:07:36,980 --> 00:07:39,220 We simply upload an SSH client. 118 00:07:39,440 --> 00:07:44,740 So we don't actually have to install services or allow for inbound connections. 119 00:07:45,040 --> 00:07:47,300 In this case, we can make outbound connections. 120 00:07:47,820 --> 00:07:51,580 So PuTTY and PLink are two easy ones for Windows-based attacks. 121 00:07:53,520 --> 00:07:55,020 So as I said... 122 00:07:55,020 --> 00:07:57,900 The SSHD runs on the local machine. 123 00:07:58,180 --> 00:07:59,560 It listens on port 22. 124 00:07:59,780 --> 00:08:02,220 Pivot runs on the... 125 00:08:02,220 --> 00:08:03,880 Or SSH client runs on the pivot. 126 00:08:04,080 --> 00:08:08,080 And on the far side, we have the target, which is running, in this case, RDP. 127 00:08:10,300 --> 00:08:16,200 So through our command execution vulnerability, which is assumed at this point, we run SSH... 128 00:08:18,000 --> 00:08:20,920 We run SSH from the pivot. 129 00:08:21,320 --> 00:08:24,740 The pivot connects outbound to our SSHD. 130 00:08:24,740 --> 00:08:28,580 It sets up a remote listener on the attacker's machine. 131 00:08:28,780 --> 00:08:31,660 And it creates the socket on the other side to the target. 132 00:08:31,820 --> 00:08:36,200 And now the attacker can still connect locally to his machine and have traffic go all the way through. 133 00:08:36,400 --> 00:08:41,660 The benefit with this, just to recap that, is you don't need A, an SSHD on your target. 134 00:08:41,760 --> 00:08:46,460 And B, you don't need inbound connectivity on port 22. 135 00:08:48,900 --> 00:08:53,840 One other option for carrying traffic is DNS to TCP. 136 00:08:54,020 --> 00:08:54,720 Which, if you have... 137 00:08:54,720 --> 00:08:56,120 If you haven't looked at it, is really, really useful. 138 00:08:57,660 --> 00:09:01,060 So DNS proxied over a bunch of protocols is fairly old. 139 00:09:01,320 --> 00:09:02,860 But it's still extremely useful. 140 00:09:03,060 --> 00:09:09,180 DNS is often one of the few protocols that is allowed out of a network from any point. 141 00:09:09,680 --> 00:09:13,800 So DNS to TCP allows you to carry TCP data over DNS. 142 00:09:14,740 --> 00:09:15,880 Check out the website. 143 00:09:16,160 --> 00:09:21,640 It's really good if you're in limited hotspots for getting Wi-Fi access for free. 144 00:09:22,680 --> 00:09:24,300 So what we have here is... 145 00:09:24,300 --> 00:09:31,820 We're going to use a combination of DNS to TCP and the latter secure shell proxy technique. 146 00:09:32,160 --> 00:09:39,820 So in other words, we are going to upload to our target both the DNS to TCP client as well as the secure shell client. 147 00:09:39,980 --> 00:09:46,800 The reason for this is we're now going to remove the explicit requirement for outbound secure shell access. 148 00:09:47,240 --> 00:09:52,620 So where the only tunnel or the only traffic that's allowed out of your network is DNS, 149 00:09:52,760 --> 00:09:54,140 we can still proxy. 150 00:09:54,300 --> 00:09:56,200 We can still proxy traffic over secure shell. 151 00:09:56,380 --> 00:09:57,300 So it's pretty simple. 152 00:09:57,420 --> 00:10:05,120 Set up your DNS to TCP tunnel outbound from the target to a DNS server that you control. 153 00:10:05,420 --> 00:10:10,420 Over that, you run that secure shell minus R attack that I spoke about. 154 00:10:13,060 --> 00:10:17,840 The attacker would connect to the listening end of that secure shell tunnel. 155 00:10:18,080 --> 00:10:21,800 And still now, he has a way to get his traffic into and out of the network. 156 00:10:22,180 --> 00:10:24,280 And in this case, we're using a... 157 00:10:24,300 --> 00:10:28,700 A combination of, as I said, secure shell and DNS to TCP. 158 00:10:29,640 --> 00:10:34,320 Taking one more step lower in terms of the protocol stack, 159 00:10:34,580 --> 00:10:39,460 some of you guys probably would have mentioned layer two bridges if we hadn't, so we will. 160 00:10:41,580 --> 00:10:48,440 One option is when connecting to target networks, one option is to connect to specific ports and IPs, 161 00:10:48,460 --> 00:10:50,660 which is what secure shell allows you to do. 162 00:10:50,760 --> 00:10:54,280 So you set up a tunnel between yourself and a very specific network. 163 00:10:54,300 --> 00:10:58,060 But if you bridge the two networks at layer two, 164 00:10:58,760 --> 00:11:06,600 then you're in a much better place to explore the remote network without having to explicitly point your tunnel at a particular host. 165 00:11:06,820 --> 00:11:10,960 So there's a couple of limitations, but it can be quite useful. 166 00:11:11,140 --> 00:11:13,980 It does require both inbound and outbound connection ability. 167 00:11:14,980 --> 00:11:16,900 So here's the quick schematic. 168 00:11:17,040 --> 00:11:21,780 You've got access through some network and a firewall onto a target machine. 169 00:11:22,320 --> 00:11:24,020 A victim, it sits in a LAN. 170 00:11:24,300 --> 00:11:28,040 You're going through a firewall at this point because you're allowed to. 171 00:11:28,660 --> 00:11:34,100 And what a layer two bridge will turn that victim into is a gateway onto the remote network. 172 00:11:34,320 --> 00:11:37,760 So in that case, you can still access all the machines on that network. 173 00:11:37,940 --> 00:11:39,100 There's a couple of pros here. 174 00:11:39,160 --> 00:11:40,720 As I said, it's protocol independent. 175 00:11:41,000 --> 00:11:44,720 It's carrying layer two traffic, not layer three, which is pretty cool. 176 00:11:44,880 --> 00:11:46,240 It's simple to use and set up. 177 00:11:46,400 --> 00:11:50,460 But any decent firewall rule set will cancel this out. 178 00:11:51,200 --> 00:11:54,140 There's a couple of examples of layer two bridges. 179 00:11:54,300 --> 00:11:57,440 Strat and MyNetwork are two of the more common ones. 180 00:12:00,520 --> 00:12:00,960 Okay. 181 00:12:02,300 --> 00:12:04,140 So just a quick recap. 182 00:12:04,300 --> 00:12:08,380 We used to be able to hit everything we wanted to way back in the old days. 183 00:12:09,820 --> 00:12:10,880 Firewalls were more forgiving. 184 00:12:11,060 --> 00:12:11,740 All was good. 185 00:12:12,860 --> 00:12:15,080 Outbound access made us amazingly happy. 186 00:12:15,120 --> 00:12:17,560 So we could tunnel stuff as long as we could go outbound. 187 00:12:18,460 --> 00:12:24,280 But these days, most networks you care to hit will be under slightly tighter lock and key. 188 00:12:24,840 --> 00:12:29,840 So what we're looking for is some way to do all of this cleanly over HTTP. 189 00:12:31,300 --> 00:12:43,220 So if we take a look at what started its life off as glenn.jsp, effectively the scenario we're looking at is we can hit our target on port 80. 190 00:12:43,760 --> 00:12:47,680 We have the ability to upload files on the server. 191 00:12:47,820 --> 00:12:50,500 But all we can do is hit it on 80. 192 00:12:51,040 --> 00:12:51,580 Okay. 193 00:12:51,600 --> 00:12:54,260 There's tons of ways that you get upload access. 194 00:12:54,260 --> 00:13:01,620 These days, if you search for JMX console, you'll still find a ton of them that allow file uploads. 195 00:13:02,620 --> 00:13:04,760 So network filtering is tight. 196 00:13:05,000 --> 00:13:06,900 We can't make outbound connections. 197 00:13:07,120 --> 00:13:08,860 We can't make other inbound connections. 198 00:13:09,440 --> 00:13:11,480 There's possible proxies in between. 199 00:13:11,640 --> 00:13:14,820 So we need to talk good HTTP to our target. 200 00:13:15,320 --> 00:13:19,320 We can't get Netcat to just bind in front and give us a shell. 201 00:13:19,580 --> 00:13:24,240 So all of these problems met one really smart internet sense problem. 202 00:13:24,260 --> 00:13:29,420 So what we ended up with is something that's currently called Reader. 203 00:13:30,220 --> 00:13:36,520 So just to paint the picture, we're looking at a network that looks something like this. 204 00:13:37,040 --> 00:13:40,260 We've got our attacker sitting down there. 205 00:13:40,840 --> 00:13:43,820 We've got access to an Ubuntu machine. 206 00:13:44,480 --> 00:13:49,540 And inside of that network, there's a term serve box and an SSH box. 207 00:13:49,920 --> 00:13:50,560 Okay. 208 00:13:50,640 --> 00:13:54,240 So really quickly, what I'm going to be doing is I'm going to go ahead and show you what I'm going to do. 209 00:13:54,240 --> 00:13:59,640 I'm going to load up a piece of JSP on the victim server. 210 00:14:00,040 --> 00:14:03,160 I'm then going to load a little proxy on my end. 211 00:14:03,400 --> 00:14:09,780 And what we're hoping for is that we can then aim traffic at our local proxy. 212 00:14:10,040 --> 00:14:19,080 The local proxy will convert TCP to HTTP GET requests, which will talk to the remote JSP. 213 00:14:19,360 --> 00:14:24,220 And the remote JSP then exits it as TCP traffic again. 214 00:14:24,240 --> 00:14:27,200 So essentially, we'll be talking clean HTTP. 215 00:14:28,300 --> 00:14:33,000 And we'll be pushing TCP clean through the network in a fairly independent way. 216 00:14:34,000 --> 00:14:34,580 Okay. 217 00:14:34,600 --> 00:14:36,920 So I'm going to quickly go through the demo. 218 00:14:38,000 --> 00:14:42,880 We've already uploaded the file to a directory called upload on the server. 219 00:14:44,400 --> 00:14:45,740 I'm going to kick that off. 220 00:14:49,000 --> 00:14:49,580 Okay. 221 00:14:49,660 --> 00:14:52,900 And what we've got there is the server saying it's cool. 222 00:14:52,900 --> 00:14:53,580 Let's talk. 223 00:14:56,180 --> 00:14:58,840 And if I had control of my mouse. 224 00:15:00,180 --> 00:15:05,640 What this then does is allows us to connect to our local proxy to give it commands. 225 00:15:06,360 --> 00:15:06,840 Okay. 226 00:15:06,860 --> 00:15:13,600 So I'm going to connect to the local proxy, cut and paste a command just so my bad typing skills don't give stuff away. 227 00:15:16,180 --> 00:15:16,660 Okay. 228 00:15:16,720 --> 00:15:22,880 And essentially, what we're going to tell it is create a tunnel on my machine, port 122. 229 00:15:23,660 --> 00:15:28,300 I'm talking to a Win2k3 box inside that network on 3389. 230 00:15:29,760 --> 00:15:34,720 Essentially, I should now be able to aim at local host 1234. 231 00:15:35,720 --> 00:15:44,320 And what you're seeing back there is all of my traffic becoming HTTP posts going off to the remote JSP page. 232 00:15:46,080 --> 00:15:51,320 And essentially, you're putting TCP completely clean through. 233 00:15:51,480 --> 00:15:51,660 Okay. 234 00:15:52,780 --> 00:15:56,120 You will find it's a little slow. 235 00:15:56,720 --> 00:15:59,220 And you will find that I can't spell. 236 00:16:05,420 --> 00:16:10,100 But what you should notice is it's perfectly usable TCP. 237 00:16:11,440 --> 00:16:19,020 And at this point, if you know how terminal services works, every movement here is requiring traffic to go to the server. 238 00:16:19,020 --> 00:16:22,300 The proxy is going to happily push that stuff through. 239 00:16:22,960 --> 00:16:32,500 Because of the way the proxy works and because Glenn is actually much cleverer than us, you can actually create multiple tunnels through this interface. 240 00:16:33,000 --> 00:16:45,680 So you could just as easily go to our control point and tell it to create another tunnel that goes to another box for SSH access. 241 00:16:46,020 --> 00:16:46,580 Okay. 242 00:16:46,580 --> 00:16:48,020 Then make your connection. 243 00:16:48,100 --> 00:16:49,100 Traffic is going through. 244 00:16:49,680 --> 00:16:57,200 What you should notice is that RDP and SSH are talking binary protocols. 245 00:16:57,660 --> 00:17:00,980 So at this point, we're not just pushing text through this. 246 00:17:01,680 --> 00:17:03,640 Essentially, you can put anything through it. 247 00:17:03,720 --> 00:17:06,940 The proxy is handling TCP completely natively. 248 00:17:07,840 --> 00:17:09,120 Let me just kill it. 249 00:17:09,860 --> 00:17:11,660 So there's no more of this. 250 00:17:12,760 --> 00:17:13,280 Okay. 251 00:17:13,320 --> 00:17:15,800 So that's the very ugly way to kill it. 252 00:17:15,840 --> 00:17:16,560 Which is kill your proxy. 253 00:17:16,560 --> 00:17:18,960 Kill your proxy while it actually wants to be running. 254 00:17:20,560 --> 00:17:21,160 Okay. 255 00:17:23,480 --> 00:17:30,660 So what it means is we have a clean, simple TCP over HTTP or HTTPS solution. 256 00:17:31,280 --> 00:17:35,920 And all it requires is the ability to create a JSP on the remote page. 257 00:17:36,260 --> 00:17:40,360 If we're going to create a JSP, surely it's not JSP specific. 258 00:17:41,260 --> 00:17:44,860 Ian at Sensepost.com ported this to ASP. 259 00:17:44,860 --> 00:17:49,460 So we have reader.ASP that'll do the same thing. 260 00:17:49,740 --> 00:17:54,400 Ghat at Sensepost.com gave us the same thing in PHP version. 261 00:17:55,000 --> 00:17:58,360 We'll release all of these tools on our blog as soon as we get back home. 262 00:17:59,100 --> 00:18:01,540 Shal and Nick drew the cool Vizios that you saw. 263 00:18:02,580 --> 00:18:09,460 Essentially, what it means is if we can create a file on your box, we can create a circuit through to internal hosts. 264 00:18:13,780 --> 00:18:14,300 Okay. 265 00:18:14,380 --> 00:18:14,840 We turn our attention to this. 266 00:18:14,840 --> 00:18:18,000 We turn our attention to a slightly different topic. 267 00:18:18,160 --> 00:18:22,260 And that is one of the coolness that we can get out of SQL boxes specifically. 268 00:18:22,520 --> 00:18:28,980 So as you see, most of the stuff that we're doing here revolves around web slash databases. 269 00:18:29,360 --> 00:18:33,740 And that's because that's typically what we come into or bump into on our assessments. 270 00:18:34,580 --> 00:18:38,560 Last year at Black Hat, we released the tool Squeezer. 271 00:18:38,720 --> 00:18:43,600 And it was just another advanced SQL injection tool aimed at MS SQL. 272 00:18:43,600 --> 00:18:51,060 And if you know the space, you know that pretty much every company, every guy who plays with the stuff has written his own tool. 273 00:18:51,540 --> 00:18:53,560 So there's a lot of tools out there. 274 00:18:53,680 --> 00:18:58,960 We figured we'd pump out one more year and we'll drop it after this. 275 00:18:59,980 --> 00:19:03,900 Squeezer had one or a slightly different approach to injection. 276 00:19:04,080 --> 00:19:11,880 And that was that it split the generation of data that it would extract from the way that the data was extracted. 277 00:19:12,360 --> 00:19:13,580 And that had an account. 278 00:19:13,600 --> 00:19:17,320 It had a couple of quite nice benefits for us. 279 00:19:17,500 --> 00:19:21,820 It meant that you could do a bunch of stuff in order to grab data on the database. 280 00:19:22,100 --> 00:19:25,480 And then you could use a number of other techniques to extract it. 281 00:19:25,720 --> 00:19:31,200 And that gave you the ability to mix and match generation modes with return channels. 282 00:19:31,300 --> 00:19:32,340 So this is the simple flow. 283 00:19:33,140 --> 00:19:34,180 Generate your content. 284 00:19:34,540 --> 00:19:36,860 We could generate content in a bunch of ways. 285 00:19:37,140 --> 00:19:38,660 The standard one is command execution. 286 00:19:39,320 --> 00:19:42,900 We also supported the ability to pull out data from the database. 287 00:19:43,600 --> 00:19:45,560 Through quasi-SQL queries. 288 00:19:46,380 --> 00:19:50,500 And we also supported the ability to copy files off the database. 289 00:19:50,560 --> 00:19:53,560 To download files from the database machine. 290 00:19:53,980 --> 00:19:56,900 So you would create the content in one of these manners. 291 00:19:57,140 --> 00:20:00,220 That data was stored in a temporary table inside the database. 292 00:20:00,460 --> 00:20:05,980 And at that point we could kick off one of our return channels to pull the data out. 293 00:20:06,180 --> 00:20:08,980 And we supported three different channels. 294 00:20:09,140 --> 00:20:09,800 The one was DNS. 295 00:20:10,080 --> 00:20:11,600 The second one was timing. 296 00:20:11,800 --> 00:20:13,580 And the third was error mapping. 297 00:20:13,580 --> 00:20:13,800 And other messages. 298 00:20:14,580 --> 00:20:16,640 DNS you've already seen a bit of noise about. 299 00:20:16,840 --> 00:20:23,460 Yesterday Robert Rick spoke about DNS extraction or exfiltration over or on Oracle. 300 00:20:23,780 --> 00:20:26,680 So the technique is fairly similar to that. 301 00:20:27,300 --> 00:20:31,340 The timing technique is nice because it requires no outbound channel. 302 00:20:31,500 --> 00:20:33,160 Or no explicit outbound channel. 303 00:20:33,420 --> 00:20:38,460 We could simply time HTTP requests and from that pull out all the data. 304 00:20:38,800 --> 00:20:41,540 Of course the timing as you can imagine was pretty slow. 305 00:20:41,680 --> 00:20:43,560 We were timing out one bit at a time. 306 00:20:43,560 --> 00:20:48,000 And when you're looking at sort of two seconds for a one bit. 307 00:20:48,820 --> 00:20:50,140 It could take a while. 308 00:20:50,360 --> 00:20:53,060 But given enough time it was usable. 309 00:20:53,800 --> 00:20:57,400 SQL error messages was fairly well known at this point. 310 00:20:58,520 --> 00:21:00,460 So this process is nice. 311 00:21:00,640 --> 00:21:04,540 It's not fast enough we think for real time applications. 312 00:21:04,580 --> 00:21:08,960 But certainly batch type applications or command line interfaces. 313 00:21:09,320 --> 00:21:10,360 It's pretty nice. 314 00:21:10,500 --> 00:21:13,540 But don't expect to relay VNC or RDP transactions. 315 00:21:13,560 --> 00:21:13,580 It's just traffic. 316 00:21:17,360 --> 00:21:19,180 So I'll do the demo shortly. 317 00:21:19,360 --> 00:21:22,640 In this case the DNS channel worked as follows. 318 00:21:22,780 --> 00:21:24,320 We had that temporary table in the database. 319 00:21:24,640 --> 00:21:27,040 There was a whole bunch of data in that table. 320 00:21:27,220 --> 00:21:30,980 We would pull out a line or a row from the temporary table. 321 00:21:31,960 --> 00:21:33,900 Chop that up into a fixed chunk. 322 00:21:34,360 --> 00:21:35,440 Convert that to hex. 323 00:21:35,580 --> 00:21:36,200 Add a domain. 324 00:21:36,500 --> 00:21:38,980 And initiate a DNS query on the domain. 325 00:21:39,540 --> 00:21:42,340 On our side, that is the attacker side. 326 00:21:42,340 --> 00:21:44,140 We'd be monitoring our DNS traffic. 327 00:21:44,380 --> 00:21:47,060 And pull that data out of it. 328 00:21:47,860 --> 00:21:49,900 The entire channel was handled in SQL. 329 00:21:51,160 --> 00:21:53,840 Elevated privs were used if found. 330 00:21:54,000 --> 00:21:55,300 But they weren't necessarily required. 331 00:21:56,020 --> 00:21:59,540 And the one nice thing with Squeezer is it did provide reliability guarantees. 332 00:21:59,780 --> 00:22:05,520 So it had the ability to re-request data and detect if data had been lost. 333 00:22:06,580 --> 00:22:10,420 SQL Ninja is another awesome injection tool that you'll find out there. 334 00:22:10,600 --> 00:22:11,940 And it's got a lot more features. 335 00:22:12,340 --> 00:22:12,880 And Squeezer. 336 00:22:13,300 --> 00:22:15,620 It also supports DNS exfiltration. 337 00:22:15,840 --> 00:22:17,900 However, it uses a slightly different model. 338 00:22:18,160 --> 00:22:22,660 The DNS channel is handled by a standalone binary that you have to upload. 339 00:22:22,860 --> 00:22:24,460 So it gets a little awkward. 340 00:22:24,640 --> 00:22:28,660 But it's still a much cooler tool for other stuff. 341 00:22:28,960 --> 00:22:30,860 So SQL Ninja for the win. 342 00:22:32,580 --> 00:22:37,180 So to provide another schematic on how the DNS exfiltration worked. 343 00:22:37,300 --> 00:22:40,620 We had the attacker pumping through some kind of filtering device. 344 00:22:40,740 --> 00:22:41,620 That only allowed. 345 00:22:41,620 --> 00:22:44,540 Our web traffic to go through. 346 00:22:44,660 --> 00:22:45,880 And outbound DNS. 347 00:22:46,400 --> 00:22:47,860 A victim SQL server. 348 00:22:49,520 --> 00:22:52,860 The attacker issues some kind of command to create data. 349 00:22:53,040 --> 00:22:56,620 And in this case he issues a command that will be executed. 350 00:22:57,760 --> 00:22:58,740 Data is stored. 351 00:22:59,060 --> 00:23:01,720 Or the data that's created is stored in a temporary table. 352 00:23:02,460 --> 00:23:04,760 And he then sends a second injection string. 353 00:23:04,820 --> 00:23:08,680 That, as I said, breaks up the data in the table row by row. 354 00:23:08,760 --> 00:23:09,440 Chunk by chunk. 355 00:23:09,480 --> 00:23:10,400 Converts it to hex. 356 00:23:12,640 --> 00:23:16,540 And performs a lookup on that hex encoded data. 357 00:23:16,720 --> 00:23:18,120 When that arrives back at us. 358 00:23:18,200 --> 00:23:20,200 We can convert it back. 359 00:23:20,420 --> 00:23:21,880 And we get the clear text. 360 00:23:23,000 --> 00:23:24,520 So to give you an idea. 361 00:23:28,080 --> 00:23:31,200 What I've got here is a squeezer setup. 362 00:23:31,880 --> 00:23:33,180 On my next console. 363 00:23:33,340 --> 00:23:34,600 I'm going to show you TCP dump. 364 00:23:34,760 --> 00:23:36,620 It's just going to pump out the DNS queries. 365 00:23:37,000 --> 00:23:39,060 So you can see I'm not completely faking this. 366 00:23:40,020 --> 00:23:41,060 I run a command. 367 00:23:41,060 --> 00:23:45,500 What is happening here is squeezer packages the command. 368 00:23:45,560 --> 00:23:48,160 In an injection string that's already configured. 369 00:23:48,380 --> 00:23:49,640 Sends it off to the server. 370 00:23:51,340 --> 00:23:56,020 And what we'll see is the server starts to make all the requests. 371 00:23:56,060 --> 00:23:57,040 Coming out with the data. 372 00:23:57,760 --> 00:23:59,000 We decode that. 373 00:23:59,220 --> 00:24:00,260 Print it out to screen. 374 00:24:00,480 --> 00:24:05,120 And you've now got a really nice command interface running over DNS. 375 00:24:06,600 --> 00:24:08,180 But again this is. 376 00:24:10,120 --> 00:24:10,980 This year. 377 00:24:10,980 --> 00:24:11,920 That's not super new. 378 00:24:14,000 --> 00:24:16,680 But we'll talk about something that we think is pretty cool. 379 00:24:16,880 --> 00:24:18,000 So in 2002. 380 00:24:18,280 --> 00:24:19,820 Which is now going on for six years. 381 00:24:19,900 --> 00:24:23,100 Chris Hanley wrote an awesome injection paper. 382 00:24:23,380 --> 00:24:26,120 And in it he discussed early objects. 383 00:24:26,340 --> 00:24:28,520 And their use in injection strings. 384 00:24:28,840 --> 00:24:30,180 And what he found was. 385 00:24:30,300 --> 00:24:32,380 It was possible to read and write files. 386 00:24:32,540 --> 00:24:33,300 Execute commands. 387 00:24:33,560 --> 00:24:36,160 And all of that cool stuff that we're used to doing in injection. 388 00:24:36,480 --> 00:24:39,720 But without using the interface that most injection tools use. 389 00:24:39,940 --> 00:24:40,960 So to execute commands. 390 00:24:40,960 --> 00:24:44,000 Most injection tools will run XPCMD shell. 391 00:24:44,620 --> 00:24:49,320 He figured out that actually you can use the early Windows shell scripting. 392 00:24:49,320 --> 00:24:50,600 I think it is object. 393 00:24:51,580 --> 00:24:53,160 However you don't see too much. 394 00:24:53,240 --> 00:24:57,140 In terms of early integration into current injection tools. 395 00:24:57,360 --> 00:24:59,080 And we wanted to explore this a little bit. 396 00:24:59,160 --> 00:25:00,940 To see how far we could push it. 397 00:25:02,100 --> 00:25:05,680 So what we got to was a SQL based port scanner. 398 00:25:06,160 --> 00:25:08,560 And this runs entirely in T-SQL. 399 00:25:08,800 --> 00:25:10,420 It doesn't require the upload. 400 00:25:10,420 --> 00:25:11,320 Of any binaries. 401 00:25:11,340 --> 00:25:11,780 Or any of that. 402 00:25:12,780 --> 00:25:13,960 Once we kick it off. 403 00:25:14,480 --> 00:25:18,720 All of that stays in the same memory space as the SQL server. 404 00:25:19,060 --> 00:25:22,500 So it's basis is the MSXML2 server. 405 00:25:23,800 --> 00:25:24,840 XMLHTTP object. 406 00:25:25,240 --> 00:25:26,920 Which is a bit of a mouthful. 407 00:25:27,920 --> 00:25:31,240 But it's the same object that's used to make. 408 00:25:31,420 --> 00:25:32,680 Or to pull in XML data. 409 00:25:34,920 --> 00:25:36,760 And it's really, really useful. 410 00:25:36,960 --> 00:25:39,700 It's installed with as I say IE and IIS. 411 00:25:40,420 --> 00:25:44,300 And what we can do here is basically craft a URL. 412 00:25:44,360 --> 00:25:48,000 Made up of our target IP and a target port. 413 00:25:48,280 --> 00:25:53,420 We use OLE to make or attempt to pull XML data from that URI. 414 00:25:53,860 --> 00:25:57,060 And then we monitor the return codes from a bunch of methods. 415 00:25:57,300 --> 00:25:58,360 And based on that. 416 00:25:58,480 --> 00:26:02,320 We can determine if a port is open, closed, filtered. 417 00:26:02,580 --> 00:26:04,180 Or running a web server. 418 00:26:04,480 --> 00:26:05,740 Which is kind of nifty. 419 00:26:07,940 --> 00:26:08,500 So. 420 00:26:11,340 --> 00:26:13,040 I've gone through I think most of this. 421 00:26:15,620 --> 00:26:18,200 So the one thing to point out. 422 00:26:18,260 --> 00:26:21,540 Is we differentiate between closed and filtered ports. 423 00:26:21,740 --> 00:26:23,500 Just through the use of timeouts. 424 00:26:23,660 --> 00:26:25,280 Which is pretty much what everyone else does. 425 00:26:25,420 --> 00:26:28,400 So the technique behind the port scanner is pretty standard. 426 00:26:28,780 --> 00:26:33,120 But what we've done is shifted this into the SQL server itself. 427 00:26:33,420 --> 00:26:37,060 Of course what it does require is either OLE objects. 428 00:26:37,280 --> 00:26:38,360 Well not either. 429 00:26:38,520 --> 00:26:39,880 It requires SA access. 430 00:26:39,880 --> 00:26:42,220 In order to use the OLE methods. 431 00:26:43,700 --> 00:26:47,480 But given the number of web servers or web apps that we see that use SA. 432 00:26:48,460 --> 00:26:50,360 Often this isn't the big problem. 433 00:26:51,160 --> 00:26:52,820 So this is the building block. 434 00:26:52,960 --> 00:26:56,180 This is a stored proc that we create on the server. 435 00:26:56,220 --> 00:26:56,980 It's called probe IP. 436 00:26:57,140 --> 00:26:58,400 You pass it an IP and a port. 437 00:27:00,060 --> 00:27:01,800 The stored proc creates the URL. 438 00:27:02,420 --> 00:27:04,280 Creates the OLE object. 439 00:27:05,700 --> 00:27:07,160 It sets some timeouts. 440 00:27:07,220 --> 00:27:08,700 It opens the object. 441 00:27:08,800 --> 00:27:09,560 Sends the request. 442 00:27:10,340 --> 00:27:11,360 Monitors the status. 443 00:27:11,880 --> 00:27:15,120 And then based on all of the return values from those methods. 444 00:27:15,200 --> 00:27:20,320 We're able to fingerprint whether that port is open, closed or so on. 445 00:27:21,260 --> 00:27:23,120 So using that as a building block. 446 00:27:23,780 --> 00:27:26,420 We can build further stored procs. 447 00:27:26,460 --> 00:27:27,400 In this case we've got two. 448 00:27:27,620 --> 00:27:28,840 The one is scan ports. 449 00:27:29,060 --> 00:27:30,120 And the other one is scan hosts. 450 00:27:30,380 --> 00:27:32,600 So across a range of either ports or hosts. 451 00:27:32,680 --> 00:27:35,380 We can scan for a single host or a single port. 452 00:27:36,740 --> 00:27:39,860 You could also write a web server detection. 453 00:27:39,860 --> 00:27:41,480 We can detect it pretty easily with this. 454 00:27:41,940 --> 00:27:45,440 So let's give you the demo. 455 00:27:48,640 --> 00:27:50,380 Again I've got another config file. 456 00:27:50,540 --> 00:27:51,480 All the setup is done. 457 00:27:51,620 --> 00:27:55,460 In this case I can specify an IP address. 458 00:27:59,900 --> 00:28:01,180 Give it a couple of ports. 459 00:28:05,400 --> 00:28:06,940 In the setup it goes through. 460 00:28:07,000 --> 00:28:08,800 It creates that building block probe IP. 461 00:28:08,800 --> 00:28:13,720 It creates the other two helper stored procs. 462 00:28:13,940 --> 00:28:15,380 And then it starts to scan. 463 00:28:15,840 --> 00:28:17,700 And we get the info out. 464 00:28:17,760 --> 00:28:19,780 It tells us that some of those ports are closed. 465 00:28:19,860 --> 00:28:20,580 Some of them are open. 466 00:28:20,660 --> 00:28:23,240 And some of the open ones are actually running web servers. 467 00:28:24,080 --> 00:28:26,580 So it seems a little convoluted. 468 00:28:26,600 --> 00:28:28,040 But consider what it buys you. 469 00:28:31,320 --> 00:28:33,660 In this case you don't have to upload nmap. 470 00:28:33,700 --> 00:28:35,200 You don't have to upload any other tool. 471 00:28:35,360 --> 00:28:38,100 What it gives you is an AV free. 472 00:28:38,100 --> 00:28:40,580 Or a detection free way of conducting port scans. 473 00:28:42,140 --> 00:28:47,420 There's also, as I say, unless you're performing traffic analysis. 474 00:28:47,540 --> 00:28:49,180 You're not going to pick this up easily. 475 00:28:49,500 --> 00:28:51,540 Specifically on the SQL server. 476 00:28:52,020 --> 00:28:54,640 It can scan almost all ports. 477 00:28:54,780 --> 00:28:59,500 What you'll find is because there's some protection built in for cross protocol attacks. 478 00:29:00,260 --> 00:29:02,760 Web server, sorry not even web server. 479 00:29:02,960 --> 00:29:05,560 The IE objects can't connect to all ports. 480 00:29:05,780 --> 00:29:07,740 But in truth it's not so much of a limitation. 481 00:29:08,600 --> 00:29:12,340 It can only not connect to I think I said six ports. 482 00:29:12,680 --> 00:29:18,120 So out of the 65,536 ports we can't scan six of them. 483 00:29:18,620 --> 00:29:22,860 And in fact they're often not the ports that you're most interested in anyway. 484 00:29:24,200 --> 00:29:26,300 The other thing that will bite you are proxies. 485 00:29:26,760 --> 00:29:28,460 So if the machine has a proxy set. 486 00:29:29,240 --> 00:29:32,120 Then your traffic is going to be directed through there. 487 00:29:32,500 --> 00:29:34,360 But in truth that's also not a limitation. 488 00:29:34,440 --> 00:29:37,080 There's an early object method to disable the proxy. 489 00:29:37,080 --> 00:29:41,700 So we figure that the early objects deserve more looking at. 490 00:29:41,760 --> 00:29:44,120 One of the things that buys you is platform independence. 491 00:29:44,580 --> 00:29:51,480 So SQL server version or SQL server across multiple versions supports this functionality. 492 00:29:51,840 --> 00:29:56,040 And we figure people should be playing with this stuff a little more. 493 00:29:58,920 --> 00:29:59,600 Okay. 494 00:30:01,040 --> 00:30:04,320 So when we first wrote Squeezer. 495 00:30:04,320 --> 00:30:07,460 We weren't specifically aiming at SQL 2005. 496 00:30:08,240 --> 00:30:11,940 We then put up 2005 because we heard a lot about it. 497 00:30:12,320 --> 00:30:16,500 And expected that most things would break by default. 498 00:30:17,200 --> 00:30:17,600 Okay. 499 00:30:17,620 --> 00:30:25,160 Because SQL 2005 has largely been Microsoft's flagship product for the STLC push. 500 00:30:25,940 --> 00:30:29,000 SQL poses interesting challenges. 501 00:30:29,980 --> 00:30:31,300 It's highly public. 502 00:30:31,540 --> 00:30:33,380 It's been highly exploited. 503 00:30:34,320 --> 00:30:37,440 And most of the exploits against it haven't been Microsoft's fault. 504 00:30:37,580 --> 00:30:40,560 So they get a bad rep for most SQL injection attacks. 505 00:30:40,780 --> 00:30:43,420 And actually it's not something they could do much about. 506 00:30:44,340 --> 00:30:48,380 So they took steps to try to reduce the attack surface. 507 00:30:49,020 --> 00:30:51,580 Essentially trying to stop people from hurting themselves. 508 00:30:52,300 --> 00:30:56,000 Pretty much like you force people to wear seat belts so they don't kill themselves. 509 00:30:57,340 --> 00:31:02,000 Lots of famous hacks or celebrities have come out saying how they hate going up against 05. 510 00:31:02,000 --> 00:31:05,360 Because of how secure 05 was. 511 00:31:06,780 --> 00:31:07,260 Okay. 512 00:31:07,660 --> 00:31:09,520 We didn't find this to be the case. 513 00:31:10,540 --> 00:31:18,160 So fundamentally probably the biggest problems that we pick up are neatly summed up I thought by this picture. 514 00:31:18,380 --> 00:31:21,620 But it turns out that I'm the only one who makes any head or tail of it. 515 00:31:22,360 --> 00:31:30,060 What we're going for with this picture is that on the one hand you've got the surgeon general telling you that smoking is a bad idea. 516 00:31:30,060 --> 00:31:34,160 On the other hand you're being told to come where the flavor is. 517 00:31:34,500 --> 00:31:39,260 And come to where the flavor is about five times the size of the surgeon general's warning. 518 00:31:39,780 --> 00:31:40,120 Okay. 519 00:31:40,140 --> 00:31:43,480 It's quite clear that this ad was not put up to tell you don't smoke. 520 00:31:44,200 --> 00:31:44,740 Okay. 521 00:31:45,040 --> 00:31:56,220 If Microsoft were trying so hard to cut down on this functionality, adding tons more functionality into SQL Server was probably not the way to go. 522 00:31:57,140 --> 00:31:59,880 So you end up with very mixed messages. 523 00:31:59,880 --> 00:32:09,940 So the ultimate in scientific tests, you do a Google, 2005 plus reduced attack surface, 106,000 hits. 524 00:32:10,620 --> 00:32:13,540 05 and new features, you get about 5 million. 525 00:32:14,160 --> 00:32:14,860 Okay. 526 00:32:14,900 --> 00:32:22,220 Any software engineer will tell you that features will win because of the dancing pigs problem. 527 00:32:22,580 --> 00:32:29,860 Mr. White pointed out that actually Ed Felton said, given a tradeoff, Gary McGraw and Ed Felton, 528 00:32:29,880 --> 00:32:36,000 given a choice between security and dancing pigs, users will choose dancing pigs every time. 529 00:32:36,780 --> 00:32:41,240 And the problem that we bump into here is management by in-flight magazine. 530 00:32:41,720 --> 00:32:47,420 You could tell your boss that SQL endpoints in SQL are a bad idea. 531 00:32:47,660 --> 00:32:56,080 But if he read that this is a shiny new feature in SQL 2005, it's a safe bet you're going to build an app making use of built-in endpoints. 532 00:32:57,620 --> 00:32:57,920 Okay. 533 00:32:57,920 --> 00:33:03,520 The second big problem that you bump into is that of in-band signaling. 534 00:33:04,220 --> 00:33:04,480 Okay. 535 00:33:04,520 --> 00:33:11,560 In-band signaling has been biting us for such a long time that it's really painful to say it, not just because of my throat. 536 00:33:12,680 --> 00:33:26,940 When Captain Crunch started attacking phone systems in the old days, the reasons he was able to do what he did was because the same channel was being used to send commands and data. 537 00:33:26,940 --> 00:33:35,240 When we look at buffer overflows today, essentially the core of it is because data and instructions look the same. 538 00:33:35,520 --> 00:33:42,880 And if we can send it data and convince the computer that those are instructions, we're able to execute commands. 539 00:33:44,300 --> 00:33:51,060 And essentially, as long as you're using in-band signaling, you can't really claim to be secure by design. 540 00:33:52,660 --> 00:33:56,920 If we take a look at the way SQL Server was getting executed. 541 00:33:56,940 --> 00:33:58,540 It was exploited across the net in the past. 542 00:33:59,260 --> 00:34:07,180 Every tool was using XP command shell, so soon every doc came out with how to disable XP command shell. 543 00:34:07,640 --> 00:34:15,360 So in the normal arms race style, every tool now has a little click box that says re-enable XP command shell. 544 00:34:15,780 --> 00:34:16,420 Okay. 545 00:34:16,480 --> 00:34:24,820 In fact, all of the features that come locked down by default on SQL can be re-enabled through SQL queries. 546 00:34:25,040 --> 00:34:25,680 Okay. 547 00:34:25,680 --> 00:34:27,400 If you've got the correct permissions. 548 00:34:27,780 --> 00:34:35,180 The in-band signaling helps administration, but it's probably not the most secure way to do this stuff. 549 00:34:36,300 --> 00:34:39,220 So ad hoc queries are disabled. 550 00:34:39,560 --> 00:34:42,660 Ad hoc distributed queries are disabled by default. 551 00:34:43,800 --> 00:34:48,500 Cesar Cerudo's data thief used to use it to take data out of your network. 552 00:34:49,040 --> 00:34:50,780 XP command shell disabled. 553 00:34:51,740 --> 00:34:53,720 CLR integration is disabled. 554 00:34:53,720 --> 00:35:05,060 And literally, as long as you've got SQL injection going, you can use the same channel to re-enable the stuff, which is part of the problem. 555 00:35:05,920 --> 00:35:10,540 So other than all of the old griping, we figured we'd have some new ones. 556 00:35:11,320 --> 00:35:18,760 And the two that we're going to look at is XML integration and CLR integration, or XML web services. 557 00:35:19,640 --> 00:35:23,700 So the marketing pitch for XML web services. 558 00:35:23,700 --> 00:35:28,580 Straight from Microsoft, basically says, use this mechanism. 559 00:35:28,700 --> 00:35:33,520 You can create SOAP endpoints from within SQL server. 560 00:35:34,120 --> 00:35:39,260 Anything that can parse XML can now send requests and talk directly to SQL. 561 00:35:40,180 --> 00:35:44,080 So already, this gives us two cool things. 562 00:35:44,380 --> 00:35:47,660 One is the ability to launch DOS attacks on the web server. 563 00:35:48,080 --> 00:35:51,480 The other is a good cross-platform query manager. 564 00:35:51,480 --> 00:35:57,740 So if we look at DOS, there's a very obvious example, which we'll run through. 565 00:35:58,160 --> 00:36:02,540 But basically, you create the SQL that says, I'm creating an endpoint. 566 00:36:03,040 --> 00:36:06,680 And my endpoint lives at slash SQL demo. 567 00:36:08,060 --> 00:36:14,160 You then, when you want to consume this web service, aim at slash SQL demo. 568 00:36:14,260 --> 00:36:15,400 It gives you a WSDL. 569 00:36:15,540 --> 00:36:21,340 And you can build a little executable that then talks to this SOAP endpoint. 570 00:36:22,980 --> 00:36:27,680 Now, this starts to become interesting to us for multiple reasons. 571 00:36:28,740 --> 00:36:33,760 If we take a really quick look at a demo web server that we've set up, 572 00:36:34,000 --> 00:36:42,980 what you should see is on slash test, we have a very basic page that basically says, welcome. 573 00:36:44,040 --> 00:36:50,320 What I'm going to do now is, in SQL server, run that create endpoint query. 574 00:36:50,320 --> 00:36:53,020 Which we demoed. 575 00:36:53,520 --> 00:36:55,120 So we create it. 576 00:36:55,180 --> 00:36:56,800 It says, come on, complete it successfully. 577 00:36:58,280 --> 00:37:07,360 And surfing to this page, you should see that, effectively, SQL server's SOAP endpoint takes precedence over IIS. 578 00:37:08,040 --> 00:37:16,420 And the reason for this is, at this point, you should be able to aim your tool at it, get the WSDL, and start talking SOAP to it. 579 00:37:17,540 --> 00:37:20,300 So, effectively, all you're doing is very simple. 580 00:37:20,300 --> 00:37:27,740 You're quickly killing SQL server, or killing IIS, by telling SQL server to write to that path instead. 581 00:37:31,320 --> 00:37:32,200 Excuse me. 582 00:37:32,520 --> 00:37:34,140 Hey, that works better. 583 00:37:35,560 --> 00:37:40,320 So, something that's obvious is, this had to come up during threat modeling. 584 00:37:40,700 --> 00:37:46,460 During threat modeling, someone had to say, hey, this is a possibility. 585 00:37:47,280 --> 00:37:48,920 But what's interesting is, 586 00:37:48,920 --> 00:37:52,860 as long as you've got SA, or as long as you've got the proofs that you need, 587 00:37:53,500 --> 00:37:55,800 you're going to be able to do this creation. 588 00:37:56,880 --> 00:38:00,360 Also interesting, and again, straight from MSDN, 589 00:38:01,180 --> 00:38:06,180 you'll see that there's an option when defining the site to use asterisks, 590 00:38:06,240 --> 00:38:12,000 which basically says, if you've got IIS serving multiple sites on this web server, 591 00:38:12,540 --> 00:38:17,540 overwrite all of them with your endpoint, not just one particular one. 592 00:38:17,540 --> 00:38:21,660 Okay, so this becomes interesting because even if file system writes, 593 00:38:21,800 --> 00:38:25,340 prevent your SQL admin from doing bad stuff to your website, 594 00:38:25,620 --> 00:38:32,360 this new plan allows him to pretty much own it by binding in front of your web page. 595 00:38:33,060 --> 00:38:38,180 Essentially, it's like the netcat port bind only ten years later. 596 00:38:40,000 --> 00:38:47,100 What's interesting about this is, I've shown you the demo via SQL query manager, 597 00:38:47,540 --> 00:38:52,820 but anything that we can do via query manager, because there's in-band signaling, 598 00:38:53,000 --> 00:38:55,580 we can actually also do via our SQL injection. 599 00:38:56,420 --> 00:39:02,900 So what we're going to take a really quick look at at this point is something like this. 600 00:39:04,940 --> 00:39:08,760 So if I quickly get to my scratch pad. 601 00:39:11,040 --> 00:39:12,280 Are we up on screen? 602 00:39:15,340 --> 00:39:16,320 Let's just... 603 00:39:17,640 --> 00:39:18,720 Turn on my ring. 604 00:39:20,060 --> 00:39:25,060 Okay, so what we're going to look at here is a very simple, straightforward, 605 00:39:26,240 --> 00:39:28,160 classic SQL injection page. 606 00:39:29,420 --> 00:39:35,620 So if we go back here, what you should see is pretty much the stuff that you're used to, 607 00:39:35,660 --> 00:39:39,660 single quote or one equals one stuff of a form that looks like this. 608 00:39:40,480 --> 00:39:45,220 Okay, and what we're going to do here is basically run this function. 609 00:39:45,740 --> 00:39:47,520 And what you're seeing up here is, 610 00:39:47,540 --> 00:39:50,180 I'm creating a function called getServerVersion, 611 00:39:50,960 --> 00:39:54,120 a little stored proc called getServerVersion, 612 00:39:54,240 --> 00:39:58,540 and adding it to SQL Server. 613 00:40:03,680 --> 00:40:06,640 You get an access denied, which is cool. 614 00:40:06,800 --> 00:40:10,040 All it means is that we've entered a good SQL. 615 00:40:10,900 --> 00:40:13,600 And then I'm going to run the second injection string, 616 00:40:13,760 --> 00:40:16,540 which basically tells it that I want to create 617 00:40:16,540 --> 00:40:22,060 a web service on path slash SQL slash demo, 618 00:40:22,760 --> 00:40:24,880 just because we couldn't think of a better name. 619 00:40:25,540 --> 00:40:30,140 But what that then means is that we can connect to that path. 620 00:40:32,080 --> 00:40:34,200 We can connect to that path. 621 00:40:35,220 --> 00:40:36,700 Let's try that one more time. 622 00:40:38,080 --> 00:40:43,240 Essentially, it means we should be able to surf to it and talk good SQL. 623 00:40:43,740 --> 00:40:44,300 Okay. 624 00:40:44,300 --> 00:40:46,320 What you should be noticing, again, 625 00:40:46,400 --> 00:40:48,200 is the SOAP endpoints created, 626 00:40:48,400 --> 00:40:53,680 and this time we created it completely remotely via our injection string. 627 00:40:54,240 --> 00:40:54,880 Okay. 628 00:40:55,060 --> 00:40:58,860 So what this should mean is that we're now in the position 629 00:40:58,860 --> 00:41:05,180 to remotely create an endpoint and get this endpoint to run the function 630 00:41:05,180 --> 00:41:07,040 that we gave it, told it to run. 631 00:41:07,160 --> 00:41:09,820 In this case, return at at version. 632 00:41:10,360 --> 00:41:14,280 So the obvious attack pattern that we were going to use, 633 00:41:14,280 --> 00:41:15,200 what we were going for here was, 634 00:41:15,380 --> 00:41:19,840 let's create a SOAP endpoint that accepts any request from us, 635 00:41:19,960 --> 00:41:23,620 then evals that request and sends us the response back. 636 00:41:24,360 --> 00:41:27,360 But it turns out that Microsoft actually beat us to it. 637 00:41:28,140 --> 00:41:33,500 If you read any of the documentation on creating SOAP endpoints, 638 00:41:34,000 --> 00:41:36,800 you'll see that something that goes along for the ride 639 00:41:36,800 --> 00:41:39,140 is something called SQL batch. 640 00:41:39,520 --> 00:41:41,780 Sorry, SQL batch, without the squeakiness. 641 00:41:42,460 --> 00:41:46,020 So if you take a look at the WSDL that we just published, 642 00:41:46,340 --> 00:41:50,660 you'll notice it actually pushes down two functions. 643 00:41:51,080 --> 00:41:52,920 The one is get server version. 644 00:41:53,140 --> 00:41:57,800 The other one is SQL batch, which is a built-in way of saying, 645 00:41:57,960 --> 00:41:59,720 I'm going to send you SQL. 646 00:41:59,900 --> 00:42:02,340 Please execute the SQL for me. 647 00:42:02,700 --> 00:42:03,300 Okay. 648 00:42:03,340 --> 00:42:05,620 And that's built in. 649 00:42:05,780 --> 00:42:09,020 So essentially we'll use our attack string. 650 00:42:09,240 --> 00:42:11,680 This time we filed it down. 651 00:42:11,780 --> 00:42:13,720 So that there's not a lot to it. 652 00:42:13,820 --> 00:42:17,040 And essentially all we're saying is create a new endpoint 653 00:42:17,800 --> 00:42:21,600 with absolutely no function behind it, 654 00:42:21,680 --> 00:42:23,840 but please enable batches. 655 00:42:24,540 --> 00:42:26,200 Okay, so that should be familiar. 656 00:42:26,440 --> 00:42:31,120 But what it does mean is we can now use any SOAP client 657 00:42:31,680 --> 00:42:35,300 and send completely arbitrary queries through to this, 658 00:42:35,440 --> 00:42:38,280 and SQL Server will execute them for us. 659 00:42:40,100 --> 00:42:41,300 Thank you very much. 660 00:42:43,540 --> 00:42:44,140 . 661 00:42:46,300 --> 00:42:46,900 Okay. 662 00:42:48,540 --> 00:42:51,200 So we can use the old technique. 663 00:42:51,640 --> 00:42:54,780 Let's do IP config, pump it to a table, 664 00:42:55,000 --> 00:42:57,700 let's query the table, and all is good. 665 00:42:58,540 --> 00:43:00,380 We're almost out of time, so really quickly, 666 00:43:00,620 --> 00:43:03,760 the next thing that was cool was CLR integration. 667 00:43:04,540 --> 00:43:09,500 When we wrote Squeezer, we did all that stuff inside of T-SQL. 668 00:43:09,500 --> 00:43:11,940 And although T-SQL is Turing complete, 669 00:43:12,300 --> 00:43:17,860 it was never intended to be building TCP replicas in it. 670 00:43:18,200 --> 00:43:20,980 And so Marco lost a lot of hair in the process. 671 00:43:22,220 --> 00:43:28,000 Fortunately for us, O5 now comes with the common language runtime built in, 672 00:43:28,100 --> 00:43:31,280 which means we don't have to inject T-SQL anymore. 673 00:43:31,420 --> 00:43:35,600 We can start injecting CLR C-sharp code. 674 00:43:36,180 --> 00:43:36,860 Okay. 675 00:43:36,860 --> 00:43:38,420 It's turned off by default, 676 00:43:38,620 --> 00:43:43,180 but again, SP reconfigure will allow us to turn it back on. 677 00:43:44,460 --> 00:43:49,160 CLR integration does allow you to give assemblies really fine-grained control, 678 00:43:49,700 --> 00:43:52,640 but you can override this fairly easily. 679 00:43:53,020 --> 00:43:56,420 So the question is, remotely, how do I load a .NET assembly? 680 00:43:57,200 --> 00:43:59,140 The first thing we came up with was, 681 00:43:59,200 --> 00:44:03,080 let's remotely create a C-sharp file on the file system. 682 00:44:03,440 --> 00:44:05,940 And so what you'll see is we use XP command shell, 683 00:44:05,940 --> 00:44:07,920 create file, create file, create file. 684 00:44:08,040 --> 00:44:08,980 It's really painstaking. 685 00:44:09,720 --> 00:44:15,800 And then we hope that the remote box has a compiler to then compile that into an EXE. 686 00:44:16,820 --> 00:44:23,820 Fortunately for us, all versions of SQL from O5 upwards now ship with a compiler built in. 687 00:44:24,000 --> 00:44:31,640 So CSC.exe will be sitting for you in the very predictable window DLL cache CSC.exe. 688 00:44:31,840 --> 00:44:34,680 So you can upload a file line by line, 689 00:44:34,680 --> 00:44:36,740 call CSC to build it, 690 00:44:36,820 --> 00:44:38,160 and then execute it. 691 00:44:38,520 --> 00:44:40,260 But that's a little bit ghetto. 692 00:44:40,720 --> 00:44:46,180 So instead, we consider using an old Windows trick, 693 00:44:46,260 --> 00:44:49,300 which is load the DLL via UNC path. 694 00:44:49,980 --> 00:44:51,820 Essentially, we tell SQL Server, 695 00:44:51,940 --> 00:44:54,840 create this assembly from this UNC path. 696 00:44:55,740 --> 00:44:58,620 SQL Server then comes to our UNC path, 697 00:44:58,960 --> 00:45:00,200 fetches the DLL, 698 00:45:00,420 --> 00:45:02,560 and runs it in its memory space. 699 00:45:03,140 --> 00:45:04,560 Okay, but even that, 700 00:45:04,680 --> 00:45:07,440 it requires outbound UNC, 701 00:45:08,140 --> 00:45:10,060 which still makes it a little ghetto. 702 00:45:11,700 --> 00:45:13,760 Fortunately, there's one more technique, 703 00:45:13,840 --> 00:45:18,380 which basically says you can pass me the hex for your assembly 704 00:45:18,380 --> 00:45:20,920 as part of your SQL query. 705 00:45:21,160 --> 00:45:23,520 Okay, so it's inbound signaling plus plus. 706 00:45:24,920 --> 00:45:26,540 Give me the hex. 707 00:45:26,760 --> 00:45:29,600 I'll build that executable for you when you need it. 708 00:45:30,100 --> 00:45:32,700 You exec it and all will be good. 709 00:45:33,120 --> 00:45:33,720 Okay. 710 00:45:33,720 --> 00:45:38,100 So when you load an executable in SQL Server, 711 00:45:38,280 --> 00:45:40,040 it gives you different options. 712 00:45:40,360 --> 00:45:43,960 By default, the executable loads as safe, 713 00:45:44,100 --> 00:45:45,580 which means it can't touch anything. 714 00:45:45,680 --> 00:45:46,620 It's sandboxed. 715 00:45:46,640 --> 00:45:48,080 But if you told it, 716 00:45:48,140 --> 00:45:50,060 I want this executable loaded, 717 00:45:50,200 --> 00:45:51,740 and I want it to be unsafe, 718 00:45:52,080 --> 00:45:54,680 then essentially your executable can do anything, 719 00:45:55,460 --> 00:45:56,780 make outbound connections, 720 00:45:57,160 --> 00:45:59,140 make arbitrary TCP connections, 721 00:45:59,460 --> 00:46:00,480 and it's fine. 722 00:46:01,100 --> 00:46:02,500 You might not have, 723 00:46:02,500 --> 00:46:03,640 so even if you SA, 724 00:46:03,880 --> 00:46:05,800 you might not be able to do that 725 00:46:05,800 --> 00:46:09,160 because SQL's surface area configuration tool 726 00:46:09,160 --> 00:46:10,060 might have turned it off. 727 00:46:10,640 --> 00:46:12,920 Fortunately, you can inject the string, 728 00:46:13,140 --> 00:46:14,320 alter database, 729 00:46:14,620 --> 00:46:16,260 set trustworthy to on, 730 00:46:16,400 --> 00:46:18,260 and everything is trusted, 731 00:46:18,340 --> 00:46:20,040 and you can then do what you want again. 732 00:46:20,920 --> 00:46:22,340 So really quickly, 733 00:46:23,200 --> 00:46:26,840 basically all we did is convert. 734 00:46:27,460 --> 00:46:30,340 We took a standard TCP socket program 735 00:46:30,340 --> 00:46:32,480 and we converted to hex. 736 00:46:32,500 --> 00:46:37,320 It gives us this insanely long injection string. 737 00:46:38,100 --> 00:46:39,700 And so essentially, 738 00:46:39,820 --> 00:46:42,440 all I'm going to tell SQL Server here is 739 00:46:42,440 --> 00:46:46,000 that I am sending you a assembly. 740 00:46:46,440 --> 00:46:48,100 Please load this assembly. 741 00:46:48,680 --> 00:46:50,900 You should see it taking a little bit longer 742 00:46:50,900 --> 00:46:53,340 because it's now building this binary for us 743 00:46:53,340 --> 00:46:55,540 inside of SQL Server. 744 00:46:56,340 --> 00:46:57,640 While that's building, 745 00:46:57,820 --> 00:46:58,680 really quickly, 746 00:46:58,700 --> 00:46:59,640 if I go here, 747 00:47:00,500 --> 00:47:02,300 we should be able to check 748 00:47:02,500 --> 00:47:03,240 and see. 749 00:47:05,720 --> 00:47:07,960 So you should be able to see down here 750 00:47:08,360 --> 00:47:10,980 the ports that are listening on SQL Server. 751 00:47:11,240 --> 00:47:13,280 And what's more important is that 752 00:47:13,280 --> 00:47:16,940 you shouldn't see a listener on 8001. 753 00:47:17,420 --> 00:47:18,840 If we go back here, 754 00:47:18,920 --> 00:47:20,240 our query is now run. 755 00:47:21,440 --> 00:47:22,480 Essentially now, 756 00:47:22,640 --> 00:47:25,620 I'm going to tell the website 757 00:47:26,560 --> 00:47:28,980 that assembly that I just sent you, 758 00:47:29,700 --> 00:47:31,540 please create a 759 00:47:31,540 --> 00:47:34,540 stored procedure that references that. 760 00:47:35,120 --> 00:47:36,840 And that seems happy. 761 00:47:37,440 --> 00:47:39,720 And essentially all that's left 762 00:47:39,720 --> 00:47:42,700 is for us to call this remotely. 763 00:47:43,140 --> 00:47:45,660 So we call this remotely. 764 00:47:46,320 --> 00:47:49,100 And what you should see on this side 765 00:47:49,100 --> 00:47:51,040 is if we now do a listen, 766 00:47:51,220 --> 00:47:54,260 there's now something listening on 8001. 767 00:47:54,740 --> 00:47:58,840 What you should notice is that 3616 is 768 00:47:58,840 --> 00:47:59,640 essentially, 769 00:48:01,520 --> 00:48:03,260 so if we did 3616, 770 00:48:03,660 --> 00:48:05,460 is actually SQL Server. 771 00:48:05,800 --> 00:48:08,200 So we broke down the EXE, 772 00:48:08,320 --> 00:48:09,820 sent it to SQL Server. 773 00:48:09,920 --> 00:48:12,580 SQL Server is now running it inside of its own space. 774 00:48:14,560 --> 00:48:17,760 Okay, so really quickly, 775 00:48:17,900 --> 00:48:19,180 what does this mean to us? 776 00:48:19,460 --> 00:48:21,360 It means the fun is just starting. 777 00:48:22,160 --> 00:48:23,900 Effectively, it gives us a remote way 778 00:48:23,900 --> 00:48:26,500 to throw binaries into SQL Server. 779 00:48:26,500 --> 00:48:28,860 That stuff's not going to be touching disk 780 00:48:29,300 --> 00:48:30,860 as an executable itself. 781 00:48:31,040 --> 00:48:32,920 It's going to be an expanded SQL table. 782 00:48:33,300 --> 00:48:35,400 So forensics get more interesting. 783 00:48:36,100 --> 00:48:37,740 We can launch this stuff 784 00:48:37,740 --> 00:48:40,680 with whatever privileges you're able to master. 785 00:48:41,000 --> 00:48:44,320 It should allow us to rewrite Squeezer in CLR 786 00:48:44,320 --> 00:48:46,100 and make Squeezer a lot more powerful. 787 00:48:46,560 --> 00:48:47,920 But in the short term, 788 00:48:48,020 --> 00:48:51,400 what it's allowed us to do is combine Squeezer 789 00:48:51,400 --> 00:48:55,860 and the redirection that we showed you via JSP or ASP. 790 00:48:55,860 --> 00:48:58,660 So essentially, what it allows us to do 791 00:48:58,660 --> 00:49:00,140 is make another picture. 792 00:49:00,420 --> 00:49:03,760 In this case, if you consider that Squeezer 793 00:49:03,760 --> 00:49:05,980 basically abstracted this link 794 00:49:05,980 --> 00:49:09,000 so that it didn't matter how many hoops you went through, 795 00:49:09,140 --> 00:49:12,460 you and the database seemed to have a clear connection. 796 00:49:12,880 --> 00:49:17,220 We can now dump the JSP file equivalent 797 00:49:17,730 --> 00:49:19,440 inside a CLR program, 798 00:49:19,880 --> 00:49:22,300 get SQL Server to execute that, 799 00:49:22,500 --> 00:49:25,760 then push our traffic through Squeezer 800 00:49:25,860 --> 00:49:28,020 so even if there's no return channel, 801 00:49:28,360 --> 00:49:31,940 Squeezer will find one either via DNS or via timing, 802 00:49:32,100 --> 00:49:38,080 and then talk aiming our RDP client at our own proxy 803 00:49:38,080 --> 00:49:41,420 would then go from proxy to Squeezer. 804 00:49:41,500 --> 00:49:43,600 Squeezer would then talk to the database 805 00:49:43,600 --> 00:49:45,820 and traffic would go in or out 806 00:49:45,820 --> 00:49:48,720 however Squeezer decided to find it for you 807 00:49:48,720 --> 00:49:52,000 and then tunnel through on the remote end perfectly clearly. 808 00:49:52,580 --> 00:49:54,360 Okay, it's really small, 809 00:49:54,360 --> 00:49:57,980 but what we do have for that is a quick video 810 00:49:59,740 --> 00:50:02,160 which I think Marco has loaded. 811 00:50:05,620 --> 00:50:07,160 Marco has loaded here. 812 00:50:08,520 --> 00:50:10,960 And essentially, if you look at this... 813 00:50:12,160 --> 00:50:12,880 Okay, cool. 814 00:50:13,000 --> 00:50:13,800 So we're out of time. 815 00:50:14,240 --> 00:50:15,780 You're going to have to believe the video. 816 00:50:16,040 --> 00:50:17,700 We'll also put it up on the blog. 817 00:50:18,080 --> 00:50:19,940 Essentially, what the video allows you to do 818 00:50:19,940 --> 00:50:21,060 is tunnel through SQL 819 00:50:21,060 --> 00:50:24,140 exactly as we tunneled through JSP 820 00:50:24,360 --> 00:50:25,500 except a lot slower. 821 00:50:26,180 --> 00:50:30,840 The stuff that pushes through SQL is super, super ghetto, 822 00:50:30,940 --> 00:50:33,880 which means we only finished it during Black Hat, 823 00:50:34,040 --> 00:50:37,220 and I don't envision that we'll be releasing that for a while. 824 00:50:37,540 --> 00:50:41,700 The ASP, JSP, PHP will be on our blog 825 00:50:41,700 --> 00:50:43,300 as soon as we get back to South Africa. 826 00:50:43,940 --> 00:50:45,880 We'll be in 105 for questions. 827 00:50:46,000 --> 00:50:46,760 Thanks much.