00:00:00.033,00:00:04.404 >>Give uh Ben and Cody another great round of applause and congratulations for making it. 00:00:04.404,00:00:09.409 [cheering] >>Thanks. Let's do it. >>Let's do it! [applause] >>Well, hi, uh, my name is Ben, 00:00:14.381,00:00:18.485 I also have Cody here with me. Uh, I'll let him do a little bit of an introduction, in a sec. 00:00:18.485,00:00:23.557 Uh, I'm a head of hacker operations at HackerOne. Uhm, somewhere on the top 20 on 00:00:23.557,00:00:28.495 HackerOne, I dunno how but somewhere in there. I found some cool bugs on Snapchat, Yahoo, 00:00:28.495,00:00:33.967 DoD, AirBnB, uhm, we'll definitely talk about Snapchat in a little bit. I also do a lot 00:00:33.967,00:00:38.405 of social media stuff on YouTube, Twitter, Twitch, whatever other social media, 00:00:38.405,00:00:44.578 it's all the same - at NahamSec. And I'll let Cody introduce himself before we get started. 00:00:44.578,00:00:49.016 >>Yea so my name Cody Brocious, I am the head of hacker education at HackerOne, uhm, 00:00:49.016,00:00:54.021 unlike Ben, not in the top 20 on HackerOne, uh, but "top 400" doesn't have the same ring to 00:00:56.356,00:01:02.162 it. [laughter] Uhm, I, uh, talked at BlackHat back in 2012 about hacking hotel locks. I 00:01:02.162,00:01:08.568 worked at hacking the Nintendo Switch, hacked iTunes, a bunch of other stuff. Uhm, my focus is 00:01:08.568,00:01:13.407 on reversing but today we're talking about web stuff. Uh, and I'm available on twitter at 00:01:13.407,00:01:19.513 dacken. >>He's also a unicorn, uh, and I do refer to this in our talk, so I'll show it in a 00:01:19.513,00:01:25.519 sec. [deep breath] So, uh, again, we're gonna talk about SSRF, uhm, this is the long 00:01:25.519,00:01:31.058 description on OWASP, uhm, Server-side request forgery; you abuse functionality; you can 00:01:31.058,00:01:36.263 update resources, read them, uh... Tons of stuff you can do - like if you're on the cloud like 00:01:36.263,00:01:41.768 AWS, you can hit the cloud metadata, pull some keys. So, TL:DR: You're just making 00:01:41.768,00:01:46.473 requests from the target host and, uh, in some cases you can run stuff like Javascript 00:01:46.473,00:01:52.045 server-side. Uhm, if you're not familiar with the cloud metadata stuff, uhm, that IP address is 00:01:52.045,00:01:57.050 wrong. [laughter] Uhm, don't go to it, it's supposed to be 169... uh, 169.254.169.254, uhm 00:01:59.419,00:02:03.490 but if you go there, there's a lot of good information. Uhm, it gives you the host name, the 00:02:03.490,00:02:08.261 internal IP address external IP address, uh, some other information. But the best part 00:02:08.261,00:02:15.035 of it is it also could give you access to the keys and the secret keys to the kingdom. Uhm, 00:02:15.035,00:02:19.072 so once you get to that, it's pretty much game over more than likely you can escalate and 00:02:19.072,00:02:24.077 start doing more stuff. That's basic examples, uhm, the best on is you go to a website, uh, they 00:02:26.313,00:02:31.184 want you to fetch your avatar, uh, you can do that from an external host, uh, you give it a 00:02:31.184,00:02:36.790 URL, it's going to fetch that image. Uhm, sometimes it looks something like this, you go to 00:02:36.790,00:02:43.130 the API, uh, and the API makes a call, fetches the URL and, uhm, it's not always straightforward 00:02:43.130,00:02:47.934 like this but you can do stuff like the filewrapper and point it to a file; read the local 00:02:47.934,00:02:53.040 file on that machine, you can see some other protocols and you can also, uh, hit internal hosts 00:02:53.040,00:02:58.412 obviously, uh, which we'll show in a little bit. But it's not always this easy, there's always 00:02:58.412,00:03:03.617 a, uhm.. This step that you're gonna think about, that you're missing in all this. There's 00:03:03.617,00:03:09.022 always some blocker, uh, some filtering maybe, uh, depending on what company you're going 00:03:09.022,00:03:12.993 after. Uh, and then this talk we're going to talk about some of the hurdles we came across 00:03:12.993,00:03:19.166 and how we were able to bypass them. So there's also a lot of CVEs out there, uhm, some really 00:03:19.166,00:03:24.404 really good ones recently. Uhm, best, best example is Jira to this day it's still vulnerable, 00:03:24.404,00:03:30.610 this is from, uh, I believe this is Alyssa's, uh, blog on the DoD program, uh, this was sicolosed 00:03:30.610,00:03:36.917 publicly on HackerOne. Uh, this came out in 2017 and it was still vulnerable two weeks ago 00:03:36.917,00:03:42.155 on other companies that I was hacking on, uhm, it's still out there, uhm, perfect example of 00:03:42.155,00:03:46.626 what I showed earlier. You pretty much are hitting an API, uhm, this is, this, uh, icon 00:03:46.626,00:03:52.799 dash url and you give it a, you know, uh, webpages, external webpage - a Google in this case 00:03:52.799,00:03:58.004 and it fetches it for you and then you switch that to the metadata, uhm, to, uh, to fetch 00:03:58.004,00:04:04.277 the internal host name and obviously comes back and gives you that internal, uhm, code 00:04:04.277,00:04:09.416 string. Pretty straight forward. Pretty dangerous stuff. Uhm, but this is pretty old. Recently, 00:04:09.416,00:04:15.088 last year, uh, Orange, if you're here, shout out to you for this, uhm, he did the same exact thing 00:04:15.088,00:04:19.993 to Jenkins, so if you find a Jenkins instance on auth; you hit this url, you point it to 00:04:19.993,00:04:25.365 the, uh, nAWS or any cloud metadata and you can pull the keys, uh and this is straight 00:04:25.365,00:04:30.203 from his blog. So, if you wanna look it up, just type in "Jenkins Orange Tsai SSRF" and 00:04:30.203,00:04:35.108 it'll come up. So, pretty straightforward stuff, uhm, nothing you really have to 00:04:35.108,00:04:40.080 bypass, or fight in order to get, uh, you know, metadata or whatever credentials you're 00:04:40.080,00:04:45.252 looking for. [deep breath] But there are a lot of problems when that's not the case. So, 00:04:45.252,00:04:50.257 example, you didn't, uh, the developers may have blocked access to the AWS metadata IP 00:04:52.259,00:04:57.130 address directly. Uhm, but, you can, again, you know, point your own domain, you can have your 00:04:57.130,00:05:01.268 domain pointing at your metadata. You hit it with the API or whatever you're 00:05:01.268,00:05:07.541 exploiting, it works. So, that's solution 1, uh, sometimes it's only white listed to the target 00:05:07.541,00:05:11.111 application - so, if you're hacking on a site dot com, you can only use resources on site 00:05:11.111,00:05:16.550 dot com. But you want to SSRF that, you go and find an open U-direct and you use that 00:05:16.550,00:05:21.788 against the application. So, you use their own functionality against themselves. Also, there 00:05:21.788,00:05:27.961 are times that, uh, I wanna say 9 out of 10 times the SSRFs that we find, and they're the fun 00:05:27.961,00:05:33.200 ones or the most impactful ones is when you have no output where you can't see the answer to it; 00:05:33.200,00:05:37.537 you can;t see what their response is from the server. But it allows you to, ex, uh, 00:05:37.537,00:05:44.010 execute Javascript server, uh, server-side which we'll talk about a lot, uhm, eventually. 00:05:44.010,00:05:49.416 So, there are a lot of, uh, valuable assets out there for this while PDF, uhm generation, 00:05:49.416,00:05:55.121 uh, PDF exploitation to work, XXS on a target is always helpful, especially if here is 00:05:55.121,00:05:57.123 PDF generator on that page, so if you have XXS on this application in the top right 00:05:57.123,00:05:59.125 corner , it says "download PDF, print PDF" you hit that, it prints the PDF with an XXS 00:05:59.125,00:06:03.430 embedded inside and if you play around with it, you can also exploit it. So, you can confirm 00:06:03.430,00:06:05.432 it to see if you'd, uh, actually rendering that, uhm, HTML or Javascript server-side by giving 00:06:05.432,00:06:07.434 it something like a script document "write 1, 2, 3" - if it works "writes 1, 2, 3" - 00:06:07.434,00:06:09.436 confirmation that it's there, and, uh, and you move onto the next phase. Uh, you can also, 00:06:09.436,00:06:14.040 you know, do iframe image, uh, if it's pretty straightforward, if you, if they let you do that 00:06:14.040,00:06:16.243 you can just do iframe, source equals to whatever you want to fetch. You don't even have to 00:06:16.243,00:06:18.245 use Javascript at that point. And there's also, uh, customisation of your PDF 00:06:18.245,00:06:20.247 generator, so if they allow you to customise the fonts; if they allow you to customise your, uh, 00:06:20.247,00:06:24.918 headers, a footer - whatever, whatever CSS is involved, you can also abuse that, uh, to get 00:06:24.918,00:06:29.923 SSRF in some cases. I will, which we'll talk about in a little bit. And always open, uh, 00:06:57.617,00:07:01.554 redirects, don't burn them if you find them. You will always, you will regret burning an open 00:07:01.554,00:07:06.426 redirect if, uh, you're not looking for a SSRF. So, if I find I'm not reporting it until 00:07:06.426,00:07:11.898 I find I find SSRF just bunch them together and report it. [sniff] So, PDF generation 00:07:11.898,00:07:16.903 process, uh, I'll let Cody explain this really quickly. Uh, go on. >>So, when you're talking 00:07:19.072,00:07:24.311 about doing PDF generation, you have two really common ways of, uh, of approaching the problem. 00:07:24.311,00:07:29.316 So, you have headless browsers and, uh, kind of, browserless HTML renders, uh, so headless 00:07:31.384,00:07:35.188 browsers are things like headless chrome which is exactly what it sounds like - it's 00:07:35.188,00:07:40.193 chrome which renders to an image or a pdf. Uh, and then you have things like WKHTML to PDF which 00:07:42.329,00:07:49.035 is, again, exactly what it sounds like, it is webkit with a PDF rendering backend. Uhm, and 00:07:49.035,00:07:53.606 those are probably the most common ways that people do conversion to PDF these days. 00:07:53.606,00:07:58.878 Generating PDFs directly is fraught with difficulty and you have to restyle everything. You 00:07:58.878,00:08:03.850 know, if you have a custom style that you're doing through CSS and HTML, that's not gonna work 00:08:03.850,00:08:08.588 in PDF. So, these convertors allow you to get round that. So, headless browsers are super 00:08:08.588,00:08:13.727 common for that kind of thing. Uhm, and there are lots of wrapper libraries, like if 00:08:13.727,00:08:18.598 you're doing this in Python, Ruby, Java, CSharp - whatever - there are libraries that will 00:08:18.598,00:08:24.804 make that really easy. Uhm, and then there's the HTML renderer side where it's not actually a 00:08:24.804,00:08:29.776 browser engine, uh, there's no Javascript support, usually CSS support is limited, like, it 00:08:29.776,00:08:35.548 would be like CSS level 1, maybe 2. Uhm, they provide a really restricted environment where 00:08:35.548,00:08:40.553 HTML is, uhm, is used but only in so much as, you know it's, uhm, it, it, it's the layout of 00:08:44.991,00:08:50.397 the page, not any real, uh, real functionality. So, WeasyPrint is a great example of this and 00:08:50.397,00:08:54.434 we'll talk about, uh, some real interesting stuff with WeasyPrint, in, uh, in a little 00:08:54.434,00:08:59.439 bit. >>So, earlier I talked about getting XXS in a PDF but we kind of want to show that 00:09:02.609,00:09:06.212 process. I know it doesn't always have to be XXS but it's just easier if you have 00:09:06.212,00:09:11.217 Javascript running, uh, in those PDF files. Uh, so what happens - you get XXS, uhm, every modern 00:09:13.653,00:09:18.558 roam application probably does this, uhm, what you want to do is, you want to make sure, uhm, 00:09:18.558,00:09:23.062 you have, you wanna have confirmation. Whatever you're, uh, you wanna make sure that 00:09:23.062,00:09:28.635 this is actually rendering this Javascript HTML server-side. And it's actually, maybe, reaching 00:09:28.635,00:09:34.574 out to an external host, uhm, such as this one. So, if I get an HTML injection in there it 00:09:34.574,00:09:41.247 shows that my HTML got rendered and put into the, uh, the PDF. The next thing I do, I reach out 00:09:41.247,00:09:46.186 to the server using HTML, something like an iframe , an image source, an object, uhm, 00:09:46.186,00:09:51.458 something to embed a file inside of it. And, as soon as it renders, it will hit your server 00:09:51.458,00:09:56.529 or opening up, uh, a port and the thing, the important thing about this is, uh, the reason 00:09:56.529,00:10:01.100 why you do this, you wanna, you wanna get a user agent. So, the user agent is very helpful to 00:10:01.100,00:10:05.405 figure out what you're going against. Uhm, in this case we're going against, uh, some sort of 00:10:05.405,00:10:11.377 a browser. But in the cases it could be WeasyPrint, uh, it could be the PDF HTML kit it 00:10:11.377,00:10:17.217 could be different things and based on that the exploitation completely changes. So again, if 00:10:17.217,00:10:23.123 you do the cloud IP address, user data, bunch of slashes folders' paths o the API key or 00:10:23.123,00:10:28.127 the secret keys. It spits this out and you have access to the AWS instance. Alright, wanna do 00:10:31.731,00:10:36.736 this one again? >>Yea, sure. So, simple is great and a lot of SSRFs are simple. They are not 00:10:39.172,00:10:44.844 something a lot of people still look for, uhm, there are simple SSRFs that have been there for 00:10:44.844,00:10:49.849 years that still haven't been found in popular programs. Uhm, but simple doesn't always work 00:10:52.719,00:10:58.391 here. Uhm, when it comes to something like headless Chrome, you're really going up against a 00:10:58.391,00:11:01.961 browser running in the cloud. Like, there's, there's no two ways about it. You're going to 00:11:01.961,00:11:06.432 run up against things like "same-origin policy" which the Javascript engine actually can, 00:11:06.432,00:11:11.437 cares about. So, you know, we've talked a lot about this metadata service this 169.254 etcetera, 00:11:14.040,00:11:17.443 uhm, you will not be able to access that that if you're in headless chrome because 00:11:17.443,00:11:21.414 same-origin policy is going to block it. The same reason that Facebook can't go talk to your 00:11:21.414,00:11:28.154 bank's website without special communication and cores. [deep breath] So, same-origin policy 00:11:28.154,00:11:32.525 really shoots a lot of this in the foot, you know, you're, you're unable to, uh, to 00:11:32.525,00:11:37.163 actually connect to the services you care about - whether that's the metadata service or some 00:11:37.163,00:11:42.168 other internal service. Uhm, so we need to find interesting ways to, uh, to get around that. Uhm, 00:11:44.537,00:11:50.843 but additionally we can't redirect, uh, so, in the old days with, uh, WKHTML to PDF you 00:11:50.843,00:11:56.849 could actually just do a standard redirect and it would have some kind of timeout. So, 00:11:56.849,00:12:02.522 it would spend, you know, ten seconds rendering at max or whatever and it would just wait 00:12:02.522,00:12:07.794 until the final page is loaded, but with headless Chrome if you do a redirect it says "Oh, the 00:12:07.794,00:12:13.166 page just finished loading, I'd better render what I've got now". Uhm, so we can't redirect 00:12:13.166,00:12:18.171 over to another service, we have to figure out another way around all this. >>Okay, so let's say, 00:12:20.807,00:12:24.944 uh, we go up against an app, like it's an application, uhm, there's no XSS available, this 00:12:24.944,00:12:30.683 is something that, uh, we found by luck a little bit. Uh, go against an application, anything 00:12:30.683,00:12:35.421 we put in XSS for doesn't work. Uh, someone already found all their cross hair scripting 00:12:35.421,00:12:42.061 vulns, reported it, that was fixed. Uhm, but we're allowed to customise CSS, you know, I can 00:12:42.061,00:12:46.933 change the fonts - the font type, the size, the colour, background whatever that is, 00:12:46.933,00:12:52.805 right? Uhm, but you can also end a style tag and get out of it and then start adding more HTML 00:12:52.805,00:12:58.478 and go back to step one and iframing things and, uh, searching for stuff. So dunno if 00:12:58.478,00:13:05.018 you guys can see that, the first one is, uh, the burp, uh, request that we got, uh it's for 00:13:05.018,00:13:10.223 a font name. It says he font name and at the end of it there's a closing style tag and 00:13:10.223,00:13:13.993 we'll generate the PDF. As you can see all our other payloads were failing on the right hand 00:13:13.993,00:13:19.065 side but then somehow this one worked and then the remainder of the CSS which screams at us 00:13:19.065,00:13:23.803 "Okay, we have something!" on this PDF generator now and we can actually start putting HTML 00:13:23.803,00:13:29.809 in there. And you go back and, uh, you change the payload to an external host so I'm pointing 00:13:29.809,00:13:34.647 this to my server and it comes back with a user agent, java so we know it's going and there's a 00:13:34.647,00:13:39.285 java application in the back-end. We started thinking of how to exploit it but it doesn't 00:13:39.285,00:13:42.789 have to be that hard you can just give it iframe after you closed that style tag. Your 00:13:42.789,00:13:47.794 closing style tag, iframe and you hit the metadata and you get the keys. So, it doesn't have to 00:13:47.794,00:13:52.999 always be XSS, if you don't find them, uh, the first thing I do is just go and look and see if I 00:13:52.999,00:13:58.538 can actually customize this PDF and if it does, I wanna say 9 out of 10 times people forget 00:13:58.538,00:14:03.176 about their style tags and you can just close it out and, uh, start inserting and inj, uh, 00:14:03.176,00:14:08.181 injecting HTML and Javascript. WeasyPrint makes hacking weasy. [laughter] I'll let Cody explain 00:14:11.084,00:14:16.089 this one, uh, this was a really fun one, uhm, we sat on this, uh, this next one took us about 00:14:18.324,00:14:23.930 three months to figure out. Uh, it took us a trip to New York for us to actually look at this 00:14:23.930,00:14:28.935 in person and figure out this WeasyPrint thing works, so, uh, I'll let Cody explain this. 00:14:32.538,00:14:37.210 >>Yea, so Ben gets all the credit here for actually finding the underlying bug here, uhm, I 00:14:37.210,00:14:42.215 just can't stop once I see a puzzle. Uhm, so WeasyPrint, as I said earlier, is, uhm, is really 00:14:46.519,00:14:52.558 really really simple. Like, it's maybe, what? 4-thousand lines of python, something like that. Uhm 00:14:52.558,00:14:58.898 it doesn't run scripts, it will not load, uh, will not load iframes, uh, it'll load images 00:14:58.898,00:15:03.836 but only kind of. Uhm, and the worst part was anytime we actually wanted to eat this 00:15:05.905,00:15:10.276 generator we were coming up against, we had to do a ride share. Uhm, so we had to 00:15:10.276,00:15:16.082 actually go take a ride somewhere, put a payload in a mobile app, wait a few minutes, 00:15:16.082,00:15:20.853 be able to test. So, we, we spent some money, took, took quite a few rides around New 00:15:20.853,00:15:27.426 York city, uh, got some really good hotdogs, it was, it was great. [click noise ] Uhm, but 00:15:27.426,00:15:31.798 the thing was, we just, eventually, we thought, okay, we're gonna send an image 00:15:31.798,00:15:36.235 source. We're gonna point it at our server and we're gonna get the user agent, and once we got 00:15:36.235,00:15:41.073 through that, uhm, and the unique difficulty of getting quotes on iOS where it'll try to 00:15:41.073,00:15:47.079 use smart quotes instead of normal straight up double quotes. Uhm, we were able to see 00:15:47.079,00:15:53.753 that this was WeasyPrint. Uh, so great thing was, it was open source, uhm, simple Python, you 00:15:53.753,00:15:56.289 know, Python library, just wrote a quick script and I was actually able to replicate this 00:15:56.289,00:16:01.227 in my own environment. And I was able to do all f the testing there. Uhm, the problem was, 00:16:03.596,00:16:06.799 this was where we kind of hit the brick wall. Like, looking through the source, this thing 00:16:06.799,00:16:12.572 nothing. It doesn't do any scripts, any iframes, no redirects, nothing. Uhm, so we 00:16:12.572,00:16:17.109 kinda hit a brick wall and just didn't feel like we could get through. [ticking noise] Uhm, 00:16:17.109,00:16:23.082 when... [indistinct talking] Yea, go for it. >>Uhm, the, this is how the WeasyPrint 00:16:23.082,00:16:26.485 application works. If you just look where we're doing it. So, this is what we had to do in 00:16:26.485,00:16:31.991 order to figure out if it's even vulnerable. Like Cody mentioned, we installed WeasyPrint locally, 00:16:31.991,00:16:37.563 uhm, what you do is... [clears throat] You will pretty much put an HTML file, so, on the left 00:16:37.563,00:16:42.268 side, I'm making that HTML file on the left and I give it to WeasyPrint and I say "output dot 00:16:42.268,00:16:47.139 output to PDF". And on the right hand side you can see what was printed. So, this is my process 00:16:47.139,00:16:51.978 of seeing what the heck can I do on this PDF thing? Like what is actually available to me? So, 00:16:51.978,00:16:58.017 obviously, basic HTML worked, uh, I did a document write - didn't work. I tried to fetch an 00:16:58.017,00:17:03.756 image, uh, you know, I titled it and at the bottom I'm writing to fetch a Google image, that one 00:17:03.756,00:17:08.895 worked but having an image really doesn't help me get clear text for the AWS keys. Worked 00:17:08.895,00:17:13.733 this a little bit. And iframe obviously didn't work. Uhm, so we needed to come up with a back 00:17:13.733,00:17:20.239 up plan, uhm, just to reiterate this again, no javascript, no iframe and, uh, but we did have 00:17:20.239,00:17:25.244 access to source, which, uh, enters this unicorn Cody. >>So, I'm hunting through it, I'm 00:17:28.281,00:17:32.985 actually just going through the entire HTML parser - when I say "entire HTML parser" it's a 00:17:32.985,00:17:37.924 couple of hundred lines of code. But at this point I'm exhausted, I'm not feeling very good about 00:17:37.924,00:17:42.495 it , I'm looking through it more as a formality to be able to be like: "Alright, I looked, I did 00:17:42.495,00:17:48.067 everything I could, I'm done, I, I'm gonna quit here". And I'm looking at it, like image, okay 00:17:48.067,00:17:53.506 they might be using a vulnerable library in the back-end, they're using, uh, uhm, some GGK library 00:17:53.506,00:17:58.511 to do decoding, maybe there's something fun there? No. Uhm, there is embed but it turns out 00:18:00.680,00:18:07.420 it just points to image, uhm, there's object again points to image. Like they really love 00:18:07.420,00:18:12.425 image processing. But then there's this link tag, and that looked really interesting to me. 00:18:15.494,00:18:19.966 Uhm, I didn't really know what it would be, you know, link is often used for spread, for style 00:18:19.966,00:18:24.971 sheets, uh, things like that. But this didn't seem to be doing that. So, that's where 00:18:27.340,00:18:32.345 rel-attachment comes in and, uh, WeasyPrint will actually just take whatever file or URL you 00:18:34.680,00:18:39.685 uh, you give it and just put it in the PDF. Uh, not visibly, but it's there. Uh, a, a three-line 00:18:43.422,00:18:48.894 Python script will pull that data right out and decompress it. And, uh, yeah, we could not 00:18:48.894,00:18:54.133 only read files but request the metadata service. Uhm, it took us three more ride shares, we 00:18:54.133,00:18:59.805 had to pull the name of, uh, their, uh, EC2, uh, access account; and then two more to 00:18:59.805,00:19:04.010 actually pull all the keys. And we had everything - we had complete control of their 00:19:04.010,00:19:09.015 environment. So, you can actually see here, just using that rel attachment, this python 00:19:11.817,00:19:16.822 script just unpacks it straight from the PDF and boom - you have antipassword >>We also use this, 00:19:20.326,00:19:25.297 uh, after we found this we actually put this in our CTF, we wanted to see, I had messed with 00:19:25.297,00:19:29.068 this for three months until him and I linked up. So, we wanted to see if other hackers would 00:19:29.068,00:19:32.938 miss it, and obviously they didn't miss it. We had a bunch of people find us as part of 00:19:32.938,00:19:37.676 our, uh, 50-million dollar, uh, HackerOne CTF. [chuckle] So, if you found this, shout out to 00:19:37.676,00:19:42.682 you! >>So, now we're gonna talk about something I, I found a really fun which is DNS 00:19:46.085,00:19:51.090 rebinding when it comes to SSRF. So, as I said before, uh, headless chrome is tough, uhm, 00:19:54.760,00:20:00.332 same-origin policy real, uh, really screws things up. You are unable to talk to anything that 00:20:00.332,00:20:07.106 is not effectively the original sub-domain, or domain that you are on. Uhm, there's really 00:20:07.106,00:20:12.111 nothing you can do about that. So, what if you do just continue talking to this same domain? 00:20:15.781,00:20:20.786 What if? So, you go to, you have the browser go to "x dot plot dot info", uhm, it does some 00:20:23.089,00:20:28.027 kind of XML, HTTP request to the metadata service, it's gonna fail. Like, we know that. This 00:20:28.027,00:20:33.032 is standard Same-Origin Policy, Javascript. [sigh] But if I go to "exploit dot info" and I do 00:20:35.134,00:20:40.573 an XML HTTP request to "exploit dot", uh, "exploit dot info" with the same path, it's gonna 00:20:40.573,00:20:46.345 succeed, like this is, this is standard stuff. So, instead, what we can do is, we can have 00:20:46.345,00:20:51.750 the browser load this page, and then once, when the page loads up, you're gonna have a script 00:20:51.750,00:20:58.324 that kicks off a message to the server that say "Okay, your DNS server now should map exploit 00:20:58.324,00:21:03.262 dot info to 169.254.169.254". Uhm, the script then goes ahead and does requests, uh, or, image 00:21:07.700,00:21:14.006 tag or, or whatever to a bunch of other domains, specifically, 25-hundred of them. Because if 00:21:14.006,00:21:20.913 you do 25-hundred of them it flushes Chrome's internal DNS cache. The next request that you 00:21:20.913,00:21:26.051 make to exploit dot info - it has no idea where you are, where you're talking to anymore. So, 00:21:26.051,00:21:30.489 it has to make a new DNS request and it turns out that it's connecting to the metadata 00:21:30.489,00:21:35.995 service now. The metadata, metadata service does not check it's host header, uh, none of 00:21:35.995,00:21:41.000 them do, EC2, Azure, GCP - none of them check their host header. So, as soon as you have done 00:21:43.536,00:21:48.574 this rebinding attack, you actually have the ability to make any request whatsoever to 00:21:48.574,00:21:52.845 metadata without any of the same-origin policy, because it thinks that it's talking to the 00:21:52.845,00:21:58.651 exact same server. What's cool is that you can actually use, uh, other ser, uh, other 00:21:58.651,00:22:04.990 domains, uh, like I used bc dot exploit dot info. Uhm, and you just have to enable cores on 00:22:04.990,00:22:09.995 them to be able to send data up to them and exfiltrate data. So, we have a little demo, uhm, this 00:22:13.666,00:22:18.671 was actually in, uhm, this was in, this was in snapchat, uh, in their ad, uh, functionality, so, 00:22:21.874,00:22:27.746 uh... [indistinct talking] Yea. >>So, what this app does is you can create adds on Snapchat, so 00:22:27.746,00:22:30.916 if you're, you know, watching your stories, click, click, click, ad comes up - this is how 00:22:30.916,00:22:37.289 you make it. But, it also lets you fetch external images from a website in order to make your ad 00:22:37.289,00:22:40.726 - so, if you wanted to use images from a page that you have created on your website and 00:22:40.726,00:22:45.731 embed that page, you fetch for it and it will grab all those, uh, images. So, we found this 00:22:49.068,00:22:55.507 end point that, uh, would make the requests to my server and on the response we couldn't see 00:22:55.507,00:23:00.379 anything and when I tried to do Javascript, Javascript worked but I couldn't just directly hit 00:23:00.379,00:23:07.286 the metadata instance and get the keys off. So, we had to do a little bit of DNS rebinding and 00:23:07.286,00:23:12.291 it looked like this. So, again, uh, we're going to this app and we're just going to create a 00:23:17.329,00:23:22.468 new, uh, advertisement on SnapChat using their own templates, uh, it'll let you, 00:23:22.468,00:23:28.307 again, customize those logos that they're giving you. And you fetch your own website which is 00:23:28.307,00:23:33.312 "fetch google" we intercept it on Burp. And we change the value from... Let's go to send to 00:23:39.351,00:23:44.556 repeater and then we're gonna change the value from google dot com to our host where we're 00:23:44.556,00:23:48.827 going to do the DNS rebinding, uh, in order to hit the metadata. So we hit the 00:23:48.827,00:23:53.832 metadata, we hit data endpoint it invokes our script on Cody's box. So, invokes it, you go to 00:23:58.170,00:24:03.075 your, uh, your host provider, we're using, we are using cloud for this instance. And you 00:24:03.075,00:24:09.782 change the IP address to the cloud metadata IP and you give it, uh, 50 loops. It takes a 00:24:09.782,00:24:14.787 while but we sped it up a little bit. And, uh, this was their GCP tokens, and, uh, secrets pulled 00:24:21.760,00:24:26.765 out in prod from Snapchat. [applause] He's gonna explain, uh, a little bit. >>So, the 00:24:31.337,00:24:36.542 reason that this took so long, uhm, is that this was before I figured out that 25-hundred 00:24:36.542,00:24:41.847 requests would flush the cache. So, you had to actually make it, just continually request, uh, 00:24:41.847,00:24:47.619 until about a minute passed which is the minimum TTL for the, uh, uhm, Google, uhm, the 00:24:47.619,00:24:52.624 built-in Chrome DNS cache. So, doing that manually kinda sucks, uhm, you have to go in, change 00:24:59.231,00:25:04.436 your, uh, DNS provider at the exact right time. Uhm, so I didn't want that, so I actually 00:25:04.436,00:25:11.176 wrote a tool called "HTTP rebind" - it's a real clever name. Uhm, I combined a DNS 00:25:11.176,00:25:17.950 server with an HTTP server and then I made it attack everything. Uh, so, you point, 00:25:17.950,00:25:22.087 your, you actually have to point this to be your name server for a domain, and once you've done 00:25:22.087,00:25:28.060 that, this will handle basically all of the exploitation for you. You, you point it at something 00:25:28.060,00:25:34.600 like Snap, in our case, this tool, uhm, it will automatically handle the rebinding because 00:25:34.600,00:25:39.204 it's got the DNS server built-in. Uh, it'll automatically figure out what 00:25:39.204,00:25:44.877 you're against and handle it appropriately so it'll work for EC2, ECS, uh, I think I have 00:25:44.877,00:25:49.615 Azure support in there - if not it'll be there in a minute - uh, Google cloud. Uhm, all of these 00:25:49.615,00:25:55.654 work automatically and because of the, the cache flush thing, uh, it works pretty much 00:25:55.654,00:26:01.994 instantaneously. Uhm, I think, uh, usually on average about a min, a second and a half, two 00:26:01.994,00:26:08.700 seconds - to pop all of the credentials for the server. Uhm, the source for that will be up 00:26:08.700,00:26:13.705 on GitHub immediately after this talk. >>Uhm, likewise, I have a tool SSRFTest, uhm, I have a 00:26:15.974,00:26:19.011 live instance of this. This is something that's actually been out there for awhile but I 00:26:19.011,00:26:23.682 haven't really talked about. Uhm, basically it acts like request, dunno if you're 00:26:23.682,00:26:28.554 familiar with it, where you can create a target, it'll show you any request that will come in. 00:26:28.554,00:26:34.760 Uhm, which is great, it's useful to just kind of get an idea of what you're doing, like you'll 00:26:34.760,00:26:39.398 get that username, the user, the user agent that's really important. Uhm, but what it'll 00:26:39.398,00:26:45.804 actually do if if it is in a browser, like an actual headless browser, uh, it'll do a, uhm, a 00:26:45.804,00:26:51.510 quick automated exploitation. So, uh, if same-origin policy is not a problem and we don't have 00:26:51.510,00:26:56.615 to go down the DNS rebinding path, this will automatically go and pull literally every ke 00:26:56.615,00:27:03.455 from, uh, from Amazon. Uhm, and this tool alone made me, uh, a lot of bounties. Uh, so the 00:27:03.455,00:27:07.826 source code for this all available, uhm but if you don't wanna run it yourself and you 00:27:07.826,00:27:14.600 trust me enough, uhm, which in theory you shouldn't, but uh, "SSRFTest dot com", uh, make 00:27:14.600,00:27:20.939 sure you go to it with HTTPS or things will go weird. Uhm, that's the, that's the public 00:27:20.939,00:27:25.911 instances for it and, uh, and this is what I personally use for all of my, uh, all of my 00:27:25.911,00:27:30.916 testing for SSRF when I'm trying to just figure out what I'm dealing with initially, >>Okay, 00:27:33.352,00:27:39.525 so, quick recap, uh, SSRFs can be dangerous. Uh, don't stop at the, you know, if you get an 00:27:39.525,00:27:44.196 external fetch, don't stop there, see what else you can do. Uh, don't give up your bugs - 00:27:44.196,00:27:48.834 WeasyPrint took me three months and some change; and a bunch of rides in New York city to figure 00:27:48.834,00:27:53.438 out. And if you see a PDF generator, it's usually vulnerable, you just gotta find 00:27:53.438,00:27:58.610 the right angle and the way to get in. Uh, disable Javascript, it's not lgood, you don't need 00:27:58.610,00:28:03.982 it in PDF generators, uhm. Create some whitelisting, backlisting, whatever what works 00:28:03.982,00:28:09.588 with you. Uh, limit the exposure to your instance at least. Uhm, properly configure your cloud 00:28:09.588,00:28:14.960 instances so the keys aren't being leaked and please be nice to hackers. Uh, again, I am at 00:28:14.960,00:28:19.665 nahamsec, Ben Sadeghipour and this Cody, uh, keep in touch with us - tweet at us, email us, 00:28:19.665,00:28:24.369 uh, if you ever find any SSRFs you can't exploit we'll have to look at it and see if we can 00:28:24.369,00:28:29.374 extend on this research. And thank you for joining us. [applause] [cheering]