1 00:00:07,930 --> 00:00:14,570 So today we're going to talk about the duality of Chad GPT and copilot in secure development. 2 00:00:14,790 --> 00:00:17,230 And so my name is Kalyani Pawar. 3 00:00:17,230 --> 00:00:19,090 Let's talk a little bit about me. 4 00:00:19,970 --> 00:00:22,430 So hi, I am Kalyani Pawar. 5 00:00:22,430 --> 00:00:24,050 I also go by Kaylee. 6 00:00:24,130 --> 00:00:30,350 I currently run the application security and vendor security side of things at a drone company called Zipline. 7 00:00:30,390 --> 00:00:33,850 I've been doing security for nearly half a decade now. 8 00:00:35,570 --> 00:00:38,850 I enjoy doing what I do in my free time. 9 00:00:39,050 --> 00:00:41,850 All the opinions throughout all these slides are mine. 10 00:00:41,850 --> 00:00:44,370 I am not representing my employer in any way. 11 00:00:45,190 --> 00:00:47,510 This is my Twitter or X handle. 12 00:00:47,510 --> 00:00:54,950 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. 13 00:00:56,250 --> 00:00:58,690 Things that I do outside of my work. 14 00:00:58,690 --> 00:01:05,330 I do review talks that get submitted to Grace Hoppers and AppSec Village every year at DEF CON. 15 00:01:05,330 --> 00:01:07,590 So that's about me. 16 00:01:08,010 --> 00:01:12,950 Now, what are we going to talk about today? 17 00:01:12,990 --> 00:01:19,130 Obviously, Chad GPT and Copilot, but some fun, cool AppSec-y things that you can do with them. 18 00:01:19,330 --> 00:01:29,550 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. 19 00:01:29,610 --> 00:01:32,230 All right, now that we know what we're going to talk about... 20 00:01:32,990 --> 00:01:34,890 Okay, quick question. 21 00:01:35,210 --> 00:01:40,250 Who in the audience today has worked with Chad GPT or Chad GPT-like models? 22 00:01:40,810 --> 00:01:41,530 Fancy. 23 00:01:41,530 --> 00:01:43,130 That is what I expect. 24 00:01:43,470 --> 00:01:48,450 So here is a quick primer for people who are not familiar with Chad GPT. 25 00:01:48,830 --> 00:01:52,550 It's an AI language model developed by OpenAI. 26 00:01:52,550 --> 00:01:56,170 It is based on generative pre-trained transformer architecture. 27 00:01:56,170 --> 00:01:57,250 It is out of scope. 28 00:01:57,250 --> 00:01:58,930 The whole architecture is out of scope for this talk. 29 00:01:58,930 --> 00:02:00,150 You don't need to know this information. 30 00:02:00,150 --> 00:02:03,690 All you've got to know is how to type in text on a browser. 31 00:02:05,250 --> 00:02:14,430 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. 32 00:02:14,470 --> 00:02:20,430 But what I find beautiful about this tool is that it has the ability to generate human-like text. 33 00:02:20,430 --> 00:02:23,150 Once you input whatever question you have for it. 34 00:02:23,170 --> 00:02:29,630 The fact that you can speak to a machine which can understand the context and nuances of whatever you talk to it. 35 00:02:30,790 --> 00:02:34,150 And it's like talking to a human interlocutor at the end of the day. 36 00:02:34,150 --> 00:02:35,770 So that is what I like about it. 37 00:02:35,770 --> 00:02:39,070 And you can just imagine the kind of functionality that this tool provides you. 38 00:02:39,070 --> 00:02:40,990 You can ask it all sorts of questions. 39 00:02:41,170 --> 00:02:45,150 You can ask it to translate into different languages you don't know about. 40 00:02:45,150 --> 00:02:51,570 You can use it to learn different things that you probably would be investing an hour reading a book. 41 00:02:51,570 --> 00:02:53,570 Rather ask Chad GPT about it. 42 00:02:54,090 --> 00:02:58,270 And, yes, when I don't know the answer to a question, that's what I do. 43 00:02:58,270 --> 00:02:59,770 Ask Chad GPT, guys. 44 00:02:59,770 --> 00:03:00,930 I don't know the answer to this. 45 00:03:00,930 --> 00:03:02,570 Use Chad GPT for this. 46 00:03:05,290 --> 00:03:08,050 How many of y'all have used Copilot? 47 00:03:09,030 --> 00:03:10,330 Y'all like it? 48 00:03:11,290 --> 00:03:12,070 Sort of? 49 00:03:12,070 --> 00:03:13,170 Yeah, same, same. 50 00:03:13,170 --> 00:03:13,990 Sort of. 51 00:03:13,990 --> 00:03:21,490 For people who don't know what Copilot is, it is an AI pair programmer developed by GitHub in collaboration with OpenAI. 52 00:03:22,550 --> 00:03:37,050 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. 53 00:03:37,050 --> 00:03:42,490 How many of y'all have struggled with code that has the worst comments in it? 54 00:03:43,130 --> 00:03:44,010 Most of us? 55 00:03:44,010 --> 00:03:44,630 Most of us? 56 00:03:44,630 --> 00:03:45,330 We don't, like... 57 00:03:45,330 --> 00:03:47,090 What the f... What is this? 58 00:03:47,610 --> 00:03:48,950 What is this? 59 00:03:49,150 --> 00:03:49,750 Right? 60 00:03:49,750 --> 00:04:00,830 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. 61 00:04:01,790 --> 00:04:02,590 Awesome. 62 00:04:04,370 --> 00:04:04,770 So... 63 00:04:04,770 --> 00:04:10,110 Oh, yeah, this is something else I like about it, that it can seamlessly integrate within VS Code, which is my choice of IDE. 64 00:04:10,110 --> 00:04:14,150 I don't have to, like, open up a different browser or an instance, like, launch this tool. 65 00:04:14,150 --> 00:04:21,890 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. 66 00:04:21,970 --> 00:04:27,150 For example, if I just ask Chad GPT Copilot that, can you generate a program that's going to create... 67 00:04:27,150 --> 00:04:29,190 that's going to generate a random number for you? 68 00:04:29,190 --> 00:04:30,370 It would just... 69 00:04:30,370 --> 00:04:30,710 Bam! 70 00:04:30,710 --> 00:04:33,770 You just press tap, and it writes the whole program for you. 71 00:04:35,210 --> 00:04:35,570 So... 72 00:04:35,570 --> 00:04:43,390 Now that we know what Copilot is, I want to talk about the problems that the unsung heroes of our community face. 73 00:04:43,390 --> 00:04:45,470 Application security engineers. 74 00:04:45,590 --> 00:04:46,970 What is the problem? 75 00:04:47,050 --> 00:04:50,810 The problem is that there's a bunch of problems that we're facing. 76 00:04:51,230 --> 00:04:53,310 And I'm going to run through them real quick. 77 00:04:54,430 --> 00:05:04,030 How many of us have been part of these meetings where they're like, hey, I found something vulnerable in my code. 78 00:05:04,030 --> 00:05:07,270 And you're like, okay, how long ago did you push this code into Prod? 79 00:05:07,270 --> 00:05:09,330 And they're like, yeah, many sprints ago. 80 00:05:09,330 --> 00:05:11,890 And you're like, are you telling me this right now? 81 00:05:11,890 --> 00:05:13,310 Like, this is what you did? 82 00:05:13,310 --> 00:05:31,410 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. 83 00:05:32,530 --> 00:05:36,130 Second, lack of security education. 84 00:05:36,130 --> 00:05:42,230 According to dark reading, about half of the developers, 48% of the developers lack security education. 85 00:05:42,230 --> 00:05:47,950 They simply develop code keeping functionality in mind and completely ignore the security aspect of it. 86 00:05:47,950 --> 00:05:51,630 So you're pushing insecure code full of vulnerabilities from the get-go. 87 00:05:51,630 --> 00:05:55,310 That is another pressing issue that we're facing. 88 00:05:56,820 --> 00:05:59,070 The resource constraints. 89 00:05:59,070 --> 00:06:02,670 Were you at Tanya Janka's talk earlier this week? 90 00:06:02,670 --> 00:06:03,570 Any hands? 91 00:06:03,570 --> 00:06:04,250 Okay. 92 00:06:04,250 --> 00:06:06,670 So she was talking about... I'm sure... 93 00:06:06,670 --> 00:06:07,970 Okay, raise your hands, okay? 94 00:06:07,970 --> 00:06:15,410 How many times have you been in an organization where there's like 200 developers and only one AppSec engineer supporting them? 95 00:06:16,790 --> 00:06:18,690 Unsung heroes, I tell you. 96 00:06:23,370 --> 00:06:32,190 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. 97 00:06:32,190 --> 00:06:34,110 So what do you do to combat this? 98 00:06:34,670 --> 00:06:37,250 You onboard different tools for it. 99 00:06:37,290 --> 00:06:44,070 Now, I am guilty of onboarding two, three different tools and just integrating it within my CICD and all of that. 100 00:06:44,070 --> 00:06:48,950 But the problem with this is that it is generating a bunch of false positives. 101 00:06:48,950 --> 00:06:55,870 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. 102 00:06:55,870 --> 00:07:02,410 It's about, okay, now we got to prioritize what risk this vulnerability holds and how are we going to clear this backlog? 103 00:07:02,410 --> 00:07:07,050 And there's just a lot of time that we spend in strategizing how to deal with this monster. 104 00:07:08,670 --> 00:07:11,150 And this is another problem. 105 00:07:11,350 --> 00:07:14,970 Ever-emerging threats, ever-emerging attack vectors. 106 00:07:14,970 --> 00:07:19,230 Every day there's something new that I read online about some new attack vector. 107 00:07:19,230 --> 00:07:27,810 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. 108 00:07:27,810 --> 00:07:34,250 Last but not the least, the hammer that is the legal regulation stick. 109 00:07:34,850 --> 00:07:48,070 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. 110 00:07:48,070 --> 00:07:50,050 How many of us take that seriously? 111 00:07:51,150 --> 00:07:53,090 We are trying, right? 112 00:07:53,090 --> 00:07:53,810 We're trying. 113 00:07:53,810 --> 00:07:57,570 It's just like an additional audit task somewhere in the sprint. 114 00:07:58,830 --> 00:07:59,330 Awesome. 115 00:07:59,810 --> 00:08:10,290 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. 116 00:08:10,290 --> 00:08:16,950 When I say AI, I'm trying to loosely refer to Chad, GPT, and Copilot for the rest of this whole conversation. 117 00:08:18,510 --> 00:08:21,170 How can we leverage AI for AppSec? 118 00:08:21,410 --> 00:08:24,370 Anyone in the crowd? 119 00:08:26,530 --> 00:08:27,410 Yes. 120 00:08:30,030 --> 00:08:31,050 Training, yes. 121 00:08:31,830 --> 00:08:33,090 Anyone else? 122 00:08:35,210 --> 00:08:35,810 Yes. 123 00:08:35,810 --> 00:08:36,190 Perfect. 124 00:08:36,190 --> 00:08:36,730 Bang on. 125 00:08:36,730 --> 00:08:37,710 Anyone else? 126 00:08:41,160 --> 00:08:41,900 Exactly. 127 00:08:41,900 --> 00:08:42,360 Yes. 128 00:08:42,360 --> 00:08:44,160 So, a couple applications here. 129 00:08:44,160 --> 00:08:47,500 You can ask Chad, GPT, like, hey, this is my code. 130 00:08:47,500 --> 00:08:50,620 Tell me what's vulnerable in it and how can I fix this. 131 00:08:50,700 --> 00:08:54,960 You can also go like, hey, Copilot, I'm generating this code right now. 132 00:08:55,260 --> 00:08:59,780 Can you give me secure coding suggestions about how this whole code is supposed to go? 133 00:09:00,920 --> 00:09:07,140 You can also be like, oh, also for, like, a developer especially, they can go like, hey, what is Heartbleed vulnerability? 134 00:09:07,140 --> 00:09:08,620 Explain to me in simple terms. 135 00:09:08,620 --> 00:09:15,880 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? 136 00:09:15,880 --> 00:09:18,820 So, there's certain applications to it. 137 00:09:18,820 --> 00:09:24,920 Now, what I see on the bright side for this is that how many times do you see yourself context switching? 138 00:09:24,920 --> 00:09:31,700 Like, one moment you're doing API security, one moment you're threat modeling, next moment you're source code reviewing. 139 00:09:31,700 --> 00:09:33,520 How many times does that happen to you in a day? 140 00:09:34,320 --> 00:09:35,240 All the time. 141 00:09:35,240 --> 00:09:36,240 All the time, right? 142 00:09:36,240 --> 00:09:39,800 This context switching is leading to burnout on the team. 143 00:09:39,800 --> 00:09:50,160 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. 144 00:09:50,240 --> 00:09:52,160 So, why not use these tools a little bit? 145 00:09:52,160 --> 00:09:53,660 Why not hack the game a little? 146 00:09:55,120 --> 00:10:00,100 So, now that we spoke about what about this approach, why this approach? 147 00:10:00,880 --> 00:10:06,480 Because here are certain reasons I think we should think this approach should be fit. 148 00:10:06,700 --> 00:10:08,020 One is efficiency. 149 00:10:08,020 --> 00:10:13,440 Since these tools use machine learning, they have the ability to generate speedy outcomes. 150 00:10:14,380 --> 00:10:16,000 It is instructional. 151 00:10:16,380 --> 00:10:24,940 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. 152 00:10:26,780 --> 00:10:27,660 Scalability. 153 00:10:27,760 --> 00:10:32,520 They can handle complex tasks and large volumes of data with little human attention. 154 00:10:33,960 --> 00:10:34,520 Automation. 155 00:10:34,520 --> 00:10:38,380 The fact that I can seamlessly integrate Copilot within my IDE. 156 00:10:38,980 --> 00:10:42,180 I feel that that brings some amount of convenience. 157 00:10:42,620 --> 00:10:43,540 And ease of use. 158 00:10:43,540 --> 00:10:49,760 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. 159 00:10:49,760 --> 00:10:54,300 The fact that it is easy to use and user-friendly, that is what appeals to me. 160 00:10:54,300 --> 00:10:58,020 So, these are some reasons why this approach might be deemed fit. 161 00:10:58,820 --> 00:11:04,260 So, now that we've done the what and the why, we should do the how, right? 162 00:11:05,540 --> 00:11:08,980 Let's dive into some fun AppSec things that we got to do. 163 00:11:08,980 --> 00:11:11,100 This is what y'all are here for, I guess, right? 164 00:11:12,480 --> 00:11:18,100 So, for the sake of time and convenience, I'm going to try to keep it to simple examples. 165 00:11:18,820 --> 00:11:25,520 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. 166 00:11:28,080 --> 00:11:28,980 Okay. 167 00:11:28,980 --> 00:11:33,740 First application is vulnerability identification and remediation with ChatGPD. 168 00:11:33,980 --> 00:11:38,700 I have broken this down into a number of steps and how you can do it. 169 00:11:39,920 --> 00:11:42,300 One, you input your code, obvious. 170 00:11:42,300 --> 00:11:47,340 Whatever script that you want to check if it is vulnerable or not, you input your code. 171 00:11:47,340 --> 00:11:49,240 Then you engineer a prompt. 172 00:11:49,240 --> 00:11:51,560 When you're engineering a prompt, you ask for... 173 00:11:52,040 --> 00:11:52,800 You're straightforward. 174 00:11:52,800 --> 00:11:53,860 It's a straightforward process. 175 00:11:53,860 --> 00:11:59,660 You ask for vulnerabilities and remediations for whatever this vulnerability might be. 176 00:11:59,680 --> 00:12:02,020 You assess the response. 177 00:12:02,020 --> 00:12:07,060 Do not just copy-paste anything that ChatGPD gives you, please. 178 00:12:07,060 --> 00:12:09,380 For the love of God, do not. 179 00:12:09,580 --> 00:12:11,060 Assess response. 180 00:12:11,300 --> 00:12:15,680 Validate the recommended fixes that they have given you. 181 00:12:16,400 --> 00:12:18,380 Test and review. 182 00:12:18,380 --> 00:12:19,440 Do not. 183 00:12:19,440 --> 00:12:23,940 Please do not just copy-paste and push it to prod, please. 184 00:12:25,260 --> 00:12:26,380 Okay. 185 00:12:26,720 --> 00:12:30,200 So, here is a prompt for you. 186 00:12:30,200 --> 00:12:34,780 And whoever gets the vulnerability right, I have some stickers to share. 187 00:12:35,700 --> 00:12:36,820 Okay. 188 00:12:37,560 --> 00:12:38,120 So... 189 00:12:38,120 --> 00:12:39,940 And please raise your hands. 190 00:12:40,340 --> 00:12:42,120 So what is the vulnerable code here? 191 00:12:42,120 --> 00:12:46,580 And the prompt that I've given ChatGPD is that, okay, is this code vulnerable to what? 192 00:12:46,580 --> 00:12:49,080 And please suggest what the remediation for this is. 193 00:12:49,080 --> 00:12:50,200 Guesses, guesses. 194 00:12:50,860 --> 00:12:51,900 Buffer overflow. 195 00:12:51,900 --> 00:12:53,400 Thank you, thank you. 196 00:12:53,860 --> 00:12:57,060 Please meet me after, so I can give you the sticker. 197 00:12:58,020 --> 00:12:58,640 Okay. 198 00:12:59,100 --> 00:13:02,280 So, ChatGPD identifies two issues with it. 199 00:13:02,280 --> 00:13:05,680 One, that there is an incorrect assignment here. 200 00:13:05,760 --> 00:13:06,980 That it should have been... 201 00:13:06,980 --> 00:13:10,440 That string two should have been assigned as an array or a pointer. 202 00:13:10,660 --> 00:13:16,700 Second, it does understand that there's a vulnerable function in there, that is string copy, right? 203 00:13:16,760 --> 00:13:25,480 The secure form of doing the same thing is to use something like string copy, which is the remediation it suggests next. 204 00:13:25,480 --> 00:13:27,760 So it does fix the code in a certain way. 205 00:13:27,760 --> 00:13:37,340 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? 206 00:13:37,340 --> 00:13:38,620 Those are 15 characters. 207 00:13:38,620 --> 00:13:41,340 So it adjusts the size of string one. 208 00:13:41,340 --> 00:13:44,900 Then it does the correct character assignment, variable assignment. 209 00:13:44,900 --> 00:13:48,880 Then it uses the correct, more secure form of the string copy. 210 00:13:48,880 --> 00:13:52,360 It uses string copy, which checks on the size of the buffer. 211 00:13:52,360 --> 00:13:54,920 And then it also ensures null termination. 212 00:13:55,400 --> 00:13:58,000 So now, clear how this thing works, right? 213 00:13:58,000 --> 00:13:59,980 This straightforward process. 214 00:14:00,520 --> 00:14:02,660 Now let's see what goes wrong. 215 00:14:04,780 --> 00:14:06,580 Who can guess the code? 216 00:14:07,020 --> 00:14:08,080 What's vulnerable? 217 00:14:08,260 --> 00:14:09,020 Yes. 218 00:14:11,580 --> 00:14:13,720 SQL injection, thank you. 219 00:14:14,060 --> 00:14:15,920 So this is SQL injection. 220 00:14:16,040 --> 00:14:18,260 Now I'm giving it a certain background, okay? 221 00:14:18,260 --> 00:14:23,860 I'm like, hey, we have three metrics, which we are going to use to calculate the severity risk score. 222 00:14:23,860 --> 00:14:26,560 One, how easy it is to exploit this vulnerability. 223 00:14:26,820 --> 00:14:28,720 Two, where does this sit? 224 00:14:28,720 --> 00:14:30,700 How hostile is my threat environment? 225 00:14:30,900 --> 00:14:35,480 Three, what is the impact that is going to happen if I exploit this vulnerability? 226 00:14:35,560 --> 00:14:38,000 And we're going to give it score between zero to 10. 227 00:14:38,100 --> 00:14:42,780 And we calculate the severity risk by adding all those three and divide them by three. 228 00:14:42,780 --> 00:14:45,340 Then I give it additional context. 229 00:14:45,340 --> 00:14:50,960 That, hey, this is used to fetch username information on a public-facing website. 230 00:14:51,120 --> 00:14:53,320 And is this program vulnerable? 231 00:14:53,320 --> 00:14:54,140 To what? 232 00:14:54,140 --> 00:14:56,620 Help me calculate the severity risk for this. 233 00:14:57,620 --> 00:14:58,560 Beautiful. 234 00:14:58,560 --> 00:15:00,980 It identifies it's SQL injection. 235 00:15:01,000 --> 00:15:02,440 So kudos on that. 236 00:15:02,620 --> 00:15:04,840 But this is where my problem lies. 237 00:15:04,960 --> 00:15:14,280 It says ease of exploit development is 10 because, hey, there's so many resources online to find this, how to exploit this. 238 00:15:14,280 --> 00:15:17,280 Hostility, it's a public-facing website, let's give it a score of 10. 239 00:15:17,280 --> 00:15:25,280 Impact, you can modify the database, you can get whatever sorts of secrets, I mean, user data and all of that, so 10. 240 00:15:25,420 --> 00:15:31,340 But what I see is it depends on the context of your application. 241 00:15:31,340 --> 00:15:34,140 What if there are certain guardrails on your public-facing website? 242 00:15:34,400 --> 00:15:40,060 What if the database isn't actually bringing out that kind of sensitive username information? 243 00:15:40,060 --> 00:15:44,080 These scores vary depending on the context of your application. 244 00:15:44,080 --> 00:15:50,660 I would have, depending on the guardrails I've given my public-facing website, I would have given hostility score 8 or 9. 245 00:15:51,480 --> 00:16:07,400 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. 246 00:16:08,080 --> 00:16:11,600 But again, do not blindly trust it. 247 00:16:11,600 --> 00:16:12,700 Trust but verify. 248 00:16:13,880 --> 00:16:18,300 The second application I want to talk about is secure coding suggestions with Copilot. 249 00:16:19,360 --> 00:16:27,940 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. 250 00:16:27,940 --> 00:16:31,500 And then it will give me all these different secure coding suggestions to do this. 251 00:16:31,760 --> 00:16:33,860 Again, breaking it down into steps. 252 00:16:33,860 --> 00:16:36,560 First, obviously, write your code. 253 00:16:37,080 --> 00:16:43,840 Then, while you're writing your code, Copilot is going to give you real-time coding suggestions about what you should be typing next. 254 00:16:44,420 --> 00:16:48,600 You assess the code that is generated by Copilot. 255 00:16:48,700 --> 00:16:50,880 Again, do not blindly believe. 256 00:16:51,860 --> 00:16:55,380 If you want to change your prompt, you can refine your prompt. 257 00:16:55,960 --> 00:16:58,940 And then, lastly, review and test. 258 00:16:58,980 --> 00:17:06,740 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. 259 00:17:07,040 --> 00:17:08,600 Hence, refine your prompts. 260 00:17:09,360 --> 00:17:12,740 So, I have a vulnerable snippet. 261 00:17:13,120 --> 00:17:14,120 We just saw this. 262 00:17:14,120 --> 00:17:15,060 Any guesses? 263 00:17:17,780 --> 00:17:18,620 Exactly. 264 00:17:18,620 --> 00:17:19,940 Yes, it is deceiving. 265 00:17:19,940 --> 00:17:21,880 I know I tried to deceive, but you all are smart. 266 00:17:23,200 --> 00:17:30,920 Okay, so the suggestion that I'm giving Copilot is, hey, identify the vulnerability in this code snippet and fix it for me. 267 00:17:31,640 --> 00:17:34,180 Now, it does a nice job. 268 00:17:34,180 --> 00:17:39,500 This is the whole, the first box is the whole, it's all suggested by Copilot. 269 00:17:39,500 --> 00:17:41,360 This is not something I've typed by myself. 270 00:17:41,360 --> 00:17:44,360 This whole slide is everything that Copilot has suggested. 271 00:17:44,480 --> 00:17:46,720 It identifies buffer overflow. 272 00:17:46,760 --> 00:17:49,720 It identifies the vulnerable function that is string copy. 273 00:17:49,720 --> 00:17:52,400 And it tells you replace it by the safer version of it. 274 00:17:52,400 --> 00:17:55,540 And it tells you why you should use string copy. 275 00:17:55,540 --> 00:17:56,660 Good, good enough context. 276 00:17:56,660 --> 00:17:59,020 There's some nuggets that I can take from this. 277 00:17:59,020 --> 00:18:11,120 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. 278 00:18:11,380 --> 00:18:11,900 Right ? 279 00:18:11,900 --> 00:18:14,000 So, yeah. 280 00:18:14,000 --> 00:18:17,600 So now we understand how this whole thing works, the whole gamut. 281 00:18:17,920 --> 00:18:19,700 Next prompt for you. 282 00:18:20,180 --> 00:18:21,540 What is this? 283 00:18:21,540 --> 00:18:22,520 Guesses. 284 00:18:24,480 --> 00:18:25,560 Guesses. 285 00:18:25,560 --> 00:18:29,100 You can go. 286 00:18:29,100 --> 00:18:30,780 You've gone once already. 287 00:18:31,440 --> 00:18:32,100 Yes? 288 00:18:33,340 --> 00:18:35,280 Part traversal, directory traversal, yes. 289 00:18:35,280 --> 00:18:36,260 Okay, perfect. 290 00:18:36,500 --> 00:18:39,160 So, again, you give it the suggestion. 291 00:18:39,500 --> 00:18:41,480 Identify this vulnerability for me. 292 00:18:41,480 --> 00:18:43,340 Rewrite the code to eliminate it. 293 00:18:44,620 --> 00:18:45,980 Now, beautiful. 294 00:18:45,980 --> 00:18:48,140 It identifies part traversal. 295 00:18:48,140 --> 00:18:50,420 But this is where the problem lies. 296 00:18:50,420 --> 00:18:53,040 It's giving you like eight different suggestions. 297 00:18:53,180 --> 00:18:55,060 It's like, use OS part join. 298 00:18:55,060 --> 00:19:00,500 Use OS part apps part, common prefix, exists, is file, rel part, norm part. 299 00:19:00,500 --> 00:19:06,120 And then it goes on to generate this 25-line code about how this can be fixed. 300 00:19:06,440 --> 00:19:25,540 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. 301 00:19:25,540 --> 00:19:29,960 And then you completely keep the last file name and focus on it. 302 00:19:29,960 --> 00:19:36,480 Albeit, this is a more secure fix, but you can still make it vulnerable. 303 00:19:36,480 --> 00:19:39,860 You can still give it some maliciously crafted regex and try to break this. 304 00:19:42,640 --> 00:19:50,520 The last one, the last application I want to talk about is security test case generation using Copilot. 305 00:19:51,800 --> 00:19:53,860 Again, we're going to break it down into... 306 00:19:53,860 --> 00:19:54,980 Wait, I'm curious. 307 00:19:54,980 --> 00:19:57,320 How many people here do security test cases? 308 00:19:59,660 --> 00:20:02,900 Three, four, five, six? 309 00:20:02,980 --> 00:20:03,660 Okay. 310 00:20:04,100 --> 00:20:04,670 Okay, that's... 311 00:20:05,060 --> 00:20:06,080 I hope this... 312 00:20:06,080 --> 00:20:07,060 We're going to work on this. 313 00:20:07,060 --> 00:20:07,940 We're going to increase this. 314 00:20:07,940 --> 00:20:09,280 Thank you to Copilot. 315 00:20:09,280 --> 00:20:12,420 Maybe we try to generate more test cases going forward. 316 00:20:13,820 --> 00:20:15,020 The breakdown. 317 00:20:15,020 --> 00:20:17,200 You identify the vulnerability. 318 00:20:17,840 --> 00:20:20,560 You obviously launch Copilot in your IDE. 319 00:20:21,760 --> 00:20:22,640 Oops, okay. 320 00:20:22,640 --> 00:20:26,620 Then you write a prompt to generate security test cases like we saw earlier. 321 00:20:26,620 --> 00:20:27,620 Hey, help me. 322 00:20:27,620 --> 00:20:29,180 Like we saw, identify the vulnerability. 323 00:20:29,180 --> 00:20:32,320 This time you're going to be like, hey, generate security test cases for me. 324 00:20:32,460 --> 00:20:35,660 And then Copilot will generate all those test cases for you. 325 00:20:35,660 --> 00:20:37,600 You execute those test cases. 326 00:20:37,600 --> 00:20:40,880 Again, review the output that it generates. 327 00:20:42,020 --> 00:20:42,760 Oh. 328 00:20:43,660 --> 00:20:44,560 Did you get that? 329 00:20:47,310 --> 00:20:48,190 Okay. 330 00:20:48,810 --> 00:20:50,710 Snippet one. 331 00:20:50,890 --> 00:20:52,110 What is this? 332 00:20:52,110 --> 00:20:53,830 What is it vulnerable to? 333 00:20:54,350 --> 00:20:56,250 Guesses, guesses. 334 00:20:57,370 --> 00:20:59,110 Not buffer overflow. 335 00:21:01,290 --> 00:21:02,610 Integer overflow. 336 00:21:02,610 --> 00:21:03,250 Perfect. 337 00:21:03,490 --> 00:21:06,170 So this is a Python program. 338 00:21:06,170 --> 00:21:16,290 Python is used to handling really large numbers, but you can make it vulnerable to integer overflow by using C-compatible data types. 339 00:21:16,510 --> 00:21:34,910 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? 340 00:21:35,050 --> 00:21:40,210 But instead, since this program is vulnerable to integer overflow, it's going to give you a negative value. 341 00:21:40,210 --> 00:21:41,990 It's going to do a whole wraparound. 342 00:21:41,990 --> 00:21:44,430 So that is how this program is vulnerable. 343 00:21:45,030 --> 00:21:48,210 Now, let's go ahead to application. 344 00:21:49,670 --> 00:21:51,190 So this is what I'm saying. 345 00:21:51,190 --> 00:21:55,750 Hey, write unit tests for vulnerable addition function and vulnerable pi. 346 00:21:57,130 --> 00:22:01,590 Then it does a good job of suggesting two cases for me. 347 00:22:01,590 --> 00:22:02,030 Or three. 348 00:22:02,030 --> 00:22:03,890 It's breaking it down into two lines here. 349 00:22:03,890 --> 00:22:06,230 Test one, normal addition. 350 00:22:06,370 --> 00:22:14,670 Test two, it should raise an exception when there's an overflow and underflow. 351 00:22:14,670 --> 00:22:22,930 Then it proceeds to write, one, normal addition, you're adding 1 and 2, should return 3, straightforward. 352 00:22:24,090 --> 00:22:33,010 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. 353 00:22:33,010 --> 00:22:34,450 Three, same thing. 354 00:22:34,450 --> 00:22:40,310 You're adding the smallest value of the 32-bit sign to minus 1, it should raise an overflow error. 355 00:22:40,310 --> 00:22:41,150 Straightforward? 356 00:22:41,150 --> 00:22:43,430 Are we following any questions so far? 357 00:22:43,590 --> 00:22:44,890 Okay, perfect. 358 00:22:47,070 --> 00:22:52,710 And it does, thankfully, generate two failures. 359 00:22:52,710 --> 00:23:00,230 It says that vulnerable addition is not generating overflow error for both the cases, the maximum values and the minimum values. 360 00:23:00,230 --> 00:23:02,130 So it works fine, right? 361 00:23:02,130 --> 00:23:04,410 This is what we were expecting it to do. 362 00:23:04,410 --> 00:23:09,910 So, this is the bad example. 363 00:23:09,930 --> 00:23:12,290 Did we follow what I just spoke about? 364 00:23:12,330 --> 00:23:13,310 Okay, great. 365 00:23:13,310 --> 00:23:17,250 So now that we understand how it's generating unit test cases, this is the second example. 366 00:23:17,470 --> 00:23:19,250 What is the vulnerability? 367 00:23:20,850 --> 00:23:22,270 We saw this. 368 00:23:24,940 --> 00:23:26,980 SQL injection, right. 369 00:23:27,620 --> 00:23:29,100 SQL injection, right. 370 00:23:29,100 --> 00:23:38,580 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. 371 00:23:38,580 --> 00:23:40,480 It does this really weird thing. 372 00:23:41,120 --> 00:23:54,460 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? 373 00:23:54,480 --> 00:24:00,360 And if I go for a non-existent user, is it going to raise an is-none, right? 374 00:24:00,360 --> 00:24:05,060 But it is completely ignoring the SQL injection. 375 00:24:05,120 --> 00:24:10,180 A good addition would have been this, right? 376 00:24:10,180 --> 00:24:12,680 Give it a maliciously crafted input, right? 377 00:24:12,680 --> 00:24:20,500 It completely ignores the fact that there is SQL injection in here, right? 378 00:24:20,500 --> 00:24:23,320 So these are the only two test cases it generates. 379 00:24:23,320 --> 00:24:27,760 Okay, so now we've seen security-focused test cases. 380 00:24:28,260 --> 00:24:29,820 Everybody follow so far? 381 00:24:29,820 --> 00:24:31,060 Okay, great. 382 00:24:33,280 --> 00:24:35,160 Another weird application. 383 00:24:35,160 --> 00:24:37,060 How many of you all use CodeQL? 384 00:24:38,740 --> 00:24:40,500 You find it annoying? 385 00:24:41,420 --> 00:24:43,020 Sort of, but does the job? 386 00:24:43,020 --> 00:24:43,220 Yeah? 387 00:24:43,480 --> 00:24:44,700 Yeah, okay. 388 00:24:44,700 --> 00:24:56,180 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? 389 00:24:56,240 --> 00:24:58,440 So think of it as a SAST. 390 00:24:58,980 --> 00:25:00,760 So now I ask... 391 00:25:00,760 --> 00:25:05,340 this is the correct query that I have generated. 392 00:25:05,340 --> 00:25:07,440 Say I want to find in my whole... 393 00:25:08,120 --> 00:25:14,700 in the entire repository, if I want to find all of the to-do comments, this is the query you give CodeQL. 394 00:25:15,300 --> 00:25:15,960 Okay? 395 00:25:15,960 --> 00:25:16,700 Looks beautiful. 396 00:25:16,780 --> 00:25:23,500 Straightforward, it's like, hey, from a comment, you get text, find this regex, it should have to-do in it, right? 397 00:25:23,500 --> 00:25:24,260 Okay. 398 00:25:24,800 --> 00:25:29,420 When I ask the same question to ChatGPD, it gives me this... 399 00:25:30,000 --> 00:25:30,960 I don't know what this is. 400 00:25:30,960 --> 00:25:32,260 It gives me this whole thing. 401 00:25:32,580 --> 00:25:39,400 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. 402 00:25:39,920 --> 00:25:41,180 And this is what I felt. 403 00:25:41,260 --> 00:25:42,100 This is what I felt. 404 00:25:42,100 --> 00:25:54,700 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. 405 00:25:54,700 --> 00:26:00,420 So, it's not a good CodeQL query developer. 406 00:26:01,380 --> 00:26:02,620 Okay. 407 00:26:02,920 --> 00:26:03,880 Praise Jesus! 408 00:26:03,880 --> 00:26:05,620 Our jobs are safe, guys! 409 00:26:08,480 --> 00:26:10,640 Our jobs are completely safe. 410 00:26:10,640 --> 00:26:13,040 It hasn't taken over our job yet. 411 00:26:13,740 --> 00:26:15,720 But, why? 412 00:26:15,720 --> 00:26:22,860 So certain limitations that I found throughout this whole research of mine, I'm just gonna list them out. 413 00:26:22,860 --> 00:26:31,060 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. 414 00:26:31,060 --> 00:26:42,180 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. 415 00:26:42,420 --> 00:26:44,440 Same thing with Copilot as well. 416 00:26:44,940 --> 00:26:48,680 And dependence on prompts, like we saw. 417 00:26:48,680 --> 00:27:02,380 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. 418 00:27:02,940 --> 00:27:05,620 Intellectual property concerns. 419 00:27:05,620 --> 00:27:06,280 Okay. 420 00:27:06,300 --> 00:27:13,420 So, do not enter, for the love of God, do not put business critical information in any of these tools. 421 00:27:13,420 --> 00:27:15,080 Please, please do not. 422 00:27:15,220 --> 00:27:20,840 Do not even put your secret, your PIIs, like your SSNs or something like that. 423 00:27:20,840 --> 00:27:32,860 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. 424 00:27:33,660 --> 00:27:36,800 Basically, don't give anything that is intellectual property. 425 00:27:37,700 --> 00:27:48,220 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. 426 00:27:48,220 --> 00:27:56,500 And lastly, we saw in all of these examples, it is introducing unintended, insecure consequences. 427 00:27:56,500 --> 00:27:59,920 It is not developing more secure form of the code from get-go. 428 00:28:00,660 --> 00:28:03,800 So, these are certain limitations that we have. 429 00:28:04,840 --> 00:28:15,500 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. 430 00:28:17,300 --> 00:28:18,940 And here's a fun meme for you. 431 00:28:18,940 --> 00:28:20,060 Thanks, Drake. 432 00:28:20,300 --> 00:28:22,500 Please do not blindly trust AI. 433 00:28:22,540 --> 00:28:26,180 Assess and review the responses that are generated by AI. 434 00:28:28,620 --> 00:28:34,260 And here is a chat GPT prompt engineering hack that I stumbled upon during my research. 435 00:28:34,260 --> 00:28:38,500 If you want to create more clearer prompts, use this. 436 00:28:38,780 --> 00:28:43,240 It's basically an iterative process where you tell chat GPT, hey, this is my question. 437 00:28:43,240 --> 00:28:44,780 It comes up with its own suggestions. 438 00:28:44,780 --> 00:28:50,580 It comes up with a revised prompt, more additional questions you should be asking to generate a better prompt. 439 00:28:50,940 --> 00:28:55,460 And, yeah, this whole iteration process continues until you let it know that, hey, I'm happy with my prompt. 440 00:28:58,460 --> 00:28:58,860 And... 441 00:29:02,600 --> 00:29:03,600 I'll wait for you. 442 00:29:13,070 --> 00:29:16,650 And here's a slide of helpful links. 443 00:29:16,650 --> 00:29:18,830 Thanks to Gavin Clonlight from AI Village. 444 00:29:19,550 --> 00:29:21,570 He has done some really amazing research. 445 00:29:21,570 --> 00:29:23,290 Feel free to check him out on Twitter. 446 00:29:23,290 --> 00:29:31,910 Some really helpful links if you want to learn prompt engineering, different stances that OpenAI has, things like that. 447 00:29:36,800 --> 00:29:37,560 And... 448 00:29:38,560 --> 00:29:39,500 Okay. 449 00:29:39,500 --> 00:29:40,620 And that's it. 450 00:29:40,620 --> 00:29:41,320 Thank you.