[00:00.680 --> 00:07.260] Hello DEF CON! Thank you so much for being here. It's like the second to last talk. [00:07.260 --> 00:11.820] It's a great turnout. I'm very honored to be here. My name is Yusro Lomarski. [00:11.820 --> 00:16.980] I'm a Zuckerman Faculty Scholar at Ben-Gurion University and head of the Offensive AI Research [00:16.980 --> 00:22.440] Lab there. And with me here today are my brilliant graduate students who will be coming up on stage [00:22.440 --> 00:29.000] also to present. They did all the hard work. There's Daniel Eisenstein and Roy Weiss in [00:29.000 --> 00:35.120] collaboration with Guy Amit, who couldn't make it. Okay, so today we're going to talk about [00:35.760 --> 00:40.380] a new side channel attack against AI assistants that enables adversaries [00:40.380 --> 00:45.920] to read encrypted response traffic, such as responses from ChatGPT. [00:48.260 --> 00:52.860] Okay, so I'm not going to go into, you know, what are AI assistants. You guys all know this [00:52.860 --> 00:58.980] very well. You have OpenAI's ChatGPT, you have Google's Gemini, you have Microsoft Copilot, [00:58.980 --> 01:04.680] the list goes on and on. And these AI assistants are integrated throughout industry in all [01:04.680 --> 01:09.860] different kinds of use cases. What's more interesting to me is the use cases of the [01:09.860 --> 01:15.520] personal level, right? A lot of users are using these AI assistants, such as ChatGPT, to get [01:15.520 --> 01:21.160] personal advice. So, for example, you may ask it some medical questions like, [01:21.160 --> 01:25.720] why do I have a rash on my back, right? And ChatGPT will get back to you and say, [01:25.720 --> 01:30.680] I'm sorry to hear you have a rash on your back. Let me give some tips how to take care of that. [01:31.020 --> 01:36.380] Or maybe you may ask ChatGPT for some relationship advice. What are the signs [01:36.380 --> 01:40.940] I'm having? My wife is having an affair, right? And get some good tips on there. [01:41.840 --> 01:45.580] Or maybe you're getting into hacking and you're going to ask ChatGPT how to get into your [01:45.580 --> 01:51.780] neighbor's Wi-Fi, right? Lots of good use cases. Or my favorite, a lot of people are using ChatGPT [01:52.340 --> 01:58.200] to edit their documents. They'll take whole documents or emails, dump it into ChatGPT and [01:58.200 --> 02:02.960] say, hey, make it better. Or, you know, finish this paragraph or what have you. And these are [02:02.960 --> 02:07.740] all very good and legitimate use cases. They're actually very productive for our society to help [02:07.740 --> 02:13.720] us, you know, progress and automate things. But the problem is that what happens if these [02:13.720 --> 02:21.760] chats aren't actually private? What happens if somebody could read these chats beyond, [02:21.760 --> 02:31.000] right? So this would be a huge breach in privacy. So in truth, we know they're encrypted, right? So [02:31.000 --> 02:35.920] you know, OpenAI is encrypting all the traffic going between the client and the servers. [02:36.220 --> 02:40.020] But is that enough? You know, maybe a little foreshadowing. [02:41.080 --> 02:46.120] So let me go back to the beginning of this story here. So several months ago, you know, [02:46.120 --> 02:51.540] late at night, I was using ChatGPT for very important stuff, such as trying to figure out [02:51.760 --> 02:58.740] what would the world be like if every country had ninjas, but Japan had the worst ninjas, [02:58.740 --> 03:05.900] right? So as I'm looking at the text glide across the screen and looking at this very insightful [03:05.900 --> 03:13.320] and thoughtful response, it kind of hits me. Wait a second. Could it possibly be that OpenAI [03:13.320 --> 03:20.700] is sending every single word as a separate packet? And could it be that every single packet has no [03:20.700 --> 03:30.120] padding so I can count the number of characters in each of these words? So I open up Wireshark [03:30.120 --> 03:36.440] and sure enough, what do I see? For every single word that's being sent from the AI assistant, [03:36.440 --> 03:42.120] I see another packet and the size of that packet increases. And if I take the delta between these [03:42.120 --> 03:48.100] packets, I know exactly how many characters in every single word. And I could use this, [03:48.100 --> 03:57.020] for example, to try and guess what those words are and potentially learn or identify what is [03:57.020 --> 04:02.380] being said in those responses. Now, before I go on to explain how we figured out what those words [04:02.380 --> 04:08.460] are, I need to take a little bit of a technical aside and clarify something. That what ChatGPT [04:08.460 --> 04:13.220] and all these different AI services are sending are not exactly words, but rather something called [04:13.220 --> 04:21.760] tokens. What tokens are, are basically the basic building block of AI language models. When you [04:21.760 --> 04:28.240] give text to a language model, it's going to first parse it down into these tokens and then each [04:28.240 --> 04:34.120] token goes to the model and the model generates text using these tokens as well. So in general, [04:34.120 --> 04:39.300] these tokens more or less correlate directly to words, but there are some cases where these [04:39.300 --> 04:44.900] tokens won't. So for example here, Lama's tokenizer will split the word cream into two separate [04:44.900 --> 04:51.940] tokens. But what's important to note is that although there's not a direct correlation from [04:51.940 --> 04:57.280] token to word, these tokenizers are public information. Doesn't matter if it's open AIs, [04:57.280 --> 05:02.460] if it's metas, you can go through the entire list, you can get the tokenizer and you can learn the [05:02.460 --> 05:07.180] exact mappings. So for all intents and purposes, these are words and we're trying to guess what [05:07.180 --> 05:17.660] these words are. So what's the threat model? So the victim types some private chat into his web [05:17.660 --> 05:24.520] browser, hits enter, and that encrypted text goes across the wire. Now we're not gonna be able to [05:24.520 --> 05:29.240] figure out what that prompt was because that's just one big block of encrypted text. But what [05:29.240 --> 05:35.560] happens after that is the AI assistant starts responding token by token by token back and we [05:35.560 --> 05:39.760] can count exactly how many characters are in each of these tokens. And once again, if we can guess [05:39.760 --> 05:47.540] what those words are, then boom, we know exactly what the response was. So why do we care? I mean, [05:47.540 --> 05:52.640] I can't figure out what the prompt was, I can't figure out what the exact question was, but [05:53.460 --> 06:00.160] it's, it turns out that a lot of information is leaked by the response itself. So imagine I read [06:00.160 --> 06:06.060] one of the responses off the network that somebody was receiving and it said, I'm sorry to hear that [06:06.060 --> 06:12.340] you have a rash. Right? I think it's pretty clear we know exactly what that user was asking for. [06:13.740 --> 06:19.180] So basically this boils down to a big wheel of fortune game, right, where I have to start guessing [06:19.180 --> 06:24.860] what those words are. And this can be a particularly challenging problem because, you know, [06:24.860 --> 06:29.760] there's many different ways you can solve this puzzle. But it gets even more challenging when [06:29.760 --> 06:34.080] you think about real responses from these AI assistants, right? They're not just one sentence, [06:34.080 --> 06:39.200] they're typically whole paragraphs with hundreds of words. So how do we solve this problem? So we [06:39.200 --> 06:45.940] turn to the age-old solution, which is AI, and we look towards a task which is very popular, [06:45.940 --> 06:51.540] which is language translation, right? But here, instead of going from a language such as [06:51.540 --> 06:59.380] French to English, we're going to go from token length sequences to plain text English. [06:59.760 --> 07:05.820] And what we'll do is we'll train an AI with lots and lots of examples of these token lengths to [07:05.820 --> 07:13.180] real English, and we'll be able to translate them very effectively. In our case, we used a [07:13.180 --> 07:19.600] state-of-the-art model called a large language model, or LLM, and this is the exact same technology [07:19.600 --> 07:24.700] that's being used in AI assistants such as ChatGPT. I'm not going to go too much into detail how it [07:24.700 --> 07:30.200] works, leave that for other YouTube videos. All right, so what's the entire attack end-to-end, [07:30.200 --> 07:34.480] how does it look like? So the attacker is looking through the network, looking for responses from a [07:34.480 --> 07:40.020] particular AI service such as ChatGPT, sees the traffic going across the network, and records [07:40.020 --> 07:46.680] down the token length sequence from those packets. He then passes that token length sequence to his [07:46.680 --> 07:50.440] trained model, which has seen lots and lots of examples, and it predicts what it thinks [07:50.440 --> 07:58.680] the original plain text was. So there's something else we can do to make this even better. So if we [07:58.680 --> 08:04.080] just, you know, give our model random arbitrary text, it's going to do so-so. It's not going to [08:04.080 --> 08:08.100] do so great, because as I said, you know, there's lots of ways we can solve that puzzle. But as it [08:08.100 --> 08:13.680] turns out, AI assistants have a very specific style of speaking, right? They're not just going to [08:13.680 --> 08:18.340] respond with some arbitrary sentence, they typically start with something like, oh sure, yeah, I can [08:18.340 --> 08:24.040] give you a recipe for tomato soup, right? So there's a certain style that's intrinsically in those [08:24.040 --> 08:30.720] responses. So what I can do is if I'm, let's say I'm trying to target Microsoft Copilot, I can send [08:30.720 --> 08:37.360] lots and lots of prompts to Microsoft Copilot and build a huge data set of responses. And those [08:37.360 --> 08:44.600] responses capture the style of that particular AI service. And once I have that, I can fine-tune my [08:44.600 --> 08:49.960] model on that, and I'll get much, much better results. And as it turns out, I can get something [08:49.960 --> 08:56.820] around 55% attack success rate. So more than half of the responses that we see in the encrypted [08:56.820 --> 09:04.820] traffic, we can decipher. Okay, so let's look at some examples. So on the screen here is the first [09:04.820 --> 09:10.280] sentences that we're trying to decipher. The first line is the original text that is being sent from [09:10.280 --> 09:15.700] the AI assistant. And the second line is our prediction. So sometimes you can see in the first [09:15.700 --> 09:21.690] example there, we get it right on the first go. And sometimes we make some mistakes. So for example, [09:22.100 --> 09:28.520] in the bottom there, the original response was, yes, there are several important legal considerations [09:29.080 --> 09:35.980] that couples should be aware of when considering a divorce. And then if we look at the inferred [09:35.980 --> 09:43.140] response, we got, yes, there are several potential legal considerations that someone should be aware [09:43.140 --> 09:48.360] of when considering a divorce. So even though we had some mistakes in the words, we're still, it's [09:48.360 --> 09:55.420] very, very clear what was the topic that the, uh, user was trying to ask the AI assistant. [09:56.800 --> 10:03.320] And then if we move over to entire paragraphs, we get something around a 35% attack success rate, [10:03.320 --> 10:10.120] which is also very, uh, significant considering how hard it is to try and guess what all these words are. [10:10.980 --> 10:15.200] And since we're using AI models, this isn't a perfect science. You know, we're using a lot of [10:15.200 --> 10:21.300] heuristics here, so we sometimes get it wrong. So here's some fails. So in the, uh, ground truth, it [10:21.300 --> 10:24.780] was something like, I would like to suggest some following strategies for team leaders to balance [10:24.780 --> 10:31.240] the needs of individual team members with the needs of the team as a whole. And we inferred it as, [10:31.240 --> 10:37.080] I would suggest the following strategies, so far so good, but then for film studios to balance [10:37.080 --> 10:41.920] the needs of production, so on and so forth, something is completely unrelated. And sometimes [10:41.920 --> 10:46.700] it gets even worse, right? So here's a case where the response has something to do with apple cider, [10:46.700 --> 10:52.120] and we thought it had to do with coral bleaching. Okay, so it's not a perfect science, but what's [10:52.120 --> 10:56.360] interesting to note is that because we're using machine learning model, the model also gives us [10:56.500 --> 11:03.280] a confidence score. How confident it is that this prediction is correct, right? So what we can do is [11:03.280 --> 11:07.400] we can look, and we're trying to attack a particular, uh, you know, token-linked sequence that [11:07.400 --> 11:11.180] we see in the network, we can try to look at the confidence of the model and say whether or not we [11:11.180 --> 11:21.040] should trust this, uh, inference or not. All right, so how common is this vulnerability? So, uh, [11:21.040 --> 11:26.960] you know, around the time of our disclosure, or prior to our disclosure around, uh, February 2024, [11:26.960 --> 11:32.860] uh, nearly every major AI vendor out there had this vulnerability. And, uh, you know, when you [11:32.860 --> 11:38.200] start wondering why is that the case, how do they overlook the seemingly obvious side channel, [11:38.200 --> 11:43.220] and there's a few reasons that might come to mind. First, uh, you know, they might, perhaps they [11:43.220 --> 11:47.840] didn't think that token links the same as word links, so maybe there was just a simple blunder. [11:47.840 --> 11:53.060] Or maybe they thought there's no way that an adversary can guess entire paragraphs of text. [11:53.060 --> 11:57.620] That's just too hard of a problem. But what I think is more likely the case is that it has something [11:57.620 --> 12:03.380] to do with the big AI gold rush, right? There's so many industries that are jumping on the AI [12:03.380 --> 12:07.460] chatbot idea and throwing it into services willy-nilly, and they don't really think about [12:07.460 --> 12:12.300] security by design. They're saying, oh, you know, the text is encrypted, not a big deal, let's move [12:12.300 --> 12:18.260] on, right? So this is probably more likely what happened there until they, of course, patched it [12:18.260 --> 12:25.540] after the fact. So why are they even sending, you know, text to streaming or token streaming across [12:25.540 --> 12:31.480] the network? Why don't they just send it as one big batch, right? So for example, Google's Gemini [12:31.480 --> 12:36.860] does this already. When you get a response from Google Gemini, it's not sending a token, token, [12:36.860 --> 12:41.220] token, it sends it as one big block, and therefore they're not vulnerable to the side channel attack. [12:41.220 --> 12:46.040] So why aren't the other vendors doing this? So there's a simple answer for that, and the answer [12:46.040 --> 12:51.260] is that, you know, these AI models are actually incredibly complex, and it takes a lot of effort [12:51.260 --> 12:56.360] to execute them. So instead of having the user wait there for, you know, a good, you know, 30 seconds [12:56.360 --> 13:01.360] for this loading screen to go by to get their response, it makes perfect sense to send those [13:01.360 --> 13:06.620] words or tokens one at a time in real time so they can read it as it's being generated. [13:07.520 --> 13:13.420] All right, so to recap so far, what we've accomplished here is that we've discovered [13:13.880 --> 13:18.540] a novel side channel attack which we call the token length side channel, and we found it's [13:18.540 --> 13:26.620] common in LLM services all over. And we've also found a way to exploit that side channel to read [13:26.620 --> 13:33.280] the hidden information behind it directly using AI and improve that performance using a known [13:33.280 --> 13:40.520] plaintext attack. Okay, so for the rest of this talk, we're going to get down into the nitty-gritty [13:40.520 --> 13:46.500] details, and first we're going to talk about how we identified response traffic inside network [13:46.500 --> 13:52.540] traffic and how we then extract the token length sequences from there. And after that, we'll talk [13:52.660 --> 13:58.520] a little bit about how we train AI models and our specific RAI model. And finally, we'll end [13:58.520 --> 14:03.020] up with some demos, defenses, and we'll talk about some bug bounties that we got along the way. [14:03.020 --> 14:07.000] So with that, I'm going to hand it off to Daniel who's going to take it from here. [14:12.640 --> 14:19.180] Thanks Israel. So, let's jump to the nitty-gritty details. So, we will talk about how to find the [14:19.180 --> 14:28.460] side channel and how to extract the token length sequence. So, the first thing we'll have to do [14:28.460 --> 14:34.000] is to capture the traffic containing the response from the assistant. So, we'll need to be positioned [14:34.000 --> 14:40.140] between the victim and the assistant. Or, we can be in the same local network as the victim [14:40.140 --> 14:47.260] sitting in the same cafe using Wi-Fi. So, we collected a lot of traffic and not all of it [14:47.260 --> 14:53.440] containing our response data from the AI assistant. So, we'll need to filter the traffic. We can do [14:53.440 --> 14:58.480] that by filtering by the IP address of the assistant. Uh, that information can be collected [14:58.480 --> 15:05.040] by OSINT or by connecting as a legitimate client to the assistant server for two different times [15:05.160 --> 15:11.420] a day from different locations and making our own data set of those IP addresses and basically [15:11.420 --> 15:18.840] filtering by those. Also, what we can do is filter by the protocol. So, every vendor is using [15:18.840 --> 15:24.300] different protocol. For example, JGPT is using quick protocol. So, we would like to search for [15:24.300 --> 15:30.940] UDP packets that are coming from port 443. And again, every vendor is using different protocol [15:30.940 --> 15:36.040] so we'll need to account for that. And also, there is a slight problem because it will add us [15:36.040 --> 15:41.640] more complexity when we will try to extract the token length sequence because again, every [15:41.640 --> 15:50.580] protocol looks differently on the wire and it has its own metadata. So, we captured the traffic, [15:50.580 --> 15:55.440] we filtered out most of the traffic that don't contain our tokens. We have the traffic that [15:55.440 --> 16:00.560] contains the response from the assistant. Let's extract the token length sequence. [16:01.860 --> 16:07.640] So, our objective is to find the token lengths. We need to remember that the traffic is [16:07.640 --> 16:13.940] encrypted so we can't really see where are the tokens and what packets contain them. But what [16:13.940 --> 16:32.120] we can see is the bandwidth patterns. Basically, the packet sizes. Oh, I'm sorry. So, we found [16:32.120 --> 16:37.920] that there is two main ways that the vendors are using to send their tokens. The first way is [16:37.920 --> 16:44.080] base plus next token. Basically, each token is sent in a separate packet by itself. So, we can [16:44.080 --> 16:49.860] infer the size of the token by just analyzing the size of the packet. The second way is token [16:49.860 --> 16:56.280] accumulation. Basically, the tokens accumulate. We are sending each time the token with all of [16:56.280 --> 17:01.920] the tokens that were previously sent. So, the packets are increasing in size. In the next [17:01.920 --> 17:07.180] slides, we'll talk more about token accumulation because this is the way that Microsoft and [17:07.180 --> 17:15.440] OpenAI are using. So, basically, our main target was JGPT. So, we'll talk about this more. So, to [17:15.440 --> 17:21.400] simplify the problem, we'll first try to identify which messages, which packets are [17:21.400 --> 17:28.840] containing the response. So, to simplify it, let's try to find the start and the end. So, again, [17:28.840 --> 17:34.420] we can analyze the bandwidth patterns and we found out that at the beginning, at the end of [17:34.420 --> 17:40.200] the response, we saw, uh, bumps, like increases in the packet sizes. That's because at the [17:40.200 --> 17:44.820] beginning, you have this, all of those handshakes and establishing of the new channel and at [17:44.820 --> 17:50.380] the end, you have those, uh, communication of the end of the response. So, you have those [17:50.380 --> 17:56.260] increases and we can basically find the start and the end. Between those two points, the start [17:56.260 --> 18:03.360] and the end, we'll try to search for this incremental pattern, the red line that you see. The [18:03.360 --> 18:09.300] packets that follow this trend contain our tokens, but sometimes we have packets that don't [18:09.300 --> 18:14.720] follow this trend. Those are sometimes control packets that do not have our tokens. So, we'll [18:14.720 --> 18:20.680] filter those out and we will be left after that filtering with a nice and smooth incremental [18:20.680 --> 18:30.500] pattern from which we can extract our token links by calculating the delta as Israel said. So, it [18:30.500 --> 18:37.540] sounds pretty simple, and some would say even easy, and too good to be true. And in reality, [18:37.540 --> 18:43.340] it's really the case. So, we have more challenges. The first challenge is message size [18:43.340 --> 18:49.000] limits and the second one is message buffering, uh, that will cause message groupings. So, [18:49.000 --> 18:55.260] let's talk about that. Message size limits. In the internet, we have this thing called MTU, [18:55.260 --> 19:00.440] Maximum Transmission Units. Basically, a maximum size that the packet can have and if we go [19:00.440 --> 19:07.640] above this value, we, we can be fragmented on the IP layer. And what we found is JGPT over [19:07.640 --> 19:17.660] QUIC has even a lower maximum size of 1,200 bytes. And as you remember, JGPT is accumulating its [19:17.660 --> 19:23.720] tokens. So, at certain point, it will reach this maximum size. So, what will happen is basically [19:23.720 --> 19:29.760] that the payload will overflow to the next packet. So now, we have two packets that are sending [19:29.760 --> 19:35.300] this token because our payload is just too big. And what will happen is basically the sort of [19:35.300 --> 19:41.340] pattern that you see now. And also, as the conversation grows and goes deeper and deeper and [19:41.340 --> 19:46.000] makes it more and more long, we basically can also overflow to the third and fourth and fifth [19:46.000 --> 19:51.620] packet. And at the filtering phase, we'll need to account for that because we don't want to [19:51.620 --> 19:59.120] throw those packets. They contain our tokens. Another challenge is that the business of the [19:59.120 --> 20:06.520] network will cause basically buffering that will cause our groupings. What does it mean? So, [20:06.520 --> 20:12.680] when the network is busy and lots of clients are connecting to the assistant servers and many [20:12.680 --> 20:20.040] chat with JGPT, what happens is that the servers tend to buffer their responses. And what it [20:20.040 --> 20:26.780] looks for the user is that basically he has a small freezes that he sees and for us, what it [20:26.780 --> 20:33.640] looks like is that some packets will contain more than one token. More than one new token. So, [20:33.640 --> 20:40.020] basically this new packet will be double the size of the original trend and what we can infer [20:40.020 --> 20:47.120] from that size is the size, is the sum of those tokens that are contained in the packets. But [20:47.120 --> 20:55.020] what we cannot infer is the size of each individual token. And this problem will be overcome [20:55.020 --> 21:02.620] in the next phase which Roy will talk about. Uh, with exploitation with AI. So, we will worry [21:02.620 --> 21:09.080] about that later. You probably wonder how did we find all of this out? So, we basically [21:09.080 --> 21:14.020] reverse engineered the traffic. We connected as a legitimate client to the assistant servers. [21:14.020 --> 21:19.080] We got the SSL key, the encryption key between our computer and the assistant server. Uh, we [21:19.080 --> 21:24.340] plugged this into Wireshark and we were able to watch the decrypted traffic, learn it, like [21:24.340 --> 21:30.440] analyze the metadata and make rules to extract the token length sequence from the encrypted [21:30.440 --> 21:37.880] traffic. So, to sum this up, we captured the traffic, we filtered the traffic and then we [21:37.880 --> 21:42.900] extracted the token length sequence. And now we would like to translate those token length [21:42.900 --> 21:49.580] sequence to plain text English and that's what Roy will talk about next in the next part, [21:49.580 --> 21:58.950] exploitation with AI. All right. Thank you Daniel. Um, let's indeed talk about how to [21:58.950 --> 22:03.750] exploit the side channel using a machine learning. But don't worry, I'm not a typical [22:03.750 --> 22:09.710] machine learning guy. We'll keep it simple. So, the first step in training a machine learning [22:09.710 --> 22:15.130] model is to basically gather a data set. We need to have a data set which will contain inputs [22:15.130 --> 22:20.770] and outputs. Then we train the model by feeding him examples of the inputs and what the [22:20.770 --> 22:27.830] outputs should look like. Training an LLM is no different. So, in our case, the attacker will [22:27.830 --> 22:34.230] first gather a huge corpus of text. He will transform the text into token length sequences and [22:34.230 --> 22:40.230] then pass them to the model. We hope that the outputs of the model, if not exact, will have the [22:40.230 --> 22:46.650] same similar semantic meaning. All right. So, now begs the question, how do you, how do you [22:46.650 --> 22:55.650] even use the model? When a, um, LLM output you, uh, gives you a response and outputs, each [22:55.650 --> 23:01.410] time you get it a bit differently. As Israel said, each time with the output you get a [23:01.410 --> 23:07.230] confidence score. Then you can basically, uh, prompt the model many times and saw the [23:07.230 --> 23:12.330] outputs based on the confidence score. And most often, the most confident output will [23:12.330 --> 23:19.270] have, um, will be the closest to the real thing. So, that sounds really simple and, uh, fun and [23:19.270 --> 23:24.730] that's what we did. We took the AI system response, transformed it into token length [23:24.730 --> 23:33.470] sequence, passed it to our trained, uh, model and it failed miserably. Well, the problem was too [23:33.470 --> 23:39.750] hard, even for an LLM. But we still had a glimpse of hope because although the semantic [23:39.750 --> 23:46.550] meaning, uh, similarity was nowhere, uh, to be found, the model still learned the high level [23:46.550 --> 23:53.090] structures such as list structure. So, we started to look around on ways to improve our [23:53.090 --> 24:00.830] approach. Um, we noticed a really interesting phenomena about AI system responses. The first [24:00.830 --> 24:07.610] sentence almost always holds the essence of the entire response. The first sentence is like a, an [24:07.610 --> 24:14.870] introduction to the coming paragraph. Learning from history, we took the hard problem and [24:14.870 --> 24:20.790] divided it into smaller problems to deal with each at the time. Because, uh, the first [24:20.790 --> 24:26.590] sentence is really unique, we first tackled it and tried to solve it and then all of the others [24:26.590 --> 24:32.210] because if you think about it, if we crack down the first sentence, we will win. We could, [24:32.210 --> 24:39.590] we could build upon that with a preserved topic in mind. But, wait, hold on. Isn't the traffic [24:39.590 --> 24:46.430] encrypted? What do we even have in the end? Token length sequence. How are we able to divide it [24:46.430 --> 24:53.890] into segments of sentences? Well, most tokenizers encode punctuation marks as a separate [24:53.890 --> 25:00.710] token. This means that almost always a token length of one is a punctuation mark. So, this [25:00.710 --> 25:08.010] means we can basically look at the token length sequence, search for one and divide it. But, um, [25:08.010 --> 25:13.250] we want to avoid false positives. For example, too short of a sentence because comma at the [25:13.250 --> 25:18.850] start. So, we apply the simple heuristic that uh, basically says we won't divide it if the [25:18.850 --> 25:25.410] sentence is too short. Alright, with this idea, because the first sentence is really unique, we [25:25.410 --> 25:32.110] train the model only on first sentences, meaning it's data set contain only first sentences. And [25:32.110 --> 25:38.670] we train another model for all of the other sentences to further help the second model try to [25:38.670 --> 25:45.490] figure out what is the right topic. We took the output which was generated by the first sentence [25:45.490 --> 25:51.850] and then passed it as part of the input to the next model. And then, uh, with other [25:51.850 --> 25:58.710] generations, we did the same and, uh, just like that, we, we have preserved the context in mind [25:58.710 --> 26:06.890] when generating the entire paragraph one by one. Alright, um, this approach is nice and we got 10 [26:06.890 --> 26:13.830] percent attack success rate, but it's not enough. Uh, we are at DEF CON after all. So, uh, there [26:13.830 --> 26:21.750] is one more thing that could help us improve. As we said, AI assistant responses are not just [26:21.750 --> 26:27.450] random Wikipedia pages. They are not random text. This, uh, they have predictive, predictable [26:27.450 --> 26:34.390] style and low response diversity. This means that we can use it to our advantage and relate to [26:34.390 --> 26:42.310] this problem as a known plain text attack. AI assistant responses have predictable style. They [26:42.310 --> 26:49.010] have warnings, templates, they follow safeguards and structure. This means that if we will [26:49.530 --> 26:56.430] train a model on those responses, the model will be able to learn those patterns and it will [26:56.430 --> 27:04.410] make our life easier. Also, as we can see here, many different prompts that talk about the same [27:04.410 --> 27:11.330] rather topic will have the same response. This means that, um, a model which is trained on AI [27:11.330 --> 27:19.210] system responses will be able to generalize to many different prompts. So, to summarize, the [27:19.210 --> 27:27.070] entire process is first collecting a data set of prompts. Then we will pass it to our target [27:27.070 --> 27:34.750] model like JGPT-4. Then we will collect the responses, transform them into token length [27:34.750 --> 27:41.810] sequences and train the model as we saw. This combined approach yields a huge boost of [27:41.810 --> 27:49.250] performance. This plot compares, uh, the, uh, performance of the combined approach, the green [27:49.250 --> 27:55.570] one, the blue one which is, uh, training the model on random text and the red one which is [27:55.570 --> 28:01.910] plainly asking JGPT please help me solve this side channel. And we can see, uh, that all of [28:01.910 --> 28:07.270] the examples to the right of the vertical line are considered successes and the green one was [28:07.270 --> 28:13.430] much better than all of the other approaches. And the numbers, we, as, as we said before, we [28:13.430 --> 28:19.430] got about 55 percent attack success rate on first sentences and 38 on entire paragraphs. We [28:19.430 --> 28:27.470] have also encountered a really interesting phenomena. Different topics were susceptible, uh, [28:27.470 --> 28:34.610] than others. In our example, uh, mental health and financial status were much more susceptible [28:34.610 --> 28:42.650] than, for example, sex, sexual health. This is mainly to the fact that those topics were much [28:42.650 --> 28:47.630] more common in the data set. This means that we've, we've, if we have an attacker with a [28:47.630 --> 28:53.570] specific goal in mind, he can train his own model on those subtopics and get better results. [28:53.570 --> 28:59.150] All right, so what about the network noise and traffic and all of the stuff Daniel said? [28:59.750 --> 29:05.930] Um, when we have high network, uh, traffic, we get grouping and buffering. So we first wanted [29:05.930 --> 29:12.390] to evaluate how much groupings were actually there. We ran a 24-hour experiment against [29:12.390 --> 29:20.090] open AI JGPT and we measured the amount of groupings we got in each hour of the day. As [29:20.090 --> 29:26.650] expected, in the day, there were much more groupings than in the night. But as we will see, [29:26.650 --> 29:33.990] it is manageable. To solve this challenge, we took our training process and our data set and [29:33.990 --> 29:40.730] just applied random groupings on the token length sequences. Then, as we can see in the first [29:40.730 --> 29:46.890] row, we still got 35 percent attack success rate on first sentences, which is really nice [29:46.890 --> 29:52.270] because the, it is way more challenging. Also, when looking around on different, uh, [29:52.270 --> 29:59.210] susceptible vendors, we found out that open AI API transmitted their messages as paired tokens, [29:59.210 --> 30:07.490] meaning each packet holded two tokens. Okay, this is more challenging, but we wanted to [30:07.490 --> 30:15.470] evaluate if we can break it and get more reward. So, uh, we took our training process and [30:15.470 --> 30:21.710] applied, uh, random, uh, not random, sorry, and we applied pairing, uh, pairing on the [30:21.710 --> 30:27.390] tokens, meaning we took the token lengths and just paired them. We still got 17 percent attack [30:27.390 --> 30:35.570] success rate on first sentences with this approach. Alright, so, after I've yucked you out [30:35.570 --> 30:43.990] with theory, let's talk business. So, um, as we all know, training an LLM from scratch is [30:43.990 --> 30:49.930] really hard. It takes, uh, months of computer time and millions of dollars in hardware and [30:49.930 --> 30:55.630] energy. We didn't have to go through such hassle. Rather, we used a common technique called [30:55.630 --> 31:00.770] fine tuning, which means we took a trained model and further trained it on, on our own [31:00.770 --> 31:06.710] translation task. We took a model called T5, which was trained... [31:06.710 --> 31:15.560] Pause, pause for a second. We need to do a small disruption, I'm sorry. [31:16.760 --> 31:23.760] Attention dev pod hackers. Halls 2 and 4 are now closed. Heavy equipment will begin operations [31:23.760 --> 31:29.560] soon. All humans need to vacate the premises before they contract and are forced to become [31:29.560 --> 31:36.400] goons for eternity. Villages and contests have now closed. All hacking of the planet must be [31:36.400 --> 31:42.480] done elsewhere. Please join us for the contest closing ceremonies in chapters 1 and 2. [31:42.900 --> 31:49.900] Attention dev pod hackers. You must vacate the hall before you become impaled by a forklift. [31:50.080 --> 32:00.260] Thank you and have a good day. Okay, good day to, uh, to you too. Yeah. So, let's recap, uh, our [32:00.260 --> 32:06.300] model was based on the T5 model, which is, uh, trained by Google and this is, it is, uh, [32:06.300 --> 32:12.560] public, publicly available. Uh, we also didn't have to go to the hassle of gathering our own [32:12.560 --> 32:17.020] data set. Rather, we used an open source one called UltraChat, which basically contains [32:17.020 --> 32:24.540] dialogues with GPT-4. We also used Hugging Face as our framework, uh, trainer, trainer, which [32:24.540 --> 32:30.780] was, which makes the technicalities of training a model much easier, even for a guy like me. [32:30.780 --> 32:37.480] Um, okay, our, uh, model was trained for, uh, two days of compute time and if we have an [32:37.480 --> 32:43.860] attacker with, uh, no GPA, GPU in hand, he can use Azure, for example, for only $200, which is [32:43.860 --> 32:52.480] fairly affordable. So, let's see some demos. Um, in this case, um, we have, uh, the victim, [32:52.480 --> 32:59.800] Quarry, uh, Microsoft Copilot. He asked the random question of what are the some, some of the [32:59.800 --> 33:04.800] latest development in machine learning and AI that could revolutionize the health industry. [33:04.800 --> 33:10.720] Besides him, the attacker, he's dropped the entire traffic. He collects, uh, traffic using [33:10.720 --> 33:18.640] Wireshark and after collecting for a bit of time, um, he will try to filter the traffic. As [33:18.640 --> 33:26.500] Daniel said, one of the common techniques to filter is based on the IP. So, the attacker does [33:26.500 --> 33:34.920] just that. And, uh, in this case, uh, the attacker manually, uh, figures out where the start is. [33:34.920 --> 33:40.700] Well, of course, the traffic is encrypted, so, uh, you just need to do it by hand and by eye. [33:40.720 --> 33:47.400] And after figuring out where the start is, the attacker will put inside the tool the token [33:47.400 --> 33:54.580] lengths, uh, so, excuse me, the packet, uh, sizes. Then the tool will calculate the deltas [33:54.580 --> 34:00.900] between the packet, uh, sizes and we will have a token length sequence. Then basically, the [34:00.900 --> 34:08.560] tool will pass it to the model to try generate the ground truth. And as we will see in a bit, [34:08.560 --> 34:17.460] um, hold on, yes, we got, we got the token lengths and now the model thinks, actually really [34:17.460 --> 34:24.560] fast and, alright, so, uh, it will be, it will zoom out in a bit. We basically got the same [34:24.580 --> 34:28.880] rather, uh, topic. Several recent advancements in machine learning and artificial [34:28.880 --> 34:36.300] intelligence, that could be a game changing tool, yada, yada. Alright, so, for the public use, [34:36.300 --> 34:44.360] we've, uh, deployed a full plug and play tool on GitHub called GPT Keylogger. Um, the tool, uh, [34:44.360 --> 34:49.220] has, has, uh, two main models, the attacker model and the trainer model. I will elaborate [34:49.220 --> 34:57.260] them in a bit. And, uh, our model is also publicly available, uh, and it is trained on GPT4 [34:57.260 --> 35:04.220] responses from February 2024. The first model, the attack model, is for you guys, uh, to try [35:04.220 --> 35:10.740] attack different vendors, um, it can receive as input packet lengths, as we saw in the demo, [35:10.740 --> 35:16.300] token lengths, which is straightforward, and the original text. The tool will basically, uh, [35:16.300 --> 35:22.760] tokenize the text, calculate the token length sequence, and, uh, try to predict. And, uh, you [35:22.760 --> 35:29.540] can use it with this simple command. If you want to target a different vendor, with a different [35:29.540 --> 35:35.180] backend LLM, you should train your own model, uh, because every LLM works differently and our [35:35.180 --> 35:42.300] model is based on GPT4 responses. So, if you want to, uh, target a model, uh, like Llama, you [35:42.300 --> 35:48.440] should train. And, uh, we offer this for you to make life much more easier, uh, with those [35:48.440 --> 35:54.560] commands. Uh, also the configuration file is also available in the GitHub, uh, page, uh, which is [35:54.560 --> 36:01.600] nice. And, uh, all right, so let's talk some defenses. We have contacted all of the vendors [36:01.600 --> 36:07.720] that we found vulnerable up to, uh, February 8th this year. Uh, all of the major vendors were [36:07.720 --> 36:13.580] really responsive and they patched the problem really quickly, uh, until March 1st. And we [36:13.580 --> 36:19.700] come, uh, we came public with this vulnerability on, um, on Ars Technica on 4th, uh, on the [36:19.700 --> 36:27.060] 14th of March this year. Out of the vendors, those five had bug bounty programs, which [36:27.060 --> 36:33.580] awarded us a small reward, which was really nice. Um, all right. So, although this side [36:33.580 --> 36:39.160] channel is really difficult to exploit, as we saw, the defenses are really easy to make. [36:39.160 --> 36:44.900] After, uh, consulting with the engineers on the, of the different vendors, we came up with [36:44.900 --> 36:52.300] three solutions. Random padding to the packets, padding to the nearest value, like nearest 100 [36:52.300 --> 36:58.980] size, or applying more buffering. Here is the mapping between the different vendors and the [36:58.980 --> 37:07.700] deployed defenses. When diving a bit deeper, OpenAI basically did padding to the nearest, uh, [37:07.700 --> 37:15.320] to the closest 32 value by adding a pad field on the transmitted JSON. And as we can see on [37:15.320 --> 37:22.020] Wireshark, the size is a line. And CloudFlare, for example, uh, deployed random pa- padding [37:23.220 --> 37:28.960] and, uh, we can see that the sizes are all messed up. All right. Let's run the demo. [37:28.980 --> 37:35.000] Let's wrap things up. So, what did we discover? We've identified a new side channel [37:35.000 --> 37:40.980] vulnerability based on token lengths. This is significant because, as we saw, it impacts [37:40.980 --> 37:49.160] multiple vendors expo- exposing sensitive information through their AI systems. This work, [37:49.160 --> 37:55.840] uh, has shown how to break a side channel use, uh, with generative AI and it is the first [37:55.840 --> 38:02.440] work to do so. While some vendors have patched this vulnerability, there is still a real [38:02.440 --> 38:10.820] concern about how new AI services will handle this issue. Now on to the key takeaways. First [38:10.820 --> 38:16.880] off, it is crucial to use encryption schemes correctly. This has repeated itself throughout [38:16.880 --> 38:23.020] history, time and after time, uh, and, uh, yeah, leading to multiple side channels and [38:23.020 --> 38:29.160] cracking of encryptions. Similarly, in modern times, even subtle details like token lengths [38:29.160 --> 38:36.180] can leak sensitive data if not properly protected. AI services are no exception to this [38:36.180 --> 38:42.360] rule. They must be designed and implemented up to the highest security measures as any other [38:42.360 --> 38:49.120] software domains. Remember, AI is your friend. It is a powerful tool both for offensive and [38:49.120 --> 38:53.940] defensive applications. We should harness its potential to identify and mitigate [38:53.940 --> 39:00.080] vulnerabilities. What seemed impossible is now possible thanks to advancements in AI. [39:00.620 --> 39:06.460] Finally, our discovery raises an important question. What other side channels are [39:06.460 --> 39:11.840] vulnerable? We encourage the community to explore and secure these potential weak points. [39:11.840 --> 39:17.120] To sum it up, we have joined throughout the process of identifying, exploiting and defending [39:17.120 --> 39:22.900] against this new side channel. This research highlights the importance of considering even the [39:22.900 --> 39:30.100] smallest details in data transmission within AI systems. I hope this inspires you to think [39:30.100 --> 39:37.960] creatively about both offensive and defensive capabilities of AI in cyber security. Thank you [39:37.960 --> 39:43.540] all for your attention. Uh, check out our tool GPTKeylogger and our labs page when we update [39:43.540 --> 39:52.160] on more research. Stay secure, stay curious and enjoy the rest short bit of DEF CON. Thank you.