1 00:00:00,680 --> 00:00:02,540 Hello DEF CON! 2 00:00:03,200 --> 00:00:05,260 Thank you so much for being here. 3 00:00:05,260 --> 00:00:07,260 It's like the second to last talk. 4 00:00:07,260 --> 00:00:08,620 It's a great turnout. 5 00:00:08,700 --> 00:00:10,180 I'm very honored to be here. 6 00:00:10,180 --> 00:00:11,820 My name is Yusro Lomarski. 7 00:00:11,820 --> 00:00:18,080 I'm a Zuckerman Faculty Scholar at Ben-Gurion University and head of the Offensive AI Research Lab there. 8 00:00:18,300 --> 00:00:23,620 And with me here today are my brilliant graduate students who will be coming up on stage also to present. 9 00:00:23,620 --> 00:00:25,440 They did all the hard work. 10 00:00:25,480 --> 00:00:31,420 There's Daniel Eisenstein and Roy Weiss in collaboration with Guy Amit, who couldn't make it. 11 00:00:32,720 --> 00:00:45,920 Okay, so today we're going to talk about a new side channel attack against AI assistants that enables adversaries to read encrypted response traffic, such as responses from ChatGPT. 12 00:00:48,260 --> 00:00:52,160 Okay, so I'm not going to go into, you know, what are AI assistants. 13 00:00:52,160 --> 00:00:53,380 You guys all know this very well. 14 00:00:53,380 --> 00:01:00,360 You have OpenAI's ChatGPT, you have Google's Gemini, you have Microsoft Copilot, the list goes on and on. 15 00:01:00,440 --> 00:01:06,580 And these AI assistants are integrated throughout industry in all different kinds of use cases. 16 00:01:06,620 --> 00:01:11,240 What's more interesting to me is the use cases of the personal level, right? 17 00:01:11,240 --> 00:01:17,400 A lot of users are using these AI assistants, such as ChatGPT, to get personal advice. 18 00:01:17,560 --> 00:01:23,440 So, for example, you may ask it some medical questions like, why do I have a rash on my back, right? 19 00:01:23,440 --> 00:01:28,660 And ChatGPT will get back to you and say, I'm sorry to hear you have a rash on your back. 20 00:01:28,660 --> 00:01:30,680 Let me give some tips how to take care of that. 21 00:01:31,020 --> 00:01:35,480 Or maybe you may ask ChatGPT for some relationship advice. 22 00:01:35,700 --> 00:01:37,220 What are the signs I'm having? 23 00:01:37,220 --> 00:01:39,300 My wife is having an affair, right? 24 00:01:39,300 --> 00:01:40,940 And get some good tips on there. 25 00:01:41,840 --> 00:01:47,840 Or maybe you're getting into hacking and you're going to ask ChatGPT how to get into your neighbor's Wi-Fi, right? 26 00:01:47,920 --> 00:01:49,060 Lots of good use cases. 27 00:01:49,060 --> 00:01:54,040 Or my favorite, a lot of people are using ChatGPT to edit their documents. 28 00:01:54,040 --> 00:01:59,220 They'll take whole documents or emails, dump it into ChatGPT and say, hey, make it better. 29 00:01:59,220 --> 00:02:02,100 Or, you know, finish this paragraph or what have you. 30 00:02:02,360 --> 00:02:05,000 And these are all very good and legitimate use cases. 31 00:02:05,000 --> 00:02:10,320 They're actually very productive for our society to help us, you know, progress and automate things. 32 00:02:10,940 --> 00:02:17,000 But the problem is that what happens if these chats aren't actually private? 33 00:02:17,000 --> 00:02:22,640 What happens if somebody could read these chats beyond, right? 34 00:02:22,640 --> 00:02:25,360 So this would be a huge breach in privacy. 35 00:02:26,960 --> 00:02:30,540 So in truth, we know they're encrypted, right? 36 00:02:30,540 --> 00:02:35,920 So you know, OpenAI is encrypting all the traffic going between the client and the servers. 37 00:02:36,220 --> 00:02:37,860 But is that enough? 38 00:02:37,860 --> 00:02:40,020 You know, maybe a little foreshadowing. 39 00:02:41,080 --> 00:02:44,020 So let me go back to the beginning of this story here. 40 00:02:44,020 --> 00:02:59,840 So several months ago, you know, late at night, I was using ChatGPT for very important stuff, such as trying to figure out what would the world be like if every country had ninjas, but Japan had the worst ninjas, right? 41 00:02:59,840 --> 00:03:09,060 So as I'm looking at the text glide across the screen and looking at this very insightful and thoughtful response, it kind of hits me. 42 00:03:09,060 --> 00:03:10,340 Wait a second. 43 00:03:10,580 --> 00:03:17,760 Could it possibly be that OpenAI is sending every single word as a separate packet? 44 00:03:18,020 --> 00:03:26,640 And could it be that every single packet has no padding so I can count the number of characters in each of these words? 45 00:03:28,440 --> 00:03:32,180 So I open up Wireshark and sure enough, what do I see? 46 00:03:32,180 --> 00:03:40,060 For every single word that's being sent from the AI assistant, I see another packet and the size of that packet increases. 47 00:03:40,440 --> 00:03:47,080 And if I take the delta between these packets, I know exactly how many characters in every single word. 48 00:03:47,080 --> 00:03:58,940 And I could use this, for example, to try and guess what those words are and potentially learn or identify what is being said in those responses. 49 00:03:59,520 --> 00:04:07,060 Now, before I go on to explain how we figured out what those words are, I need to take a little bit of a technical aside and clarify something. 50 00:04:07,200 --> 00:04:14,320 That what ChatGPT and all these different AI services are sending are not exactly words, but rather something called tokens. 51 00:04:14,780 --> 00:04:21,480 What tokens are, are basically the basic building block of AI language models. 52 00:04:21,580 --> 00:04:32,960 When you give text to a language model, it's going to first parse it down into these tokens and then each token goes to the model and the model generates text using these tokens as well. 53 00:04:33,220 --> 00:04:40,380 So in general, these tokens more or less correlate directly to words, but there are some cases where these tokens won't. 54 00:04:40,380 --> 00:04:46,020 So for example here, Lama's tokenizer will split the word cream into two separate tokens. 55 00:04:46,340 --> 00:04:55,500 But what's important to note is that although there's not a direct correlation from token to word, these tokenizers are public information. 56 00:04:55,500 --> 00:05:03,760 Doesn't matter if it's open AIs, if it's metas, you can go through the entire list, you can get the tokenizer and you can learn the exact mappings. 57 00:05:03,760 --> 00:05:08,620 So for all intents and purposes, these are words and we're trying to guess what these words are. 58 00:05:10,040 --> 00:05:12,120 So what's the threat model? 59 00:05:12,740 --> 00:05:23,720 So the victim types some private chat into his web browser, hits enter, and that encrypted text goes across the wire. 60 00:05:23,720 --> 00:05:28,520 Now we're not gonna be able to figure out what that prompt was because that's just one big block of encrypted text. 61 00:05:28,620 --> 00:05:38,740 But what happens after that is the AI assistant starts responding token by token by token back and we can count exactly how many characters are in each of these tokens. 62 00:05:38,800 --> 00:05:44,240 And once again, if we can guess what those words are, then boom, we know exactly what the response was. 63 00:05:45,340 --> 00:05:47,120 So why do we care? 64 00:05:47,260 --> 00:05:58,680 I mean, I can't figure out what the prompt was, I can't figure out what the exact question was, but it's, it turns out that a lot of information is leaked by the response itself. 65 00:05:58,680 --> 00:06:07,380 So imagine I read one of the responses off the network that somebody was receiving and it said, I'm sorry to hear that you have a rash. 66 00:06:07,840 --> 00:06:08,120 Right? 67 00:06:08,120 --> 00:06:12,340 I think it's pretty clear we know exactly what that user was asking for. 68 00:06:13,740 --> 00:06:21,360 So basically this boils down to a big wheel of fortune game, right, where I have to start guessing what those words are. 69 00:06:21,620 --> 00:06:27,220 And this can be a particularly challenging problem because, you know, there's many different ways you can solve this puzzle. 70 00:06:27,700 --> 00:06:32,980 But it gets even more challenging when you think about real responses from these AI assistants, right? 71 00:06:32,980 --> 00:06:36,820 They're not just one sentence, they're typically whole paragraphs with hundreds of words. 72 00:06:37,160 --> 00:06:38,940 So how do we solve this problem? 73 00:06:38,940 --> 00:06:48,600 So we turn to the age-old solution, which is AI, and we look towards a task which is very popular, which is language translation, right? 74 00:06:48,600 --> 00:06:59,380 But here, instead of going from a language such as French to English, we're going to go from token length sequences to plain text English. 75 00:06:59,760 --> 00:07:10,040 And what we'll do is we'll train an AI with lots and lots of examples of these token lengths to real English, and we'll be able to translate them very effectively. 76 00:07:10,980 --> 00:07:22,960 In our case, we used a state -of-the-art model called a large language model, or LLM, and this is the exact same technology that's being used in AI assistants such as ChatGPT. 77 00:07:22,960 --> 00:07:27,560 I'm not going to go too much into detail how it works, leave that for other YouTube videos. 78 00:07:28,440 --> 00:07:31,020 All right, so what's the entire attack end-to-end, how does it look like? 79 00:07:31,020 --> 00:07:43,000 So the attacker is looking through the network, looking for responses from a particular AI service such as ChatGPT, sees the traffic going across the network, and records down the token length sequence from those packets. 80 00:07:43,060 --> 00:07:52,700 He then passes that token length sequence to his trained model, which has seen lots and lots of examples, and it predicts what it thinks the original plain text was. 81 00:07:53,640 --> 00:07:57,260 So there's something else we can do to make this even better. 82 00:07:58,000 --> 00:08:03,800 So if we just, you know, give our model random arbitrary text, it's going to do so-so. 83 00:08:03,800 --> 00:08:07,440 It's not going to do so great, because as I said, you know, there's lots of ways we can solve that puzzle. 84 00:08:07,640 --> 00:08:13,060 But as it turns out, AI assistants have a very specific style of speaking, right? 85 00:08:13,060 --> 00:08:21,120 They're not just going to respond with some arbitrary sentence, they typically start with something like, oh sure, yeah, I can give you a recipe for tomato soup, right? 86 00:08:21,120 --> 00:08:25,100 So there's a certain style that's intrinsically in those responses. 87 00:08:25,560 --> 00:08:36,980 So what I can do is if I'm, let's say I'm trying to target Microsoft Copilot, I can send lots and lots of prompts to Microsoft Copilot and build a huge data set of responses. 88 00:08:37,140 --> 00:08:41,860 And those responses capture the style of that particular AI service. 89 00:08:42,220 --> 00:08:47,760 And once I have that, I can fine-tune my model on that, and I'll get much, much better results. 90 00:08:48,100 --> 00:08:52,900 And as it turns out, I can get something around 55% attack success rate. 91 00:08:52,900 --> 00:08:58,880 So more than half of the responses that we see in the encrypted traffic, we can decipher. 92 00:09:00,400 --> 00:09:02,840 Okay, so let's look at some examples. 93 00:09:03,100 --> 00:09:06,580 So on the screen here is the first sentences that we're trying to decipher. 94 00:09:06,580 --> 00:09:11,580 The first line is the original text that is being sent from the AI assistant. 95 00:09:11,580 --> 00:09:14,200 And the second line is our prediction. 96 00:09:14,400 --> 00:09:18,700 So sometimes you can see in the first example there, we get it right on the first go. 97 00:09:18,700 --> 00:09:20,560 And sometimes we make some mistakes. 98 00:09:20,840 --> 00:09:32,400 So for example, in the bottom there, the original response was, yes, there are several important legal considerations that couples should be aware of when considering a divorce. 99 00:09:33,080 --> 00:09:45,020 And then if we look at the inferred response, we got, yes, there are several potential legal considerations that someone should be aware of when considering a divorce. 100 00:09:45,020 --> 00:09:55,420 So even though we had some mistakes in the words, we're still, it's very, very clear what was the topic that the, uh, user was trying to ask the AI assistant. 101 00:09:56,800 --> 00:10:10,120 And then if we move over to entire paragraphs, we get something around a 35% attack success rate, which is also very, uh, significant considering how hard it is to try and guess what all these words are. 102 00:10:10,980 --> 00:10:14,260 And since we're using AI models, this isn't a perfect science. 103 00:10:14,260 --> 00:10:18,000 You know, we're using a lot of heuristics here, so we sometimes get it wrong. 104 00:10:18,000 --> 00:10:19,360 So here's some fails. 105 00:10:19,360 --> 00:10:29,280 So in the, uh, ground truth, it was something like, I would like to suggest some following strategies for team leaders to balance the needs of individual team members with the needs of the team as a whole. 106 00:10:29,560 --> 00:10:41,120 And we inferred it as, I would suggest the following strategies, so far so good, but then for film studios to balance the needs of production, so on and so forth, something is completely unrelated. 107 00:10:41,500 --> 00:10:43,320 And sometimes it gets even worse, right? 108 00:10:43,320 --> 00:10:49,000 So here's a case where the response has something to do with apple cider, and we thought it had to do with coral bleaching. 109 00:10:49,220 --> 00:10:57,860 Okay, so it's not a perfect science, but what's interesting to note is that because we're using machine learning model, the model also gives us a confidence score. 110 00:10:57,880 --> 00:11:02,160 How confident it is that this prediction is correct, right? 111 00:11:02,160 --> 00:11:14,200 So what we can do is we can look, and we're trying to attack a particular, uh, you know, token-linked sequence that we see in the network, we can try to look at the confidence of the model and say whether or not we should trust this, uh, inference or not. 112 00:11:16,120 --> 00:11:18,900 All right, so how common is this vulnerability? 113 00:11:19,700 --> 00:11:31,260 So, uh, you know, around the time of our disclosure, or prior to our disclosure around, uh, February 2024, uh, nearly every major AI vendor out there had this vulnerability. 114 00:11:31,900 --> 00:11:40,100 And, uh, you know, when you start wondering why is that the case, how do they overlook the seemingly obvious side channel, and there's a few reasons that might come to mind. 115 00:11:40,400 --> 00:11:47,840 First, uh, you know, they might, perhaps they didn't think that token links the same as word links, so maybe there was just a simple blunder. 116 00:11:47,840 --> 00:11:53,060 Or maybe they thought there's no way that an adversary can guess entire paragraphs of text. 117 00:11:53,060 --> 00:11:54,680 That's just too hard of a problem. 118 00:11:54,940 --> 00:12:00,360 But what I think is more likely the case is that it has something to do with the big AI gold rush, right? 119 00:12:00,360 --> 00:12:08,700 There's so many industries that are jumping on the AI chatbot idea and throwing it into services willy-nilly, and they don't really think about security by design. 120 00:12:08,700 --> 00:12:13,300 They're saying, oh, you know, the text is encrypted, not a big deal, let's move on, right? 121 00:12:13,340 --> 00:12:19,280 So this is probably more likely what happened there until they, of course, patched it after the fact. 122 00:12:20,540 --> 00:12:26,040 So why are they even sending, you know, text to streaming or token streaming across the network? 123 00:12:26,040 --> 00:12:28,840 Why don't they just send it as one big batch, right? 124 00:12:28,860 --> 00:12:32,580 So for example, Google's Gemini does this already. 125 00:12:32,580 --> 00:12:41,220 When you get a response from Google Gemini, it's not sending a token, token, token, it sends it as one big block, and therefore they're not vulnerable to the side channel attack. 126 00:12:41,220 --> 00:12:43,040 So why aren't the other vendors doing this? 127 00:12:43,100 --> 00:12:52,600 So there's a simple answer for that, and the answer is that, you know, these AI models are actually incredibly complex, and it takes a lot of effort to execute them. 128 00:12:52,600 --> 00:13:06,620 So instead of having the user wait there for, you know, a good, you know, 30 seconds for this loading screen to go by to get their response, it makes perfect sense to send those words or tokens one at a time in real time so they can read it as it's being generated. 129 00:13:07,520 --> 00:13:21,720 All right, so to recap so far, what we've accomplished here is that we've discovered a novel side channel attack which we call the token length side channel, and we found it's common in LLM services all over. 130 00:13:21,780 --> 00:13:34,620 And we've also found a way to exploit that side channel to read the hidden information behind it directly using AI and improve that performance using a known plaintext attack. 131 00:13:36,960 --> 00:13:51,280 Okay, so for the rest of this talk, we're going to get down into the nitty-gritty details, and first we're going to talk about how we identified response traffic inside network traffic and how we then extract the token length sequences from there. 132 00:13:51,720 --> 00:13:57,740 And after that, we'll talk a little bit about how we train AI models and our specific RAI model. 133 00:13:57,820 --> 00:14:03,020 And finally, we'll end up with some demos, defenses, and we'll talk about some bug bounties that we got along the way. 134 00:14:03,020 --> 00:14:07,000 So with that, I'm going to hand it off to Daniel who's going to take it from here. 135 00:14:12,640 --> 00:14:13,900 Thanks Israel. 136 00:14:14,180 --> 00:14:17,000 So, let's jump to the nitty-gritty details. 137 00:14:17,020 --> 00:14:22,300 So, we will talk about how to find the side channel and how to extract the token length sequence. 138 00:14:26,420 --> 00:14:32,200 So, the first thing we'll have to do is to capture the traffic containing the response from the assistant. 139 00:14:32,440 --> 00:14:36,880 So, we'll need to be positioned between the victim and the assistant. 140 00:14:37,340 --> 00:14:43,200 Or, we can be in the same local network as the victim sitting in the same cafe using Wi-Fi. 141 00:14:44,340 --> 00:14:50,440 So, we collected a lot of traffic and not all of it containing our response data from the AI assistant. 142 00:14:50,580 --> 00:14:52,640 So, we'll need to filter the traffic. 143 00:14:52,960 --> 00:14:56,440 We can do that by filtering by the IP address of the assistant. 144 00:14:56,660 --> 00:15:13,120 Uh, that information can be collected by OSINT or by connecting as a legitimate client to the assistant server for two different times a day from different locations and making our own data set of those IP addresses and basically filtering by those. 145 00:15:13,540 --> 00:15:16,580 Also, what we can do is filter by the protocol. 146 00:15:16,780 --> 00:15:20,140 So, every vendor is using different protocol. 147 00:15:20,140 --> 00:15:22,860 For example, JGPT is using quick protocol. 148 00:15:22,860 --> 00:15:28,020 So, we would like to search for UDP packets that are coming from port 443. 149 00:15:28,320 --> 00:15:33,420 And again, every vendor is using different protocol so we'll need to account for that. 150 00:15:33,480 --> 00:15:46,300 And also, there is a slight problem because it will add us more complexity when we will try to extract the token length sequence because again, every protocol looks differently on the wire and it has its own metadata. 151 00:15:48,280 --> 00:15:54,500 So, we captured the traffic, we filtered out most of the traffic that don't contain our tokens. 152 00:15:54,500 --> 00:15:58,220 We have the traffic that contains the response from the assistant. 153 00:15:58,360 --> 00:16:00,560 Let's extract the token length sequence. 154 00:16:01,860 --> 00:16:05,580 So, our objective is to find the token lengths. 155 00:16:05,960 --> 00:16:13,220 We need to remember that the traffic is encrypted so we can't really see where are the tokens and what packets contain them. 156 00:16:13,360 --> 00:16:16,240 But what we can see is the bandwidth patterns. 157 00:16:16,240 --> 00:16:17,960 Basically, the packet sizes. 158 00:16:24,590 --> 00:16:26,210 Oh, I'm sorry. 159 00:16:30,800 --> 00:16:36,800 So, we found that there is two main ways that the vendors are using to send their tokens. 160 00:16:36,800 --> 00:16:39,040 The first way is base plus next token. 161 00:16:39,040 --> 00:16:42,920 Basically, each token is sent in a separate packet by itself. 162 00:16:43,020 --> 00:16:48,160 So, we can infer the size of the token by just analyzing the size of the packet. 163 00:16:48,280 --> 00:16:50,860 The second way is token accumulation. 164 00:16:51,060 --> 00:16:53,040 Basically, the tokens accumulate. 165 00:16:53,040 --> 00:16:58,540 We are sending each time the token with all of the tokens that were previously sent. 166 00:16:58,620 --> 00:17:01,180 So, the packets are increasing in size. 167 00:17:01,440 --> 00:17:08,680 In the next slides, we'll talk more about token accumulation because this is the way that Microsoft and OpenAI are using. 168 00:17:08,680 --> 00:17:11,720 So, basically, our main target was JGPT. 169 00:17:11,720 --> 00:17:13,700 So, we'll talk about this more. 170 00:17:14,960 --> 00:17:22,980 So, to simplify the problem, we'll first try to identify which messages, which packets are containing the response. 171 00:17:22,980 --> 00:17:27,440 So, to simplify it, let's try to find the start and the end. 172 00:17:28,160 --> 00:17:39,120 So, again, we can analyze the bandwidth patterns and we found out that at the beginning, at the end of the response, we saw, uh, bumps, like increases in the packet sizes. 173 00:17:39,160 --> 00:17:49,500 That's because at the beginning, you have this, all of those handshakes and establishing of the new channel and at the end, you have those, uh, communication of the end of the response. 174 00:17:49,500 --> 00:17:53,840 So, you have those increases and we can basically find the start and the end. 175 00:17:54,640 --> 00:18:00,920 Between those two points, the start and the end, we'll try to search for this incremental pattern, the red line that you see. 176 00:18:02,920 --> 00:18:10,460 The packets that follow this trend contain our tokens, but sometimes we have packets that don't follow this trend. 177 00:18:10,460 --> 00:18:14,360 Those are sometimes control packets that do not have our tokens. 178 00:18:14,360 --> 00:18:28,000 So, we'll filter those out and we will be left after that filtering with a nice and smooth incremental pattern from which we can extract our token links by calculating the delta as Israel said. 179 00:18:28,580 --> 00:18:35,800 So, it sounds pretty simple, and some would say even easy, and too good to be true. 180 00:18:35,940 --> 00:18:38,740 And in reality, it's really the case. 181 00:18:38,740 --> 00:18:40,680 So, we have more challenges. 182 00:18:41,180 --> 00:18:48,460 The first challenge is message size limits and the second one is message buffering, uh, that will cause message groupings. 183 00:18:48,660 --> 00:18:50,420 So, let's talk about that. 184 00:18:50,880 --> 00:18:52,400 Message size limits. 185 00:18:52,400 --> 00:18:56,880 In the internet, we have this thing called MTU, Maximum Transmission Units. 186 00:18:56,880 --> 00:19:04,900 Basically, a maximum size that the packet can have and if we go above this value, we, we can be fragmented on the IP layer. 187 00:19:05,180 --> 00:19:13,780 And what we found is JGPT over QUIC has even a lower maximum size of 1,200 bytes. 188 00:19:14,320 --> 00:19:18,480 And as you remember, JGPT is accumulating its tokens. 189 00:19:18,480 --> 00:19:21,940 So, at certain point, it will reach this maximum size. 190 00:19:21,940 --> 00:19:27,160 So, what will happen is basically that the payload will overflow to the next packet. 191 00:19:27,160 --> 00:19:32,920 So now, we have two packets that are sending this token because our payload is just too big. 192 00:19:33,040 --> 00:19:37,280 And what will happen is basically the sort of pattern that you see now. 193 00:19:37,460 --> 00:19:46,840 And also, as the conversation grows and goes deeper and deeper and makes it more and more long, we basically can also overflow to the third and fourth and fifth packet. 194 00:19:46,960 --> 00:19:52,540 And at the filtering phase, we'll need to account for that because we don't want to throw those packets. 195 00:19:52,540 --> 00:19:54,360 They contain our tokens. 196 00:19:56,240 --> 00:20:04,300 Another challenge is that the business of the network will cause basically buffering that will cause our groupings. 197 00:20:04,300 --> 00:20:05,400 What does it mean? 198 00:20:05,400 --> 00:20:18,960 So, when the network is busy and lots of clients are connecting to the assistant servers and many chat with JGPT, what happens is that the servers tend to buffer their responses. 199 00:20:19,280 --> 00:20:30,660 And what it looks for the user is that basically he has a small freezes that he sees and for us, what it looks like is that some packets will contain more than one token. 200 00:20:30,660 --> 00:20:32,320 More than one new token. 201 00:20:32,620 --> 00:20:46,920 So, basically this new packet will be double the size of the original trend and what we can infer from that size is the size, is the sum of those tokens that are contained in the packets. 202 00:20:46,920 --> 00:20:51,680 But what we cannot infer is the size of each individual token. 203 00:20:52,320 --> 00:20:58,400 And this problem will be overcome in the next phase which Roy will talk about. 204 00:20:58,460 --> 00:21:01,140 Uh, with exploitation with AI. 205 00:21:01,140 --> 00:21:03,980 So, we will worry about that later. 206 00:21:04,820 --> 00:21:08,160 You probably wonder how did we find all of this out? 207 00:21:08,160 --> 00:21:10,840 So, we basically reverse engineered the traffic. 208 00:21:10,840 --> 00:21:14,020 We connected as a legitimate client to the assistant servers. 209 00:21:14,020 --> 00:21:18,480 We got the SSL key, the encryption key between our computer and the assistant server. 210 00:21:18,480 --> 00:21:31,480 Uh, we plugged this into Wireshark and we were able to watch the decrypted traffic, learn it, like analyze the metadata and make rules to extract the token length sequence from the encrypted traffic. 211 00:21:32,900 --> 00:21:39,800 So, to sum this up, we captured the traffic, we filtered the traffic and then we extracted the token length sequence. 212 00:21:39,800 --> 00:21:51,180 And now we would like to translate those token length sequence to plain text English and that's what Roy will talk about next in the next part, exploitation with AI. 213 00:21:54,390 --> 00:21:55,510 All right. 214 00:21:55,510 --> 00:21:56,830 Thank you Daniel. 215 00:21:57,010 --> 00:22:02,110 Um, let's indeed talk about how to exploit the side channel using a machine learning. 216 00:22:02,110 --> 00:22:04,870 But don't worry, I'm not a typical machine learning guy. 217 00:22:04,870 --> 00:22:06,190 We'll keep it simple. 218 00:22:06,450 --> 00:22:12,190 So, the first step in training a machine learning model is to basically gather a data set. 219 00:22:12,190 --> 00:22:16,350 We need to have a data set which will contain inputs and outputs. 220 00:22:16,570 --> 00:22:22,290 Then we train the model by feeding him examples of the inputs and what the outputs should look like. 221 00:22:22,290 --> 00:22:24,950 Training an LLM is no different. 222 00:22:25,810 --> 00:22:30,370 So, in our case, the attacker will first gather a huge corpus of text. 223 00:22:30,710 --> 00:22:35,990 He will transform the text into token length sequences and then pass them to the model. 224 00:22:36,130 --> 00:22:42,430 We hope that the outputs of the model, if not exact, will have the same similar semantic meaning. 225 00:22:43,070 --> 00:22:43,710 All right. 226 00:22:43,710 --> 00:22:47,990 So, now begs the question, how do you, how do you even use the model? 227 00:22:49,070 --> 00:22:57,730 When a, um, LLM output you, uh, gives you a response and outputs, each time you get it a bit differently. 228 00:22:58,150 --> 00:23:02,090 As Israel said, each time with the output you get a confidence score. 229 00:23:02,090 --> 00:23:08,930 Then you can basically, uh, prompt the model many times and saw the outputs based on the confidence score. 230 00:23:08,930 --> 00:23:16,370 And most often, the most confident output will have, um, will be the closest to the real thing. 231 00:23:16,370 --> 00:23:20,490 So, that sounds really simple and, uh, fun and that's what we did. 232 00:23:20,490 --> 00:23:30,890 We took the AI system response, transformed it into token length sequence, passed it to our trained, uh, model and it failed miserably. 233 00:23:31,070 --> 00:23:35,450 Well, the problem was too hard, even for an LLM. 234 00:23:35,450 --> 00:23:49,350 But we still had a glimpse of hope because although the semantic meaning, uh, similarity was nowhere, uh, to be found, the model still learned the high level structures such as list structure. 235 00:23:49,870 --> 00:23:54,010 So, we started to look around on ways to improve our approach. 236 00:23:54,430 --> 00:24:00,330 Um, we noticed a really interesting phenomena about AI system responses. 237 00:24:00,330 --> 00:24:05,730 The first sentence almost always holds the essence of the entire response. 238 00:24:05,730 --> 00:24:10,150 The first sentence is like a, an introduction to the coming paragraph. 239 00:24:11,130 --> 00:24:18,890 Learning from history, we took the hard problem and divided it into smaller problems to deal with each at the time. 240 00:24:19,370 --> 00:24:31,610 Because, uh, the first sentence is really unique, we first tackled it and tried to solve it and then all of the others because if you think about it, if we crack down the first sentence, we will win. 241 00:24:31,610 --> 00:24:36,770 We could, we could build upon that with a preserved topic in mind. 242 00:24:37,170 --> 00:24:38,830 But, wait, hold on. 243 00:24:38,830 --> 00:24:40,670 Isn't the traffic encrypted? 244 00:24:40,670 --> 00:24:43,230 What do we even have in the end? 245 00:24:43,230 --> 00:24:44,530 Token length sequence. 246 00:24:44,530 --> 00:24:48,690 How are we able to divide it into segments of sentences? 247 00:24:49,070 --> 00:24:54,930 Well, most tokenizers encode punctuation marks as a separate token. 248 00:24:54,930 --> 00:25:00,250 This means that almost always a token length of one is a punctuation mark. 249 00:25:00,250 --> 00:25:06,370 So, this means we can basically look at the token length sequence, search for one and divide it. 250 00:25:06,850 --> 00:25:09,950 But, um, we want to avoid false positives. 251 00:25:09,950 --> 00:25:14,030 For example, too short of a sentence because comma at the start. 252 00:25:14,130 --> 00:25:20,510 So, we apply the simple heuristic that uh, basically says we won't divide it if the sentence is too short. 253 00:25:21,030 --> 00:25:31,050 Alright, with this idea, because the first sentence is really unique, we train the model only on first sentences, meaning it's data set contain only first sentences. 254 00:25:31,950 --> 00:25:41,370 And we train another model for all of the other sentences to further help the second model try to figure out what is the right topic. 255 00:25:41,370 --> 00:25:49,990 We took the output which was generated by the first sentence and then passed it as part of the input to the next model. 256 00:25:50,270 --> 00:26:02,010 And then, uh, with other generations, we did the same and, uh, just like that, we, we have preserved the context in mind when generating the entire paragraph one by one. 257 00:26:02,810 --> 00:26:10,330 Alright, um, this approach is nice and we got 10 percent attack success rate, but it's not enough. 258 00:26:10,330 --> 00:26:12,470 Uh, we are at DEF CON after all. 259 00:26:12,490 --> 00:26:16,790 So, uh, there is one more thing that could help us improve. 260 00:26:17,970 --> 00:26:23,310 As we said, AI assistant responses are not just random Wikipedia pages. 261 00:26:23,310 --> 00:26:24,870 They are not random text. 262 00:26:24,990 --> 00:26:30,530 This, uh, they have predictive, predictable style and low response diversity. 263 00:26:30,530 --> 00:26:37,410 This means that we can use it to our advantage and relate to this problem as a known plain text attack. 264 00:26:39,610 --> 00:26:42,250 AI assistant responses have predictable style. 265 00:26:42,250 --> 00:26:47,330 They have warnings, templates, they follow safeguards and structure. 266 00:26:47,390 --> 00:26:58,250 This means that if we will train a model on those responses, the model will be able to learn those patterns and it will make our life easier. 267 00:26:58,930 --> 00:27:07,450 Also, as we can see here, many different prompts that talk about the same rather topic will have the same response. 268 00:27:07,930 --> 00:27:16,490 This means that, um, a model which is trained on AI system responses will be able to generalize to many different prompts. 269 00:27:16,710 --> 00:27:24,810 So, to summarize, the entire process is first collecting a data set of prompts. 270 00:27:24,810 --> 00:27:29,890 Then we will pass it to our target model like JGPT-4. 271 00:27:30,050 --> 00:27:37,690 Then we will collect the responses, transform them into token length sequences and train the model as we saw. 272 00:27:38,390 --> 00:27:42,910 This combined approach yields a huge boost of performance. 273 00:27:43,510 --> 00:27:59,690 This plot compares, uh, the, uh, performance of the combined approach, the green one, the blue one which is, uh, training the model on random text and the red one which is plainly asking JGPT please help me solve this side channel. 274 00:27:59,890 --> 00:28:10,350 And we can see, uh, that all of the examples to the right of the vertical line are considered successes and the green one was much better than all of the other approaches. 275 00:28:10,730 --> 00:28:19,150 And the numbers, we, as, as we said before, we got about 55 percent attack success rate on first sentences and 38 on entire paragraphs. 276 00:28:19,150 --> 00:28:23,690 We have also encountered a really interesting phenomena. 277 00:28:24,030 --> 00:28:28,570 Different topics were susceptible, uh, than others. 278 00:28:28,570 --> 00:28:37,410 In our example, uh, mental health and financial status were much more susceptible than, for example, sex, sexual health. 279 00:28:38,450 --> 00:28:44,550 This is mainly to the fact that those topics were much more common in the data set. 280 00:28:44,550 --> 00:28:53,570 This means that we've, we've, if we have an attacker with a specific goal in mind, he can train his own model on those subtopics and get better results. 281 00:28:53,570 --> 00:28:59,150 All right, so what about the network noise and traffic and all of the stuff Daniel said? 282 00:28:59,750 --> 00:29:05,170 Um, when we have high network, uh, traffic, we get grouping and buffering. 283 00:29:05,170 --> 00:29:09,110 So we first wanted to evaluate how much groupings were actually there. 284 00:29:09,110 --> 00:29:19,410 We ran a 24-hour experiment against open AI JGPT and we measured the amount of groupings we got in each hour of the day. 285 00:29:19,450 --> 00:29:25,130 As expected, in the day, there were much more groupings than in the night. 286 00:29:25,130 --> 00:29:27,910 But as we will see, it is manageable. 287 00:29:28,610 --> 00:29:37,810 To solve this challenge, we took our training process and our data set and just applied random groupings on the token length sequences. 288 00:29:38,270 --> 00:29:49,570 Then, as we can see in the first row, we still got 35 percent attack success rate on first sentences, which is really nice because the, it is way more challenging. 289 00:29:49,670 --> 00:30:02,910 Also, when looking around on different, uh, susceptible vendors, we found out that open AI API transmitted their messages as paired tokens, meaning each packet holded two tokens. 290 00:30:03,310 --> 00:30:11,410 Okay, this is more challenging, but we wanted to evaluate if we can break it and get more reward. 291 00:30:11,750 --> 00:30:25,070 So, uh, we took our training process and applied, uh, random, uh, not random, sorry, and we applied pairing, uh, pairing on the tokens, meaning we took the token lengths and just paired them. 292 00:30:25,230 --> 00:30:30,510 We still got 17 percent attack success rate on first sentences with this approach. 293 00:30:31,010 --> 00:30:37,470 Alright, so, after I've yucked you out with theory, let's talk business. 294 00:30:38,190 --> 00:30:44,910 So, um, as we all know, training an LLM from scratch is really hard. 295 00:30:44,910 --> 00:30:50,870 It takes, uh, months of computer time and millions of dollars in hardware and energy. 296 00:30:50,910 --> 00:30:53,390 We didn't have to go through such hassle. 297 00:30:53,390 --> 00:31:02,230 Rather, we used a common technique called fine tuning, which means we took a trained model and further trained it on, on our own translation task. 298 00:31:02,930 --> 00:31:06,710 We took a model called T5, which was trained... 299 00:31:06,710 --> 00:31:08,070 Pause, pause for a second. 300 00:31:08,070 --> 00:31:08,610 We need to do 301 00:31:13,460 --> 00:31:15,560 a small disruption, I'm sorry. 302 00:31:16,760 --> 00:31:18,960 Attention dev pod hackers. 303 00:31:19,100 --> 00:31:21,940 Halls 2 and 4 are now closed. 304 00:31:21,940 --> 00:31:24,880 Heavy equipment will begin operations soon. 305 00:31:24,980 --> 00:31:31,220 All humans need to vacate the premises before they contract and are forced to become goons for eternity. 306 00:31:31,500 --> 00:31:34,320 Villages and contests have now closed. 307 00:31:34,400 --> 00:31:37,560 All hacking of the planet must be done elsewhere. 308 00:31:37,760 --> 00:31:42,480 Please join us for the contest closing ceremonies in chapters 1 and 2. 309 00:31:42,900 --> 00:31:45,020 Attention dev pod hackers. 310 00:31:45,120 --> 00:31:49,900 You must vacate the hall before you become impaled by a forklift. 311 00:31:50,080 --> 00:31:52,520 Thank you and have a good day. 312 00:31:54,000 --> 00:31:56,480 Okay, good day to, uh, to you too. 313 00:31:56,480 --> 00:31:57,000 Yeah. 314 00:31:57,080 --> 00:32:08,400 So, let's recap, uh, our model was based on the T5 model, which is, uh, trained by Google and this is, it is, uh, public, publicly available. 315 00:32:08,700 --> 00:32:13,300 Uh, we also didn't have to go to the hassle of gathering our own data set. 316 00:32:13,300 --> 00:32:18,960 Rather, we used an open source one called UltraChat, which basically contains dialogues with GPT-4. 317 00:32:19,360 --> 00:32:30,780 We also used Hugging Face as our framework, uh, trainer, trainer, which was, which makes the technicalities of training a model much easier, even for a guy like me. 318 00:32:30,780 --> 00:32:45,080 Um, okay, our, uh, model was trained for, uh, two days of compute time and if we have an attacker with, uh, no GPA, GPU in hand, he can use Azure, for example, for only $200, which is fairly affordable. 319 00:32:45,360 --> 00:32:47,640 So, let's see some demos. 320 00:32:48,080 --> 00:32:55,420 Um, in this case, um, we have, uh, the victim, Quarry, uh, Microsoft Copilot. 321 00:32:55,940 --> 00:33:04,800 He asked the random question of what are the some, some of the latest development in machine learning and AI that could revolutionize the health industry. 322 00:33:04,800 --> 00:33:08,840 Besides him, the attacker, he's dropped the entire traffic. 323 00:33:09,080 --> 00:33:18,440 He collects, uh, traffic using Wireshark and after collecting for a bit of time, um, he will try to filter the traffic. 324 00:33:18,440 --> 00:33:23,480 As Daniel said, one of the common techniques to filter is based on the IP. 325 00:33:23,980 --> 00:33:27,640 So, the attacker does just that. 326 00:33:28,780 --> 00:33:34,920 And, uh, in this case, uh, the attacker manually, uh, figures out where the start is. 327 00:33:34,920 --> 00:33:40,700 Well, of course, the traffic is encrypted, so, uh, you just need to do it by hand and by eye. 328 00:33:40,720 --> 00:33:51,900 And after figuring out where the start is, the attacker will put inside the tool the token lengths, uh, so, excuse me, the packet, uh, sizes. 329 00:33:51,900 --> 00:33:59,640 Then the tool will calculate the deltas between the packet, uh, sizes and we will have a token length sequence. 330 00:33:59,720 --> 00:34:05,500 Then basically, the tool will pass it to the model to try generate the ground truth. 331 00:34:05,700 --> 00:34:23,160 And as we will see in a bit, um, hold on, yes, we got, we got the token lengths and now the model thinks, actually really fast and, alright, so, uh, it will be, it will zoom out in a bit. 332 00:34:23,160 --> 00:34:26,140 We basically got the same rather, uh, topic. 333 00:34:26,140 --> 00:34:33,060 Several recent advancements in machine learning and artificial intelligence, that could be a game changing tool, yada, yada. 334 00:34:33,760 --> 00:34:41,640 Alright, so, for the public use, we've, uh, deployed a full plug and play tool on GitHub called GPT Keylogger. 335 00:34:42,480 --> 00:34:48,560 Um, the tool, uh, has, has, uh, two main models, the attacker model and the trainer model. 336 00:34:48,560 --> 00:34:50,560 I will elaborate them in a bit. 337 00:34:50,700 --> 00:34:59,760 And, uh, our model is also publicly available, uh, and it is trained on GPT4 responses from February 2024. 338 00:35:00,540 --> 00:35:14,100 The first model, the attack model, is for you guys, uh, to try attack different vendors, um, it can receive as input packet lengths, as we saw in the demo, token lengths, which is straightforward, and the original text. 339 00:35:14,100 --> 00:35:21,620 The tool will basically, uh, tokenize the text, calculate the token length sequence, and, uh, try to predict. 340 00:35:22,280 --> 00:35:25,100 And, uh, you can use it with this simple command. 341 00:35:26,140 --> 00:35:37,920 If you want to target a different vendor, with a different backend LLM, you should train your own model, uh, because every LLM works differently and our model is based on GPT4 responses. 342 00:35:37,920 --> 00:35:43,220 So, if you want to, uh, target a model, uh, like Llama, you should train. 343 00:35:43,240 --> 00:35:49,000 And, uh, we offer this for you to make life much more easier, uh, with those commands. 344 00:35:49,060 --> 00:35:55,420 Uh, also the configuration file is also available in the GitHub, uh, page, uh, which is nice. 345 00:35:55,500 --> 00:35:58,400 And, uh, all right, so let's talk some defenses. 346 00:35:59,420 --> 00:36:05,600 We have contacted all of the vendors that we found vulnerable up to, uh, February 8th this year. 347 00:36:05,680 --> 00:36:13,160 Uh, all of the major vendors were really responsive and they patched the problem really quickly, uh, until March 1st. 348 00:36:13,160 --> 00:36:21,660 And we come, uh, we came public with this vulnerability on, um, on Ars Technica on 4th, uh, on the 14th of March this year. 349 00:36:22,240 --> 00:36:29,660 Out of the vendors, those five had bug bounty programs, which awarded us a small reward, which was really nice. 350 00:36:30,060 --> 00:36:32,080 Um, all right. 351 00:36:32,080 --> 00:36:39,160 So, although this side channel is really difficult to exploit, as we saw, the defenses are really easy to make. 352 00:36:39,160 --> 00:36:46,820 After, uh, consulting with the engineers on the, of the different vendors, we came up with three solutions. 353 00:36:47,340 --> 00:36:55,020 Random padding to the packets, padding to the nearest value, like nearest 100 size, or applying more buffering. 354 00:36:55,360 --> 00:37:00,340 Here is the mapping between the different vendors and the deployed defenses. 355 00:37:00,900 --> 00:37:14,140 When diving a bit deeper, OpenAI basically did padding to the nearest, uh, to the closest 32 value by adding a pad field on the transmitted JSON. 356 00:37:14,340 --> 00:37:17,820 And as we can see on Wireshark, the size is a line. 357 00:37:18,580 --> 00:37:26,700 And CloudFlare, for example, uh, deployed random pa- padding and, uh, we can see that the sizes are all messed up. 358 00:37:27,100 --> 00:37:28,360 All right. 359 00:37:28,580 --> 00:37:28,960 Let's run the demo. 360 00:37:28,980 --> 00:37:30,180 Let's wrap things up. 361 00:37:30,740 --> 00:37:32,920 So, what did we discover? 362 00:37:32,920 --> 00:37:37,740 We've identified a new side channel vulnerability based on token lengths. 363 00:37:37,760 --> 00:37:47,440 This is significant because, as we saw, it impacts multiple vendors expo- exposing sensitive information through their AI systems. 364 00:37:48,040 --> 00:37:57,280 This work, uh, has shown how to break a side channel use, uh, with generative AI and it is the first work to do so. 365 00:37:57,920 --> 00:38:07,140 While some vendors have patched this vulnerability, there is still a real concern about how new AI services will handle this issue. 366 00:38:08,260 --> 00:38:10,580 Now on to the key takeaways. 367 00:38:10,580 --> 00:38:15,120 First off, it is crucial to use encryption schemes correctly. 368 00:38:15,220 --> 00:38:24,980 This has repeated itself throughout history, time and after time, uh, and, uh, yeah, leading to multiple side channels and cracking of encryptions. 369 00:38:25,020 --> 00:38:33,780 Similarly, in modern times, even subtle details like token lengths can leak sensitive data if not properly protected. 370 00:38:33,980 --> 00:38:37,000 AI services are no exception to this rule. 371 00:38:37,000 --> 00:38:43,840 They must be designed and implemented up to the highest security measures as any other software domains. 372 00:38:44,240 --> 00:38:46,540 Remember, AI is your friend. 373 00:38:46,540 --> 00:38:50,600 It is a powerful tool both for offensive and defensive applications. 374 00:38:50,600 --> 00:38:55,280 We should harness its potential to identify and mitigate vulnerabilities. 375 00:38:55,280 --> 00:39:00,080 What seemed impossible is now possible thanks to advancements in AI. 376 00:39:00,620 --> 00:39:04,560 Finally, our discovery raises an important question. 377 00:39:04,560 --> 00:39:07,460 What other side channels are vulnerable? 378 00:39:07,460 --> 00:39:11,840 We encourage the community to explore and secure these potential weak points. 379 00:39:11,840 --> 00:39:19,100 To sum it up, we have joined throughout the process of identifying, exploiting and defending against this new side channel. 380 00:39:19,100 --> 00:39:27,680 This research highlights the importance of considering even the smallest details in data transmission within AI systems. 381 00:39:27,680 --> 00:39:36,580 I hope this inspires you to think creatively about both offensive and defensive capabilities of AI in cyber security. 382 00:39:37,100 --> 00:39:39,780 Thank you all for your attention. 383 00:39:39,780 --> 00:39:45,860 Uh, check out our tool GPTKeylogger and our labs page when we update on more research. 384 00:39:45,860 --> 00:39:51,500 Stay secure, stay curious and enjoy the rest short bit of DEF CON. 385 00:39:51,500 --> 00:39:52,160 Thank you.