start	end	text
0	2980	Hi and welcome to my talk on malicious proxies.
3920	8280	So let me tell you a little bit about myself. My name is Ed Zebrowski and I've been in security
8280	13300	for about 12 years. Through those 12 years, I've moved back and forth through the various
13300	18740	disciplines of malicious logic, incident response, intrusion detection, and pen testing.
19640	24260	During this moving back and forth, I've found that I really enjoy the pen testing the most
24260	30280	because it gives me the ability to tackle problems and evolving challenges that I normally
30280	31400	wouldn't encounter.
32880	37280	So one thing I want to get out of the way talking about proxies, when I use the term
37280	43760	proxy, I'm focusing only on web proxies. And there's also plenty of reasons why you'd want
43760	50100	to deploy a proxy legitimately, but who really cares? I'm not here to espouse on the benefits
50100	51140	of a proxy.
53060	57220	So why would I come up with a malicious proxy anyways? I wanted to come up with as many
57220	63800	ways as I could to screw with a user's web browsing session anytime I could. And also
63800	69100	as a pen tester, it gave me the ability to gather information that I might not have accessibility
69100	69920	to.
71860	77700	So a quick simplistic rundown of how proxies work. You have the client that requests a
77700	83300	page through a proxy and that proxy then requests it from the server. The server passes
83300	89700	that page back to the proxy and from the proxy to the client, rendering the page. A malicious
89700	97020	proxy isn't much different because it still sends the request through the proxy to the
97740	104340	server and back to the proxy. The only difference here is the proxy now has a chance to modify
104340	111980	this data. And here's a screenshot of an excerpt of slash dot before and after it modifies
111980	118440	it. Now, what you see here is on the bottom screen, a couple elements being added on to
118440	127550	the page there, inserting some JavaScript. That JavaScript or page as it's been modified
127550	132210	by the proxy is then passed right back on to the client where it's now rendered with
132210	134070	the modifications you made to it.
135110	140650	So, as I mentioned, a malicious proxy isn't much different from a standard proxy but it
140650	147930	can modify and change the HTTP responses and requests and it can also add and remove data.
151970	156810	So there are a couple ways you would want to go about modifying the content. One way
156810	163650	is via modifying the static HTML. Now, that takes a lot of customization on a per page
163650	168730	basis and it's just really kind of difficult to do for every single page that you would
168730	174450	possibly want to modify. Another way to do it is via injecting JavaScript directly into
174450	179710	the page. And that's a lot easier because we only need to find one thing that all pages
179710	187270	should have in common like a head tag and add that JavaScript to that element. This
187270	196170	way it allows the client to render the page for us and do it in a consistent way, modifying
196170	202870	the DOM. So there are some potential issues you might encounter when deploying malicious
202870	208870	proxy. One is that inserted JavaScript may be blocked by elements, or excuse me, by extensions
208870	214350	like NoScript. There are ways around this though because if you can inject JavaScript
214350	219470	as it's traveling through the proxy, you can just directly inject the JavaScript, making
219470	225850	it look like it's from whatever trusted site that the user is going to. Also, I've encountered
225850	232270	that some AJAX heavy sites don't play very well, especially in the area of forms. If
232730	239390	a site sends the form request off in an AJAX request, it might not get picked up. But if
239390	248290	it's sent via a form post to a separate handler, it will get picked up. Another issue is
248290	257570	compressed pages. Because everything uses the HTTP 1.1 standard these days, excuse me,
260950	266110	because everything uses the HTTP 1.1 standard these days, pages will come by in a binary
266110	271210	format making it hard for us to make our changes. So we have a couple options there. We can
271210	276250	either modify, decompress and modify the page when it comes to the proxy or we can
276250	282010	just strip out the header request as it's going out from the client. Also, modifying
282010	287290	the page itself slows down delivery. So if you're doing this on a large scale, you might
287290	292370	run into more issues and that's another reason why they use JavaScript to let it do the lifting
292370	300210	and the clients do the processing for you. So backing up now, how would you go about
300210	305190	assigning a proxy? Well, in a pen test statically is not the best way to do it and it's kind
305190	313930	of like cheating. You can also do it dynamically via DNS or DHCP. DNS has this functionality
313930	320230	called a WPAD record and what that does is any browser set up to use autoproxy detection
320230	329290	will look for a domain name with a WPAD host appended to it or pre-appended to it. If it
329290	335790	finds it, it will look for a file on a web host at that URL and that file contains the
335790	342530	proxy configuration file of where it should proxy through. The same thing with the DHCP
342530	348310	option 252, the only difference is you get more flexible about the URL. And again, that
348310	354570	only works for browsers using autoproxy detection. And of course, there are the other ways you
354570	360990	can do it via like ARP spoofing as well. So I'm going to start talking about Topple
360990	366050	Ganger, the tool I wrote to do this kind of stuff. When I started writing it, I wrote
366050	373090	it as a kind of personal exercise learning Ruby. So the code isn't pretty and the documentation
373090	377550	is sparse but that's a work in progress. I also wrote it as a proof of concept so some
377550	381930	things might not always work but if you find yourself wanting to download it and you do
381930	386350	and you find something wrong with it, feel free to let me know about it. I won't mind
386350	392290	you make improvements. Now for the tool itself, I wanted it to be able to set down on the
392290	397790	network and just go immediately. I didn't want to have to configure it a whole lot and
397790	404610	I wanted it to target all sites out of the box. So Topple Ganger itself can create that
404610	410230	WPAD record for us and I found that if you can manage to get on a network, usually the
410230	417870	networks trust internal DNS updates so therefore you can become the proxy for the internal
417870	423970	networks. And if any of you are familiar with Grease Monkey, this is kind of like Grease
423970	433010	Monkey for an entire network. Additionally, you can use Google APIs for part of the JavaScript
433010	438390	so that way you don't need to have the clients pinging your local machine to get them. You
438390	444890	can go to an already trusted site and let them download from there. So Doppelganger, as I
444890	451510	mentioned, uses Ruby. And the core and heart and soul of Doppelganger is Webrick. It uses
451510	458670	that as the HTTP server serving up any files like the WPAD file or any other images that
458670	465390	might be sent to the client. It also uses Ruby gems, DNS Ruby for updating the DNS, Packer
465390	472310	for packing JavaScript and injecting it directly into the page. And the bottom two, Windows
472310	477770	PR and Win32 process for Windows interoperability. But I haven't had any success with it binding
477770	485710	to a port on Windows yet so I won't count on that working. So as I mentioned, Doppelganger
487170	493150	generically works as a malicious proxy and can operate on both the headers and the content
493150	501850	of the page. Specifically, it has these abilities and these can be customized or added to or
501850	506850	what not but this is out of the boxes. I've written it. And you only need to create a
506850	512070	JavaScript file containing the directives you want it to do. So I can insert a calling
512070	517310	card and calling card is a pretty obvious attack. Not always useful for a pen test but
517310	522930	it has its uses at times. Also injecting flash applets. I can also scrape and decode the
522930	528070	basic authentication of any users authenticating to a site because that basic auth is only
528070	534890	base 64 encoded. I can use it to steal form data and other header data such as cookies.
540440	547160	So inserting a calling card simply just removes all the children tag and the body tag and
547160	557060	it adds new image to display on the page prominently. Header capturing works just as it sounds.
557080	562860	As a header is coming in or out, you can grab it. Like I said, this works for HTTP basic
562860	567320	authentication and it can decode it for us on the fly so that way we don't need to bother
567320	572540	putting it through our base 64 decoder and we can also grab cookies to steal other people's
572540	578760	sessions. For injecting flash, we can just append that onto the end of the body of the
578760	585700	page and this allows us to gather more information about hosts and potentially even exploit flash
585700	592780	vulnerabilities. In capturing form data, the way this works is it binds to the submit event
592780	599920	on all forms and when the user clicks on the submit button, it serializes that data, sends
599920	606400	it back to the proxy to a non-existent URL where it's then logged by Doppelganger. And
606400	613560	this is pretty useful too, especially for those pages that are HTTP only but then post
613560	623650	the data to the form, excuse me, to a secure page. So, an example of what you might see
623650	630410	is here, a tragic event happening on June 23rd, a separation of a couple because that
630410	635810	never happens. But if you're running Doppelganger and you had the calling card functionality,
635810	644910	they might see something more like this. Stealing form data, here's an excerpt from the Slack
644930	652190	Flash.login box and I have my username and my password in there and at the bottom in
652190	656570	the red is the form data that's serialized and posted back to Doppelganger that contains
656570	664160	all the information that the user put into that form. So, Doppelganger has some other
664160	670760	uses potentially. You could use it in phishing attacks. You could also use it in Csurf attacks
670760	678720	or exploiting other things like Adobe Flash or the Oday Firefox vulnerabilities that just
678720	687740	recently came out. And where I'd like to take it in the future is add more addition or more
687740	693000	control over what pages that you can manipulate. Right now, as I mentioned, it just kind of
693000	699220	gets everything out of the box. You might want to be able to filter out some of those
699220	702820	pages and only get the ones that might be of interest to you. Also, a little more
702820	709400	interactivity because there's chances are you might want to add more JavaScript to it via
709400	715560	Google APIs, in which case you have to stop Doppelganger, start it back up and run it. And
715560	721340	during that time, you might miss something or if somebody's looking at you as a proxy and
721340	728360	you're not running, you could effectively denial of service the network. And additionally,
728360	733340	I'd also like to add some functionality for the SSL strip and SSL sniff that Moxie's been
733340	739940	working on. That's some pretty good work right there. So now some curious findings about
739940	746540	when I was creating this tool. One of the things I found out when I started with the WPAD
747120	754360	was that when I first updated that DNS record, I had about 320 hosts pinging my laptop as
754920	761760	their proxy in about an hour's worth of time. But in our environment, we don't use, our
761760	767840	environment uses a GPO to push out proxy as well as baseline image, so we were getting
767840	774800	about 320 hosts that were looking at my laptop to be their proxy. Also, additionally, not
774800	780420	on the slides, is I found that big surprise, IE was the biggest offender of using the WPAD,
780420	784380	the autoproxy detection. But there were still some other browsers in there that were using
784380	791060	it as well, such as Firefox and Opera, which was a little bit of a surprise to me. So there
791060	796520	are some things you can do about the WPAD attack. One of the things is you can serve out
796520	804740	the DHCP option 252 yourself, or the DNS option, although browsers look at the DHCP option
804740	809780	first, so that would be the better way to go. Also, you could ensure that the browsers
809780	815260	aren't set to use autoproxy detection, and as I mentioned, this only protects against
815260	825660	the WPAD, not the ARP spoofing type of attacks. So below is the URL for the code, and it's
825660	830960	hosted at Google, and it has the fine seal of works on my machine approval, so you might
830960	837220	get a, your mileage may vary, but again, let me know and I'll always look to fixing it.
837220	853120	So, that's it. Thanks. I have time for questions if anyone has any questions. Yes?
854740	861040	No, I'm not decrypting SSL. I had actually added functionality originally to create self-signed
861040	867960	certificates on the fly, and I had that partially working, but then I figured I'd just back
867960	874600	off of that and use Moxie's SSL sniff and SSL stripping, which I intend on putting in
874600	882420	there to do that kind of functionality. Okay, well, thank you.
