← All talks

Attack of the Clones! How AI can boost your API Security!

BSides Tampa20:4868 viewsPublished 2024-06Watch on YouTube ↗
Speakers
Tags
StyleTalk
About this talk
Attack of the Clones! How AI can boost your API Security! by Dr. Sunny Wear Description Learn how Artificial Intelligence (AI) can be used to improve the security posture of your API endpoints. Leveraging the power of AI, see how you can protect your organization against some of the deadliest API attacks occurring today. While developers are coding, building, and testing APIs, these techniques can help to mitigate against some of the most common security bugs found in the wild.
Show transcript [en]

[Music]

[Music] Dr Sunny wear is a web security architect and penetration tester she provides secure coding classes creates software and performs penetration testing against web API and mobile app applications she has more than 25 years of Hands-On software programming architecture and security experience and holds a doctor of Science in cyber security she is a published author burp site burp sweet cookbook first and second edition developer of mobile apps and is a content creator on courses related to web security and penetration testing she regularly speaks and holds classes at security conferences such as Defcon hackfest and besides here is sunny wear attack of the Clones how AI can boost your API security did a great nice job thank you

okay thank you for sticking around so you know you guys are awesome um so I want to talk to you today about attack of the Clones how you can use AI to boost your API security uh there we go of course already did the introduction anybody that gets a book if you need me to sign it let me know even after this we do OAS events and things like that so all right apis the new hotness they're everywhere I I love the web app like she's really giving him the look um but yeah they're everywhere and so that makes for great target practice so in this talk I want to talk about three objectives first we're going to

look at some of the deadliest API attacks occurring today secondly I want to talk to the attackers out the bit out there about how they can use AI to identify areas uh of attack surface in API endpoints and then last uh is for the Defenders out there how can they use AI to improve the secur posture of their apis so let's get into the first objective when we talk about deadly attacks what is it that we're talking about exactly well this brings us right to the OAS top 10 for API security and we're not going to have time today today to go through each one of these but I do want you to focus on the very first one

broken object level authorization so otherwise known as Bola uh we're going to get into the details of that in just a moment so this one we have a very simple example to help grasp the concept so you can see here with uh an authorized user if there is an exposed in this case digit um that may be seen in the query string of the URL you just change the number of your store in this case say you're the authenticated user your store is one you change it to store two and now you can see the details of a completely different store store owner very bad let's look at an actual bug Bounty that was submitted

so I'm not revealing who the company is but basically um the authenticated user went to print uh their statement their bank statement and noticed that there was a very easily guessable ID um for their account so they change that account number to a different digit and voila they could see bank statements of a completely different user very bad so that kind of gives you the principle of what this vulnerability is all about so as to I'm speaking now to all those penetration testers bug bounty hunters red teamers in the room how can you use AI I to basically identify attack surface areas um in API endpoints well let's talk about it however before we get into the brass

tax you really need to kind of go through a methodology of how you're going to approach AI so you need to start with something very very specific that you're going to ask uh and think about that question as as narrowly as you possibly can you're going to get some feedback in Step number two from the AI you're going to need to massage um your question down more in order to meet your objective number three you might be able to provide more specifics around what it is that you're attacking such as uploading a file uh which I'm going to demo very soon um or giving a direct URL Etc or code snippet what have you and

then of course number four is the rinse and repeat so the tool that we're going to look at for attacking is chat GPT but a particular one so I'm going to be showing you um the hacking apis GPT this particular instance of chat GPT was written by Corey b ball he is the author of hacking apis by no starch press um chat GPT is subscription based if you're not already aware so here's the first of four demos um so these four demos I I start you off with um sort of some easy things like a word list and we're going to give the AI uh an API endpoint that's available on the internet followed by um

we'll go to http Ben which is a website that um has lot of endpoints we'll look at a couple of those then I'm going to show you how you can feed um the chat GPT your Postman collection and basically have it um tell you what you should be hacking on and then um the Json web token analysis where you feed it a jot and it can tell you um different areas that you should be looking in the jot uh okay so now comes the demo part um so we've had uh some technical difficulties with two of my videos um but because I've done a lot of talks before and had things not work right I have some screenshots of the

first video so bear with me for just a moment because I put it at the end of the slideshow okay so the video for the first demo isn't working but but this is what what we ask what the prompt is to the AI is we type in provide a list of payloads that I can use to fuzz API parameters pretty standard thing that you might ask AI is going to produce for you a very long list that you can then copy and feed that into your burp Intruder or what have you or you know fuff or whatever you might be using the second demo is where we take a publicly accessible API endpoint and we

feed that directly to the AI and we say uh yeah what parameter in here should I fuzz um you know in order to abuse it and so the AI the the answer is much much longer than what's shown on the screen but you get the general idea right where uh we have um you can look for eye door and secure direct object reference SQL injection Etc okay okay so the next demo which is demo 2 uh you'll get to watch so I'm just going to grab um you can see this website's got lots of API endpoints that you can play around with I'm just going to grab this one for a user agent I just grab the curl just we're

going to feed that right directly to the API so I'm typing at the bottom of the screen and by the way I don't um feed any of my content to train the AI if any of you were wondering um I don't want to put it in the collective Hive um so basically I just said hey AI look at this endpoint and tell me what's vulnerable and I just pasted that curl right in there and then what you can see is the output first AI will describe what it's looking at and it recognizes that it's actually a publicly accessible API endpoint and then if you'll notice it's got specifics for where in the OAS top 10 are the V the places where

vulnerabilities will occur so you can see all the sensitive data exposure access control ssrf and now we've Mo moved on to the to the to nextend point but you get the idea um where you can directly feed information to the chat GPT uh in order to get some information back now if you might be thinking well what do I do with some of this information because some of this information is boilerplate and where you would go is thinking back the methodology that I was talking about is you would refine your questions from there so let's say say it says something about um security misconfiguration well then you could go into more detailed questions against your endpoint about security okay what

kind of security miscon configurations well what about samide attribute you know you can go into more depth in that

way so these are just more areas uh that it's showing here okay so we'll move on now to you can see it says here given the nature of the endpoint is part of a public API testing service it's designed to demonstrate how cookies like it's it understands pretty much what it's looking at but I did give this thing some testing of myself like I purposefully put some uh Easter eggs in there to see what it would do um so I'm going to flip back to the thank you nice job there okay so demo 3 unfortunately the video is not working so I'll just show you the screenshots um but the idea here is you can see at the very top I fed it um my

Postman collection for cryptocurrency that I wrote and then it spits out um each of the uh endpoints that I wrote in in my collection and gives me information about the areas of each endpoint that I should be looking at for possible vulnerabilities um and I think I'm just gonna do this one with the screenshots it's okay um so then the last demo that I have for you is looking at Json web tokens so I purposefully created a jot that had a very long expiration policy because I wanted to see if if you know the chat gbt would pick up on that um it goes through and kind of explains that it understands uh well you

can see my prompt at the top I said read this jot and tell me what's vulnerable um and then I pasted it in there uh and it it came back with a bunch of basically good information but it never said anything about my long expiration policy so I put it in there for like five days um so it kind of goes along with the same thing you've been hearing about make sure that you always um verify the things that you're reading okay um I let me go back in my presentation okay so this leads us to the third objective which this part of the present ation is designed for the Defenders out there uh those developers

that uh write apis so if you're familiar with Postman there's a new feature inside of Postman called post bot post bot is a generative AI assistant and what it can do is it can generate for you contextually based test scripts uh from your endpoints that it reads in the collection and there's the little icon for it is like it looks like a little helmet like a little Spaceman helmet uh and it'll be at the top and it's also at the bottom footer inside of postar so the idea here is to use post spot but have it with an oasp twist and what this means is we could take known test cases from OAS and change the prompts slightly

in order to conform to testing some sort of vulnerability so here you can see uh this example prompt down here add a test that injects a tick at the end of the query parameter fail this test if the response status is not 200 so the idea is that you're trying to put into early in the sdlc more regression testing around security so that developers will be looking for this stuff way before it gets penetration tested so this is the last demo that I have for you um this basically goes through uh building some prompts in post bot um for addressing Bola so can we have the uh fifth demo please it's not working no okay all

right well then we'll look at the screenshots uh okay not a problem okay so demo five all right so the first part of the demo just sort of gives you an idea that this particular endpoint has a bow of problem or ID door if you want to refer to it as idore when you change the numbers it shows different people's information um so what we want to do is we want to focus on a particular user which is actually the number four uh which I don't know if I made um a screenshot of it but the N the person at number four is Jim Hal he's the one that's logged in he should only be

seeing his own data so if we change this number and it's somebody else's data that's a fail okay so that's the premise of of this uh writing the prompt you're going to have have at the very top of your prompt environmental setup then you're going to go in through a through a loop we've only got four records to go through we go through that and we basically determine what a pass is and what a fail is pass is going to be if the authenticated user is only seeing their own data a fail is if they see somebody else's so we copy that we paste it into post spot and we look at the generated code

I'm not going to go through through this um but believe me it's there um this is the loop oh that's basically we have three failed test cases since the username does not match the username returned in the response and then the pass is at the very bottom so that is an idea of how you could use post bot from a defensive point of view let me go back I've got like one more slide and then then we can go [Laughter] drink all right so in summary I hope that this was informative for some of you um sometimes you're left with not knowing where to start uh when it comes to API so maybe this will broaden your

horizons give you some new ideas from a Defender perspective um the post poot is a great tool especially if you incorporate OAS test cases with it and always be learning so any questions thank you yes

sir yes hello

John well so I think it depends on how good they are at asking the questions um so because you saw a lot of boilerplate stuff there which it it's something you know um you really need to start digging in like knowing what to look for uh in order to get to a level where but but having said that I mean there's going to be new versions of the chat GPT coming out and they're going to get more advanced and more people will be contributing to The Hive so sorry uh yes

sir uh for the Post bot oh the chat GPT uh you need a subscription uh so that's a good question question so I bought the um Enterprise or the company one and that you can say I don't want you to train off of my questions um I I I don't I can't speak to the basic I I'm sorry I don't know but

yeah okay okay thank you so much yeah exactly which is so go with the Enterprise Sean uh or I mean Shane yeah anybody else anybody at the at the top up there no nobody all right thank you all for your attention [Music]

[Music]