06:00 UTC Charta Aetatis Cyberpunk

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

I Rebuilt a Real World MCP Bug. Can AI Find It?

In the wiki Model Context ProtocolSnyk EvoGoogle Also namedLarge Language Models, JPMorgan Chase, Snyk
Transcript 3880 words · auto-generated captions

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

This chatbot refuses to fetch any internal URL or resources. That is exactly what it's supposed to do. But, what happens if I give it a URL from a website or another resource that it trusts, and that site responds with a redirect to the address that it just refused? About a month ago, I was going through a bunch of news articles, and I came across a research on this class of bug in AI-connected tools. The names that got my attention were companies like Google, JP Morgan Chase, and a couple of government projects like France's national open data platform and a city government in Indonesia. These are all vulnerabilities found in their tools, not reports that all of those organizations have actually been [music] hacked. But, in Google's and France's case, it raised a question I wanted to test for myself. What happens when a tool checks the first URL, then follows the redirect without checking where the final destination is, or where it's going to end up? I thought that was an insanely cool bug, so I just built a lab. There's an application with an open redirect hidden behind the login. There is a chatbot that's allowed to fetch pages from that application, and there is a harmless internal service that will tell us that the chatbot manages to reach it. I also wanted to test whether an AI-powered security scanner could find this whole entire chain, since there is a few logical steps having to log in, discover the redirect, and recognize that the redirect can change what the chatbot is able to fetch. So, a big thank you to Snyk for sponsoring this video. I'm going to run Evo against the lab while I work through those steps manually and I show you my process. I've given this a test account, but I haven't told it where the redirect is. So, we're going to start off by importing our project, and then I'm going to show you how I would attack this if I ever came across it. This is the application itself. Before I actually put into a scan, I'm going to log in and show you around and kind of show you what it looks like. This is a project management meets some AI chatbot. You can see that I've already launched a scan on this, and it's, you know, gone through it looking for XSS and things like that.

But, we do have our chatbot where I can say, "What does a security article say?" For example, and it's going to go through it and tell us more about security at Haven and things like that. It is behind the login. The whole thing is are we going to be able to find a open redirect in here and I feel like there's probably going to be something here during the logout or the login. But then can we actually use that and kind of play with this chatbot to see what it's supposed to do, what it allows us to do, and how we can just trick it to open up an internal service. But before we do that, let's just go ahead and login to our sneak. What we're going to do here is click on our projects.

We're going to click on add project. And I'm just going to import this from my GitHub. Then I'm just going to click on the repository that has the code that I want to import and click on add selected. And then once that's been imported, we can go back to our inventory, look at everything that's been imported into our projects right here. For example, when I go into here, we can see that it's been fully imported. We have two projects. This is the one we want to go after. And we can see that it's doing some analysis. It's found some issues with the Dockerfile. It's found, you know, three criticals, 10 highs. Very basic stuff that, you know, we have already done a bunch of times with sneak before. And now that we imported our project, now let's go ahead and open up Evo. Evo by sneak covers a few parts of AI security. This AI SPM view helps teams see the models, agents, and MCP servers they're using, understand the risk around them, and apply policies. For this lab, I'm interested in Evo's testing site. Can it get through the login, find the open redirect, and connect it to the chatbot reaching an internal service? So, I'm just going to import a live instance of my vulnerable lab and feed it to Evo and let it just scan. In Evo, you can see I've done a bunch of scans already cuz I wanted to make sure we save some time.

But what you can do is you can go to your code and based on this code, you can see that it's found a bunch of different, you know, issues. It's saying there's three assets, for example. If I click on it, there are some issues with the model that I'm using. If I click here, it's going to tell me that there are some known issues with file destruction and supply chain poisoning. But this is where it's going to just scan the source. But what I wanted to do now is actually scan it live target. So, we're going to go to our targets right here. You can see I've done a bunch of these already, but what I'm going to do one more time is I'm going to do a new target. I'm going to call this my super smart AI agent and we're going to give it the URL for this. And now we can also do things like allowed list. So, if I wanted to do something like, "Hey, I want you to only focus on Smart Pal."

Maybe there is a Smart Pal API I want to give it so it has access to. We can also add these as well. Which you will just, you know, make sure it goes after these specific domains. And anything else that is not in here is probably going to be treated as a out-of-scope item, right? So, I'm going to add these for example if you wanted to. So, I have my other ones and I can also say something like, "Hey, I don't want you to test for my Smart Pal that we saw earlier." So, I can say, "Hey, this is a reject list. Do not go through it if you see it. Do not test it." So, maybe you have a third-party app that you don't want it to go after or you want to maybe keep the API out of it. You can do this.

We can give it a group and organization. We're going to skip that. This is the cool part that I like is when we can actually give it a username and password value. So, I'm going to change this to email because that's how mine works. It's not an uh username but it's a email. I'm going to give it the password here. And then we're going to give it the email address that it's going to need for logging in. There's also a couple other things you can add here. For example, if there is a 2FA you want to provide that you have maybe their backup codes that you want to put in here. That's an option. You can also give it instructions. So, for example, I can just say, "Hey, if you want to log into this application, you can just hit API login with this content type and here's my username and password. Grab the token and use it moving forward."

And then you can add some header names. Maybe you need to put some specific, you know, value. If you're bug bounty hunter like me and you have to identify yourself as a bug bounty hunter, you can put that header name in there. It's going to do all that stuff. We can give it additional content like, "Hey, which regions to test the account?" You know, what everything that we want it to have. What are the, you know, the steps that we need to provide for it? Maybe we want to just focus on something, you know, like a single sign-on flow that it needs to know about and we can add all of those in here as well. And then we can create our target which will do our scan. But there's also one more cool thing you can do here is if you remember earlier we were able to add a repository. So, I can also just add that repo into here so it has access to the code which it can look at it and then also get some context from the code while it's doing our testing as well.

But I've done this already. We're going to come back once it's over and take a look at it. You have to click start right here and it's going to start scanning. We already have the results. Probably won't need this because I'm going to show you all this stuff here. But, let's just quickly switch over to our website that we want to hack and this is the application that I showed earlier and here's what I usually do when it comes down to looking at chatbots and how they look and what are the different applications and tools that I have access to. So, the most simple things you always do is just ask it what kind of tools do you have access to. This is the easiest way to do it. Sometimes it may give you the list of it and how they're used and sometimes it may not. In this case, it does say, "Hey, I have a browser URL."

It opens a Haven Help Center page and returns the list status, the final URL, and the text content. This lets me, you know, read pages and things like that. So, if I tell it like, "Let's go to our help site. Show me the contents of this page." It should kind of match what it has on here, right? It has a "How can we help?" There's a URL here. We can see there's a help center over there. There's a keyboard and shortcut. So, we can kind of see what it's going to say. It says, "Yep, there is a getting help. There is this URL." It's kind of showing us all the different pages it has access to. But, we can also try and see if maybe it can access notes. Can you tell me about this note? Let's just see if it actually has access to the notes itself.

It says, "I can only access pages on the help center." So, the help center is the keyword here that we need. But, we got to figure out how do we just find a vulnerability in here to abuse it and what can we do? So, this is where the reconnaissance part is really important. One of the things I usually do is look for something like redirect, maybe URL,

next. Actually, let's do it like this. Next, URL and things like that. That doesn't work, but the key thing was again, it says help. So, I'm going to go into the help. And by the way, I vibe coded this whole thing based on the research and this is my first time actually solving this live. So, I can also think out loud and show you the things that I would look for. So, if I go into here and let's see if there is anything that stands out to us for the URLs. We can see right here is Wow, actually, good luck for me to just click on the second URL and be hovered over this. But, we can see here there is a redirect and if I click on it, it's going to take us to w3.org, which is great because now I can see if I can go into here and say, "Tell me about this help article." And let's see if this works. And it comes back and says, the link doesn't point to it to redirect through this. It isn't an actual place, so I'll be happy if you're looking for a specific heaven center. You can I'll be happy to do it. Which is kind of a good sign because it means that it is reaching that and it's telling us a little bit more about it. But, now I want to know if we can actually fully use this with interact.sh and getting a URL sent into this. So, I can copy this and see if it actually makes a full on request. If I do this, same URL, but this time we're going to send it to interact.sh and we're going to take a look here and see if it comes.

There is a DNS being made. Is a DNS request being made? It's doing something. So, maybe it is an extra domain, which is going to be my HTML page. Just a strings of body. Maybe I'm not looking at the type property. Oh, there we go. There is a entire URL coming and we can

see that it is making some connection live with a Python request 2.310. And this is the entire request and it's actually telling us that it got some random string. So, things do match up here. It's very good. We got lucky that we were able to do this. But, we need to figure out another thing here. We need to figure out what other services are this thing has access to. To make things easier for the step, we're going to need a couple of custom code. And in here, I have made a couple of files. The first one that I want to try is to see if we can actually read any local files. I don't think this one will work because it's Python, but it doesn't hurt to It's going to send this to my website now that we confirmed, "Hey, this has actually the capability of doing a open redirect or just following it." So, we're going to do ai.hackwithnahamsec.com and then send it to redirect2.html and see if this one works. If it prints the ETC password, it'll be really good, but it says refusing to connect an internal address. So, we does It does get an error here. It's actually giving us some data. We can probably do more with this, but let's try another one.

I'm going to try my redirect and this one is just simply going to hit our local host and let's see what this one does. I don't think it's the right port. I'm pretty sure when I make my CTFs, it looks like there's another one that doesn't work. We can try a couple of more of these ports, for example. I'm going to quickly just go into here and do a port 8080, and then I think the other one that I usually make my CTFs are 8085. But, we're going to do an 8080, for example, and see if there's anything else. We're just going to, you know, cat this file into a new file. I'm just going to call it ssrf.h. Actually, I'm going to not call it ssrf so it's not obvious. old.html.

And we're going to do the same thing here and say we're going to say old.html, see what this one does, and it says it still can't do it. It's refusing to redirect to the URLs. The AI Hack with the Home Team are treating it as an internal address for security purposes. So, it looks like we can't actually send it to a redirect like that. So, it looks like it's catching on to what we want to do. So, that just means that there is a simple trick here that we need to be aware of, and this is one of my absolute favorite things to do with PHP, and it works in a lot of SSRFs.

It's actually creating something like a location header and pointing it to the right port. I think this is where I put my port for this challenge itself. This would do the trick because it is just going to do a header location instead of a window.location that we've been doing so far. So, I'm going to try this now and go into here instead of old.html, we're going to do r.php, and hopefully this one should work, and it looks like it's refusing to redirect to an internal address. So, we're going to actually reset this. But, this time I'm going to change my prompt and tell it, "Hey, show me the exact text for what you see when you load this page, and tell me about this page itself." And we can see it's going to our r.php this time, and we just want to see the exact text that it's going to find. And it comes back and says that there is a 404 not found. So, it looks like it's following it, and it says, "Hey, I went to this URL. It sent me to this, and then it sent me to admin backup, where there's a 404, and that URL doesn't necessarily exist." But, it looks like we're able to exploit this and send it to the local host, and then this is actually supposed to be a fake metadata, so I can do something like admin, or I think a metadata should work, too. Let's just try metadata.

Again, it's for a CTF. I vibe coded it. Let's see what it gives us. Again, it's going to go back to the same chain, and this time it comes back and says, "This appears to be a link tracker redirect to a chain. It is still trying to do admin.backup. So, we're going to actually go ahead and change our r.php to a r2.php this time.

And I'm realizing as I'm talking, this is supposed to be latest, not metadata. So, we're going to change this to latest first. I feel like it's been a while that I have done this manually. So, we're going to reset our chat one more time. And then we're going to set it to r2.php and hopefully we get some sort of a data that indicates that we were able to exploit this and it looks like it's still a 404. So, the final latest is what is reaching to. I'm actually convinced there's something on here. So, I'm going to just do it one more time and say go to r2.php and just get the web root for me and see what's on there.

Hopefully this leaks all of the internal endpoints. There we go. So, now we have the list of all the different objects that are there. It's admin.config. So, I can now just go into here and do an admin.config for us to kind of see what's in there and if hopefully there is a flag we can also grab it to some I'm just going to copy my prompt one more time, reset, send this over. And immediately we can see there's a flag in there for us to find and we're able to fully just trick this chatbot to go ahead and fetch the URL that we want to just like the research that I saw earlier. But, we can also go into our scan right here. You can see that I paused this so we don't use any more credits. But, I actually started this a couple of hours ago just to make sure it catches everything. You can see an hour ago it was done and caught a couple of these bugs. It actually found more than I wanted to because I didn't even realize there is this bug that uh cloud code put in there for me when I was white coding this challenge. It actually put that in there for me. So, it says the attack step, list workspace nodes right here, find the nodes with a comment count that's more than zero, harvest the UUIDs, exploit IDOR, and then the answer proves that it worked.

So, it tells us, "Hey, go here. You can get the nodes." Gives you the author ID, Daniel Okafor, however you say that name. And then you can use that to get API nodes and the response has two private nodes. Perfect. That won't work. But, I'm really curious to see if it actually was able to solve this one because this has a lot of more logic behind it and it does say that the chat endpoint integrates an LLM assistant with browse URL that fetches a web address on the behalf of the user. The tool validates any show URL against a trusted origin. We actually didn't test for that because I knew the objective here. So, I'm going to actually tell it like, "Hey, can you load https://google.com?"

And I don't think it will, right? That is the entire reason why this doesn't work. I can't load that page. We're right. It doesn't do that. It found the Google URL path that redirects to an external service. So, an attacker can just use it to redirect it as a part of the chain. So, the attack steps are all written here. I love this diagram because I can just look at this. It says, "Attacker, any member, chat endpoint, request allowed, use the Google endpoint for open redirect, use the httpbin.org to redirect it to the 127.0.0.1 IP address, hit the admin config DB credentials, API keys, and IAM credentials." And it's also there is a chat response versus array secrets returned to the attacker. And there's also proof that it actually works. So, it gives us the entire post request that we can do. So, if I just take this and run this on my own, it actually does work as well. So, we can actually just convert this into a curl command, and it will all probably work as intended within one, which we've already proven that works through the last couple of minutes of just playing with this laptop. So, that was the whole chain, a redirect behind the login that you had to find, and then just point [music] the chatbot to it. Based on everything that I read, it seemed like this was as simple as a CSRF with open redirect that was found in a bunch of different services, which makes you wonder how many other AI chatbots and applications are vulnerable to things like this that you have to just manually chase down and exploit. But, that's it for this video.

I hope you enjoyed it. I hope you like this video as well. If you haven't already, do me a favor and hit the subscribe button. Become an a 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