06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Bug Bounty · NahamSec · · 14:21 runtime

How One File Upload Got Me the Entire Customer Database

In the wiki Teleport Also namedChatGPT, Ghostscript
Transcript 3341 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

A company hired me to break into their environment. This wasn't just to run a scan or do a checklist of pen tests. They wanted me to actually attempt and reach the stuff that would ruin their entire week if an attacker got access to. So, think about things like their internal network, their databases, customer data, and so on. Most of this work though usually is a lot of research. You map out the entire app, find every place that it takes input, and then you look for that one door that is not locked as everyone assumes. So, in this case, that door was a file upload, especially one that converts whatever you send it into another file format. And I'm going to show you all of that, plus how AI does that tedious half of the research for me. But first, here is where this one ended. The whole customer database just by uploading a single file. Real quick though, before we get into this, this is a sponsored video by Teleport, and I actually think what they do is worth explaining.

Teleport is how companies give their engineers access to their infrastructure, their servers, their database, their Kubernetes clusters without handing out any SSH keys, any VPN logins, or sharing credentials. So, instead of a permanent key sitting on someone's laptop, you log in as yourself with a pass key, and Teleport hands you a short-lived certificate that expires on its own. Their whole idea is that identity is the perimeter. Access is tied to who you are, not the key that anyone can find and reuse. And here's why they've been sponsoring this video, because they're going to actually allow me to break into a company. So, I built this entire app where you can watch me break in, and then Teleport is going to stop me. I am going to run the same exact attack twice, once against the environment the way I found it, where it wins and we get to get access, and then one with Teleport in place where the identical attack just dies. So, it's just me doing the both of them, same steps, two very different endings. But more on that later. So, let's talk about what we're actually looking at. And this company is some sort of a media company that allows you to do proofing. It is a print studio, so the designers and clients upload their artwork and the site generates a proof for sign-off. So, think about it as uploading a file, it does some stuff to it, you have to approve it. That stuff that happens in the background is what we want to do.

But, in this case we're hitting the staging instance and I want to plant something because it is the whole point of this video. Most breaches aren't clever after the first step. The first bug gets you into the door. Everything after that is just standing credentials lying around on a network that trusts anything already inside of it. So, hold on to that. Now, I said the way in was a file upload. So, let me tell you why those are so good. When a site lets you upload a file and then does something to it, think about it resizing it, rendering the proof, turning it into a PDF, it is running your file through some heavy piece of software on their back end. And that software usually tends to have some vulnerabilities. The trick is knowing which one. That used to be hours of manual research. Now, I let AI handle all of that. I pointed to the exact software that I think is doing the conversion or I assume that it's doing the conversion and I asked for it to show me all the vulnerabilities and then I skim right through it and within minutes I have my candidates. But, it's a lot more work than that, but instead of just telling you, let me show you instead. So, originally what I did for this pen test was I ran into ChatGPT and just simply asked it, "List any known RCEs or local file include vulnerabilities that affect anything that converts an SVG to a PNG, JPEG, PDF, or EPS, which is a high-resolution file to a PDF, PNG, JPEG for Ghostscript because that is seems to be usually the issue with all these file uploads and image renders. And I'm asking it to do the last 3 years and then I'm asking it also to just give me those with a public or known POC that are preferred and we can get a list easily just like that.

It's just giving us all of these and actually the one that I wanted is, I believe, this one right here was the one that I ended up using. But, anyways, it does that and it gives us a good understanding of how it works, what they do, and we just start hunting for these, right? You can go and read the write-up, see if you can recreate the the POC, and maybe leverage ChatGPT or something similar to do it for you. But, instead I wanted something clever this time for this video because I also want you to be able to do this on your own, and going through code, and I'm actually going to use the UI for it or the desktop app for it so it's easier to watch for the video, but I just pretty much asked it, "Hey, can you do the same thing, but instead of just looking for them and indexing them, I want you to actually look for each of those POCs, do not run them on my system, but I want you to generate a folder, and then show me in each folder how does it work, and if you have a final POC, I want you to also include it in there." And you can see that it has done 14 by impact. So, if I go into my folder here, and I look at all of the different files that I have, we can see all these POCs now exist, and we can just create POCs for each of these and test them. Typically though, the the good thing for me to do is as these drop, I usually try to create a POC for them and put them into a folder and have it for all my bug bounty and pen testing, and honestly, it is a really good practice to get into and just create them as they drop. But, you can run this whole thing every few months or every few years and get all the POCs you need and just have them on your box thanks to AI. But, this isn't where the hacking happens. Let me show you where the bug lives and how we exploited it and how the story unfolds. So, now let's take a look at our application. This is just a normal application that allows us to upload files, and it would do some proofing. And if you've ever done any print media, you know that this is a big part of their entire ecosystem, and the thing that is interesting is being able to find flaws in that conversion. So, a lot of things that I tried originally was could I have this, you know, SVG that I can upload with an SSRF in there, doing just simple XML within the SVG, sending more files, see if you can bypass the file upload, and things like that. And then eventually I was like, "You know what? Screw it. They are specifically telling me, 'Hey, upload EPS, PS, PDF, AI, and JPEG files,

right?'" So, they're asking for specific ones, and and I just upload this without RCE, it would say that, "Hey, we're going to just send you a proof shortly." And usually those proofs when it gets emailed to you, it is a PDF. So, I know there's a conversion happening. The SVG tricks that I knew all with the SSRFs and PDF renders didn't work. So, the conversion was interesting, and that's why there's all that research around just indexing all the known CVEs and trying to POCs. So, so because of that line of EPS file, I don't have to worry about anything, right? All I had to do was go one by one through all the CVEs, create files whether it's a EPS, whether it's a PDF, whether it's a JPEG, or it's a PNG. And then those file formats that worked, all I had to do was create them and start one by one sending them through this. The key thing here was that every single one of these was a different payload. So, sometimes it was a you know, maybe a RCE callback for me so I can get shell. Some of them are local file reads. Some of them are not even going to work, right? But now let's just assume that we have what we need right here, and we're just uploading all of them. And eventually if it does work, we get a shell, we get into this application, and we have gained our initial access. So, the whole thing here was testing out everything we can think of when it comes down to the PDF itself.

And if you've seen any of my content, you know how much I love hacking on PDFs, whether it was SSRFs, whether it was finding XSS within them, playing with conversions, uploading logos, things of that nature. And I've just kind of really good grip of how all this works. So, the first 10 to 15 hours of it was just automating all this, testing every single one of these entry points, and like I was showing earlier, getting a shell so we can get in. But this is not exactly the cleanest way or the best thing that we can do. We have shell, but we don't have database access. We don't know what else we can do, and this is where things actually get really interesting. So, within my search when I was actually looking at this entire box, we came across a folder. And again, these folder names are all uh imaginary here, even though their path may not make sense. And if we go into backups for example, let me do that one more time. CD backups. We saw that there was a backup or a bunch of backups in there that existed. The key thing with backups is that it's a goldmine for a couple different reasons, especially if you're doing an engagement. One is if the backup has access to the entire source code, then that just gives you the entire application that you can just rip apart and find vulnerabilities, whether it's a SQL injection, whether it's you're looking for a RCE, SSRF, maybe some XSS on other endpoints, and everything else, right? And it's a good place to start. It's a great place actually because it helps you with that pen test and you just find a lot of better bugs and you get massive coverage. But the key thing here wasn't what the backup did is also going further and seeing if there's any hardcoded credentials because if there is, for example, some sort of a uh database that has access to and has a configuration file for it, then we can just extract that data and see if it's, for example, MySQL or Maria DB or something like that, and then connecting to it directly and just, you know, seeing if we can access the database and dumping data, which is the ultimate goal of all these engagements, showing the maximum impact, especially as someone who's been doing bug bounties for years, and that's all I care about is getting the maximum impact and making sure both the clients are the bug bounty programs are happy with my reports. So, after going through a dozen files, eventually I found this, and I'm so glad I always do a LS - LA because it is easy to miss this .ssh folder, and one of those folders was actually entire home directory folder. I don't know why they had that that backed up on their staging machine, but it gave us a good foothold.

I can actually just use that key and authenticate myself to that box. Again, this is a test box. I'm doing it with Docker. The the you know, the routing has been different for the ports, but essentially, I can just drop into this machine and get access to it. The key thing to understand about SSH keys isn't that it gives us an access to this box alone, it is also extending our entire attack surface to anything else that that key could be authorized to. So, if for example, if it's a specific employee's authorized keys, then I can just use that to authenticate to multiple machines, then we're just moving around the network and just hitting every single machine that has SSH open, or maybe this box itself has access to more other machines that we can hit internally and just SSH into them, and it's kind of like the point of this video is one key just gives you access to everything else within that network. So, and the last bit of it with this pen test was just finding a way to get access to the credentials and I'm going to show you if you've done a lot of these like tryhackmes, hacktheboxs, or even our hacking cup machines, you know that the key thing is knowing how to look for information. A lot of times you want to look for passwords, you want to look for usernames, see what other configuration files are in there. So, we're just doing a find here and we're looking for things like ENV, CNF, config, and so on and we're looking to see what comes up and eventually we see there is a file right here that allows us to read the config file. Again, this is all fake to show you what the the story was behind this pen test and eventually can just log into the MySQL and hit the host with the username and password that was leaked in there and just do a select from the customers. Obviously, not that simple, but to make this video short, this is kind of what the gist of it all was. So, so far we got our shell, we got our key, we have access to almost anything that we want with the database and I kind of want to show you what the other side would be when Teleport is in charge and it kind of takes away that one key access to everything away. But, for that to work we got to do a couple more things and we're going to rebuild this image and put Teleport within our build and show you kind of how that looks like. So, let me just jump in really quick. And just to make everything easier, I've just put this uh built on the station together. It's going to just rebuild our entire image.

It's going to use Teleport uh once it is built. Uh it's going to use Docker Compose exec and actually just run Teleport to see what node has access to. Then it's going to add a demo user using Teleport user

add demo with the access logins as root so we can access that uh application with SSH as root and then it's going to give us this uh setup link that we can go to and set up our entire user for us to be able to connect to our SSH. So, if we go to Teleport here, we can easily just set a password. I'm going to just set a fake password for this. And we're going to just do a and the same method with a passkey created and let's call this my personal web auth device for example, right? And once we're set up, it's going to go to our cluster and this is what Teleport looks like. It allows you to either add your new resources. We can look at all the other different functionalities like our instance inventory for example, if we have things like that on identity governance and our audits and see what logs have existed there. You can see some of the stuff that I've been working on today with all of these different things, but the cool thing is also that we can just click connect and log in as root for example here and we're back into our machine that we had earlier, right? So, if nothing works and we really want to get access to it, we have that from here as well. But, what we want to try and do next is I want to show you what it looks like when I SSH into that box now again using the same method. It says public key denied, so the SSH key does no longer work even though it was working earlier. We're going to use Teleport here and tell it that we want to log in and we're just going to use an insecure because I'm using my local host and I don't have any uh cert set up. Our user is demo and then MFA mode is auto, so it can automatically take what it needs. It is going to automatically log us in because I think I already have my key in there, my finger on there that it worked. Even if we didn't, we can log out and do it again if needed, but you can see now that we are able to log into this profile. We're logged in as demo. This is the cluster name for it. Uh we have access role and our login is going to be root. Uh Kubernetes is enabled if we need it and you can see this is valid until this time. So, this is going to be

what it would be valid for the next 12 hours to do whatever we needed to. We can always see, you know, change these and uh modify it and things like that. But, now we're just going to do SSH and tell it that this is the box that I want to SSH into and you can see that we're back and actually able to log in to this server using terminal TSH

instead of just doing a good old SSH which is cool because it just prevents all this misusing reuse of keys which was the entire issue with our pen test. So, there you have it. That was the entire process around the pen test, how I got in, and how you can prevent it. If you've actually enjoyed watching this, will you do me a favor and drop me a comment? Let me know. Make sure you go and check out our sponsor, Teleport. I will link them down below. You can go right here. There will be a link. You can go check out their product. Honestly, if you don't have to even use it as a developer, I'm switching all of my boxes to be managed to Teleport because it's just easier to manage everything, and I don't have to worry about my boxes getting owned, and I have that, you know, peace of mind using their software. So, actually, since they reached out to me, I've looked into it.

It seems like a good solution, and I have genuinely enjoyed it. So, if you have also, make sure you go check them out. All right, that's it. Do me a favor. Hit that like. Hit that subscribe button. Become an homie, and I will see you all in next week's video. Peace.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 538 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks