Uh, Ben and Cody, another great round of applause and congratulations for making it. Thanks. Let's do it, dude. Let's do it. Well, hi. Uh, my name is Ben. I also have Cody here with me. Uh, I'll let him do a little bit of an introduction in a sec. Uh, I'm a head of hacker operations at HackerOne. Um, somewhere in the top 20 on HackerOne. I don't know how, but somewhere in there. I found some cool bugs on Snapchat, Yahoo, DoD, Airbnb. Um, we'll definitely talk about Snapchat in a little bit. I also do a lot of social media stuff on YouTube, Twitter, Twitch, whatever other social media. It's all the same at Nahamsec. And I'll let Cody introduce himself before we get started. Yeah, so my name is Cody Brocious. I am the head of hacker education at HackerOne. Um, I am, unlike Ben, not in the top 20 on HackerOne. Uh, but top 400 doesn't have the same ring to it. Um, I, uh, talked to BlackHat back in 2012 about hacking hotel locks. Uh, I worked on hacking the Nintendo Switch, hacked iTunes, a bunch of other stuff. Um, my focus is all on reversing, but today we're talking about web stuff. Uh, and I am available on Twitter at Dakin. He's also a unicorn and, uh, I'll have proof for this in our talk, so I'll show it in a sec. So, uh, again, we're going to talk about SSRF. Uh, SSRF is a, uh, this is the long description on OWASP. Um, server side request forgery, you abuse functionality. You can update resources, read them. Uh, tons of stuff you can do. If you're on the cloud, like AWS, you can hit the cloud metadata, pull some keys. So, TLDR, you're just making a request from the target host. Uh, and in some cases you can run stuff like JavaScript server side. Um, if you're not familiar with the cloud metadata stuff, um, that IP address is wrong. Um, you can run, um, don't go to it. It's supposed to be 169, uh, 254, 169, 254. Um, but if you go there, there is a lot of good information. Um, it gives you the host name, the internal IP address, external IP address, uh, some other information. But the best part of it is it also could give you access to the keys and the secret keys to the kingdom. Um, so once you get to that, it's pretty much game over and more than likely you can escalate and start doing more stuff. Those basic examples, um, the best one is you go to a website, uh, they want you to fetch your avatar. Uh, you can do that from an external host. Uh, you give it a URL. It's going to fetch that image. Um, sometimes it looks like something like this. You go to the API. Um, the API makes a call, fetches that URL. And, um, it's not always straight forward like this, but you can do stuff like a file wrapper and po-point it to a file. Read the local file on that machine. You can use some other protocols and you can also, uh, hit internal host obviously. Okay. Um, and you can also, um, uh, set up like, I'm VSC um which we'll show in a little bit. But it's not always this easy, there's always a um this step that you're gonna think about that you're missing in all this. There's always some blocker uh some filtering maybe uh depending on what company you're going after. Uh and in this talk we're going to talk about some of the hurdles we came across and how we were able to bypass them. So there's also a lot of CVEs out there um some really really good ones recently. Um best best example is Jira to this day it's still vulnerable. This is from uh I believe this is Alyssa's uh blog on the DOD program uh that was disclosed publicly on Hacker One. Uh this came out in 2017 and it was still vulnerable two weeks ago on other companies I was hacking on. Um it's still out there. Um perfect example of what I showed earlier you pretty much are hitting an API. Um this is uh icon-url and you give it a you know a password and uh web page external web page at Google in this case and it fetches it for you and then you switch that to a metadata um to to uh fetch the internal host name and obviously it comes back and gives you that internal um host name. Pretty straight forward, pretty dangerous stuff. Um but this is pretty old. Recently last year uh Orange if you're here shout out to you for this. Um he did the same exact thing to Jenkins. So if you find a Jenkins instance on auth you hit this url you point it to him and it will send you a message. Um so this is a to the uh AWS or any cloud metadata and you can pull the keys. Uh and this is straight from his blog. So if you want to look it up just type in Jenkins Orange Sci uh SSRF and it will come up. So pretty straight forward stuff. Um nothing you have to really bypass or fight in order to get um you know metadata or whatever credentials you're looking for. But there are a lot of problems when that's not the case. So example you uh the the developers may have blocked access to the AWS metadata IP address directly. Um but you can you know point your own domain. You can have your domain pointing to the metadata. You hit it with the API or whatever you're exploiting works. So that's solution one. Um sometimes it's only white listed to the target application. So if you're hacking on site dot com you can only use resources on site dot com. But you want to SSRF that you go find an open redirect and you use it against the application. So you use the own functionality against themselves. Also there is times that uh I want to say 9 out of 10 times SSRFs that we find and they're the fun ones or the most impactful ones is when you have no output where you can't see the answer to it. You can't see what the response is from the server. But it allows you to uh execute JavaScript so uh server side which we'll talk about a lot. Um eventually. So there are a lot of uh valuable assets out there for this whole PDF. Uh generation uh PDF exploitation to work. Uh XSS on a target is always helpful especially if there is a PDF generator on that page. So if you have XSS on this application on the right top corner says download PDF, print PDF. You hit that. It prints the PDF with an XSS embedded inside. And if you play around with it you can also exploit it. So you can confirm it to see if you it's uh actually rendering that um HTML or JavaScript server side by giving it something like a script write one two three. If it works write one two three. Confirmation that it's there uh and you move on to the next phase. Uh you can also you know do iframe image uh if it's pretty straightforward. If they let you do that you can just do iframe source equals to whatever you want to fetch. You don't even have to use JavaScript at that point. And there's also uh customization of your PDF generator. So if they allow you to customize the fonts. If they allow you to customize your uh headers, the footer, whatever system you want to use. Uh you can use XSS as involved. You can also abuse that uh to get SSRF in some cases. And we'll which we'll talk about in a little bit. And always uh open redirects. Don't burn them if you find them. You will always you will regret burning an open redirect if you're not uh looking for SSRF. So if I find one I'm not reporting it until I find the SSRF. Just bunch them together and report it. So PDF generation process. Uh I'll let Cody explain this really quickly. Um go ahead. So when you're talking about doing PDF generation you have two really common ways of uh of approaching the problem. So you have headless browsers and kind of uh browserless HTML renderers. Uh so headless browsers are things like headless Chrome which is exactly what it sounds like. It's Chrome that renders to an image or a PDF. Um and then you have things like WKHTML to PDF which is again exactly what it sounds like. It is WebKit with a PDF rendering backend. Um and then you have a headless browser. Um and those are probably the most common ways that people do conversion to PDF these days. Generating PDFs directly is fraught with difficulty and you have to restyle everything. You know if you have a custom style that you're doing through CSS and HTML that's not going to work in a PDF. So these converters allow you to get around that. So headless browsers are super common for that kind of thing. Um and there are lots of wrapper libraries. Like if you're doing this in Python, Ruby, Java, C sharp, whatever. There are libraries that will make that really easy. Um and then there's the HTML renderer side where it's not actually a browser engine. Um there's no Javascript support. Usually CSS support is limited. Like it'll be like CSS level one maybe two. Um they provide a really restricted environment where HTML is um is used but only in so much as you know it's um it's it's the layout of the page not any uh any real functionality. So WheezyPrint is a great example of this and we'll talk about uh some really interesting stuff with WheezyPrint and uh in a little bit. Um so yeah earlier I talked about getting XSS in a PDF but we want to kind of show that process. Uh it doesn't always have to be XSS but it's just easier if you have Javascript running uh in these PDF files. Uh so what happens you get XSS um any modern web application probably does this. Um what you want to do is you want to make sure um you have you want to have confirmation. Whatever um you're exploiting you want to make sure that this is actually rendering this Javascript HTML server side and it's actually maybe reaching out to an external host um such as this one. So if I get an HTML injection in there it shows that my HTML got rendered and put into the uh PDF. The next thing I do is I reach out to the server using HTML something like maybe an iframe, an image source, an object uh something to embed over there. Uh and then I can just like I can just like I can just like I can put a file inside of it and as soon as it renders it will hit your server where you're opening up an uh a port. And the thing the important thing about this is uh the reason why you do this you want to get a user agent. So the user agent is very helpful to figure out what you're going against. Um in this case we're going against uh some sort of uh browser but in other cases it could be Weezy print uh it could be the PDF HTML kit so there could be different things and based on that the exploitation completely changes. So again if you do uh the cloud IP address, user data, a bunch of slashes, folders, paths to the API key or the secret keys it spits this out and you have access to the AWS instance. Alright we'll do this one again. Sure. So simple is great and a lot of SSRFs are simple. They are not something that a lot of people still look for. Um there are simple SSRFs that have been there for years that still haven't been found in popular code. So I'm going to show you some of the popular programs. Um but simple doesn't always work here. Um when it comes to something like headless chrome you're really going up against a browser running in the cloud. Like there's there's no two ways about it. You're going to run up against things like same origin policy which the javascript engine actually cares about. So you know we've talked a lot about this metadata service 169, 254, etc. Um you will not be able to access that if you're in headless chrome because same origin policy is going to block it. The same reason that Facebook can't go talk to your bank website without special communication and cores. So same origin policy really shoots a lot of this in the foot. You know you're you're unable to uh to actually connect to the services that you care about. Uh whether that's the metadata service or some other internal service. Um so we need to find interesting ways to uh to get around that. Um additionally we can't redirect. Uh so in the old days with uh WKHTML to PDF you could actually just do a standard redirect and it would have some kind of time out. So it would spend you know 10 seconds rendering at max or whatever. And it would just wait until the final page is loaded. But with headless chrome if you do a redirect it says oh the page is finished loading I better render what I've got now. Um so we can't redirect over to another service. Um so we can't redirect. We have to figure out a way around all this. So let's say uh we're going against an app against an application. Um there's no XSS available. This is something that uh we found by luck a little bit. Um we go against an application anything we put an XSS for doesn't work. Um someone already found all their crosshair scripting bones, reported it, that was gotten fixed. Um but we're allowed to customize CSS. You know I can change the fonts, uh the font type, size, the color, background whatever that is right. Um but you can also end a style tag and get out of it and start adding more HTML and go back to step 1 and iframe-ing things and uh fetching for stuff. So I don't know if you guys can see that. The first one is uh the burp uh request that we got. It's for a font name. It says the font name and then at the end of it there's a closing style tag. And when we generate the PDF you can see all of our other payloads were failing on the right side. Um and then we can get our font name and then add a style tag to it. And it can be but then somehow this one worked. We see that the remainder of the CSS which screams at us okay we have something on this PDF generator now and we can actually start putting HTML in there. And you go back and uh you change the payload to an external host so I'm pointing this to my server and it comes back with a user agent Java so we know we're going against a Java application in the backend we start thinking of how to exploit it but it doesn't have to be that hard you can just give it an iframe after you close the style tag it's supposed to be a closing style tag iframe and you hit the metadata and you get the keys. So it doesn't have to always be XSS if you don't find them uh the first thing I do is just go and look and see if I can actually customize this PDF and if it does I want to say 9 out of 10 times people forget about their style tags and you can just close it out and uh start inserting uh injecting HTML or JavaScript. Weezy print mix hacking Weezy. I'll let Cody explain this one uh this was a really fun one um we sat on this uh this next one that really took us about 3 months to figure out uh it took us a trip to New York for us to actually look at this in person and uh figure out how this whole Weezy print thing works so I'll let uh Cody explain this. Yeah so Ben gets all the credit here for actually finding the underlying bug here um I just can't stop once I see a puzzle. Um so Weezy print does a really good job of finding the underlying bug here um I can't get the whole thing out so we're gonna do the same thing. Um but the problem is the problem is that it's really really really simple like it's maybe what 4000 lines of python something like that um it doesn't run scripts it will not load uh will not load iframes um it'll load images but only kind of. Um and the worst part was anytime we wanted to actually test this generator we were coming up against we had to do a ride share um so we had to actually go take a ride somewhere, put a payload in a mobile app, wait a few minutes, be able to test. So, we, we spent some money, took, took quite a few rides around New York City, uh, got some really good hot dogs, it was, it was great. Uh, but, the thing was, we just, eventually we thought, okay, we're going to send an image source, we're going to point it to our server, and we're going to get the user agent. And once we got through that, um, and the difficulty of quotes on IOS, uh, where it'll try to use smart quotes instead of normal straight up double quotes, um, we were able to see that this was WeezyPrint. Um, so, great thing was, it was open source, um, simple Python, you know, Python library, just wrote a quick script, and then I was able to actually replicate this in my own environment. And I was able to do all the testing there. Um, the problem was, this was where we kind of hit the brick wall. Like, looking through the source, this thing did nothing. It doesn't do, it doesn't do anything any scripts, any iframes, no redirects, nothing. Um, so we kind of hit a brick wall and just didn't feel like we could get through. Um, when, yeah, go for it. Um, this is the, this is how the WeezyPrint application works if you're just locally doing it. So this is what we had to do in order to figure out if it's even vulnerable. Like Cody mentioned, we installed WeezyPrint locally. Uh, what you do is, you will pretty much put in an HTML file. So on the left side I'm making that HTML file on the left and I give it to WeezyPrint and I say output to output.pdf. And on the right hand side you can see what was printed. So this is my process of seeing what the heck can I do on this PDF thing? Like, what is actually available to me? So obviously basic HTML worked. Uh, I did a document write that didn't work. I tried to fetch an image. Um, you know, I, I titled it and at the bottom I'm writing it to fetch a Google image. That one worked, but having an image really doesn't help me get clear text for the AWS key. Um, so I'm trying to, I'm trying to get clear text for the AWS keys. Worked this a little bit. An iframe obviously didn't work. Um, so we needed to come up with a backup plan. Um, just to reiterate this again, no JavaScript, no iframe. And, uh, but we did have access to source. Which, uh, enters this unicorn, Cody. So I'm hunting through and I'm actually just going through the entire HTML parser. When I say entire HTML parser, it's a couple hundred lines of code. Um, but at this point I'm exhausted. I'm not feeling very good about it. Um, so I'm just going through the code. I'm looking through it more as a formality to be able to be like, alright, I lo- I did everything I could. I'm done. I, I'm gonna quit here. And I'm looking at it and I'm like, image, okay, they might be using a vulnerable library on the backend. They're using like, um, some, uh, GTK library to do decoding. Maybe there's something fun there. No. Um, there is embed, but it turns out that it just points to image. Um, there's object, again, points to image. Like, they really love image processing. But then there's this link tag. And that looked really interesting to me. Um, I didn't really know what it would be. You know, link is often used for spread, uh, for style sheets, uh, things like that. But this didn't seem to be doing that. So that's where rel attachment comes in. And, uh, WeezyPrint will actually just take whatever file or URL you, uh, you give it and just put it in the PDF. Uh, not visibly, but it's there. Uh, a, a three-line Python script will pull that data right out and decompress it. And, uh, yeah, we could not only read files, but make requests to the metadata service. Um, it took us three more rideshares. We had to pull the name of their, uh, EC2, uh, access account. And then two more to actually pull all the keys. And we had everything. Um, so, uh, we're able to do anything. We had complete control of their environment. So you can actually see here, just using that, uh, rel attachment, this, uh, this Python script just unpacks it straight from the PDF and boom, you have Etsy password. Um, we also used this, uh, after we found this, we actually put this in our CTF. We wanted to see, I missed this for three months until him and I linked up. So we wanted to see if other hackers would miss it. And obviously they didn't miss it. We had a bunch of people find this as a part of our, uh, we had a bunch of people find this. Uh, $50 million HackerOne, uh, CTF. So, uh, if you found this, shoutouts to you. So, now we're gonna talk about something that I, I found really fun, which is DNS rebinding when it comes to SSRF. So, as I said before, uh, headless Chrome is tough. Um, same origin policy really, uh, really screws things up. You are unable to talk to anything that is not effectively the original subdomain or domain that you are on. Um, there's really nothing that you can do about that. So, what if you do just keep talking to the same domain? What if, so you go to, uh, you have the browser go to x.ploit.info. Um, it does some kind of XML HTTP request to the metadata service. It's gonna fail. Like, we know that. This is standard, same origin policy, JavaScript. But if I go to x.ploit.info and I do an XML HTTP request to x.ploit.info, info with the same path, it's gonna succeed. Like, this is, this is standard stuff. So, instead, what we can do is we can have the browser load this page. And then when the page loads up, you're gonna have a script that kicks off a message to the server that says, okay, your DNS server now should map x.ploit.info to 169.254.169.254. Um, the script then goes ahead and does requests, uh, or an image tag or or whatever, to a bunch of other domains. Specifically, 2500 of them. Because if you do 2500 of them, it flushes Chrome's internal DNS cache. The next request that you make to x.ploit.info, it has no idea where you're, where you're talking to anymore. So it has to go and make a new DNS request and it turns out that it's connecting to the metadata service now. The metadata, metadata service does not check its host header. Uh, none of them do. EC2, Azure, GCP, none of them check the host header. So as soon as you have done this rebinding attack, you actually have the ability to make any request whatsoever to metadata without any of the same origin policy because it thinks that it's talking to the exact same server. What's really cool is that you can actually use other server, uh, other domains, uh, like I used bc.exploit.info, um, and you just have to enable cores on them to be able to send data up to them and exfiltrate data. So. What company is this? We have a little demo. Um, this was actually in, um, this was in, this was in Snapchat, uh, in their ad, uh, function. Uh, this was actually in Snapchat. So, uh, so what this app does is you can create ads on Snapchat. So if you're, you know, watching your stories, click, click, click, ad comes up. This is how you make it. But it also lets you fetch external images from a website in order to make your ad. So if you wanted to use images from a page that you have created on your website and embed that page, you fetch for it and it will grab all those, uh, images. So, um, we found this endpoint that, uh, would make the request to my server, and on the response we couldn't see anything, and when I tried to do JavaScript, JavaScript worked, but I couldn't just directly hit the metadata, uh, instance, and get the keys off. So we had to do a little bit of DNS rebinding, and it looked like this. So again, uh, we're going to this app, and we're just going to create a new, uh, advertisement on Snapchat using their own templates uh it let you again customize those logos that they're giving you and you fetch your own website we just fetch Google we intercept it on burp and we change the value from let's go send it to repeater and then we're going to change the value from google.com to our host where we're going to do the DNS rebinding uh in order to hit the metadata so we hit the uh we hit that uh endpoint it invokes our script on Cody's box so it invokes it you go to your uh your provider who you're using we're using uh Cloudflare for this instance and you change the IP address to the cloud metadata IP and you give it uh 50 loops it takes a while but we split it up a little bit and then uh and uh this was their GCP tokens and uh secrets pulled out in prod from snapchat I'm going to explain a little bit here. So the reason that this took so long is that this was actually before I figured out that 2500 requests would flush the cache so you had to actually make it just continually request until uh about a minute passed which is the minimum TTL for the um Google um the built in chrome DNS cache. So doing that manually kind of sucks. Um you have to go in change your DNS uh DNS provider at the exact right time. Um so I didn't want that. So I actually wrote a tool called HTTP rebind. It's a real clever name. Um I combined a DNS server with an HTTP server. Um and then I made it attack everything. Um so you point your you actually have to point this to be your name server for a domain. And once you've done that this will handle basically all of the exploitation for you. You point um you point something like snap in in our case to this tool. Um it'll automatically handle the rebinding because it's got the DNS server built in. Um and then you can um it'll automatically figure out what you're attacking against and handle it appropriately. So it'll work for EC2, ECS. Uh I think I have Azure support in there. If not it'll be there in a minute. Uh Google Cloud. Um all of these work automatically. And because of the the cache flush thing uh it works pretty much instantaneously. Um I think uh usually on average about a second and a half, two seconds to pop all of the credentials for the server. Um the source for that will be up on GitHub immediately after this talk. Um likewise I have a tool SSRF test. Um I have a live instance of this. This is something that's actually been out there for a while but I haven't really talked about. Um basically it acts like request bin if you're familiar with it where you can create a target. It'll show you any requests that come in. Um which is great. It's useful to just kind of get an idea of what you're doing. Like you'll get that user uh the user agent. That's really important. Um so I'm going to show you the source code. Um but what it'll actually do is if it's if it is in a browser like an actual headless browser. Uh it'll do a um a quick automated exploitation. So uh if same origin policy is not a problem and we don't have to go down the DNS rebinding path. This will automatically go and pull literally every key from uh from Amazon. Um and this tool alone made me a lot of bounties. Um so the source code for this is all available. Um but if you don't want to run it yourself and you trust me enough. Um which in theory you shouldn't but uh if you want to ssrftest.com uh make sure you go to it with HTTPS or things will go weird. Um that's uh that's the public instance for it and uh this is what I personally use for all of my uh all of my testing for SSRF when I'm trying to just figure out what I'm dealing with initially. So a quick recap. Uh SSRFs can be dangerous. Uh SSRFs can be dangerous. Uh SSRFs can be uh don't stop at the you know if you get an external fetch don't stop there. See what else you can do. Uh don't give up your bugs. Wheezy plant took me 3 months and some change and a bunch of rides in New York City to figure out. Uh and if you see a PDF generator I promise you it's usually vulnerable. You just gotta find the right uh angle and the way to get in. Uh disable Javascript. It's not good. You don't need any PDF generators. Um create some whitelisting, blacklisting whatever uh works with you. Limit the exposure to your instance at least. Um properly configure your cloud instances so the keys aren't being leaked. And please be nice to hackers. Uh again I'm uh Noam Seck, Ben Sadegapour and this is Cody. Uh keep in touch with us. Tweet at us, email us. Uh if you ever find any SSRFs you can't exploit we'd love to look at it and see if we can uh extend on this research. And thank you guys for joining us.