Hello DEF CON. So, I'm very happy to be here. This has been a dream of mine for many, many years. And thanks for being part of it. This research is about a cool story about secrets in public cloud resources. And you know, who thinks we will never run out of customers public, public, sharing secrets in public cloud resources? Yeah, I think, I think we will never run out of that. And um, my name is Eduard Agavriluai. I was a senior penetration tester at KPMG Romania while I've done this research. A huge shout out to them for supporting the research and trusting this idea. I was also a contractor at Syncubes. I mean, I still am and I'm doing offensive cloud projects there. I also worked one month at CrowdStrike but I resigned on Friday. So, so I'm open for new opportunities and um, yeah, I'm trying to do some cloud security research. Now, I started um, a cloud configuration review for a customer of Syncubes. And um, I got the initial access um, and I started using uh, Scoutsuite as I uh, always uh, as I always do. And um, I checked the report. I saw the S3 findings, the CloudTrail findings, the YAM findings. And when I looked at the EC2 dashboard, I saw for the first time, the critical finding AMI is set to public. And who knows what an AMI is? Okay, cool. And um, who used at least once an EC2 instance? Okay, so if you used an EC2 instance, you kind of know what an AMI is because every time you start an EC2 instance, you are using an AMI. It's like a snapshot of a virtual machine and you can pre-configure an AMI to contain your applications, secrets, um, so to have a baseline right? And then you can start new EC2 instances starting from this AMI. And you have AWS Marketplace AMI that are official and from trusted vendors which are the recommended ones you can use. And you can also have community AMIs that are published by anyone. And you have to be careful with uh, with them because if you don't trust the publisher, you might have some back doors, malware and so on. But in any case, the thing is that an AMI can be public or private. And by default, they are private and it's actually hard to make one public. And I think you can see where I'm going with this. The issue is that they can be public. And this customer had five public AMIs um, exposed for multiple years and when I asked them, hey, can I take a look inside the AMIs to see what's inside of them? And um, they were like, no. So I regretted I even asked. But I got this question, what was inside the AMIs? And this actually gave me the research idea if there are other companies with secrets in public AMIs out there. So um, first we wanted to do this research so bad that we haven't checked any previous work but when we are, when we were in the middle of it, we discovered the work done by Dolev Farhi who scanned based on keywords AMIs in a single AWS region which was fine but it was not enough from our perspective. And also the work done by Ben Morris who searched secrets in public ABS snapshots but we will see shortly that there is very little overlap between his work. And funny story, last day I was talking about the research with someone and he was like, hey, you know who did something similar? He searched public ABS snapshots. He's Ben and he pointed at someone and it was Ben Morris and he was like, yeah. And, sorry. So yeah, I've met Ben Morris. I've been saying his name a lot rehearsing the presentation. It was a pleasure to meet him in person. He's a lovely guy. Now, uh, we set some goals for the research to dig for secrets in every public AMI across all AWS regions to have some fun and do some responsible disclosure. We also had a hidden goal to get some bounties and uh, my colleague Matei will tell you more about it. Starting the research we had to collect every public AMI across all AWS regions and to do that you have to, you have to use the CLI because AWS automatically deprecates images after two years after they were published. And if they are deprecated you can find them in the web portal. Also customers can deprecate their images whenever they want. So you have to use the CLI and specify the flag include deprecated to make sure you get all the AMIs. And we did that and we got 3.1 million AMIs and uh, we were sure that this was too much for us to scan all of them and we started asking if we can remove AMIs based on the chances of having secrets. So we removed AMIs from marketplace, that left us with 1.5 million. We removed AMIs owned by AWS that were not in the marketplace, that left us with 1 million. And we went further and we removed the owners that had more than 50 public AMIs because honestly if you are a company and you have more than 50 public AMIs security wise you are in a point of no return or you are an official publisher, an unofficial publisher, right? And that left us with 27,000 AMIs. Now we did some sanity filtering because some AMIs had 17 volumes or volumes as big as 20 terabytes. Obviously I'm very curious what's inside of them but for our budget we had to remove them and that left us with 26,000 AMIs. Now the distribution from our list looks like this. Obviously the most AMIs were in U.S. East 1 and the region with the smallest number of AMIs was IL Central 1, Israel Central 1 with only 30 public AMIs after our filtering. And when I'm saying that we collected the AMIs this is what I mean by it. So we got the JSON definition for each AMI and you have a lot of information like the ones highlighted, the image ID, the information about the snapshot but you also have other important information like description, title and the owner of the AMI and we'll see how we can use that shortly. Now that we had our list we need a way to access the contents of the AMI and this should be time and cost effective, automated and as reliable as possible. And we looked for various methods some of them might work in certain situations but only the fourth option was the right one for us. So first we tried to copy the snapshot of the AMI in our own AWS account and download it. But even if the AMI is public the ABS snapshot is not by default and that's why it's very little overlap between our work and the work done by Ben Morris. Next we tried to start an EC2 instance based on the target AMI, create an ABS snapshot of its volume and download it. But we quickly realized that this would take a lot of time for an ABS snapshot of 100 gigabytes. It took around 20, 30 minutes to download and we were sure that AWS will block our IP since we are downloading terabytes of data. So definitely not an option. But we realized we had to operate as much as possible within the native AWS features to achieve the faster method. And we tried to start a new EC2 instance based on the target AMI and connect directly to the instance. But for some reason the instances were not in a state that allowed us to connect to them. Either through SSH or through SSM features it just didn't work. But we did a work around and we got to this method. So we have a secret search instance. We call it like this because it's an instance that we already have in our own AWS account and it's working. We can connect to it. And next we start an EC2 instance based on the target AMI, detach its volume and reattach it to our secret search instance where we can connect and analyze the data. It's like having a working laptop and someone brought a laptop that doesn't work but you can get out the hard disk and connect it to your laptop and basically that's how you can access the data. And everything is happening within the AWS environment so it was both fast and it was both as reliable as possible. Now I'll show you a demo on how you can manually access the contents of one AMI. Let me see if I can start this. So we can search based on the description. You can use this to target certain technologies or companies. You have to mention the right region because otherwise you will not find the AMI and you also have to specify the flag include deprecated to make sure you get all the images, right? If you know the AWS account ID, you can try to find all the images owned by that account so that might be useful for bug counter, right? But let's stick with our description based search. So let's try to copy the ABS snapshot as a first step. Let's try. So you will see that if you try to copy the snapshot in our own AWS account, we will get the error message source snapshot is not found. That's because the ABS snapshot is not public only the AMI is. Now we will do the method with the secret searcher instance so we have our instance that it's running and now we will start a new instance based on the target AMI and we will place it in the same availability zone as our secret searcher instance. You need the same availability zone to make sure you have, you can move the volume between the instances. Now, the instance is running, we will stop it and we will detach the volume and we will reattach it to the secret searcher instance. After you detach the volume, you can delete the EC2 instance that is based on the AMI if you want to reduce some cost but in any case, you can just attach the volume and then you can connect to it. We use the web portal because it was easier for the demo but you can also connect to SSH. A common error that we encountered was an ID collision between the new volume and the root volume that was attached to the instance. And we have to use all kinds of weird tools I have never heard about in order to fix this issue but once that is done, you will be able to mount the volume and connect, to mount the volume and access the files. And now that it's mounted, let's look for some AWS credentials, right? We found some and now let's check if they are valid. Because for some older instances, the secrets might not be valid anymore so every time you have to check them. So, surprise, yes, they are working. And that's exactly how we felt when we found our first AWS access keys and the same day we found ten other valid access keys so we realized that this was a big issue indeed. This is the high level architecture we put in place. We had a master EC2 instance where we ran our big script and in each region we started the secret searcher instance and then we started batches of 20 instances based on AMIs to make sure we reduced the time. And for each instance we detached the volume, we reattached it to the secret searcher instance where we will search for secrets and sensitive files. And after writing 1.2K lines of code, 14 days of scanning time and a bill of 450 dollars, we collected 500 gigabytes of carefully selected files and data um, that we had now to, to analyze. And I invite my colleague Matej Josic to tell you more about it. Thank you. Cool. Good morning everybody and thank you so much for being here. It's actually an absolute pleasure to be on stage at DEF CON 32. This is the secret searcher section where I'm going to talk about how we search for secrets, what sorts of secrets we found and what we were able to do with them. I am Matej Anthony-Josephs. I've been with KPMG for about a year and a half and I'd like to take this opportunity to thank them for the time and the budget for this project right here. Other than that I'm a senior security researcher with experience in pen testing, threat hunting, vulnerability management and a bit of people management as well. Now, completely unrelated to this research, I've also set up a company alongside my wife, Alexa. Our company is called Hivehack because we're absolutely fascinated by the collaborative trace of bees whereby up to 60,000 bees work together in a colony for the greater good of the community. Similarly, we think that collaboration is probably the most important part of cyber security. And while I don't know the exact numbers, just looking around DEF CON, I can see why. There's quite a hive of hackers around here. That's enough about me, back to Cloud Query. For our initial strategy, we decided to be as lazy as possible. And trust me, being lazy is a good thing here. We wanted to avoid reinventing the wheel and wanted to use known tools as much as possible, such as Truffle Hog, but we quickly realized that this was not going to work. In fact, the tools which we tried to use were quite slow and produced loads of false positives. And while we could have worked through the false positives, the fact that the tools were slow was the main issue because slow scanning times meant that our EC2 instances ran longer, which in turn meant that our AWS bill would have been way higher, leaving us broke and lazy rather than just lazy. So, with this in mind, we had to pivot and we went back to the Zen of Python. More specifically, the following section of it. Simple is better than complex, complex is better than complicated, and special cases aren't special enough to break the rules. So, with this in mind, we reduced our scope even further and became even lazier. We ended up only looking for specific types of files or directories, such as, uh, well, environment secrets, secrets leaked within Git repositories, AWS credentials, private keys, and a few others. Now we faced another issue, and that is finding the right tool for this. We had to find a tool which allowed us to search for files and directories on the file system based on their names. The tool had to be quick and simple. So, you can probably see where I'm going with this. We ended up using the native Unix utility, find, of course. So, uh, we, we skipped the Windows directory, program files directories because they're full of junk and slow down our scans. We skipped everything about, above 25 megabytes because, well, this is only a proof of concept. We don't need to find everything really. And searched for all of these various files and directories. So, besides our, well, proprietary and very complex use of find, and I'm only joking as well, it's not that complex, we had to set up a few other things. And one of them was an automation for verifying AWS credentials. And you'll see in a minute exactly why we needed that. Secondly, we used Git leaks for checking Git repositories for secrets. Also, we had to set up a few other automations for verifying API keys and other types of credentials. And for this we used key hacks, which is a fantastic repository of methods for validating keys and credentials. However, even if we had all of these automations set up, we're still left with, well, a shit load of manual work to be fair. So, following our data collection phase, we were left with 2 million generic API keys, and of course many of them are false positives. Over 100,000 potential AWS credentials, several private keys, you can see some slack tokens, Stripe, Telegram, and so on and so forth. So you can probably see why we needed all of these automations for validating the keys and credentials. So, out of the about 100,000 AWS credentials, only about 120 of them were valid, out of which 20 were root. Now, I know that this does not seem like a lot. I mean, what is, 120 out of 100,000 is nothing, right? But, think about it this way. These, these keys allowed us to access the AWS accounts of over 100 companies. So this gave us initial access there, and for 20 of them we had absolute complete control. So, let that sink in for a bit. Now, we face another issue, and that is identifying the donors. And for this, we used the get contact information call, which gave us, well, the company name, in some cases the name of the contact, phone number, email address, and so on and so forth. So with this in mind, we found something surprising. And that is, that it's not only small boutique like companies affected by this. In fact, many of the companies are on the Fortune 500 list. Some of the most valuable ones were worth 200, respectively 50 billion dollars. We found three large telecom companies, which you've definitely heard about in the past. Ten relevant security and tech companies, and several others in consulting, education, health, manufacturing. Now, unfortunately, we cannot disclose much more about the companies at the moment, but maybe in the coming weeks or months we will be able to do so. Now, you may ask, well, anybody can write whatever they like in the contact information in the AWS account, right? And you're absolutely right. And then our efforts for identifying the owners could have been completely in vain. However, here is where our OSINT came in. We did quite a bit of OSINT, went on social media, including LinkedIn, and found several of these owners. Funnily enough, many of them had several AWS certifications on their accounts, suggesting that they are security aware and know how to properly configure their AWS accounts. Now, one of these companies, which was and still is actually on the Fortune 500 list, had a program on bug crowd. So we reported it. And this way we got our first P1, our first confirmed critical vulnerability on a bug bounty platform. That was actually fantastic for us. Oh, thank you. Thank you. Now, let's see, how much do you guys think we made out of it? So who thinks we made between $10,000 and $100,000? So let's say five digits. Yeah, only a few hands up. Maybe four digits, so a thousand and ten thousand. Right, a few more. Well, let's say AWS or cloud in general is niche, maybe they don't really care about these accounts. Maybe three digits? Okay, yeah, that's pretty low. Yeah, we made zero dollars out of it, nothing. Yeah, thank you, absolutely. Well, to be fair, there's a bit of a catch. It wasn't a bug bounty program, it was a vulnerability discloser program. And we weren't too disappointed, to be fair, because we didn't really aim to make money out of this research. We just wanted to make the internet a safer place, although this sounds a bit cliche. But still, we quickly forgot about this because we found something else which I think was more interesting than this. I like to call this story how we earned and lost three million dollars in a week. And, well, we're in Vegas right now, we all know a thing or two about losing and earning money quickly, right? Maybe not quite three million dollars. For a bit of context, we found this company which had a public AMI, there was a Git repository within that AMI, and within the Git repository we found a Stripe API key. And for those of you who don't know, Stripe is a payment service not unlike PayPal. So our first thought was, okay, let's run a balance call to the API and that's what we got. Seven digits in the USD currency. So what looked like 3.1 million dollars. Fantastic. So our first thought, of course, was, well, how would a threat actor go about transferring these funds into their own account? For research purposes only, trust me. Only research. So we went to the documentation and we quickly realized that the amount is in cents. So what we thought was 3.1 million was actually 31,000. Of course we were very disappointed. We had to get over the disappointment that our net worth reduced from 3.1 million to 31,000 by simply reading the documentation. So if there's any conclusion here, don't read the documentation. Just joking, of course. So we wrote an e-mail to their security contact, let them know what's up and waited and waited and waited. And all we got was radio silence for a few weeks. It was pretty annoying to be fair. We thought, well, did we do something wrong? Didn't we prove impact? So we thought of proving impact and that's what we did. We, or I, registered to their cheapest plan which was 9.99 per month, confirmed the transaction from the API and did a refund call which was successful. Fantastic. And a second level of validation was that the transaction was reverted. So my money was back in my account and I could still use their services which I didn't do because I didn't need their services. But now this was a bingo moment for us because we knew that we can talk about money. So we contacted the CEO but for this we had to go on LinkedIn, found the CEO, do a bit of OSINT, get their e-mail address and write to them. And guess what? Within a couple of hours we got a response where he also cc'd the CTO and asked us for more info. And we provided more info. We gave them a comprehensive report including the finding, the impact of the finding and steps for remediating this. And what we got in response was a pretty dry message from the CTO saying, thanks for sharing the relevant information, we have made the AMI private. For now? What? For now? Okay. And we'll be replacing the keys. Thanks so much for responsible disclosure. We took that as a thanks bye. And yeah, honestly we were a bit disappointed but we had a lot of research to do. We had to go back to our research and just dig through the 500 gigabytes of data which we already got. However, one month later I was forced to remember the issue. I checked my bank account and there's a 999 transaction. So I was so excited about being able to do the refund that I completely forgot to cancel my subscription. Well, remember that we are fairly broke so I didn't want to let 999 go by just like that. So I went back into the API, did the same call again and guess what? Money was back in my account. Yes, thank you. Yep. Well, we were disappointed initially by the dry response. But you cannot even imagine our disappointment that the issue was still not fixed one month later. Now, there's way more impact than just this. Think about it this way. We had to spawn several EC2 instances in our account, we got a bill of 500 dollars which, well, I'd have preferred to avoid. So yeah, if we weren't ethical, we could have went and used the victim, so to speak, AWS accounts to do this research for free. Now, a second potential area of impact which I think has a bit more potential, well, AWS based ransomware. And this way I could have come to DEF CON for free. So typically when we think about ransomware, we think about these teams of developers working 24 7, working on evasion and stuff like that. Perhaps when we talk about ransomware as a service, they're using 24 7 customer support teams and call centers. Well, in here, with access to the profiles, to the accounts, we could have used this, well, one liner or four liner, depends how you write it, to list every S3 bucket within the accounts, copy all of the data to the local systems and then remove all the data. Now, instead of the data which they expect to have on their accounts, they could find something along these lines, a ransom note. All your files have been stolen. You must buy us a Romania Las Vegas ticket to get your files. And honestly, that would have been pretty reasonable. It's only what, 500, a thousand dollars? So yeah, pretty decent ransom. And I need this disclaimer here, this is just a joke. We didn't do this and we wouldn't do this, but it's pretty cool that we could have done this, right? Now, Edward, want to take over? So, the research was done, we collected the data, we found secrets, we validated them, but we wanted to bring down the impact of the affected companies before we published the research. So, we looked for contact details and we couldn't find many. We had to search for websites to go find their contact information, give some generic e-mail just to make sure we don't give out too much information to someone that doesn't need to know it. So we sent almost 70 responsible disclosure e-mails and we received less than ten responses. We had to do some weird things like contacting the national search for one company, scheduled a sales call just to tell them about the vulnerability, and 90 days later after we did all this, only ten AWS keys were invalidated. So, that sucked and it's like companies are using AWS and they are ignoring responsible disclosure, they don't have contact details, they never wrote access keys and they are like, man, this cloud thing is so unsafe. It's not like that, right? And in a desperate attempt to invalidate more keys, we notified AWS security team and we were like, I know this is weird but we got 120 access keys that are valid. Here is the proof. Can you invalidate them? We have a research we want to publish. And the AWS security team, the most amazing team we worked with, they made me rethink about the whole responsible disclosure process. And after a few days after contacting them, more than 60 AWS keys were invalidated. We had a meeting about the research, we provided some ideas, we discussed fixes and it was overall an amazing experience and I want to give a huge shout out to Christian Sever from AWS security team and AWS security outreach team. So, please give them a round of applause. Thank you. Now, to discuss a bit about detecting and defending against this and let's start with defending. So, if your AWS account has this yellow warning signs, you might want to look into it. So, the settings block public access for AMIs and ABS snapshots should be enabled. They should look like this. They should have this green check mark. You can also use the CLI to validate if you have public AMIs. Make sure to check every region and make sure to check for deprecated images. You have to be careful about this because one technique attackers are using to exfiltrate data is by making AMIs public and accessing them from their account. And if that happens to you, you should look in CloudTrail for this event, shared snapshot volume created. This is the only event you get in CloudTrail if someone accesses your public AMI. And it doesn't have a lot of information. As you can see, the IP address is hidden which I get it. It's protecting the customer that is accessing the AMI. That is cool. But the only identifiable information you have is the account ID which you can't do much with it. So, better be careful, better protect your account and enable the settings if you don't plan to publish AMIs or ABS snapshots. Now, we have a lot of data and we did other research with it. And one idea we had was, so we had 20K JSON web tokens and we looked if there are any tokens that were not expired, maybe they had some secrets in them, any other misconfigurations but nothing came out of it. However, it was a good try. Next, we looked through our 4K unique SSH private keys. We generated public keys and a figure print and we searched on showdown but nothing came out of it. One idea was to perform the same scan from within the AWS network. Maybe that's how we might find some servers but that was just too much work and it wasn't worth it. Another cool idea we had but we haven't started this yet. So, we collected a lot of private, a lot of repositories and some of them are surely private. We wanted to identify the private repositories to identify the deployed web application in the wild and then perform source code review in order to find some vulnerabilities, get some CVs, get some bounties, but that is a lot of work and we are keeping it for later. And that on the topic of further research. Well, we still have about 500 gigabytes of potential secrets and we tried our best to dig through that data but there's definitely way more to find. Moreover, our colleague from KPMG Romania, Stefan Tito, worked on some similar research on Azure and we are looking forward to his research being published as well in the near future. Also, we will soon make a word list public with all the files which we found in all these public AMIs which we scanned. Now, going back to the research objectives formulated by Edward at the beginning of this talk, we aim to dig for secrets in every public AMI across all AWS regions. And while we didn't dig into all public AMIs, we dug into all public AMIs which we found interesting. So I'd say that this was achieved. Also, we aim to have fun. And, yeah, we did. We found a lot more stuff than we expected. It was a roller coaster and thanks, Edward, for this. Lastly, responsible disclosure. Well, I was a bit disappointed by the responsible disclosure process in general. Well, many of the owners didn't respond to us. Others, well, didn't have any sort of information for us to contact them. However, the experience of responsibly disclosing this to the AWS team definitely made up for all of the less pleasant experiences, so this was definitely achieved as well. Now that we are approaching the end of this talk, here are our conclusions. Firstly, the impact of this research is not yet fully uncovered. There's still way more to find out there. We have found several secrets already in the data which we collected. There's definitely more in the data which we already collected, but there's definitely way more out there which we did not collect yet. Potentially a nice area of research would be continuously monitoring new AMIs becoming public. Secondly, security by obscurity is definitely insufficient. So many developers definitely thought that their Git repositories were safe because they're private, right? But how is anything private if it's placed in a public resource? Also, you may be thinking, hey, I won't be a target of this, right? Nobody cares about my AMIs. Well, think about it this way. Edward and I, two cyber security guys from Romania, were able to do this. Think about what threat actors could do. So definitely don't make your AMIs public if you don't have to. Now, AMIs are only the tip of the iceberg here. There are still a lot of other interesting things to find across several other public cloud providers. Who knows, maybe next year we'll be back here talking about how we dug for secrets in a different cloud resource. And still we encourage you to do your own research as well. And please let us know if you have any sort of ideas. We're happy to help. Actually, going back to my initial point within the secret searcher section, collaboration is definitely the most important aspect of cyber security. So please connect with us. Let us know if you need any help with any sort of research in the future. And we'll definitely be happy to help. This being said, thank you very much everybody. We appreciate you being here. Any questions? Yep. Sure. Go ahead. Is the mic on? Not yet. Can we get the question mic on please? Perhaps just speak really loudly. We don't know. So we didn't perform any calls beside the contact information. So we tried to get security operation and another type of contact details but we didn't check the permissions. I'm sure for some of them we surely could have but that was too much because surely there was some automation based on the access keys and we might have broken something. Also please note that just having the S3 ransomware sort of code in my terminal got my adrenaline rushing. So we didn't try to do anything like that. Yes. I didn't have the permission to do anything like that. So I don't know if you have to. I wanted to. I'm looking for new opportunities. If you have something in mind in the offensive security, cloud research or cloud security, just give me a message and I'll start applying next week. So thanks. Cool. Any other questions? Yes please. No and to be fair we didn't even expect that. I mean we had KPMG for that. So thanks KPMG and uh we are waiting some t-shirts from the companies we disclosed this. Thank you. Cool. Mic's working so if anybody has any questions you can speak in the mic. Cool. Doesn't look like any other questions. We'll just be around here so please let us know guys. Nice talking to you. Thank you.