[00:00.000 --> 00:02.980] Hi and welcome to my talk on malicious proxies. [00:03.920 --> 00:08.280] So let me tell you a little bit about myself. My name is Ed Zebrowski and I've been in security [00:08.280 --> 00:13.300] for about 12 years. Through those 12 years, I've moved back and forth through the various [00:13.300 --> 00:18.740] disciplines of malicious logic, incident response, intrusion detection, and pen testing. [00:19.640 --> 00:24.260] During this moving back and forth, I've found that I really enjoy the pen testing the most [00:24.260 --> 00:30.280] because it gives me the ability to tackle problems and evolving challenges that I normally [00:30.280 --> 00:31.400] wouldn't encounter. [00:32.880 --> 00:37.280] So one thing I want to get out of the way talking about proxies, when I use the term [00:37.280 --> 00:43.760] proxy, I'm focusing only on web proxies. And there's also plenty of reasons why you'd want [00:43.760 --> 00:50.100] to deploy a proxy legitimately, but who really cares? I'm not here to espouse on the benefits [00:50.100 --> 00:51.140] of a proxy. [00:53.060 --> 00:57.220] So why would I come up with a malicious proxy anyways? I wanted to come up with as many [00:57.220 --> 01:03.800] ways as I could to screw with a user's web browsing session anytime I could. And also [01:03.800 --> 01:09.100] as a pen tester, it gave me the ability to gather information that I might not have accessibility [01:09.100 --> 01:09.920] to. [01:11.860 --> 01:17.700] So a quick simplistic rundown of how proxies work. You have the client that requests a [01:17.700 --> 01:23.300] page through a proxy and that proxy then requests it from the server. The server passes [01:23.300 --> 01:29.700] that page back to the proxy and from the proxy to the client, rendering the page. A malicious [01:29.700 --> 01:37.020] proxy isn't much different because it still sends the request through the proxy to the [01:37.740 --> 01:44.340] server and back to the proxy. The only difference here is the proxy now has a chance to modify [01:44.340 --> 01:51.980] this data. And here's a screenshot of an excerpt of slash dot before and after it modifies [01:51.980 --> 01:58.440] it. Now, what you see here is on the bottom screen, a couple elements being added on to [01:58.440 --> 02:07.550] the page there, inserting some JavaScript. That JavaScript or page as it's been modified [02:07.550 --> 02:12.210] by the proxy is then passed right back on to the client where it's now rendered with [02:12.210 --> 02:14.070] the modifications you made to it. [02:15.110 --> 02:20.650] So, as I mentioned, a malicious proxy isn't much different from a standard proxy but it [02:20.650 --> 02:27.930] can modify and change the HTTP responses and requests and it can also add and remove data. [02:31.970 --> 02:36.810] So there are a couple ways you would want to go about modifying the content. One way [02:36.810 --> 02:43.650] is via modifying the static HTML. Now, that takes a lot of customization on a per page [02:43.650 --> 02:48.730] basis and it's just really kind of difficult to do for every single page that you would [02:48.730 --> 02:54.450] possibly want to modify. Another way to do it is via injecting JavaScript directly into [02:54.450 --> 02:59.710] the page. And that's a lot easier because we only need to find one thing that all pages [02:59.710 --> 03:07.270] should have in common like a head tag and add that JavaScript to that element. This [03:07.270 --> 03:16.170] way it allows the client to render the page for us and do it in a consistent way, modifying [03:16.170 --> 03:22.870] the DOM. So there are some potential issues you might encounter when deploying malicious [03:22.870 --> 03:28.870] proxy. One is that inserted JavaScript may be blocked by elements, or excuse me, by extensions [03:28.870 --> 03:34.350] like NoScript. There are ways around this though because if you can inject JavaScript [03:34.350 --> 03:39.470] as it's traveling through the proxy, you can just directly inject the JavaScript, making [03:39.470 --> 03:45.850] it look like it's from whatever trusted site that the user is going to. Also, I've encountered [03:45.850 --> 03:52.270] that some AJAX heavy sites don't play very well, especially in the area of forms. If [03:52.730 --> 03:59.390] a site sends the form request off in an AJAX request, it might not get picked up. But if [03:59.390 --> 04:08.290] it's sent via a form post to a separate handler, it will get picked up. Another issue is [04:08.290 --> 04:17.570] compressed pages. Because everything uses the HTTP 1.1 standard these days, excuse me, [04:20.950 --> 04:26.110] because everything uses the HTTP 1.1 standard these days, pages will come by in a binary [04:26.110 --> 04:31.210] format making it hard for us to make our changes. So we have a couple options there. We can [04:31.210 --> 04:36.250] either modify, decompress and modify the page when it comes to the proxy or we can [04:36.250 --> 04:42.010] just strip out the header request as it's going out from the client. Also, modifying [04:42.010 --> 04:47.290] the page itself slows down delivery. So if you're doing this on a large scale, you might [04:47.290 --> 04:52.370] run into more issues and that's another reason why they use JavaScript to let it do the lifting [04:52.370 --> 05:00.210] and the clients do the processing for you. So backing up now, how would you go about [05:00.210 --> 05:05.190] assigning a proxy? Well, in a pen test statically is not the best way to do it and it's kind [05:05.190 --> 05:13.930] of like cheating. You can also do it dynamically via DNS or DHCP. DNS has this functionality [05:13.930 --> 05:20.230] called a WPAD record and what that does is any browser set up to use autoproxy detection [05:20.230 --> 05:29.290] will look for a domain name with a WPAD host appended to it or pre-appended to it. If it [05:29.290 --> 05:35.790] finds it, it will look for a file on a web host at that URL and that file contains the [05:35.790 --> 05:42.530] proxy configuration file of where it should proxy through. The same thing with the DHCP [05:42.530 --> 05:48.310] option 252, the only difference is you get more flexible about the URL. And again, that [05:48.310 --> 05:54.570] only works for browsers using autoproxy detection. And of course, there are the other ways you [05:54.570 --> 06:00.990] can do it via like ARP spoofing as well. So I'm going to start talking about Topple [06:00.990 --> 06:06.050] Ganger, the tool I wrote to do this kind of stuff. When I started writing it, I wrote [06:06.050 --> 06:13.090] it as a kind of personal exercise learning Ruby. So the code isn't pretty and the documentation [06:13.090 --> 06:17.550] is sparse but that's a work in progress. I also wrote it as a proof of concept so some [06:17.550 --> 06:21.930] things might not always work but if you find yourself wanting to download it and you do [06:21.930 --> 06:26.350] and you find something wrong with it, feel free to let me know about it. I won't mind [06:26.350 --> 06:32.290] you make improvements. Now for the tool itself, I wanted it to be able to set down on the [06:32.290 --> 06:37.790] network and just go immediately. I didn't want to have to configure it a whole lot and [06:37.790 --> 06:44.610] I wanted it to target all sites out of the box. So Topple Ganger itself can create that [06:44.610 --> 06:50.230] WPAD record for us and I found that if you can manage to get on a network, usually the [06:50.230 --> 06:57.870] networks trust internal DNS updates so therefore you can become the proxy for the internal [06:57.870 --> 07:03.970] networks. And if any of you are familiar with Grease Monkey, this is kind of like Grease [07:03.970 --> 07:13.010] Monkey for an entire network. Additionally, you can use Google APIs for part of the JavaScript [07:13.010 --> 07:18.390] so that way you don't need to have the clients pinging your local machine to get them. You [07:18.390 --> 07:24.890] can go to an already trusted site and let them download from there. So Doppelganger, as I [07:24.890 --> 07:31.510] mentioned, uses Ruby. And the core and heart and soul of Doppelganger is Webrick. It uses [07:31.510 --> 07:38.670] that as the HTTP server serving up any files like the WPAD file or any other images that [07:38.670 --> 07:45.390] might be sent to the client. It also uses Ruby gems, DNS Ruby for updating the DNS, Packer [07:45.390 --> 07:52.310] for packing JavaScript and injecting it directly into the page. And the bottom two, Windows [07:52.310 --> 07:57.770] PR and Win32 process for Windows interoperability. But I haven't had any success with it binding [07:57.770 --> 08:05.710] to a port on Windows yet so I won't count on that working. So as I mentioned, Doppelganger [08:07.170 --> 08:13.150] generically works as a malicious proxy and can operate on both the headers and the content [08:13.150 --> 08:21.850] of the page. Specifically, it has these abilities and these can be customized or added to or [08:21.850 --> 08:26.850] what not but this is out of the boxes. I've written it. And you only need to create a [08:26.850 --> 08:32.070] JavaScript file containing the directives you want it to do. So I can insert a calling [08:32.070 --> 08:37.310] card and calling card is a pretty obvious attack. Not always useful for a pen test but [08:37.310 --> 08:42.930] it has its uses at times. Also injecting flash applets. I can also scrape and decode the [08:42.930 --> 08:48.070] basic authentication of any users authenticating to a site because that basic auth is only [08:48.070 --> 08:54.890] base 64 encoded. I can use it to steal form data and other header data such as cookies. [09:00.440 --> 09:07.160] So inserting a calling card simply just removes all the children tag and the body tag and [09:07.160 --> 09:17.060] it adds new image to display on the page prominently. Header capturing works just as it sounds. [09:17.080 --> 09:22.860] As a header is coming in or out, you can grab it. Like I said, this works for HTTP basic [09:22.860 --> 09:27.320] authentication and it can decode it for us on the fly so that way we don't need to bother [09:27.320 --> 09:32.540] putting it through our base 64 decoder and we can also grab cookies to steal other people's [09:32.540 --> 09:38.760] sessions. For injecting flash, we can just append that onto the end of the body of the [09:38.760 --> 09:45.700] page and this allows us to gather more information about hosts and potentially even exploit flash [09:45.700 --> 09:52.780] vulnerabilities. In capturing form data, the way this works is it binds to the submit event [09:52.780 --> 09:59.920] on all forms and when the user clicks on the submit button, it serializes that data, sends [09:59.920 --> 10:06.400] it back to the proxy to a non-existent URL where it's then logged by Doppelganger. And [10:06.400 --> 10:13.560] this is pretty useful too, especially for those pages that are HTTP only but then post [10:13.560 --> 10:23.650] the data to the form, excuse me, to a secure page. So, an example of what you might see [10:23.650 --> 10:30.410] is here, a tragic event happening on June 23rd, a separation of a couple because that [10:30.410 --> 10:35.810] never happens. But if you're running Doppelganger and you had the calling card functionality, [10:35.810 --> 10:44.910] they might see something more like this. Stealing form data, here's an excerpt from the Slack [10:44.930 --> 10:52.190] Flash.login box and I have my username and my password in there and at the bottom in [10:52.190 --> 10:56.570] the red is the form data that's serialized and posted back to Doppelganger that contains [10:56.570 --> 11:04.160] all the information that the user put into that form. So, Doppelganger has some other [11:04.160 --> 11:10.760] uses potentially. You could use it in phishing attacks. You could also use it in Csurf attacks [11:10.760 --> 11:18.720] or exploiting other things like Adobe Flash or the Oday Firefox vulnerabilities that just [11:18.720 --> 11:27.740] recently came out. And where I'd like to take it in the future is add more addition or more [11:27.740 --> 11:33.000] control over what pages that you can manipulate. Right now, as I mentioned, it just kind of [11:33.000 --> 11:39.220] gets everything out of the box. You might want to be able to filter out some of those [11:39.220 --> 11:42.820] pages and only get the ones that might be of interest to you. Also, a little more [11:42.820 --> 11:49.400] interactivity because there's chances are you might want to add more JavaScript to it via [11:49.400 --> 11:55.560] Google APIs, in which case you have to stop Doppelganger, start it back up and run it. And [11:55.560 --> 12:01.340] during that time, you might miss something or if somebody's looking at you as a proxy and [12:01.340 --> 12:08.360] you're not running, you could effectively denial of service the network. And additionally, [12:08.360 --> 12:13.340] I'd also like to add some functionality for the SSL strip and SSL sniff that Moxie's been [12:13.340 --> 12:19.940] working on. That's some pretty good work right there. So now some curious findings about [12:19.940 --> 12:26.540] when I was creating this tool. One of the things I found out when I started with the WPAD [12:27.120 --> 12:34.360] was that when I first updated that DNS record, I had about 320 hosts pinging my laptop as [12:34.920 --> 12:41.760] their proxy in about an hour's worth of time. But in our environment, we don't use, our [12:41.760 --> 12:47.840] environment uses a GPO to push out proxy as well as baseline image, so we were getting [12:47.840 --> 12:54.800] about 320 hosts that were looking at my laptop to be their proxy. Also, additionally, not [12:54.800 --> 13:00.420] on the slides, is I found that big surprise, IE was the biggest offender of using the WPAD, [13:00.420 --> 13:04.380] the autoproxy detection. But there were still some other browsers in there that were using [13:04.380 --> 13:11.060] it as well, such as Firefox and Opera, which was a little bit of a surprise to me. So there [13:11.060 --> 13:16.520] are some things you can do about the WPAD attack. One of the things is you can serve out [13:16.520 --> 13:24.740] the DHCP option 252 yourself, or the DNS option, although browsers look at the DHCP option [13:24.740 --> 13:29.780] first, so that would be the better way to go. Also, you could ensure that the browsers [13:29.780 --> 13:35.260] aren't set to use autoproxy detection, and as I mentioned, this only protects against [13:35.260 --> 13:45.660] the WPAD, not the ARP spoofing type of attacks. So below is the URL for the code, and it's [13:45.660 --> 13:50.960] hosted at Google, and it has the fine seal of works on my machine approval, so you might [13:50.960 --> 13:57.220] get a, your mileage may vary, but again, let me know and I'll always look to fixing it. [13:57.220 --> 14:13.120] So, that's it. Thanks. I have time for questions if anyone has any questions. Yes? [14:14.740 --> 14:21.040] No, I'm not decrypting SSL. I had actually added functionality originally to create self-signed [14:21.040 --> 14:27.960] certificates on the fly, and I had that partially working, but then I figured I'd just back [14:27.960 --> 14:34.600] off of that and use Moxie's SSL sniff and SSL stripping, which I intend on putting in [14:34.600 --> 14:42.420] there to do that kind of functionality. Okay, well, thank you.