So today we're going to talk about the duality of Chad GPT and copilot in secure development. And so my name is Kalyani Pawar. Let's talk a little bit about me. So hi, I am Kalyani Pawar. I also go by Kaylee. I currently run the application security and vendor security side of things at a drone company called Zipline. I've been doing security for nearly half a decade now. I enjoy doing what I do in my free time. All the opinions throughout all these slides are mine. I am not representing my employer in any way. This is my Twitter or X handle. I don't post a lot, but I promise everything that I learn, all the prompts that we're talking about today, I'm going to talk about them on the Twitter soon. Things that I do outside of my work. I do review talks that get submitted to Grace Hoppers and AppSec Village every year at DEF CON. So that's about me. Now, what are we going to talk about today? Obviously, Chad GPT and Copilot, but some fun, cool AppSec-y things that you can do with them. And while we are exploring the fun side of things, let us proceed with caution and not fall directly for the responses that it is generating for us. All right, now that we know what we're going to talk about... Okay, quick question. Who in the audience today has worked with Chad GPT or Chad GPT-like models? Fancy. That is what I expect. So here is a quick primer for people who are not familiar with Chad GPT. It's an AI language model developed by OpenAI. It is based on generative pre-trained transformer architecture. It is out of scope. The whole architecture is out of scope for this talk. You don't need to know this information. All you've got to know is how to type in text on a browser. So what I like about Chad GPT is it is trained on a range of diverse data that you find on the Internet, on various books and sources of information that are available online. But what I find beautiful about this tool is that it has the ability to generate human-like text. Once you input whatever question you have for it. The fact that you can speak to a machine which can understand the context and nuances of whatever you talk to it. And it's like talking to a human interlocutor at the end of the day. So that is what I like about it. And you can just imagine the kind of functionality that this tool provides you. You can ask it all sorts of questions. You can ask it to translate into different languages you don't know about. You can use it to learn different things that you probably would be investing an hour reading a book. Rather ask Chad GPT about it. And, yes, when I don't know the answer to a question, that's what I do. Ask Chad GPT, guys. I don't know the answer to this. Use Chad GPT for this. How many of y'all have used Copilot? Y'all like it? Sort of? Yeah, same, same. Sort of. For people who don't know what Copilot is, it is an AI pair programmer developed by GitHub in collaboration with OpenAI. It is trained on a diverse range of public code repositories that are available, so it does understand the coding styles of millions of developers all over the world, and what their documentation styles would be. How many of y'all have struggled with code that has the worst comments in it? Most of us? Most of us? We don't, like... What the f... What is this? What is this? Right? So, what I like about Chad GPT is that, while you are coding, it does also generate comments so that someone else is going to read your code, does understand what have you done, the beauty that you've created. Awesome. So... Oh, yeah, this is something else I like about it, that it can seamlessly integrate within VS Code, which is my choice of IDE. I don't have to, like, open up a different browser or an instance, like, launch this tool. As I'm typing, it's going to generate real-time suggestions about, hey, this is probably what you should be writing, instead of whatever you're thinking of writing. For example, if I just ask Chad GPT Copilot that, can you generate a program that's going to create... that's going to generate a random number for you? It would just... Bam! You just press tap, and it writes the whole program for you. So... Now that we know what Copilot is, I want to talk about the problems that the unsung heroes of our community face. Application security engineers. What is the problem? The problem is that there's a bunch of problems that we're facing. And I'm going to run through them real quick. How many of us have been part of these meetings where they're like, hey, I found something vulnerable in my code. And you're like, okay, how long ago did you push this code into Prod? And they're like, yeah, many sprints ago. And you're like, are you telling me this right now? Like, this is what you did? So I understand with advent of DevOps and Agile, we are shipping and deploying code at 100 miles an hour, which is amazing, but also it's leaving potential security gaps because we are falling short on providing coverage and all the code that has been deployed. Second, lack of security education. According to dark reading, about half of the developers, 48% of the developers lack security education. They simply develop code keeping functionality in mind and completely ignore the security aspect of it. So you're pushing insecure code full of vulnerabilities from the get-go. That is another pressing issue that we're facing. The resource constraints. Were you at Tanya Janka's talk earlier this week? Any hands? Okay. So she was talking about... I'm sure... Okay, raise your hands, okay? How many times have you been in an organization where there's like 200 developers and only one AppSec engineer supporting them? Unsung heroes, I tell you. Security teams are usually smaller in size and it's getting difficult to literally review every line of code that is generated by your organization. So what do you do to combat this? You onboard different tools for it. Now, I am guilty of onboarding two, three different tools and just integrating it within my CICD and all of that. But the problem with this is that it is generating a bunch of false positives. And now we're all sitting and investing our time and sifting through what the true positives are, what the false positives are, and it just does not end there. It's about, okay, now we got to prioritize what risk this vulnerability holds and how are we going to clear this backlog? And there's just a lot of time that we spend in strategizing how to deal with this monster. And this is another problem. Ever-emerging threats, ever-emerging attack vectors. Every day there's something new that I read online about some new attack vector. And it's just difficult for this one brain of mine to constantly catch up with everything that's going on outside on the threat landscape. Last but not the least, the hammer that is the legal regulation stick. Depending on the kind of product you're making or the kind of jurisdiction you're part of or the business that you are in, you've got to make sure that your product is compliant with certain industry regulated standards like SOC 2 or GDPR. How many of us take that seriously? We are trying, right? We're trying. It's just like an additional audit task somewhere in the sprint. Awesome. So, now that we know the bunch of problems that we are facing, a possible solution, a possible solution would be to leverage AI for AppSec. When I say AI, I'm trying to loosely refer to Chad, GPT, and Copilot for the rest of this whole conversation. How can we leverage AI for AppSec? Anyone in the crowd? Yes. Training, yes. Anyone else? Yes. Perfect. Bang on. Anyone else? Exactly. Yes. So, a couple applications here. You can ask Chad, GPT, like, hey, this is my code. Tell me what's vulnerable in it and how can I fix this. You can also go like, hey, Copilot, I'm generating this code right now. Can you give me secure coding suggestions about how this whole code is supposed to go? You can also be like, oh, also for, like, a developer especially, they can go like, hey, what is Heartbleed vulnerability? Explain to me in simple terms. They ask this question to Chad, GPT, and they don't have to go through, like, a bunch of web pages to understand what Heartbleed is, right? So, there's certain applications to it. Now, what I see on the bright side for this is that how many times do you see yourself context switching? Like, one moment you're doing API security, one moment you're threat modeling, next moment you're source code reviewing. How many times does that happen to you in a day? All the time. All the time, right? This context switching is leading to burnout on the team. I feel like a hamster on a wheel all the time because I'm constantly switching into, like, different projects all the time because it comes down to that 200 developers being supported by this one AppSec engineer. So, why not use these tools a little bit? Why not hack the game a little? So, now that we spoke about what about this approach, why this approach? Because here are certain reasons I think we should think this approach should be fit. One is efficiency. Since these tools use machine learning, they have the ability to generate speedy outcomes. It is instructional. Since it has the ability, ChatGPT has the ability to have, like, a conversation with you, you can ask it questions and you can learn new things from it. Scalability. They can handle complex tasks and large volumes of data with little human attention. Automation. The fact that I can seamlessly integrate Copilot within my IDE. I feel that that brings some amount of convenience. And ease of use. The fact that I can just open up a browser and go, like, chat, open AI, and then just ask a bunch of questions to the tool. The fact that it is easy to use and user-friendly, that is what appeals to me. So, these are some reasons why this approach might be deemed fit. So, now that we've done the what and the why, we should do the how, right? Let's dive into some fun AppSec things that we got to do. This is what y'all are here for, I guess, right? So, for the sake of time and convenience, I'm going to try to keep it to simple examples. But if you're open to, like, if you want to know more about other research that I've done on this, feel free to reach out to me. Okay. First application is vulnerability identification and remediation with ChatGPD. I have broken this down into a number of steps and how you can do it. One, you input your code, obvious. Whatever script that you want to check if it is vulnerable or not, you input your code. Then you engineer a prompt. When you're engineering a prompt, you ask for... You're straightforward. It's a straightforward process. You ask for vulnerabilities and remediations for whatever this vulnerability might be. You assess the response. Do not just copy-paste anything that ChatGPD gives you, please. For the love of God, do not. Assess response. Validate the recommended fixes that they have given you. Test and review. Do not. Please do not just copy-paste and push it to prod, please. Okay. So, here is a prompt for you. And whoever gets the vulnerability right, I have some stickers to share. Okay. So... And please raise your hands. So what is the vulnerable code here? And the prompt that I've given ChatGPD is that, okay, is this code vulnerable to what? And please suggest what the remediation for this is. Guesses, guesses. Buffer overflow. Thank you, thank you. Please meet me after, so I can give you the sticker. Okay. So, ChatGPD identifies two issues with it. One, that there is an incorrect assignment here. That it should have been... That string two should have been assigned as an array or a pointer. Second, it does understand that there's a vulnerable function in there, that is string copy, right? The secure form of doing the same thing is to use something like string copy, which is the remediation it suggests next. So it does fix the code in a certain way. First, it says, it adjusts the size of your source buffer to destination buffer and says 15, because you see string two has ABCD or N, right? Those are 15 characters. So it adjusts the size of string one. Then it does the correct character assignment, variable assignment. Then it uses the correct, more secure form of the string copy. It uses string copy, which checks on the size of the buffer. And then it also ensures null termination. So now, clear how this thing works, right? This straightforward process. Now let's see what goes wrong. Who can guess the code? What's vulnerable? Yes. SQL injection, thank you. So this is SQL injection. Now I'm giving it a certain background, okay? I'm like, hey, we have three metrics, which we are going to use to calculate the severity risk score. One, how easy it is to exploit this vulnerability. Two, where does this sit? How hostile is my threat environment? Three, what is the impact that is going to happen if I exploit this vulnerability? And we're going to give it score between zero to 10. And we calculate the severity risk by adding all those three and divide them by three. Then I give it additional context. That, hey, this is used to fetch username information on a public-facing website. And is this program vulnerable? To what? Help me calculate the severity risk for this. Beautiful. It identifies it's SQL injection. So kudos on that. But this is where my problem lies. It says ease of exploit development is 10 because, hey, there's so many resources online to find this, how to exploit this. Hostility, it's a public-facing website, let's give it a score of 10. Impact, you can modify the database, you can get whatever sorts of secrets, I mean, user data and all of that, so 10. But what I see is it depends on the context of your application. What if there are certain guardrails on your public-facing website? What if the database isn't actually bringing out that kind of sensitive username information? These scores vary depending on the context of your application. I would have, depending on the guardrails I've given my public-facing website, I would have given hostility score 8 or 9. So that it does, one thing I want to point out here is that the more clear you are with your questions, the more context you give chat GPT, the better is the quality of the output or the response it generates. But again, do not blindly trust it. Trust but verify. The second application I want to talk about is secure coding suggestions with Copilot. Why I like this is because I'm writing a function and I can be like, help me give it a suggestion, like, help me write this in a secure fashion. And then it will give me all these different secure coding suggestions to do this. Again, breaking it down into steps. First, obviously, write your code. Then, while you're writing your code, Copilot is going to give you real-time coding suggestions about what you should be typing next. You assess the code that is generated by Copilot. Again, do not blindly believe. If you want to change your prompt, you can refine your prompt. And then, lastly, review and test. Why I say refine the prompt is because sometimes, again, looping back, the more context you give, the better output it's going to generate. Hence, refine your prompts. So, I have a vulnerable snippet. We just saw this. Any guesses? Exactly. Yes, it is deceiving. I know I tried to deceive, but you all are smart. Okay, so the suggestion that I'm giving Copilot is, hey, identify the vulnerability in this code snippet and fix it for me. Now, it does a nice job. This is the whole, the first box is the whole, it's all suggested by Copilot. This is not something I've typed by myself. This whole slide is everything that Copilot has suggested. It identifies buffer overflow. It identifies the vulnerable function that is string copy. And it tells you replace it by the safer version of it. And it tells you why you should use string copy. Good, good enough context. There's some nuggets that I can take from this. Now, it does correct the code as well, but it would have been more secure if it would have adjusted the size of string one to accommodate string two. Right? So, yeah. So now we understand how this whole thing works, the whole gamut. Next prompt for you. What is this? Guesses. Guesses. You can go. You've gone once already. Yes? Part traversal, directory traversal, yes. Okay, perfect. So, again, you give it the suggestion. Identify this vulnerability for me. Rewrite the code to eliminate it. Now, beautiful. It identifies part traversal. But this is where the problem lies. It's giving you like eight different suggestions. It's like, use OS part join. Use OS part apps part, common prefix, exists, is file, rel part, norm part. And then it goes on to generate this 25-line code about how this can be fixed. But if you add the human touch to it, the domain-specific knowledge to it, you would rather realize that you should use something like OS part base name because it would directly break your whole part into two different parts, the head and the tail, separating the whole directory component. And then you completely keep the last file name and focus on it. Albeit, this is a more secure fix, but you can still make it vulnerable. You can still give it some maliciously crafted regex and try to break this. The last one, the last application I want to talk about is security test case generation using Copilot. Again, we're going to break it down into... Wait, I'm curious. How many people here do security test cases? Three, four, five, six? Okay. Okay, that's... I hope this... We're going to work on this. We're going to increase this. Thank you to Copilot. Maybe we try to generate more test cases going forward. The breakdown. You identify the vulnerability. You obviously launch Copilot in your IDE. Oops, okay. Then you write a prompt to generate security test cases like we saw earlier. Hey, help me. Like we saw, identify the vulnerability. This time you're going to be like, hey, generate security test cases for me. And then Copilot will generate all those test cases for you. You execute those test cases. Again, review the output that it generates. Oh. Did you get that? Okay. Snippet one. What is this? What is it vulnerable to? Guesses, guesses. Not buffer overflow. Integer overflow. Perfect. So this is a Python program. Python is used to handling really large numbers, but you can make it vulnerable to integer overflow by using C-compatible data types. So what is basically happening in this program is that if you give it big numbers, for example, A is using the maximum size of the 32-bit sign integer, so 2x minus 31 minus 1, and you give it B, 1, you would expect it to be some positive big number, right? But instead, since this program is vulnerable to integer overflow, it's going to give you a negative value. It's going to do a whole wraparound. So that is how this program is vulnerable. Now, let's go ahead to application. So this is what I'm saying. Hey, write unit tests for vulnerable addition function and vulnerable pi. Then it does a good job of suggesting two cases for me. Or three. It's breaking it down into two lines here. Test one, normal addition. Test two, it should raise an exception when there's an overflow and underflow. Then it proceeds to write, one, normal addition, you're adding 1 and 2, should return 3, straightforward. Two, it should raise an overflow error when you're adding a really big number, 2x minus 31 with 1, should raise an overflow error. Three, same thing. You're adding the smallest value of the 32-bit sign to minus 1, it should raise an overflow error. Straightforward? Are we following any questions so far? Okay, perfect. And it does, thankfully, generate two failures. It says that vulnerable addition is not generating overflow error for both the cases, the maximum values and the minimum values. So it works fine, right? This is what we were expecting it to do. So, this is the bad example. Did we follow what I just spoke about? Okay, great. So now that we understand how it's generating unit test cases, this is the second example. What is the vulnerability? We saw this. SQL injection, right. SQL injection, right. So now, I go ahead and tell it, generate security-focused test cases for me, for the previous function, and then it does this thing. It does this really weird thing. One, it looks, hey, is this generating, is when I enter the correct username, is it rendering, when I enter the correct combination for the username and password, is it a success? And if I go for a non-existent user, is it going to raise an is-none, right? But it is completely ignoring the SQL injection. A good addition would have been this, right? Give it a maliciously crafted input, right? It completely ignores the fact that there is SQL injection in here, right? So these are the only two test cases it generates. Okay, so now we've seen security-focused test cases. Everybody follow so far? Okay, great. Another weird application. How many of you all use CodeQL? You find it annoying? Sort of, but does the job? Yeah? Yeah, okay. So for people who don't know what CodeQL is, it's an amazing tool that is generated by GitHub to find out if there are any vulnerabilities in the code that you've pushed, right? So think of it as a SAST. So now I ask... this is the correct query that I have generated. Say I want to find in my whole... in the entire repository, if I want to find all of the to-do comments, this is the query you give CodeQL. Okay? Looks beautiful. Straightforward, it's like, hey, from a comment, you get text, find this regex, it should have to-do in it, right? Okay. When I ask the same question to ChatGPD, it gives me this... I don't know what this is. It gives me this whole thing. When I try to run it, the results are so bad, there's so many errors in it, it doesn't even fit in a screenshot. And this is what I felt. This is what I felt. I would have rather invested all my time understanding how CodeQL works and making the query, but instead, ChatGPD generated this query for me for five hours, and then I was trying to debug it and debug it and debug it, and I invested my whole day, and then I was irritated. So, it's not a good CodeQL query developer. Okay. Praise Jesus! Our jobs are safe, guys! Our jobs are completely safe. It hasn't taken over our job yet. But, why? So certain limitations that I found throughout this whole research of mine, I'm just gonna list them out. One, ChatGPD, the cutoff data for it is September 2021, so all of the vulnerabilities that came out after, it has no idea about those. If I even give it a requirements.txt with a bunch of vulnerable packages, it's not gonna identify which is vulnerable because it does not have most updated knowledge on it. Same thing with Copilot as well. And dependence on prompts, like we saw. The more context you give, the more breakdown in your prompts that you give, the less vagueness that your prompts have, the better the output of ChatGPD and Copilot will be. Intellectual property concerns. Okay. So, do not enter, for the love of God, do not put business critical information in any of these tools. Please, please do not. Do not even put your secret, your PIIs, like your SSNs or something like that. If you're trying to use, if you're trying to make, if you're trying to generate a response that contains IP addresses, give it some fake IP address or give it some fake website name, like this is www.example.com or something like that. Basically, don't give anything that is intellectual property. Since these tools are in the nascent phases of development, they do have potential bias and they are still prone to false positives and negatives, like we saw throughout the presentation in different examples. And lastly, we saw in all of these examples, it is introducing unintended, insecure consequences. It is not developing more secure form of the code from get-go. So, these are certain limitations that we have. So, if there's one thing you can take home today from your flight back, from this whole talk, would be please do not fall for the false sense of security that these tools are providing, please. And here's a fun meme for you. Thanks, Drake. Please do not blindly trust AI. Assess and review the responses that are generated by AI. And here is a chat GPT prompt engineering hack that I stumbled upon during my research. If you want to create more clearer prompts, use this. It's basically an iterative process where you tell chat GPT, hey, this is my question. It comes up with its own suggestions. It comes up with a revised prompt, more additional questions you should be asking to generate a better prompt. And, yeah, this whole iteration process continues until you let it know that, hey, I'm happy with my prompt. And... I'll wait for you. And here's a slide of helpful links. Thanks to Gavin Clonlight from AI Village. He has done some really amazing research. Feel free to check him out on Twitter. Some really helpful links if you want to learn prompt engineering, different stances that OpenAI has, things like that. And... Okay. And that's it. Thank you.