1 00:00:00,000 --> 00:00:02,980 Hi and welcome to my talk on malicious proxies. 2 00:00:03,920 --> 00:00:05,900 So let me tell you a little bit about myself. 3 00:00:05,900 --> 00:00:09,960 My name is Ed Zebrowski and I've been in security for about 12 years. 4 00:00:10,460 --> 00:00:18,740 Through those 12 years, I've moved back and forth through the various disciplines of malicious logic, incident response, intrusion detection, and pen testing. 5 00:00:19,640 --> 00:00:31,400 During this moving back and forth, I've found that I really enjoy the pen testing the most because it gives me the ability to tackle problems and evolving challenges that I normally wouldn't encounter. 6 00:00:32,880 --> 00:00:40,440 So one thing I want to get out of the way talking about proxies, when I use the term proxy, I'm focusing only on web proxies. 7 00:00:41,120 --> 00:00:48,540 And there's also plenty of reasons why you'd want to deploy a proxy legitimately, but who really cares? 8 00:00:48,540 --> 00:00:51,140 I'm not here to espouse on the benefits of a proxy. 9 00:00:53,060 --> 00:00:55,720 So why would I come up with a malicious proxy anyways? 10 00:00:56,120 --> 00:01:02,900 I wanted to come up with as many ways as I could to screw with a user's web browsing session anytime I could. 11 00:01:03,340 --> 00:01:09,920 And also as a pen tester, it gave me the ability to gather information that I might not have accessibility to. 12 00:01:11,860 --> 00:01:15,220 So a quick simplistic rundown of how proxies work. 13 00:01:15,300 --> 00:01:22,300 You have the client that requests a page through a proxy and that proxy then requests it from the server. 14 00:01:22,320 --> 00:01:28,220 The server passes that page back to the proxy and from the proxy to the client, rendering the page. 15 00:01:29,140 --> 00:01:40,460 A malicious proxy isn't much different because it still sends the request through the proxy to the server and back to the proxy. 16 00:01:40,740 --> 00:01:45,340 The only difference here is the proxy now has a chance to modify this data. 17 00:01:45,820 --> 00:01:52,660 And here's a screenshot of an excerpt of slash dot before and after it modifies it. 18 00:01:53,080 --> 00:02:00,980 Now, what you see here is on the bottom screen, a couple elements being added on to the page there, inserting some JavaScript. 19 00:02:05,010 --> 00:02:14,070 That JavaScript or page as it's been modified by the proxy is then passed right back on to the client where it's now rendered with the modifications you made to it. 20 00:02:15,110 --> 00:02:27,930 So, as I mentioned, a malicious proxy isn't much different from a standard proxy but it can modify and change the HTTP responses and requests and it can also add and remove data. 21 00:02:31,970 --> 00:02:35,910 So there are a couple ways you would want to go about modifying the content. 22 00:02:36,230 --> 00:02:39,870 One way is via modifying the static HTML. 23 00:02:40,310 --> 00:02:50,570 Now, that takes a lot of customization on a per page basis and it's just really kind of difficult to do for every single page that you would possibly want to modify. 24 00:02:51,230 --> 00:02:55,390 Another way to do it is via injecting JavaScript directly into the page. 25 00:02:55,530 --> 00:03:06,550 And that's a lot easier because we only need to find one thing that all pages should have in common like a head tag and add that JavaScript to that element. 26 00:03:06,930 --> 00:03:17,150 This way it allows the client to render the page for us and do it in a consistent way, modifying the DOM. 27 00:03:18,990 --> 00:03:23,870 So there are some potential issues you might encounter when deploying malicious proxy. 28 00:03:24,150 --> 00:03:30,210 One is that inserted JavaScript may be blocked by elements, or excuse me, by extensions like NoScript. 29 00:03:30,550 --> 00:03:43,490 There are ways around this though because if you can inject JavaScript as it's traveling through the proxy, you can just directly inject the JavaScript, making it look like it's from whatever trusted site that the user is going to. 30 00:03:44,610 --> 00:03:51,790 Also, I've encountered that some AJAX heavy sites don't play very well, especially in the area of forms. 31 00:03:51,990 --> 00:03:59,030 If a site sends the form request off in an AJAX request, it might not get picked up. 32 00:03:59,030 --> 00:04:05,690 But if it's sent via a form post to a separate handler, it will get picked up. 33 00:04:06,830 --> 00:04:09,610 Another issue is compressed pages. 34 00:04:09,610 --> 00:04:17,570 Because everything uses the HTTP 1.1 standard these days, excuse me, 35 00:04:20,950 --> 00:04:29,090 because everything uses the HTTP 1.1 standard these days, pages will come by in a binary format making it hard for us to make our changes. 36 00:04:29,090 --> 00:04:30,830 So we have a couple options there. 37 00:04:30,830 --> 00:04:40,010 We can either modify, decompress and modify the page when it comes to the proxy or we can just strip out the header request as it's going out from the client. 38 00:04:40,930 --> 00:04:44,750 Also, modifying the page itself slows down delivery. 39 00:04:44,750 --> 00:04:55,810 So if you're doing this on a large scale, you might run into more issues and that's another reason why they use JavaScript to let it do the lifting and the clients do the processing for you. 40 00:04:57,830 --> 00:05:01,630 So backing up now, how would you go about assigning a proxy? 41 00:05:01,910 --> 00:05:06,230 Well, in a pen test statically is not the best way to do it and it's kind of like cheating. 42 00:05:07,730 --> 00:05:12,010 You can also do it dynamically via DNS or DHCP. 43 00:05:12,270 --> 00:05:28,330 DNS has this functionality called a WPAD record and what that does is any browser set up to use autoproxy detection will look for a domain name with a WPAD host appended to it or pre-appended to it. 44 00:05:28,890 --> 00:05:40,710 If it finds it, it will look for a file on a web host at that URL and that file contains the proxy configuration file of where it should proxy through. 45 00:05:40,950 --> 00:05:46,990 The same thing with the DHCP option 252, the only difference is you get more flexible about the URL. 46 00:05:47,350 --> 00:05:51,870 And again, that only works for browsers using autoproxy detection. 47 00:05:52,530 --> 00:05:56,930 And of course, there are the other ways you can do it via like ARP spoofing as well. 48 00:05:58,890 --> 00:06:03,890 So I'm going to start talking about Topple Ganger, the tool I wrote to do this kind of stuff. 49 00:06:04,410 --> 00:06:10,430 When I started writing it, I wrote it as a kind of personal exercise learning Ruby. 50 00:06:10,870 --> 00:06:15,350 So the code isn't pretty and the documentation is sparse but that's a work in progress. 51 00:06:15,410 --> 00:06:25,630 I also wrote it as a proof of concept so some things might not always work but if you find yourself wanting to download it and you do and you find something wrong with it, feel free to let me know about it. 52 00:06:25,630 --> 00:06:27,870 I won't mind you make improvements. 53 00:06:29,010 --> 00:06:34,690 Now for the tool itself, I wanted it to be able to set down on the network and just go immediately. 54 00:06:34,990 --> 00:06:39,970 I didn't want to have to configure it a whole lot and I wanted it to target all sites out of the box. 55 00:06:41,750 --> 00:06:58,830 So Topple Ganger itself can create that WPAD record for us and I found that if you can manage to get on a network, usually the networks trust internal DNS updates so therefore you can become the proxy for the internal networks. 56 00:06:59,770 --> 00:07:05,710 And if any of you are familiar with Grease Monkey, this is kind of like Grease Monkey for an entire network. 57 00:07:06,850 --> 00:07:18,210 Additionally, you can use Google APIs for part of the JavaScript so that way you don't need to have the clients pinging your local machine to get them. 58 00:07:18,210 --> 00:07:21,310 You can go to an already trusted site and let them download from there. 59 00:07:24,010 --> 00:07:26,210 So Doppelganger, as I mentioned, uses Ruby. 60 00:07:26,770 --> 00:07:30,650 And the core and heart and soul of Doppelganger is Webrick. 61 00:07:31,010 --> 00:07:40,290 It uses that as the HTTP server serving up any files like the WPAD file or any other images that might be sent to the client. 62 00:07:40,910 --> 00:07:50,870 It also uses Ruby gems, DNS Ruby for updating the DNS, Packer for packing JavaScript and injecting it directly into the page. 63 00:07:51,150 --> 00:07:55,730 And the bottom two, Windows PR and Win32 process for Windows interoperability. 64 00:07:55,830 --> 00:08:01,310 But I haven't had any success with it binding to a port on Windows yet so I won't count on that working. 65 00:08:03,570 --> 00:08:15,510 So as I mentioned, Doppelganger generically works as a malicious proxy and can operate on both the headers and the content of the page. 66 00:08:16,970 --> 00:08:23,530 Specifically, it has these abilities and these can be customized or added to or what not but this is out of the boxes. 67 00:08:23,530 --> 00:08:24,510 I've written it. 68 00:08:24,890 --> 00:08:29,510 And you only need to create a JavaScript file containing the directives you want it to do. 69 00:08:30,450 --> 00:08:34,950 So I can insert a calling card and calling card is a pretty obvious attack. 70 00:08:34,950 --> 00:08:38,670 Not always useful for a pen test but it has its uses at times. 71 00:08:38,990 --> 00:08:41,070 Also injecting flash applets. 72 00:08:41,250 --> 00:08:49,690 I can also scrape and decode the basic authentication of any users authenticating to a site because that basic auth is only base 64 encoded. 73 00:08:50,190 --> 00:08:54,890 I can use it to steal form data and other header data such as cookies. 74 00:09:00,440 --> 00:09:11,340 So inserting a calling card simply just removes all the children tag and the body tag and it adds new image to display on the page prominently. 75 00:09:13,700 --> 00:09:17,060 Header capturing works just as it sounds. 76 00:09:17,080 --> 00:09:20,320 As a header is coming in or out, you can grab it. 77 00:09:20,740 --> 00:09:33,280 Like I said, this works for HTTP basic authentication and it can decode it for us on the fly so that way we don't need to bother putting it through our base 64 decoder and we can also grab cookies to steal other people's sessions. 78 00:09:34,780 --> 00:09:46,780 For injecting flash, we can just append that onto the end of the body of the page and this allows us to gather more information about hosts and potentially even exploit flash vulnerabilities. 79 00:09:48,820 --> 00:10:05,500 In capturing form data, the way this works is it binds to the submit event on all forms and when the user clicks on the submit button, it serializes that data, sends it back to the proxy to a non-existent URL where it's then logged by Doppelganger. 80 00:10:06,100 --> 00:10:17,940 And this is pretty useful too, especially for those pages that are HTTP only but then post the data to the form, excuse me, to a secure page. 81 00:10:20,630 --> 00:10:31,610 So, an example of what you might see is here, a tragic event happening on June 23rd, a separation of a couple because that never happens. 82 00:10:31,970 --> 00:10:37,810 But if you're running Doppelganger and you had the calling card functionality, they might see something more like this. 83 00:10:41,570 --> 00:10:58,990 Stealing form data, here's an excerpt from the Slack Flash.login box and I have my username and my password in there and at the bottom in the red is the form data that's serialized and posted back to Doppelganger that contains all the information that the user put into that form. 84 00:11:02,880 --> 00:11:06,380 So, Doppelganger has some other uses potentially. 85 00:11:06,380 --> 00:11:08,120 You could use it in phishing attacks. 86 00:11:08,500 --> 00:11:20,020 You could also use it in Csurf attacks or exploiting other things like Adobe Flash or the Oday Firefox vulnerabilities that just recently came out. 87 00:11:22,600 --> 00:11:31,440 And where I'd like to take it in the future is add more addition or more control over what pages that you can manipulate. 88 00:11:31,440 --> 00:11:34,500 Right now, as I mentioned, it just kind of gets everything out of the box. 89 00:11:34,500 --> 00:11:41,740 You might want to be able to filter out some of those pages and only get the ones that might be of interest to you. 90 00:11:42,000 --> 00:11:55,460 Also, a little more interactivity because there's chances are you might want to add more JavaScript to it via Google APIs, in which case you have to stop Doppelganger, start it back up and run it. 91 00:11:55,460 --> 00:12:05,620 And during that time, you might miss something or if somebody's looking at you as a proxy and you're not running, you could effectively denial of service the network. 92 00:12:07,300 --> 00:12:14,420 And additionally, I'd also like to add some functionality for the SSL strip and SSL sniff that Moxie's been working on. 93 00:12:14,540 --> 00:12:16,240 That's some pretty good work right there. 94 00:12:18,140 --> 00:12:21,860 So now some curious findings about when I was creating this tool. 95 00:12:22,580 --> 00:12:37,480 One of the things I found out when I started with the WPAD was that when I first updated that DNS record, I had about 320 hosts pinging my laptop as their proxy in about an hour's worth of time. 96 00:12:38,660 --> 00:12:52,220 But in our environment, we don't use, our environment uses a GPO to push out proxy as well as baseline image, so we were getting about 320 hosts that were looking at my laptop to be their proxy. 97 00:12:53,520 --> 00:13:01,880 Also, additionally, not on the slides, is I found that big surprise, IE was the biggest offender of using the WPAD, the autoproxy detection. 98 00:13:02,300 --> 00:13:08,060 But there were still some other browsers in there that were using it as well, such as Firefox and Opera, which was a little bit of a surprise to me. 99 00:13:10,360 --> 00:13:14,720 So there are some things you can do about the WPAD attack. 100 00:13:15,080 --> 00:13:27,400 One of the things is you can serve out the DHCP option 252 yourself, or the DNS option, although browsers look at the DHCP option first, so that would be the better way to go. 101 00:13:27,740 --> 00:13:38,080 Also, you could ensure that the browsers aren't set to use autoproxy detection, and as I mentioned, this only protects against the WPAD, not the ARP spoofing type of attacks. 102 00:13:39,760 --> 00:13:57,220 So below is the URL for the code, and it's hosted at Google, and it has the fine seal of works on my machine approval, so you might get a, your mileage may vary, but again, let me know and I'll always look to fixing it. 103 00:13:57,220 --> 00:13:58,220 So, that's it. 104 00:13:58,220 --> 00:13:58,920 Thanks. 105 00:14:06,040 --> 00:14:08,820 I have time for questions if anyone has any questions. 106 00:14:12,840 --> 00:14:13,120 Yes? 107 00:14:14,740 --> 00:14:16,960 No, I'm not decrypting SSL. 108 00:14:16,960 --> 00:14:36,580 I had actually added functionality originally to create self-signed certificates on the fly, and I had that partially working, but then I figured I'd just back off of that and use Moxie's SSL sniff and SSL stripping, which I intend on putting in there to do that kind of functionality. 109 00:14:41,280 --> 00:14:42,420 Okay, well, thank you.