1 00:00:00,000 --> 00:00:05,040 Okay, as a quick disclaimer, for those of you that saw Dan Kaminsky's presentation yesterday or at Black Hat, 2 00:00:05,240 --> 00:00:09,060 you'll notice that there's some overlap between mine and the first half of his presentation. 3 00:00:09,500 --> 00:00:15,400 I'll be doing some more live demonstrations, though, and we'll also go into more details about the attack technique. 4 00:00:16,980 --> 00:00:21,200 So while I was preparing my presentation, I was thinking about how firewalls have become so common 5 00:00:21,200 --> 00:00:23,420 that they've really entered pop culture. 6 00:00:23,820 --> 00:00:29,180 I've never seen a movie where the hero is rushing off to update IDS signatures or to install the latest Microsoft patch, 7 00:00:29,180 --> 00:00:31,120 but you hear firewalls mentioned all the time. 8 00:00:31,440 --> 00:00:33,880 There's even that movie last year named Firewall. 9 00:00:34,540 --> 00:00:36,520 And the movies never get the details right, of course, 10 00:00:36,580 --> 00:00:40,820 but the point is that firewalls have become synonymous with security for many people, 11 00:00:40,880 --> 00:00:46,780 ranging from senior citizens checking their email at home to, realistically, most IT professionals, 12 00:00:46,980 --> 00:00:52,600 and even some security professionals seem to be under the impression that firewalls are some kind of magical black box, 13 00:00:52,800 --> 00:00:56,900 drop them at a perimeter, and suddenly their private network is protected from the rest of the world. 14 00:00:57,320 --> 00:00:59,100 Now, I'm pretty sure that most people here have already, 15 00:00:59,180 --> 00:01:00,480 come to the realization that it's not, 16 00:01:00,980 --> 00:01:04,740 but what I'm going to demonstrate today is how anti-DNS pinning attacks can be used 17 00:01:04,740 --> 00:01:09,180 to completely bypass perimeter firewalls using technology that's so ubiquitous 18 00:01:09,180 --> 00:01:11,860 that only the most paranoid of organizations are completely immune. 19 00:01:13,580 --> 00:01:16,720 Now, to set some terminology real quick, 20 00:01:16,980 --> 00:01:20,500 you sometimes hear anti-DNS pinning referred to as DNS rebinding attacks, 21 00:01:20,800 --> 00:01:23,320 or even more rarely as quick swap DNS attacks. 22 00:01:23,740 --> 00:01:28,040 A quick Google search shows that anti-DNS pinning is the most common term, 23 00:01:28,100 --> 00:01:28,320 but, 24 00:01:28,320 --> 00:01:29,380 strictly speaking, 25 00:01:29,620 --> 00:01:32,320 DNS rebinding refers to a broader category of attack, 26 00:01:32,560 --> 00:01:35,040 and anti-DNS pinning is a specialized form of that. 27 00:01:35,340 --> 00:01:37,540 I'll be touching on some other forms of DNS rebinding, 28 00:01:37,680 --> 00:01:42,940 but the bulk of my presentation and the demonstrations will be on actual anti-DNS pinning. 29 00:01:45,660 --> 00:01:47,640 Now, out of curiosity, by show of hands, 30 00:01:47,740 --> 00:01:52,020 how many of you have heard of anti-DNS pinning or DNS rebinding before you saw the Black Hat schedule? 31 00:01:54,060 --> 00:01:55,420 Okay, yeah, not that many. 32 00:01:55,580 --> 00:01:58,280 Now, how many have heard of and know how to launch a cross-site script? 33 00:02:01,360 --> 00:02:06,680 I'm going to be referring to some more common forms of JavaScript and web-based malware, 34 00:02:07,000 --> 00:02:10,300 things like cross-site scripting, port scanning using JavaScript. 35 00:02:11,360 --> 00:02:14,440 There's a lot of different techniques that have been well documented, 36 00:02:14,520 --> 00:02:16,360 much more than DNS rebinding. 37 00:02:16,680 --> 00:02:17,940 I'm not going to talk about these, 38 00:02:18,100 --> 00:02:22,420 but if web security is part of your responsibilities or part of your interest, 39 00:02:22,460 --> 00:02:23,700 if you're more on the supply side, 40 00:02:23,980 --> 00:02:26,800 then you definitely should be familiar with these techniques. 41 00:02:28,840 --> 00:02:30,800 There are four things that I will be covering in the presentation. 42 00:02:31,320 --> 00:02:34,220 First, I'll talk about what simple DNS rebinding attacks are 43 00:02:34,220 --> 00:02:37,020 and why DNS pinning was the proper solution for them. 44 00:02:37,460 --> 00:02:43,760 I'll show how anti-DNS pinning attacks can be used to turn a web browser into an HTTP proxy 45 00:02:43,760 --> 00:02:44,920 using nothing but JavaScript. 46 00:02:45,660 --> 00:02:48,540 Even better, I'll show how a web browser can be turned into a SOX proxy 47 00:02:48,540 --> 00:02:50,040 using nothing but Java applets. 48 00:02:50,280 --> 00:02:54,580 And then finally, I'll touch on some other DNS rebinding attacks that are related. 49 00:02:56,460 --> 00:02:58,080 I'm not going to get too much into fundamentals, 50 00:02:58,080 --> 00:02:59,780 but I do want to talk about the same origin policy 51 00:02:59,780 --> 00:03:04,140 because it is so critical to most of the web browser security model. 52 00:03:04,800 --> 00:03:08,540 The same origin policy was introduced by Netscape along with Navigator 2 53 00:03:08,540 --> 00:03:09,720 when they debuted JavaScript. 54 00:03:10,180 --> 00:03:14,260 And essentially, the policy says that a script from origin A 55 00:03:14,640 --> 00:03:17,100 cannot read or manipulate data from origin B. 56 00:03:18,980 --> 00:03:22,000 The origin is defined as the protocol or scheme, 57 00:03:22,160 --> 00:03:24,260 so usually HTTP versus HTTPS, 58 00:03:24,780 --> 00:03:26,600 the host name, and the port number. 59 00:03:26,740 --> 00:03:28,020 If any one of those three change, 60 00:03:28,080 --> 00:03:31,320 then it becomes a different origin and the script can't manipulate that data. 61 00:03:31,760 --> 00:03:34,220 The IP address is not part of the same origin policy. 62 00:03:34,600 --> 00:03:39,080 Originally, that was because of virtual hosting and load balancing issues, 63 00:03:39,740 --> 00:03:42,740 but that is critical to the attacks I'll be demonstrating 64 00:03:42,740 --> 00:03:47,160 since IP address is actually how servers and hosts on the internet communicate. 65 00:03:49,200 --> 00:03:52,100 The same origin policy was a good idea when Netscape first introduced it, 66 00:03:52,140 --> 00:03:54,020 and it's definitely prevented a lot of attacks over the years. 67 00:03:54,140 --> 00:03:56,000 But as you'll see the rest of my presentation, 68 00:03:56,180 --> 00:03:58,020 it's also very flawed and very broken today. 69 00:03:58,020 --> 00:04:01,440 Probably the best known example of that is cross-site scripting, 70 00:04:01,480 --> 00:04:06,540 which essentially gets around the policy by injecting references to JavaScript into the targeted host. 71 00:04:07,140 --> 00:04:09,400 Now, with a properly secured website, 72 00:04:09,500 --> 00:04:11,100 it's not going to be vulnerable to cross-site scripting, 73 00:04:11,100 --> 00:04:13,400 with the exception of a handful of rare client-side vulnerabilities. 74 00:04:14,260 --> 00:04:18,540 But if an attacker is able to control the DNS server for an internet domain, 75 00:04:18,680 --> 00:04:22,520 a new type of attack to bypass the same origin policy becomes possible, 76 00:04:22,680 --> 00:04:24,580 and that's simple DNS rebinding. 77 00:04:25,680 --> 00:04:26,880 Now, as I alluded to earlier, 78 00:04:27,200 --> 00:04:28,000 simple DNS rebinding is a very simple DNS rebinding. 79 00:04:28,020 --> 00:04:31,820 Simple DNS rebinding is kind of the grandfather of anti-DNS pinning attacks, 80 00:04:31,980 --> 00:04:35,480 so you'll see a lot of similarities between this slide and some future ones. 81 00:04:36,660 --> 00:04:38,900 The DNS rebinding goes something like this. 82 00:04:39,300 --> 00:04:42,260 A web browser is convinced to visit a malicious site, 83 00:04:42,340 --> 00:04:43,740 probably through cross-site scripting. 84 00:04:43,840 --> 00:04:49,300 So the first thing it does is send a DNS query for that host name. 85 00:04:49,480 --> 00:04:50,840 The attacker controls DNS, 86 00:04:51,020 --> 00:04:54,680 so he responds with the IP address of his attack web server. 87 00:04:54,960 --> 00:04:56,540 The browser sends a request there, 88 00:04:56,600 --> 00:04:58,000 and some kind of attack payload is retrieved. 89 00:04:58,000 --> 00:05:00,500 Now, at this point, we're still looking at it from a high level, 90 00:05:00,560 --> 00:05:02,100 so this payload could be written in anything. 91 00:05:03,320 --> 00:05:04,600 The browser becomes infected, 92 00:05:04,880 --> 00:05:08,960 pauses long enough for the TTL or lifetime on that DNS record to expire, 93 00:05:09,480 --> 00:05:12,180 and then initiates a new request back to the same host name. 94 00:05:12,820 --> 00:05:17,020 Because the IP address is timed out and is no longer in the DNS cache of the browser, 95 00:05:17,200 --> 00:05:19,900 the browser sends a new query back to the same DNS server. 96 00:05:20,360 --> 00:05:24,720 But this time, the attacker responds with the IP address of the victim server, 97 00:05:24,940 --> 00:05:26,980 which is usually on the same private network as the browser. 98 00:05:28,320 --> 00:05:30,880 The browser lets the payload connect to that server, 99 00:05:31,020 --> 00:05:32,240 some kind of attack is launched, 100 00:05:32,540 --> 00:05:34,180 presumably useful data is returned, 101 00:05:34,440 --> 00:05:35,880 and then forward back to the attacker. 102 00:05:36,260 --> 00:05:39,080 Now, this entire time, the protocol didn't change, 103 00:05:39,280 --> 00:05:40,400 the host name didn't change, 104 00:05:40,560 --> 00:05:41,540 and the port number didn't change, 105 00:05:41,640 --> 00:05:44,000 which means that none of this violates the same origin policy. 106 00:05:46,380 --> 00:05:48,620 DNS pinning was introduced to prevent this type of attack. 107 00:05:49,080 --> 00:05:54,120 Essentially, it causes a browser to lock the first IP address it sees for a host name 108 00:05:54,120 --> 00:05:55,480 into its cache to pin it there. 109 00:05:55,960 --> 00:05:57,920 In theory, almost subsequently, 110 00:05:58,000 --> 00:06:00,420 a quit request to the same host name should use that IP address, 111 00:06:01,080 --> 00:06:05,240 and no further requires of DNS during that pinning period should be possible. 112 00:06:06,360 --> 00:06:10,740 The first attack against DNS pinning was documented in 96 by some researchers at Princeton. 113 00:06:11,720 --> 00:06:13,800 It was against the JVM, not against web browsers, 114 00:06:13,840 --> 00:06:15,520 so I'll go into detail about it more later. 115 00:06:16,360 --> 00:06:19,600 Interestingly, though, DNS pinning is really a violation of the standard. 116 00:06:19,900 --> 00:06:27,060 RFC 2616 clearly states that any HTTP client that is going to cache DNS responses 117 00:06:27,060 --> 00:06:28,900 must respect the TTL. 118 00:06:29,940 --> 00:06:31,420 Now, if this was actually implemented, 119 00:06:31,640 --> 00:06:34,660 then it would cause simple DNS rebinding attacks to be trivial against browsers. 120 00:06:35,620 --> 00:06:41,460 Ironically, the reason that the authors put this rule in the standard was for security. 121 00:06:41,620 --> 00:06:45,520 They were concerned that if a client cached an IP address for too long, 122 00:06:46,020 --> 00:06:48,920 that during that caching period, 123 00:06:49,160 --> 00:06:51,420 the IP address might be reassigned to a different party. 124 00:06:51,680 --> 00:06:54,560 And if the client decided to send more data to that IP address, 125 00:06:54,720 --> 00:06:56,100 then the data would be subject to abuse 126 00:06:56,100 --> 00:06:57,300 by the new owners. 127 00:06:59,420 --> 00:07:02,800 Realistically, IP addresses don't change ownership that often these days, 128 00:07:02,960 --> 00:07:09,500 and using this rule puts too much faith in the response that's provided by the DNS server, 129 00:07:09,640 --> 00:07:11,900 which shouldn't be done. 130 00:07:12,140 --> 00:07:15,380 There's no reason to trust just some random DNS server on the Internet. 131 00:07:17,160 --> 00:07:23,200 The first attack against web browser pinning was documented in 2003 by Josh Soroff, 132 00:07:23,200 --> 00:07:24,480 a developer on the Mozilla project. 133 00:07:25,300 --> 00:07:25,840 And... 134 00:07:26,100 --> 00:07:26,980 it was pretty much ignored. 135 00:07:27,220 --> 00:07:29,420 The security community didn't look at it much. 136 00:07:29,620 --> 00:07:32,180 It didn't get much reference that I could find, at least, 137 00:07:32,220 --> 00:07:33,020 until last summer, 138 00:07:33,140 --> 00:07:37,000 when a MIT client made a reference to it in a post on the WebAppSec mailing list. 139 00:07:38,260 --> 00:07:39,820 The attack goes something like this. 140 00:07:40,500 --> 00:07:42,400 Trick a browser into going to a malicious site. 141 00:07:42,480 --> 00:07:43,580 Browser downloads a payload. 142 00:07:44,100 --> 00:07:47,360 And the attacker either waits for the user to close the browser 143 00:07:47,360 --> 00:07:48,840 or causes the browser to crash, 144 00:07:49,000 --> 00:07:50,600 which I think most of us know is usually trivial. 145 00:07:51,140 --> 00:07:52,980 Now, this point is pretty easy, fairly straightforward. 146 00:07:53,380 --> 00:07:55,980 The hard part is that the attacker has to get the browser, 147 00:07:55,980 --> 00:08:00,060 to somehow reload that payload from its local disk cache, the content cache. 148 00:08:00,740 --> 00:08:02,140 That's a pretty tricky thing to do. 149 00:08:02,620 --> 00:08:05,900 Josh had suggested using a compromised advertising service, 150 00:08:06,020 --> 00:08:08,660 which is a good idea, but it's still as far from simple. 151 00:08:09,500 --> 00:08:11,280 If the attacker manages to do this, 152 00:08:11,400 --> 00:08:15,960 then the payload, when it's reloaded, 153 00:08:15,980 --> 00:08:23,120 will cause the browser to send a new request to the same host, 154 00:08:23,640 --> 00:08:25,820 but this time the attacker will... 155 00:08:25,820 --> 00:08:28,260 will, of course, have the DNS server respond with the victim IP address, 156 00:08:28,420 --> 00:08:32,020 and then the rest of the attack is very similar to the simple DNS rebinding. 157 00:08:34,040 --> 00:08:36,320 Now, on the one hand, this attack is fairly difficult to defeat 158 00:08:36,320 --> 00:08:37,940 with conventional browser design, 159 00:08:38,100 --> 00:08:40,420 because you have to drop the DMS cache at some point, 160 00:08:40,460 --> 00:08:42,740 and the browser closing is a logical time to do that. 161 00:08:43,120 --> 00:08:44,600 But on the other hand, it's easy to defeat 162 00:08:44,600 --> 00:08:47,900 by having the browser clear its content cache on exit, 163 00:08:48,060 --> 00:08:49,740 something that a lot of users already do automatically. 164 00:08:51,520 --> 00:08:54,860 It's also very difficult to launch because of the payload reloading problem. 165 00:08:55,060 --> 00:08:55,720 And even if... 166 00:08:55,820 --> 00:08:57,500 even if the attacker manages to accomplish all of this, 167 00:08:57,640 --> 00:08:59,620 it is still very, very slow, 168 00:08:59,780 --> 00:09:02,200 because every time the attacker wants to contact a new server, 169 00:09:02,460 --> 00:09:04,560 he has to repeat the process of loading the payload, 170 00:09:04,720 --> 00:09:06,280 crashing the browser, reloading the payload, 171 00:09:06,840 --> 00:09:08,060 which is pretty time-consuming. 172 00:09:08,480 --> 00:09:10,660 But there are more effective techniques that are possible. 173 00:09:11,800 --> 00:09:17,740 Shortly after Amit Klein posted that comment on Web AppSec last year, 174 00:09:18,120 --> 00:09:20,100 Martin Johns documented that modern browsers, 175 00:09:20,280 --> 00:09:23,160 namely IE and Firefox, but pretty much all of them, 176 00:09:23,820 --> 00:09:25,700 don't fully implement DNS pinning. 177 00:09:26,520 --> 00:09:30,900 It turns out that if the browser detects that a web server is unavailable, 178 00:09:31,120 --> 00:09:33,900 it will dump the cache and re-query DNS. 179 00:09:34,280 --> 00:09:38,660 Now, the intent was to allow browsers to more gracefully recover from web server outages, 180 00:09:39,220 --> 00:09:43,140 but the result is that an attacker can coordinate a firewall rule change, 181 00:09:43,280 --> 00:09:44,980 simulating a web server outage, 182 00:09:45,060 --> 00:09:50,600 with a DNS change pointing it at a victim server to launch a successful attack. 183 00:09:51,960 --> 00:09:53,200 It looks something like this. 184 00:09:53,240 --> 00:09:55,160 And again, this is very similar to simple DNS rebinding. 185 00:09:55,320 --> 00:09:55,800 It looks something like this. And again, this is very similar to simple DNS rebinding. 186 00:09:55,820 --> 00:09:56,140 It looks something like this. And again, this is very similar to simple DNS rebinding. 187 00:09:56,140 --> 00:10:00,840 The victim browser goes to a malicious site, pins the response, this time in its cache, 188 00:10:01,460 --> 00:10:04,780 gets the attack payload, this time the firewall rule is set up, 189 00:10:05,800 --> 00:10:10,860 and the payload, when it runs, will try to reconnect to the original server. 190 00:10:11,160 --> 00:10:13,380 The request will time out because of the firewall rule, 191 00:10:13,540 --> 00:10:18,080 which causes the browser to dump its cache and re-query DNS. 192 00:10:18,440 --> 00:10:21,900 Of course, this time it gets the IP address of the victim server back 193 00:10:21,900 --> 00:10:24,020 and proceeds with the attack, same way. 194 00:10:24,860 --> 00:10:29,640 In my demonstration of this attack, there's a few different components that deserve more explanation. 195 00:10:30,240 --> 00:10:34,380 As I mentioned, the victim browser is just a simple browser using JavaScript only, 196 00:10:34,440 --> 00:10:36,360 no plugins are required. I'll be using Firefox. 197 00:10:39,220 --> 00:10:41,960 The victim web server is usually on a private network, 198 00:10:42,080 --> 00:10:45,260 the same one that the victim browser is on. 199 00:10:45,720 --> 00:10:47,740 The attack server is where most of the cool stuff happens. 200 00:10:47,840 --> 00:10:48,720 There's two IP addresses. 201 00:10:49,420 --> 00:10:53,340 Well, first of all, there's a backend DNS or MySQL server 202 00:10:53,340 --> 00:10:56,660 for communication between the different components on the attack server. 203 00:10:56,920 --> 00:11:02,140 Then on the primary IP address, there's a number of sort of supporting functions. 204 00:11:02,380 --> 00:11:05,440 The authoritative DNS server for the attacker's domain is there. 205 00:11:05,620 --> 00:11:09,680 There's an HTTP proxy that accepts requests from the attacker's browser 206 00:11:09,680 --> 00:11:11,820 and forwards them to the payload running on the victim browser. 207 00:11:13,600 --> 00:11:20,120 There is finally a multifunction CGI script that does a number of functions. 208 00:11:20,200 --> 00:11:23,320 It will present an attack server, 209 00:11:23,320 --> 00:11:26,260 an attack console to the attacker web-based console for issuing new commands. 210 00:11:26,680 --> 00:11:30,940 It accepts polls for new commands or new requests from the victim browser, 211 00:11:31,160 --> 00:11:33,820 and also accepts response data from the victim browser. 212 00:11:34,120 --> 00:11:39,700 On the secondary IP address, the CGI script will actually serve up the payload 213 00:11:39,700 --> 00:11:44,560 that's being used to perform the client-side logic for the anti-DNS pinning attack. 214 00:11:44,800 --> 00:11:46,580 Now, it's important that there be a secondary IP address 215 00:11:46,580 --> 00:11:53,080 because while the secondary IP address is firewalled off to simulate a web server outage, 216 00:11:53,320 --> 00:11:56,880 the primary IP address still needs to be available for command and control functions. 217 00:11:58,880 --> 00:12:05,800 These components communicate using a number of fairly well-established techniques for JavaScript malware. 218 00:12:07,760 --> 00:12:10,580 Now, some of these might seem a little convoluted on the surface, 219 00:12:10,660 --> 00:12:14,220 but keep in mind that all of the communication has to be initiated by the victim browser. 220 00:12:14,480 --> 00:12:16,140 It's not accepting any inbound connections. 221 00:12:16,860 --> 00:12:22,880 So, for requesting new commands from the control server, the attack server, 222 00:12:23,320 --> 00:12:27,200 it's implementing it using script requests, and I'll get into that in a bit. 223 00:12:27,660 --> 00:12:30,940 To send data, it uses either image requests or HTML forms, 224 00:12:31,060 --> 00:12:36,160 and the victim browser requests data from the victim server using XML HTTP requests. 225 00:12:39,740 --> 00:12:46,860 Remember that the same origin policy states that a script from origin A should not be able to access, 226 00:12:47,300 --> 00:12:49,760 should not be able to read or manipulate data on origin B. 227 00:12:50,180 --> 00:12:52,920 A glaring exception to this are other JavaScript files. 228 00:12:53,320 --> 00:12:57,400 And that's how the payload communicates with the attack server. 229 00:12:57,720 --> 00:13:02,960 Essentially, the payload will append a new script tag onto the document periodically, 230 00:13:03,340 --> 00:13:07,740 and the source of that tag is set to the controller script on the attack server. 231 00:13:08,020 --> 00:13:13,580 The attack server responds with the data in JavaScript with a predictably named variable, 232 00:13:13,780 --> 00:13:15,860 in this case, just an element of an array. 233 00:13:16,680 --> 00:13:21,220 Now, theoretically, I can imagine some cross-site scripting filters detecting this, 234 00:13:21,320 --> 00:13:23,200 because it is really cross-site scripting. 235 00:13:24,040 --> 00:13:28,480 I want to emphasize, though, that cross-site scripting is not required for any of the parts of my demonstration. 236 00:13:28,720 --> 00:13:31,140 It's the most elegant solution for some things, especially this. 237 00:13:31,560 --> 00:13:35,740 But there are other techniques available for tunneling data off-domain, 238 00:13:35,740 --> 00:13:36,940 essentially out-of-band communications. 239 00:13:37,740 --> 00:13:42,500 Two that I've experimented with are tunneling data over the image and width of an image request, 240 00:13:43,160 --> 00:13:50,660 and also using parameters within that can be inferred from a cross-site, excuse me, cascading style sheet. 241 00:13:51,460 --> 00:13:53,180 I don't really have time to go into these in detail, 242 00:13:53,260 --> 00:13:53,300 I don't really have time to go into these in detail, 243 00:13:53,320 --> 00:13:56,260 but the white paper associated with my presentation does. 244 00:13:58,600 --> 00:14:02,940 To send data from the victim browser to the attack server, there's two methods that can be used. 245 00:14:03,280 --> 00:14:08,520 The first one, if it's a small amount of data, an image object is created by the JavaScript payload. 246 00:14:08,860 --> 00:14:11,920 The source of the image is set to the controller script on the attack server, 247 00:14:12,600 --> 00:14:17,200 and once it's appended to the document, the browser will automatically process the request 248 00:14:17,860 --> 00:14:19,840 and send it to the attack server. 249 00:14:20,100 --> 00:14:23,300 The controller script on the attack server doesn't even need to respond with a value, 250 00:14:23,300 --> 00:14:23,600 it's just a valid image. 251 00:14:25,360 --> 00:14:31,220 The data is actually appended into the URL of the query of the URL string. 252 00:14:32,200 --> 00:14:34,640 If it's a larger amount of data that can't fit into a URL, 253 00:14:35,120 --> 00:14:38,080 or if it's binary data that you don't want to encode for some reason, 254 00:14:38,300 --> 00:14:43,020 then an HTML form is used, the data is put into a text input box, 255 00:14:43,260 --> 00:14:47,940 the action of the form is set to the controller script on the attack server, 256 00:14:48,200 --> 00:14:52,620 the target is set to an iframe that's unused so that the web page won't redirect 257 00:14:52,620 --> 00:14:56,200 to the action destination, and of course it's submitted with POST. 258 00:14:57,780 --> 00:15:03,240 Finally, the XMLHttpRequest, like I said, is used to request data by the victim browser 259 00:15:03,240 --> 00:15:04,520 from the victim web server. 260 00:15:06,280 --> 00:15:09,760 XMLHttpRequest is an object in the HTML document object model. 261 00:15:10,000 --> 00:15:17,180 It's probably best known for being the core functionality of AJAX sites like Google Maps 262 00:15:17,180 --> 00:15:18,160 or Yahoo Mail. 263 00:15:20,420 --> 00:15:22,000 Normally it can only return text data. 264 00:15:22,000 --> 00:15:25,100 As the name implies, it was designed for exchanging XML sheets. 265 00:15:25,580 --> 00:15:33,120 And fortunately, Marcus Granato documented how binary data can be retrieved 266 00:15:33,120 --> 00:15:35,960 by setting the character set to XUserDefine. 267 00:15:36,040 --> 00:15:37,440 Now, I have no idea how he figured this out. 268 00:15:37,900 --> 00:15:41,520 It's a rather esoteric application of Unicode, but it works. 269 00:15:41,680 --> 00:15:46,320 And without it, you wouldn't be able to request binary files like images or PDFs, things like that. 270 00:15:48,040 --> 00:15:51,980 Remember, well, I should say that one important thing to remember about XMLHttpRequest 271 00:15:52,000 --> 00:15:55,140 is that it can only communicate back with the origin server, 272 00:15:55,320 --> 00:15:58,060 because otherwise it would be a blatant violation of the same origin policy. 273 00:15:58,800 --> 00:16:01,940 Once the IP address has been switched in the anti-DMS pinning attack, 274 00:16:02,200 --> 00:16:07,500 the victim server is considered origin, which means that XMLHttpRequest can't be used 275 00:16:07,500 --> 00:16:09,560 to communicate back to the attack server at that point. 276 00:16:09,620 --> 00:16:13,140 And that's why those previous methods were required for out-of-band communication. 277 00:16:14,740 --> 00:16:16,960 This is a representation of the demonstration environment. 278 00:16:17,280 --> 00:16:21,160 It's a fairly realistic scenario for most corporate networks. 279 00:16:21,160 --> 00:16:26,140 The internal network is using private IP space, separated from the internet by a firewall. 280 00:16:26,480 --> 00:16:29,300 The firewall allows no inbound connections from the internet. 281 00:16:29,580 --> 00:16:34,100 The only outbound connections are allowed on ports 80 and 443 for web traffic, 282 00:16:34,420 --> 00:16:38,360 and DNS is allowed out from the internal resolving DNS server. 283 00:16:39,580 --> 00:16:43,040 Of course, a lot of corporate environments use proxy servers, 284 00:16:43,220 --> 00:16:46,860 which doesn't necessarily break anti-DMS pinning attacks, 285 00:16:47,060 --> 00:16:48,820 and in some cases can even make them more powerful. 286 00:16:50,240 --> 00:16:51,140 That's not going to happen. 287 00:16:51,140 --> 00:16:52,160 It's going to be in this demonstration, though. 288 00:16:53,260 --> 00:16:55,440 There are three devices on the corporate network. 289 00:16:55,620 --> 00:16:59,320 There's a Linux server that's running a simple web application with a MySQL backend. 290 00:16:59,840 --> 00:17:05,840 There's a Windows server that has file sharing enabled and also acts as the internal resolving DNS. 291 00:17:06,220 --> 00:17:09,000 And then finally, there's the victim browser, victim workstation, 292 00:17:09,240 --> 00:17:15,100 which is running Windows XP, fully patched version to Firefox, at least as of a few weeks ago. 293 00:17:15,820 --> 00:17:18,200 And the user is running with non-administrative rights. 294 00:17:18,280 --> 00:17:20,600 So I'm saying that just to reinforce. 295 00:17:20,600 --> 00:17:24,620 This is not using any patchable vulnerabilities in software. 296 00:17:24,940 --> 00:17:27,440 It's not using privilege escalation or anything like that. 297 00:17:27,540 --> 00:17:30,180 This is standard JavaScript browser functionality. 298 00:17:31,600 --> 00:17:37,240 On the internet side, there's a fictional website that has already been compromised by the attacker. 299 00:17:37,580 --> 00:17:39,300 Some cross-site scripting has been injected. 300 00:17:39,800 --> 00:17:40,780 These are a dime a dozen. 301 00:17:40,900 --> 00:17:43,140 Google, Yahoo, they've all had problems with cross-site scripting. 302 00:17:43,820 --> 00:17:48,240 The attack server we've already talked about, and of course, there's the attacker's workstation. 303 00:17:49,400 --> 00:17:50,580 From a physical point of view, 304 00:17:50,580 --> 00:17:54,160 the attack, the environment is implemented on two laptops, 305 00:17:54,420 --> 00:17:57,980 both running multiple virtual machines connected by a firewall running DDWRT. 306 00:17:58,700 --> 00:18:01,640 Thank you to my colleague, Eric Dupre, for assistance in getting the firewall 307 00:18:01,640 --> 00:18:03,500 and several of the virtual machines set up. 308 00:18:05,520 --> 00:18:08,700 Now, I've already gone over into DNS pinning from a high, maybe even a medium level, 309 00:18:08,800 --> 00:18:11,580 but it's, for at least a web-based attack, it's fairly complicated. 310 00:18:11,740 --> 00:18:13,640 So I'm going to go over it again in more detail, step by step. 311 00:18:14,480 --> 00:18:17,860 Of course, it starts off with the victim browser visiting a malicious website 312 00:18:18,380 --> 00:18:20,420 and loading some small piece of JavaScript. 313 00:18:20,580 --> 00:18:21,000 And that's what we're going to talk about in a little bit. 314 00:18:21,000 --> 00:18:22,260 The first thing we're going to talk about is the malicious JavaScript malware as a result. 315 00:18:23,720 --> 00:18:26,300 The malicious JavaScript is pretty simple. 316 00:18:26,360 --> 00:18:32,880 The only thing it does is redirect the browser to a malicious web page on the attacker's web server. 317 00:18:33,160 --> 00:18:38,100 Now, in a real attack, this would probably be in maybe a pop-under window, in an invisible iframe. 318 00:18:38,280 --> 00:18:43,480 There's a number of ways of hiding the fact that malicious JavaScript is running from the user. 319 00:18:43,600 --> 00:18:44,980 I'm not going to talk about any of these. 320 00:18:45,160 --> 00:18:49,920 In my presentation, the window will be large, so that debug statements can help narrate the attack. 321 00:18:49,920 --> 00:18:55,140 But properly done, the user would be very unlikely to notice anything amiss. 322 00:18:58,200 --> 00:19:00,340 The base attack page is also pretty simple. 323 00:19:00,460 --> 00:19:04,820 Every second and a half, it appends a new script tag using the technologies we discussed earlier. 324 00:19:04,980 --> 00:19:07,580 It asks the attack server for new commands. 325 00:19:10,280 --> 00:19:12,820 Every time it pulls, the first time rather it pulls, 326 00:19:13,780 --> 00:19:17,140 the controller script will insert a record of the session into the database, 327 00:19:17,260 --> 00:19:19,700 so that the attacker can see it on the attack console. 328 00:19:19,700 --> 00:19:24,580 Every time it pulls, it asks the controller script to go out to the database 329 00:19:24,580 --> 00:19:26,680 and look to see if there are any new commands for it. 330 00:19:26,820 --> 00:19:30,420 If there are, it will return it in JavaScript format to the victim browser. 331 00:19:31,760 --> 00:19:37,000 Now, at this point, the attacker can start executing arbitrary JavaScript on the victim browser 332 00:19:37,000 --> 00:19:39,740 to probe the network, perform reconnaissance. 333 00:19:39,980 --> 00:19:41,060 We're going to skip this step. 334 00:19:41,180 --> 00:19:42,880 We're going to assume the attacker has already performed recon 335 00:19:43,340 --> 00:19:46,180 and has identified a web browser, excuse me, a web server, 336 00:19:46,860 --> 00:19:49,680 in this case, the Linux box that he wants to use. 337 00:19:49,700 --> 00:19:57,360 So, the attacker starts up the HTTP proxy server and running on the attack server. 338 00:19:57,720 --> 00:20:01,840 The first time that he sends a request to the proxy server, 339 00:20:02,000 --> 00:20:05,100 it checks to see if it's seen any other requests for that specific IP address. 340 00:20:05,400 --> 00:20:10,380 If it hasn't, it knows that it needs to set the base for a new anti-DNS pinning attack. 341 00:20:10,780 --> 00:20:13,440 So, the first thing it does is create a random host name 342 00:20:13,440 --> 00:20:18,200 and a corresponding A record on the attack domain's DNS server. 343 00:20:18,540 --> 00:20:19,680 That is the first thing it does is create a random host name and a corresponding A record on the attack domain's DNS server. 344 00:20:19,680 --> 00:20:25,000 Initially, that record points at the secondary IP address on the attack web server. 345 00:20:26,600 --> 00:20:31,300 It also creates a command for the victim browser to create a new iframe. 346 00:20:31,580 --> 00:20:43,000 And the iframe source points at this random host name and the controller script asking for a new iframe attack payload. 347 00:20:43,120 --> 00:20:45,400 Basically, the client side piece of the DNS switch. 348 00:20:48,300 --> 00:20:52,300 Once the iframe payload completes loading from the attack server, 349 00:20:52,540 --> 00:20:58,120 then it will immediately send back a message to the attack server saying, 350 00:20:58,200 --> 00:21:01,220 I'm done, the payload's loaded, we're ready to proceed with the DNS switch. 351 00:21:01,800 --> 00:21:04,580 So, the attack server creates a firewall rule, 352 00:21:04,720 --> 00:21:09,020 blocking access from the victim browser to the attack server on the secondary IP address. 353 00:21:09,200 --> 00:21:15,280 And then also switches that DNS record to point at the victim IP address that was provided by the attacker's proxy request. 354 00:21:18,460 --> 00:21:23,440 At the same time, the iframe payload retrieves the next URL that's going to be processed, 355 00:21:23,580 --> 00:21:28,660 the first one that was sent by the attacker, and creates an XML HTTP request object for it. 356 00:21:29,080 --> 00:21:34,680 The browser will start to process it and will try to connect to the IP address that it's pinned in its cache, 357 00:21:34,820 --> 00:21:36,740 but it's going to fail due to the firewall rule. 358 00:21:37,480 --> 00:21:44,240 Eventually, the browser will dump its DNS cache, because it timed out, and re-query DNS. 359 00:21:45,400 --> 00:21:49,720 Once this happens, the attack server, of course, will reply with the IP address of the victim server. 360 00:21:57,880 --> 00:22:05,320 As soon as the payload sees that the new IP address has come down, 361 00:22:05,580 --> 00:22:08,760 it sends a message back to the control server saying, okay, we're done. 362 00:22:09,140 --> 00:22:13,860 The victim browser has pinned the victim server's IP address in its cache. 363 00:22:14,860 --> 00:22:15,380 We're ready to proceed. 364 00:22:15,400 --> 00:22:16,440 We're ready to start processing requests. 365 00:22:16,760 --> 00:22:18,460 You can get rid of that firewall rule. 366 00:22:22,580 --> 00:22:26,900 And right after that, the browser will process the XML HTTP request object, 367 00:22:27,860 --> 00:22:30,040 sending it this time to, of course, the victim server, 368 00:22:30,260 --> 00:22:34,860 which will respond with some kind of content and forward it back to the attack server. 369 00:22:35,600 --> 00:22:40,160 This whole time, the proxy server has been polling the database, 370 00:22:40,280 --> 00:22:43,380 looking for a response to that initial request that was sent by the attacker. 371 00:22:43,380 --> 00:22:47,840 As soon as it sees this response, it grabs it, sends it back to the attacker's browser, 372 00:22:48,020 --> 00:22:48,700 and, of course, it's rendered. 373 00:22:50,000 --> 00:22:53,880 So, I'm sure that all clears mud, and let's get started with the demonstration. 374 00:23:17,260 --> 00:23:18,340 There we go. Okay. 375 00:23:26,000 --> 00:23:30,860 Okay, this is the attacker's workstation, the console. 376 00:23:31,020 --> 00:23:33,900 There's nothing running on it right now since there's no session that's active. 377 00:23:36,160 --> 00:23:40,420 This is the victim's workstation, starting up a new instance of Firefox. 378 00:23:40,420 --> 00:23:51,400 And we'll start off with the victim just going to some fictitious website. 379 00:23:51,700 --> 00:23:58,120 It's already been processed, attacked by the attacker with some cross-site scripting. 380 00:23:58,200 --> 00:24:01,480 The user clicks on a link and is redirected to an attacker page. 381 00:24:01,720 --> 00:24:06,240 Now, of course, normally none of this would be visible to the victim. 382 00:24:06,460 --> 00:24:09,140 If we switch back to the attacker's browser, 383 00:24:09,140 --> 00:24:13,180 we can refresh and see that the session has appeared in the console. 384 00:24:13,440 --> 00:24:15,460 We can run some arbitrary JavaScript. 385 00:24:15,940 --> 00:24:19,420 If we switch back, it pops up. Clear that. 386 00:24:19,740 --> 00:24:23,660 So, this would normally be the point that the attacker starts performing recon. 387 00:24:24,020 --> 00:24:26,980 We're going to just start up the HTTP proxy 388 00:24:30,100 --> 00:24:34,080 and confirm that the web browser is configured to use it, and it is. 389 00:24:34,160 --> 00:24:36,220 This is the primary IP address of the attack server. 390 00:24:45,080 --> 00:24:49,980 Okay, so if we switch back to the victim side, we can see that a new iframe has popped up. 391 00:24:50,540 --> 00:24:55,920 This time it is, well, it's going to a random host name. 392 00:24:58,900 --> 00:25:01,480 I forgot to start up the Wireshark earlier. 393 00:25:01,900 --> 00:25:05,720 Now, at this point, the DNS change has already been made. 394 00:25:05,820 --> 00:25:07,740 The firewall rule has already been created. 395 00:25:07,740 --> 00:25:17,720 So, if we start the packet capture, we should see that it's starting to time out. 396 00:25:17,820 --> 00:25:21,320 Now, I wanted to show you some other packets, and I forgot to start this earlier. 397 00:25:24,420 --> 00:25:26,300 We're going to have a minute to wait now. 398 00:25:28,320 --> 00:25:31,020 You can see that Firefox is essentially hung at this point. 399 00:25:32,760 --> 00:25:33,960 There's a few reasons for that. 400 00:25:34,140 --> 00:25:37,720 One of them is that the payload is fairly low. 401 00:25:37,720 --> 00:25:43,360 It's fairly aggressive in trying to cause the browser to recognize that the web server is down. 402 00:25:43,540 --> 00:25:49,300 If the payload is less aggressive, it won't cause Firefox to hang. 403 00:25:49,480 --> 00:25:50,300 So, you can hide that. 404 00:25:51,320 --> 00:25:54,000 There's also some other techniques. 405 00:25:54,140 --> 00:26:00,060 If both addresses were on the internet, then you can actually flip it in just under a second. 406 00:26:00,140 --> 00:26:05,900 There was a white paper that was released by the security lab at Stanford 407 00:26:05,900 --> 00:26:07,640 that referenced some techniques on that. 408 00:26:07,640 --> 00:26:10,900 But they don't work, at least from what I can tell, 409 00:26:10,980 --> 00:26:14,880 they don't work if you're using a private IP address as the victim. 410 00:26:18,060 --> 00:26:18,540 Okay. 411 00:26:19,860 --> 00:26:23,240 So, you can see that the victim browser switched over. 412 00:26:23,320 --> 00:26:26,700 This is the iframe that is being posted back in. 413 00:26:26,780 --> 00:26:27,660 Here's the HTML form. 414 00:26:28,260 --> 00:26:37,140 If we go back to the browser, you can see that a fairly primitive web application has been displayed. 415 00:26:37,800 --> 00:26:40,020 And at this point, the attacker can start interacting. 416 00:26:41,900 --> 00:26:42,680 Well, let's see. 417 00:26:42,740 --> 00:26:44,800 We can just run a simple query, first of all. 418 00:26:47,140 --> 00:26:48,380 And get data back. 419 00:26:48,700 --> 00:26:52,940 The attacker can start looking for common vulnerabilities, like cross-site scripting, 420 00:26:59,140 --> 00:27:00,260 which it's vulnerable to. 421 00:27:01,380 --> 00:27:06,400 And you can look for a SQL injection, given the quality of the web page. 422 00:27:06,540 --> 00:27:07,620 I'm pretty sure it's quick to tolerate. 423 00:27:07,640 --> 00:27:08,920 The technology will find one. 424 00:27:10,180 --> 00:27:10,960 And it does. 425 00:27:11,120 --> 00:27:13,080 And if we go back to the victim side, 426 00:27:13,400 --> 00:27:20,440 you can actually see the requests as they came through, as they were being proxied. 427 00:27:21,780 --> 00:27:25,700 So, at this point, the attacker would be able to continue browsing this website, 428 00:27:25,880 --> 00:27:28,040 or perhaps look for something more interesting. 429 00:27:37,740 --> 00:27:41,660 Now, those of you that were paying close attention may have noticed something that I failed to mention earlier. 430 00:27:41,760 --> 00:27:42,400 Intentionally so. 431 00:27:43,420 --> 00:27:48,440 Remember that the XML HTTP request object can only communicate with the origin server. 432 00:27:48,960 --> 00:27:54,140 And the origin server has to be on an attacker-controlled domain in order to perform that DNS switch. 433 00:27:54,420 --> 00:27:58,520 Which means that when XML HTTP request reaches out to the victim server, 434 00:27:58,760 --> 00:28:02,780 it's going to be using a host name and a domain name that that web server has never seen before. 435 00:28:03,140 --> 00:28:05,580 On most web servers, that means that the... 436 00:28:06,300 --> 00:28:09,320 Only the default website will respond with good data. 437 00:28:10,280 --> 00:28:16,500 That's led some people to suggest that validating host headers might be a valid defense against anti-DMS pinning. 438 00:28:17,180 --> 00:28:17,840 It's not. 439 00:28:18,140 --> 00:28:19,560 Host headers are not security. 440 00:28:20,800 --> 00:28:22,020 There's several reasons for this. 441 00:28:22,060 --> 00:28:23,380 One of them is that the... 442 00:28:24,060 --> 00:28:27,940 There's been a number of vulnerabilities in the past, both with Internet Explorer and with Firefox, 443 00:28:28,100 --> 00:28:33,320 that allow an attacker to arbitrarily set the host headers and override it. 444 00:28:33,620 --> 00:28:35,560 There's no reason to believe that all browsers are the same. 445 00:28:35,580 --> 00:28:36,760 All browsers out there have this vulnerability fixed, 446 00:28:36,880 --> 00:28:40,200 and there's no reason to believe that similar vulnerabilities won't be found in the future. 447 00:28:40,420 --> 00:28:42,360 In fact, there is a vulnerability like that with Flash. 448 00:28:43,760 --> 00:28:48,020 But going beyond that, there are plenty of default websites that are out there. 449 00:28:48,180 --> 00:28:51,460 There's tons of them on the Internet, and there's probably even more in private networks. 450 00:28:52,860 --> 00:28:56,280 A major web application is almost always going to have a dedicated server, 451 00:28:56,400 --> 00:28:58,560 which means it's usually going to be the default website as well. 452 00:29:00,080 --> 00:29:03,880 Even if the attacker doesn't find a default website that's of interest, 453 00:29:03,980 --> 00:29:05,200 he still has some recourse, though. 454 00:29:07,660 --> 00:29:11,540 Attacks can be launched against the web server itself instead of the website. 455 00:29:11,880 --> 00:29:15,640 Something that's complicated, like a chunked encoding overflow, say, 456 00:29:15,780 --> 00:29:18,240 aren't possible to hit XML HTTP requests. 457 00:29:18,600 --> 00:29:21,780 But something simpler, say a buffer overflow in the URL 458 00:29:21,780 --> 00:29:26,580 or in a header that the JavaScript is allowed to manipulate, could be launched. 459 00:29:27,380 --> 00:29:29,640 More likely, though, those aren't that common of attacks. 460 00:29:29,900 --> 00:29:35,560 So the attacker would probably look for some old, rarely used, long-forgotten website 461 00:29:35,560 --> 00:29:37,960 web application that I'm sure most people have back at work. 462 00:29:38,100 --> 00:29:42,160 It's probably written by junior developers, probably riddled with SQL injection flaws. 463 00:29:43,180 --> 00:29:48,300 And if the attacker's lucky, then the database on the back end might have a tertiary flaw, 464 00:29:48,440 --> 00:29:52,120 say, XP command shell, which could allow a more traditional 465 00:29:52,120 --> 00:29:54,440 and more flexible tunneling method to be set up. 466 00:29:55,720 --> 00:29:58,240 However, if the victim browser has Java installed, 467 00:29:58,440 --> 00:30:00,280 then some more powerful attacks become possible. 468 00:30:02,100 --> 00:30:05,540 To do a bit of a Java security refresher, there's two types of Java apps. 469 00:30:05,540 --> 00:30:06,780 There's trusted and untrusted. 470 00:30:07,000 --> 00:30:10,920 A trusted applet is either digitally signed, much like ActiveX controls are, 471 00:30:11,060 --> 00:30:13,440 or is installed locally. 472 00:30:13,780 --> 00:30:17,600 A trusted applet has pretty much the same level of permissions that a user does. 473 00:30:17,840 --> 00:30:23,040 It can interact with the file system, read, write, delete, create, whatever the user can do. 474 00:30:23,220 --> 00:30:25,100 It can create and terminate processes. 475 00:30:25,540 --> 00:30:29,220 And it has full socket access, either outbound to other hosts 476 00:30:29,220 --> 00:30:31,360 or even acting as a listening socket. 477 00:30:32,220 --> 00:30:33,300 On the other hand, 478 00:30:35,120 --> 00:30:37,720 untrusted applets have very few rights. 479 00:30:37,840 --> 00:30:39,460 They cannot interact with the local file system. 480 00:30:39,720 --> 00:30:41,380 They have no process management capability. 481 00:30:41,940 --> 00:30:46,080 And the only socket connections they can establish are outbound to the origin host, 482 00:30:46,260 --> 00:30:48,500 but they can connect to any port on the origin. 483 00:30:50,500 --> 00:30:53,180 As I mentioned before, the first anti-DNS pending attack 484 00:30:53,180 --> 00:30:57,160 was documented in 96 by Princeton researchers against the JVM. 485 00:31:01,200 --> 00:31:03,280 The Princeton attack was documented in 96 by Princeton researchers against the JVM. 486 00:31:03,280 --> 00:31:08,500 What they noticed was that if the DNS server responded with two IP addresses for the origin name, 487 00:31:08,960 --> 00:31:12,240 the Java would consider either of those IP addresses to be an acceptable destination 488 00:31:12,240 --> 00:31:16,260 for untrusted applets to create socket connections to. 489 00:31:16,920 --> 00:31:19,460 Sun addressed the problem pretty quickly and said that in the future, 490 00:31:19,680 --> 00:31:24,560 applets would only be able to connect to the IP address that they were actually downloaded from. 491 00:31:24,960 --> 00:31:31,080 I don't have an 11-year-old version of Java to test to see whether or not they actually implemented that, 492 00:31:31,220 --> 00:31:32,520 but as you'll see in a little bit, 493 00:31:32,520 --> 00:31:35,760 that is not the behavior that the JVM exhibits today. 494 00:31:37,940 --> 00:31:39,880 The Princeton attack looks something like this. 495 00:31:39,980 --> 00:31:42,180 Again, it's very similar to a simple DNS rebinding attack. 496 00:31:42,500 --> 00:31:45,920 The victim browser goes somewhere to a malicious site. 497 00:31:46,180 --> 00:31:51,160 This time, the browser could be performing perfect pinning with that IP address. 498 00:31:51,700 --> 00:31:56,200 The attack server comes back with some kind of HTML referencing an applet, 499 00:31:56,220 --> 00:31:58,780 which causes the browser to fire up the JVM. 500 00:31:58,860 --> 00:32:01,780 The first thing the JVM does is issue its own DNS query. 501 00:32:02,540 --> 00:32:04,500 This time, it gets two addresses back. 502 00:32:05,320 --> 00:32:09,700 It's going to take that first IP address and request the applet from it, which it gets. 503 00:32:10,460 --> 00:32:15,240 As soon as the applet is loaded, it establishes a socket connection to that second IP address. 504 00:32:16,700 --> 00:32:21,240 Because both IP addresses were pinned in cache coming from the origin server, 505 00:32:21,860 --> 00:32:24,040 Java allows the connection to establish. 506 00:32:24,480 --> 00:32:28,120 Of course, the attack proceeds much as with previous examples. 507 00:32:29,580 --> 00:32:31,040 That attack doesn't work anymore. 508 00:32:31,040 --> 00:32:34,640 There are some variants on it that do that we'll talk about in a minute. 509 00:32:36,660 --> 00:32:38,680 There's another attack that's viable with LiveConnect. 510 00:32:38,860 --> 00:32:41,080 LiveConnect is a technology that was introduced by Netscape. 511 00:32:41,240 --> 00:32:43,500 Essentially, it's a two-way bridge between Java and JavaScript. 512 00:32:43,880 --> 00:32:48,540 It allows Java applets to interact with the DOM, so they can create new elements on a page. 513 00:32:48,700 --> 00:32:50,420 They can modify attributes, things like that. 514 00:32:50,820 --> 00:32:58,880 More importantly, it allows JavaScript to instantiate standard classes that are part of the Java distribution, including socket classes. 515 00:33:00,540 --> 00:33:01,020 It's very simple. 516 00:33:01,040 --> 00:33:04,520 It's supported by Firefox and Opera, and maybe a few other browsers, but not by Internet Explorer. 517 00:33:04,720 --> 00:33:07,480 The next demonstration I'm performing will not work with IE, 518 00:33:07,620 --> 00:33:13,820 but some other vulnerabilities I'll be discussing do work in a similar fashion. 519 00:33:15,780 --> 00:33:18,480 Earlier this year, Martin Johns and Konotoko 520 00:33:19,180 --> 00:33:20,520 It's not Konotoko Anvil. 521 00:33:20,600 --> 00:33:24,740 I was told that Konotoko actually means anvil in Japanese, so that's a typo. 522 00:33:25,740 --> 00:33:29,780 It documented that if JavaScript was creating... 523 00:33:31,200 --> 00:33:33,440 socket objects, that as soon as one was created, 524 00:33:33,760 --> 00:33:39,840 the JVM would start up and issue a DNS query for the host name that was supplied. 525 00:33:40,300 --> 00:33:44,720 Now, since there's no applet to download, this query was being used only for pitting purposes, 526 00:33:44,920 --> 00:33:53,100 which means that, essentially, the JVM will allow the socket object, the JavaScript, 527 00:33:53,300 --> 00:33:57,200 to connect back to whatever IP address it wants to, whatever is returned by the attacker. 528 00:33:58,900 --> 00:34:01,780 This has a lot of advantages over the previous attack. 529 00:34:01,920 --> 00:34:05,900 For one, there's no delay caused with the firewall and the cache timeouts that we saw earlier. 530 00:34:07,500 --> 00:34:17,620 The host header restriction is lifted because you can create your own sockets and your own arbitrary HTTP requests. 531 00:34:18,100 --> 00:34:26,020 But going well beyond that, pretty much any application protocol, text or binary, UDP or TCP, even limited ICMP support is possible. 532 00:34:26,660 --> 00:34:28,520 This has huge potential, obviously. 533 00:34:29,800 --> 00:34:34,040 SSH, Telnet, SNMP, NIS, CIFS, database protocols. 534 00:34:34,280 --> 00:34:40,340 Pretty much the vast majority of data that travels over a network can be tunneled through Firefox using this technique. 535 00:34:42,120 --> 00:34:46,940 So my demonstration of this attack, it's a very similar environment to the first demonstration. 536 00:34:47,360 --> 00:34:52,900 A few exceptions. Instead of an HTTP proxy, I'll be using a SOX proxy. 537 00:34:53,140 --> 00:34:56,000 For those of you who aren't familiar with it, SOX is a protocol that lets users, 538 00:34:56,020 --> 00:34:58,180 UDP or TCP, be tunneled through a proxy server. 539 00:35:00,640 --> 00:35:02,540 Like I mentioned, there's no need for a firewall. 540 00:35:02,740 --> 00:35:08,560 On the attacker's workstation, there's a generic SOX client that is loaded from a Hummingbird client. 541 00:35:09,200 --> 00:35:18,660 It's bound to the IP stack, so that any requests going out to the 10-dot address range will be redirected invisibly to the proxy server. 542 00:35:18,820 --> 00:35:22,260 Which means that pretty much any application can be tunneled over this. 543 00:35:23,620 --> 00:35:26,000 And finally, the reads and writes are handled differently. 544 00:35:26,000 --> 00:35:30,080 They're handled asynchronously using the kind of pseudo-threading that JavaScript gives you with setTimeout. 545 00:35:30,160 --> 00:35:31,740 And that gives you a little bit of a performance boost. 546 00:35:32,660 --> 00:35:33,700 So, let's do this prep. 547 00:35:36,940 --> 00:35:41,120 Let me just reset the environment real quick from the first demonstration. 548 00:35:42,380 --> 00:35:45,060 I'm not going to be doing the fakenews.com thing again. 549 00:35:45,140 --> 00:35:46,980 I think that the point was made the first time around. 550 00:36:01,580 --> 00:36:02,040 Okay. 551 00:36:08,280 --> 00:36:10,240 So, this is a victim browser. 552 00:36:10,420 --> 00:36:11,440 It's on the attack site. 553 00:36:11,640 --> 00:36:16,640 We can run some quick JavaScript to confirm that connectivity is in place, which it is. 554 00:36:17,960 --> 00:36:21,020 And we'll start the SOX proxy. 555 00:36:21,660 --> 00:36:23,960 The first thing that we're going to send through the SOX proxy 556 00:36:23,960 --> 00:36:25,220 is a simple 557 00:36:26,780 --> 00:36:27,440 Nessus scan. 558 00:36:28,160 --> 00:36:31,480 As you might guess, this is a fairly focused scan. 559 00:36:31,940 --> 00:36:35,040 It's not very interesting watching Nessus run under any circumstances. 560 00:36:42,000 --> 00:36:42,500 Okay. 561 00:36:44,140 --> 00:36:46,400 Just take a second for Nessus to initialize. 562 00:36:53,340 --> 00:36:53,980 All right. 563 00:36:53,980 --> 00:36:58,200 So, if we go back to the victim side, you can see that traffic's coming in. 564 00:36:58,840 --> 00:37:04,320 If we go back to the attacker side, you can see that there's traffic that's coming through. 565 00:37:04,400 --> 00:37:08,440 Now, it's identifying as NetBIOS. 566 00:37:08,560 --> 00:37:13,340 But if you actually look at the packet capture, I'm not doing anything fishy here. 567 00:37:13,440 --> 00:37:16,380 It starts off as SOX, performs the handshake. 568 00:37:16,760 --> 00:37:21,300 Wireshark is smart enough to identify the underlying protocol that's being tunneled by SOX. 569 00:37:21,380 --> 00:37:23,960 So, even though it's being identified as Nessus, 570 00:37:23,960 --> 00:37:27,100 the NetBIOS session, it's still running over port 1080, 571 00:37:27,320 --> 00:37:30,180 which is the default port for SOX. 572 00:37:31,800 --> 00:37:33,040 And let's see here. 573 00:37:33,840 --> 00:37:35,080 Done in just a second. 574 00:37:37,360 --> 00:37:40,080 If we go back here real quick, I can show you some more details about it. 575 00:37:40,740 --> 00:37:43,420 You can see the iframe that things are being posted to. 576 00:37:45,580 --> 00:37:51,000 Data's changing as it's being posted back to the attack server in this HTML form. 577 00:37:51,260 --> 00:37:53,940 These are the placeholders for the images that are required 578 00:37:53,940 --> 00:37:57,380 and requested from the attack server using that technique I mentioned earlier. 579 00:38:00,720 --> 00:38:02,280 Pretty close to being done here. 580 00:38:07,400 --> 00:38:07,840 Okay. 581 00:38:09,880 --> 00:38:13,060 As you can see, the administrators haven't done a very good job patching the server, 582 00:38:13,180 --> 00:38:15,080 which is pretty typical for an intranet site. 583 00:38:16,340 --> 00:38:18,080 A couple of vulnerabilities were identified. 584 00:38:18,940 --> 00:38:20,740 We were able to perform some reconnaissance. 585 00:38:20,900 --> 00:38:22,740 We can see that it's running Windows 2003. 586 00:38:23,940 --> 00:38:25,540 At this point, we can start launching an attack. 587 00:38:27,680 --> 00:38:31,580 One of the nice things about, from an attacker's point of view, 588 00:38:31,600 --> 00:38:35,500 about this method is that once you're on the inside of a network, 589 00:38:35,580 --> 00:38:37,480 you don't really need that sophisticated of knowledge 590 00:38:37,480 --> 00:38:43,360 because most internal networks are not secured nearly as well as the company's DMZ 591 00:38:43,360 --> 00:38:44,680 or the organization's DMZ. 592 00:38:45,240 --> 00:38:48,500 So, we'll use pretty much the hacker equivalent of off-the-shelf software. 593 00:38:48,780 --> 00:38:51,660 Just launch a quick RPC attack with Metasploit. 594 00:38:53,940 --> 00:38:59,300 For this attack, the payload that I'll be using is a straight TCP shell. 595 00:38:59,640 --> 00:39:06,700 In the real attack, the hacker would probably be using a reverse shell 596 00:39:06,700 --> 00:39:11,540 so that the victim server connects back over the internet 597 00:39:11,540 --> 00:39:14,380 to a server that's controlled by the attacker. 598 00:39:16,260 --> 00:39:21,920 The reason for me doing it this way is that it's a little bit faster. 599 00:39:22,120 --> 00:39:23,920 You should see the attack coming through. 600 00:39:25,120 --> 00:39:28,200 It's a little bit faster because you don't have to set up something like Netcat listening, 601 00:39:28,420 --> 00:39:39,800 but in an extended scenario, it's slow because it has to be tunneled over the SOX proxy. 602 00:39:40,280 --> 00:39:43,420 And while it's an effective attack tool still, it's not all that speedy. 603 00:39:44,720 --> 00:39:50,320 So, you can see the first thing that Metasploit does is it tries to connect in on port 4444, 604 00:39:50,500 --> 00:39:53,500 which is where the shell is going to be bound. 605 00:39:54,480 --> 00:39:56,760 It's checking just to see if anything is already listening there. 606 00:39:56,920 --> 00:40:01,740 It's not, so Java's throwing this exception, which is normal. 607 00:40:02,720 --> 00:40:04,700 And we can see traffic coming in. 608 00:40:04,960 --> 00:40:09,920 If we switch back to the attack server, 609 00:40:11,340 --> 00:40:14,200 I'm assuming that's as blurry for everyone else as it is for me. 610 00:40:15,720 --> 00:40:19,280 We're about to get a DOS shell there, although I'm not sure how well people, 611 00:40:19,380 --> 00:40:21,040 especially in the back, will be able to make it out. 612 00:40:23,440 --> 00:40:28,460 Okay, so now we have a shell with system level rights since it was from RPC. 613 00:40:29,180 --> 00:40:35,480 We can go to the administrator's desktop. 614 00:40:41,260 --> 00:40:47,380 And we just switch over real quick to the victim side and we'll pull up the victim server. 615 00:40:48,440 --> 00:40:48,920 Okay. 616 00:40:51,040 --> 00:40:51,780 Let me log in real quick here. 617 00:40:57,640 --> 00:40:58,940 Okay, empty desktop. 618 00:41:00,460 --> 00:41:03,040 And we'll just put something on the desktop here. 619 00:41:06,720 --> 00:41:07,480 Switch back. 620 00:41:08,180 --> 00:41:08,940 There it is. 621 00:41:09,080 --> 00:41:14,600 So, system level, root level access from the internet to a private network all totaled over Firefox. 622 00:41:28,080 --> 00:41:28,480 Okay. 623 00:41:30,160 --> 00:41:32,000 So, as I mentioned before, that doesn't work on AE. 624 00:41:32,120 --> 00:41:37,120 But I'm willing to bet the vast majority of you are using Firefox as your primary web browser. 625 00:41:37,320 --> 00:41:38,900 You might not have Java enabled. 626 00:41:39,080 --> 00:41:41,800 But there's some other attacks that will work on Internet Explorer. 627 00:41:42,760 --> 00:41:44,420 I documented three last month. 628 00:41:44,660 --> 00:41:46,560 The first one isn't really a new attack per se. 629 00:41:47,200 --> 00:41:50,480 It turns out that the Princeton attack will still work 630 00:41:50,480 --> 00:41:57,760 if both the attack server, the victim browser, and the victim server are all on the same subnet. 631 00:41:57,900 --> 00:42:00,120 Now, there's not all that many scenarios where that's useful. 632 00:42:00,280 --> 00:42:05,800 But it still is telling about how DNS binding does or doesn't work on the JVM. 633 00:42:06,280 --> 00:42:08,220 The second attack's a little bit more useful. 634 00:42:09,600 --> 00:42:10,940 It's also based on Princeton. 635 00:42:13,400 --> 00:42:19,120 If DNS returns two IP addresses, the JVM will perform a reverse DNS lookup on both of those addresses. 636 00:42:19,120 --> 00:42:23,140 If the pointer records associated with those return the same host name, 637 00:42:23,300 --> 00:42:29,400 then the JVM will consider both of them to be an acceptable destination for sockets. 638 00:42:30,000 --> 00:42:39,900 Normally, an attacker wouldn't be able to control the resolution of a privately numbered IP space. 639 00:42:40,200 --> 00:42:42,280 But there are a few scenarios where he might be able to. 640 00:42:42,400 --> 00:42:46,880 If the attacker has compromised the authoritative DNS server for that IP address range, 641 00:42:47,080 --> 00:42:49,100 or has compromised the resolving DNS server, 642 00:42:49,100 --> 00:42:53,560 for the victim browser, or if some kind of DNS cache poisoning is possible, 643 00:42:53,680 --> 00:42:54,600 then this attack could work. 644 00:42:54,840 --> 00:42:57,240 I don't see it as being a major flaw in the JVM, though, 645 00:42:57,300 --> 00:43:02,480 because it relies pretty heavily on secondary vulnerabilities that are completely outside of their control. 646 00:43:03,060 --> 00:43:06,420 The third attack is a lot more feasible, though, especially in a corporate environment. 647 00:43:07,300 --> 00:43:11,020 If the JVM is configured to use an HTTP proxy server, 648 00:43:11,320 --> 00:43:17,620 it will download the applet file, the jar or the class, through the proxy server, 649 00:43:17,620 --> 00:43:21,900 but still perform a DNS lookup for pinning purposes. 650 00:43:22,240 --> 00:43:25,280 Now, much like with the LiveConnect attack, 651 00:43:28,000 --> 00:43:31,740 the JVM has no way of knowing whether those two IP addresses match. 652 00:43:33,500 --> 00:43:42,000 If the attacker is able to coordinate it so that the IP address sent to the JVM is for the victim server, 653 00:43:42,240 --> 00:43:44,840 and the IP address sent to the proxy server is for the attack server, 654 00:43:45,100 --> 00:43:46,560 then an attack becomes possible. 655 00:43:46,820 --> 00:43:47,600 Of course, this really doesn't work. 656 00:43:47,620 --> 00:43:52,120 It relies on the internal host on a corporate network or a private network 657 00:43:52,120 --> 00:43:57,480 to be able to resolve Internet host names while still using a proxy server, 658 00:43:57,600 --> 00:43:58,300 but that's fairly common. 659 00:43:58,420 --> 00:44:01,740 There's a lot of enterprises that have their systems deployed that way. 660 00:44:03,680 --> 00:44:08,520 Proxy servers, well, first, Java and JavaScript aren't the only vectors for this type of attack. 661 00:44:09,020 --> 00:44:11,520 Proxy servers have been suspected to be vulnerable for a while. 662 00:44:11,800 --> 00:44:17,460 Last month, David Studdard, aka Port Swigger, released a paper on proxy server vulnerability. 663 00:44:17,620 --> 00:44:20,600 And documented that the two most popular proxy servers, 664 00:44:20,760 --> 00:44:24,200 Microsoft Internet Security Acceleration and SquidCache, are both vulnerable. 665 00:44:25,780 --> 00:44:29,200 Microsoft enforces a minimum TTL of six minutes, which isn't bad. 666 00:44:29,960 --> 00:44:31,420 That's better than, say, Firefox. 667 00:44:32,200 --> 00:44:36,480 But it still means that anti-DNS pinning is possible, although just a little bit more inconvenient. 668 00:44:37,060 --> 00:44:39,700 Squid, on the other hand, completely respects the TTL, 669 00:44:39,760 --> 00:44:44,180 which is in accordance with the RFC, but means that a simple DNS rebinding attack is trivial. 670 00:44:45,640 --> 00:44:47,600 A lot of people don't know this, but Flash actually does. 671 00:44:47,620 --> 00:44:48,700 It actually supports sockets, too. 672 00:44:48,880 --> 00:44:51,220 It's a little squirrelly with some of the restrictions on there, 673 00:44:51,340 --> 00:44:56,500 but it's still definitely possible to launch a DNS rebinding attack through it 674 00:44:56,500 --> 00:44:58,760 because it does not use any pinning as well. 675 00:44:58,840 --> 00:45:00,140 It respects the TTL. 676 00:45:01,180 --> 00:45:06,860 Konotoko had documented this earlier this year and has a proof of concept on his website. 677 00:45:08,000 --> 00:45:10,120 Martin Johns may have been involved with that, too. I'm not sure. 678 00:45:11,040 --> 00:45:15,960 This Stanford paper that I referenced earlier has some other information on that in there. 679 00:45:16,040 --> 00:45:16,620 It's a great paper. 680 00:45:16,620 --> 00:45:21,800 I really wish that I'd had time to incorporate some more of their findings into it, 681 00:45:21,880 --> 00:45:23,980 but I highly recommend that you go and take a look at it. 682 00:45:25,320 --> 00:45:31,080 If I did a poor job and you still don't understand what anti-DNS pinning is or DNS rebinding, 683 00:45:31,780 --> 00:45:34,080 take a look at this blog posting by Christian. 684 00:45:34,280 --> 00:45:34,800 It's very good. 685 00:45:34,960 --> 00:45:38,920 It's a step-by-step explanation of how DNS rebinding attacks work. 686 00:45:39,840 --> 00:45:42,860 If you do understand it, definitely take a look at the Stanford paper. 687 00:45:43,000 --> 00:45:43,360 It's great. 688 00:45:43,440 --> 00:45:46,260 It goes into more detail about defense, which, since this is DEF CON, 689 00:45:46,260 --> 00:45:48,760 I didn't think that was important. I did go into that at Black Hat. 690 00:45:51,180 --> 00:45:52,860 DNSrebinding.net is the easiest way of getting there. 691 00:45:52,920 --> 00:45:57,560 That will redirect to their paper, their webpage with the proof of concept as well. 692 00:45:58,240 --> 00:45:58,900 That's all I have. 693 00:45:59,260 --> 00:46:01,380 If there are any questions, I think we have a few more minutes for in here, 694 00:46:01,440 --> 00:46:02,400 and then we can move to another room. 695 00:46:04,860 --> 00:46:05,140 Thank you.