WEBVTT

00:00.680 --> 00:02.540
Hello DEF CON!

00:03.200 --> 00:05.260
Thank you so much for being here.

00:05.260 --> 00:07.260
It's like the second to last talk.

00:07.260 --> 00:08.620
It's a great turnout.

00:08.700 --> 00:10.180
I'm very honored to be here.

00:10.180 --> 00:11.820
My name is Yusro Lomarski.

00:11.820 --> 00:18.080
I'm a Zuckerman Faculty Scholar at Ben-Gurion University and head of the Offensive AI Research Lab there.

00:18.300 --> 00:23.620
And with me here today are my brilliant graduate students who will be coming up on stage also to present.

00:23.620 --> 00:25.440
They did all the hard work.

00:25.480 --> 00:31.420
There's Daniel Eisenstein and Roy Weiss in collaboration with Guy Amit, who couldn't make it.

00:32.720 --> 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.

00:48.260 --> 00:52.160
Okay, so I'm not going to go into, you know, what are AI assistants.

00:52.160 --> 00:53.380
You guys all know this very well.

00:53.380 --> 01:00.360
You have OpenAI's ChatGPT, you have Google's Gemini, you have Microsoft Copilot, the list goes on and on.

01:00.440 --> 01:06.580
And these AI assistants are integrated throughout industry in all different kinds of use cases.

01:06.620 --> 01:11.240
What's more interesting to me is the use cases of the personal level, right?

01:11.240 --> 01:17.400
A lot of users are using these AI assistants, such as ChatGPT, to get personal advice.

01:17.560 --> 01:23.440
So, for example, you may ask it some medical questions like, why do I have a rash on my back, right?

01:23.440 --> 01:28.660
And ChatGPT will get back to you and say, I'm sorry to hear you have a rash on your back.

01:28.660 --> 01:30.680
Let me give some tips how to take care of that.

01:31.020 --> 01:35.480
Or maybe you may ask ChatGPT for some relationship advice.

01:35.700 --> 01:37.220
What are the signs I'm having?

01:37.220 --> 01:39.300
My wife is having an affair, right?

01:39.300 --> 01:40.940
And get some good tips on there.

01:41.840 --> 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?

01:47.920 --> 01:49.060
Lots of good use cases.

01:49.060 --> 01:54.040
Or my favorite, a lot of people are using ChatGPT to edit their documents.

01:54.040 --> 01:59.220
They'll take whole documents or emails, dump it into ChatGPT and say, hey, make it better.

01:59.220 --> 02:02.100
Or, you know, finish this paragraph or what have you.

02:02.360 --> 02:05.000
And these are all very good and legitimate use cases.

02:05.000 --> 02:10.320
They're actually very productive for our society to help us, you know, progress and automate things.

02:10.940 --> 02:17.000
But the problem is that what happens if these chats aren't actually private?

02:17.000 --> 02:22.640
What happens if somebody could read these chats beyond, right?

02:22.640 --> 02:25.360
So this would be a huge breach in privacy.

02:26.960 --> 02:30.540
So in truth, we know they're encrypted, right?

02:30.540 --> 02:35.920
So you know, OpenAI is encrypting all the traffic going between the client and the servers.

02:36.220 --> 02:37.860
But is that enough?

02:37.860 --> 02:40.020
You know, maybe a little foreshadowing.

02:41.080 --> 02:44.020
So let me go back to the beginning of this story here.

02:44.020 --> 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?

02:59.840 --> 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.

03:09.060 --> 03:10.340
Wait a second.

03:10.580 --> 03:17.760
Could it possibly be that OpenAI is sending every single word as a separate packet?

03:18.020 --> 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?

03:28.440 --> 03:32.180
So I open up Wireshark and sure enough, what do I see?

03:32.180 --> 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.

03:40.440 --> 03:47.080
And if I take the delta between these packets, I know exactly how many characters in every single word.

03:47.080 --> 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.

03:59.520 --> 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.

04:07.200 --> 04:14.320
That what ChatGPT and all these different AI services are sending are not exactly words, but rather something called tokens.

04:14.780 --> 04:21.480
What tokens are, are basically the basic building block of AI language models.

04:21.580 --> 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.

04:33.220 --> 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.

04:40.380 --> 04:46.020
So for example here, Lama's tokenizer will split the word cream into two separate tokens.

04:46.340 --> 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.

04:55.500 --> 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.

05:03.760 --> 05:08.620
So for all intents and purposes, these are words and we're trying to guess what these words are.

05:10.040 --> 05:12.120
So what's the threat model?

05:12.740 --> 05:23.720
So the victim types some private chat into his web browser, hits enter, and that encrypted text goes across the wire.

05:23.720 --> 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.

05:28.620 --> 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.

05:38.800 --> 05:44.240
And once again, if we can guess what those words are, then boom, we know exactly what the response was.

05:45.340 --> 05:47.120
So why do we care?

05:47.260 --> 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.

05:58.680 --> 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.

06:07.840 --> 06:08.120
Right?

06:08.120 --> 06:12.340
I think it's pretty clear we know exactly what that user was asking for.

06:13.740 --> 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.

06:21.620 --> 06:27.220
And this can be a particularly challenging problem because, you know, there's many different ways you can solve this puzzle.

06:27.700 --> 06:32.980
But it gets even more challenging when you think about real responses from these AI assistants, right?

06:32.980 --> 06:36.820
They're not just one sentence, they're typically whole paragraphs with hundreds of words.

06:37.160 --> 06:38.940
So how do we solve this problem?

06:38.940 --> 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?

06:48.600 --> 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.

06:59.760 --> 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.

07:10.980 --> 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.

07:22.960 --> 07:27.560
I'm not going to go too much into detail how it works, leave that for other YouTube videos.

07:28.440 --> 07:31.020
All right, so what's the entire attack end-to-end, how does it look like?

07:31.020 --> 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.

07:43.060 --> 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.

07:53.640 --> 07:57.260
So there's something else we can do to make this even better.

07:58.000 --> 08:03.800
So if we just, you know, give our model random arbitrary text, it's going to do so-so.

08:03.800 --> 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.

08:07.640 --> 08:13.060
But as it turns out, AI assistants have a very specific style of speaking, right?

08:13.060 --> 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?

08:21.120 --> 08:25.100
So there's a certain style that's intrinsically in those responses.

08:25.560 --> 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.

08:37.140 --> 08:41.860
And those responses capture the style of that particular AI service.

08:42.220 --> 08:47.760
And once I have that, I can fine-tune my model on that, and I'll get much, much better results.

08:48.100 --> 08:52.900
And as it turns out, I can get something around 55% attack success rate.

08:52.900 --> 08:58.880
So more than half of the responses that we see in the encrypted traffic, we can decipher.

09:00.400 --> 09:02.840
Okay, so let's look at some examples.

09:03.100 --> 09:06.580
So on the screen here is the first sentences that we're trying to decipher.

09:06.580 --> 09:11.580
The first line is the original text that is being sent from the AI assistant.

09:11.580 --> 09:14.200
And the second line is our prediction.

09:14.400 --> 09:18.700
So sometimes you can see in the first example there, we get it right on the first go.

09:18.700 --> 09:20.560
And sometimes we make some mistakes.

09:20.840 --> 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.

09:33.080 --> 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.

09:45.020 --> 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.

09:56.800 --> 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.

10:10.980 --> 10:14.260
And since we're using AI models, this isn't a perfect science.

10:14.260 --> 10:18.000
You know, we're using a lot of heuristics here, so we sometimes get it wrong.

10:18.000 --> 10:19.360
So here's some fails.

10:19.360 --> 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.

10:29.560 --> 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.

10:41.500 --> 10:43.320
And sometimes it gets even worse, right?

10:43.320 --> 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.

10:49.220 --> 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.

10:57.880 --> 11:02.160
How confident it is that this prediction is correct, right?

11:02.160 --> 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.

11:16.120 --> 11:18.900
All right, so how common is this vulnerability?

11:19.700 --> 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.

11:31.900 --> 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.

11:40.400 --> 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.

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:54.680
That's just too hard of a problem.

11:54.940 --> 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?

12:00.360 --> 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.

12:08.700 --> 12:13.300
They're saying, oh, you know, the text is encrypted, not a big deal, let's move on, right?

12:13.340 --> 12:19.280
So this is probably more likely what happened there until they, of course, patched it after the fact.

12:20.540 --> 12:26.040
So why are they even sending, you know, text to streaming or token streaming across the network?

12:26.040 --> 12:28.840
Why don't they just send it as one big batch, right?

12:28.860 --> 12:32.580
So for example, Google's Gemini does this already.

12:32.580 --> 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.

12:41.220 --> 12:43.040
So why aren't the other vendors doing this?

12:43.100 --> 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.

12:52.600 --> 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.

13:07.520 --> 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.

13:21.780 --> 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.

13:36.960 --> 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.

13:51.720 --> 13:57.740
And after that, we'll talk a little bit about how we train AI models and our specific RAI model.

13:57.820 --> 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.

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:13.900
Thanks Israel.

14:14.180 --> 14:17.000
So, let's jump to the nitty-gritty details.

14:17.020 --> 14:22.300
So, we will talk about how to find the side channel and how to extract the token length sequence.

14:26.420 --> 14:32.200
So, the first thing we'll have to do is to capture the traffic containing the response from the assistant.

14:32.440 --> 14:36.880
So, we'll need to be positioned between the victim and the assistant.

14:37.340 --> 14:43.200
Or, we can be in the same local network as the victim sitting in the same cafe using Wi-Fi.

14:44.340 --> 14:50.440
So, we collected a lot of traffic and not all of it containing our response data from the AI assistant.

14:50.580 --> 14:52.640
So, we'll need to filter the traffic.

14:52.960 --> 14:56.440
We can do that by filtering by the IP address of the assistant.

14:56.660 --> 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.

15:13.540 --> 15:16.580
Also, what we can do is filter by the protocol.

15:16.780 --> 15:20.140
So, every vendor is using different protocol.

15:20.140 --> 15:22.860
For example, JGPT is using quick protocol.

15:22.860 --> 15:28.020
So, we would like to search for UDP packets that are coming from port 443.

15:28.320 --> 15:33.420
And again, every vendor is using different protocol so we'll need to account for that.

15:33.480 --> 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.

15:48.280 --> 15:54.500
So, we captured the traffic, we filtered out most of the traffic that don't contain our tokens.

15:54.500 --> 15:58.220
We have the traffic that contains the response from the assistant.

15:58.360 --> 16:00.560
Let's extract the token length sequence.

16:01.860 --> 16:05.580
So, our objective is to find the token lengths.

16:05.960 --> 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.

16:13.360 --> 16:16.240
But what we can see is the bandwidth patterns.

16:16.240 --> 16:17.960
Basically, the packet sizes.

16:24.590 --> 16:26.210
Oh, I'm sorry.

16:30.800 --> 16:36.800
So, we found that there is two main ways that the vendors are using to send their tokens.

16:36.800 --> 16:39.040
The first way is base plus next token.

16:39.040 --> 16:42.920
Basically, each token is sent in a separate packet by itself.

16:43.020 --> 16:48.160
So, we can infer the size of the token by just analyzing the size of the packet.

16:48.280 --> 16:50.860
The second way is token accumulation.

16:51.060 --> 16:53.040
Basically, the tokens accumulate.

16:53.040 --> 16:58.540
We are sending each time the token with all of the tokens that were previously sent.

16:58.620 --> 17:01.180
So, the packets are increasing in size.

17:01.440 --> 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.

17:08.680 --> 17:11.720
So, basically, our main target was JGPT.

17:11.720 --> 17:13.700
So, we'll talk about this more.

17:14.960 --> 17:22.980
So, to simplify the problem, we'll first try to identify which messages, which packets are containing the response.

17:22.980 --> 17:27.440
So, to simplify it, let's try to find the start and the end.

17:28.160 --> 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.

17:39.160 --> 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.

17:49.500 --> 17:53.840
So, you have those increases and we can basically find the start and the end.

17:54.640 --> 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.

18:02.920 --> 18:10.460
The packets that follow this trend contain our tokens, but sometimes we have packets that don't follow this trend.

18:10.460 --> 18:14.360
Those are sometimes control packets that do not have our tokens.

18:14.360 --> 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.

18:28.580 --> 18:35.800
So, it sounds pretty simple, and some would say even easy, and too good to be true.

18:35.940 --> 18:38.740
And in reality, it's really the case.

18:38.740 --> 18:40.680
So, we have more challenges.

18:41.180 --> 18:48.460
The first challenge is message size limits and the second one is message buffering, uh, that will cause message groupings.

18:48.660 --> 18:50.420
So, let's talk about that.

18:50.880 --> 18:52.400
Message size limits.

18:52.400 --> 18:56.880
In the internet, we have this thing called MTU, Maximum Transmission Units.

18:56.880 --> 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.

19:05.180 --> 19:13.780
And what we found is JGPT over QUIC has even a lower maximum size of 1,200 bytes.

19:14.320 --> 19:18.480
And as you remember, JGPT is accumulating its tokens.

19:18.480 --> 19:21.940
So, at certain point, it will reach this maximum size.

19:21.940 --> 19:27.160
So, what will happen is basically that the payload will overflow to the next packet.

19:27.160 --> 19:32.920
So now, we have two packets that are sending this token because our payload is just too big.

19:33.040 --> 19:37.280
And what will happen is basically the sort of pattern that you see now.

19:37.460 --> 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.

19:46.960 --> 19:52.540
And at the filtering phase, we'll need to account for that because we don't want to throw those packets.

19:52.540 --> 19:54.360
They contain our tokens.

19:56.240 --> 20:04.300
Another challenge is that the business of the network will cause basically buffering that will cause our groupings.

20:04.300 --> 20:05.400
What does it mean?

20:05.400 --> 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.

20:19.280 --> 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.

20:30.660 --> 20:32.320
More than one new token.

20:32.620 --> 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.

20:46.920 --> 20:51.680
But what we cannot infer is the size of each individual token.

20:52.320 --> 20:58.400
And this problem will be overcome in the next phase which Roy will talk about.

20:58.460 --> 21:01.140
Uh, with exploitation with AI.

21:01.140 --> 21:03.980
So, we will worry about that later.

21:04.820 --> 21:08.160
You probably wonder how did we find all of this out?

21:08.160 --> 21:10.840
So, we basically reverse engineered the traffic.

21:10.840 --> 21:14.020
We connected as a legitimate client to the assistant servers.

21:14.020 --> 21:18.480
We got the SSL key, the encryption key between our computer and the assistant server.

21:18.480 --> 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.

21:32.900 --> 21:39.800
So, to sum this up, we captured the traffic, we filtered the traffic and then we extracted the token length sequence.

21:39.800 --> 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.

21:54.390 --> 21:55.510
All right.

21:55.510 --> 21:56.830
Thank you Daniel.

21:57.010 --> 22:02.110
Um, let's indeed talk about how to exploit the side channel using a machine learning.

22:02.110 --> 22:04.870
But don't worry, I'm not a typical machine learning guy.

22:04.870 --> 22:06.190
We'll keep it simple.

22:06.450 --> 22:12.190
So, the first step in training a machine learning model is to basically gather a data set.

22:12.190 --> 22:16.350
We need to have a data set which will contain inputs and outputs.

22:16.570 --> 22:22.290
Then we train the model by feeding him examples of the inputs and what the outputs should look like.

22:22.290 --> 22:24.950
Training an LLM is no different.

22:25.810 --> 22:30.370
So, in our case, the attacker will first gather a huge corpus of text.

22:30.710 --> 22:35.990
He will transform the text into token length sequences and then pass them to the model.

22:36.130 --> 22:42.430
We hope that the outputs of the model, if not exact, will have the same similar semantic meaning.

22:43.070 --> 22:43.710
All right.

22:43.710 --> 22:47.990
So, now begs the question, how do you, how do you even use the model?

22:49.070 --> 22:57.730
When a, um, LLM output you, uh, gives you a response and outputs, each time you get it a bit differently.

22:58.150 --> 23:02.090
As Israel said, each time with the output you get a confidence score.

23:02.090 --> 23:08.930
Then you can basically, uh, prompt the model many times and saw the outputs based on the confidence score.

23:08.930 --> 23:16.370
And most often, the most confident output will have, um, will be the closest to the real thing.

23:16.370 --> 23:20.490
So, that sounds really simple and, uh, fun and that's what we did.

23:20.490 --> 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.

23:31.070 --> 23:35.450
Well, the problem was too hard, even for an LLM.

23:35.450 --> 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.

23:49.870 --> 23:54.010
So, we started to look around on ways to improve our approach.

23:54.430 --> 24:00.330
Um, we noticed a really interesting phenomena about AI system responses.

24:00.330 --> 24:05.730
The first sentence almost always holds the essence of the entire response.

24:05.730 --> 24:10.150
The first sentence is like a, an introduction to the coming paragraph.

24:11.130 --> 24:18.890
Learning from history, we took the hard problem and divided it into smaller problems to deal with each at the time.

24:19.370 --> 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.

24:31.610 --> 24:36.770
We could, we could build upon that with a preserved topic in mind.

24:37.170 --> 24:38.830
But, wait, hold on.

24:38.830 --> 24:40.670
Isn't the traffic encrypted?

24:40.670 --> 24:43.230
What do we even have in the end?

24:43.230 --> 24:44.530
Token length sequence.

24:44.530 --> 24:48.690
How are we able to divide it into segments of sentences?

24:49.070 --> 24:54.930
Well, most tokenizers encode punctuation marks as a separate token.

24:54.930 --> 25:00.250
This means that almost always a token length of one is a punctuation mark.

25:00.250 --> 25:06.370
So, this means we can basically look at the token length sequence, search for one and divide it.

25:06.850 --> 25:09.950
But, um, we want to avoid false positives.

25:09.950 --> 25:14.030
For example, too short of a sentence because comma at the start.

25:14.130 --> 25:20.510
So, we apply the simple heuristic that uh, basically says we won't divide it if the sentence is too short.

25:21.030 --> 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.

25:31.950 --> 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.

25:41.370 --> 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.

25:50.270 --> 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.

26:02.810 --> 26:10.330
Alright, um, this approach is nice and we got 10 percent attack success rate, but it's not enough.

26:10.330 --> 26:12.470
Uh, we are at DEF CON after all.

26:12.490 --> 26:16.790
So, uh, there is one more thing that could help us improve.

26:17.970 --> 26:23.310
As we said, AI assistant responses are not just random Wikipedia pages.

26:23.310 --> 26:24.870
They are not random text.

26:24.990 --> 26:30.530
This, uh, they have predictive, predictable style and low response diversity.

26:30.530 --> 26:37.410
This means that we can use it to our advantage and relate to this problem as a known plain text attack.

26:39.610 --> 26:42.250
AI assistant responses have predictable style.

26:42.250 --> 26:47.330
They have warnings, templates, they follow safeguards and structure.

26:47.390 --> 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.

26:58.930 --> 27:07.450
Also, as we can see here, many different prompts that talk about the same rather topic will have the same response.

27:07.930 --> 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.

27:16.710 --> 27:24.810
So, to summarize, the entire process is first collecting a data set of prompts.

27:24.810 --> 27:29.890
Then we will pass it to our target model like JGPT-4.

27:30.050 --> 27:37.690
Then we will collect the responses, transform them into token length sequences and train the model as we saw.

27:38.390 --> 27:42.910
This combined approach yields a huge boost of performance.

27:43.510 --> 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.

27:59.890 --> 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.

28:10.730 --> 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.

28:19.150 --> 28:23.690
We have also encountered a really interesting phenomena.

28:24.030 --> 28:28.570
Different topics were susceptible, uh, than others.

28:28.570 --> 28:37.410
In our example, uh, mental health and financial status were much more susceptible than, for example, sex, sexual health.

28:38.450 --> 28:44.550
This is mainly to the fact that those topics were much more common in the data set.

28:44.550 --> 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.

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.170
Um, when we have high network, uh, traffic, we get grouping and buffering.

29:05.170 --> 29:09.110
So we first wanted to evaluate how much groupings were actually there.

29:09.110 --> 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.

29:19.450 --> 29:25.130
As expected, in the day, there were much more groupings than in the night.

29:25.130 --> 29:27.910
But as we will see, it is manageable.

29:28.610 --> 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.

29:38.270 --> 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.

29:49.670 --> 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.

30:03.310 --> 30:11.410
Okay, this is more challenging, but we wanted to evaluate if we can break it and get more reward.

30:11.750 --> 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.

30:25.230 --> 30:30.510
We still got 17 percent attack success rate on first sentences with this approach.

30:31.010 --> 30:37.470
Alright, so, after I've yucked you out with theory, let's talk business.

30:38.190 --> 30:44.910
So, um, as we all know, training an LLM from scratch is really hard.

30:44.910 --> 30:50.870
It takes, uh, months of computer time and millions of dollars in hardware and energy.

30:50.910 --> 30:53.390
We didn't have to go through such hassle.

30:53.390 --> 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.

31:02.930 --> 31:06.710
We took a model called T5, which was trained...

31:06.710 --> 31:08.070
Pause, pause for a second.

31:08.070 --> 31:08.610
We need to do

31:13.460 --> 31:15.560
a small disruption, I'm sorry.

31:16.760 --> 31:18.960
Attention dev pod hackers.

31:19.100 --> 31:21.940
Halls 2 and 4 are now closed.

31:21.940 --> 31:24.880
Heavy equipment will begin operations soon.

31:24.980 --> 31:31.220
All humans need to vacate the premises before they contract and are forced to become goons for eternity.

31:31.500 --> 31:34.320
Villages and contests have now closed.

31:34.400 --> 31:37.560
All hacking of the planet must be done elsewhere.

31:37.760 --> 31:42.480
Please join us for the contest closing ceremonies in chapters 1 and 2.

31:42.900 --> 31:45.020
Attention dev pod hackers.

31:45.120 --> 31:49.900
You must vacate the hall before you become impaled by a forklift.

31:50.080 --> 31:52.520
Thank you and have a good day.

31:54.000 --> 31:56.480
Okay, good day to, uh, to you too.

31:56.480 --> 31:57.000
Yeah.

31:57.080 --> 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.

32:08.700 --> 32:13.300
Uh, we also didn't have to go to the hassle of gathering our own data set.

32:13.300 --> 32:18.960
Rather, we used an open source one called UltraChat, which basically contains dialogues with GPT-4.

32:19.360 --> 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.

32:30.780 --> 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.

32:45.360 --> 32:47.640
So, let's see some demos.

32:48.080 --> 32:55.420
Um, in this case, um, we have, uh, the victim, Quarry, uh, Microsoft Copilot.

32:55.940 --> 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.

33:04.800 --> 33:08.840
Besides him, the attacker, he's dropped the entire traffic.

33:09.080 --> 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.

33:18.440 --> 33:23.480
As Daniel said, one of the common techniques to filter is based on the IP.

33:23.980 --> 33:27.640
So, the attacker does just that.

33:28.780 --> 33:34.920
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: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.

33:51.900 --> 33:59.640
Then the tool will calculate the deltas between the packet, uh, sizes and we will have a token length sequence.

33:59.720 --> 34:05.500
Then basically, the tool will pass it to the model to try generate the ground truth.

34:05.700 --> 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.

34:23.160 --> 34:26.140
We basically got the same rather, uh, topic.

34:26.140 --> 34:33.060
Several recent advancements in machine learning and artificial intelligence, that could be a game changing tool, yada, yada.

34:33.760 --> 34:41.640
Alright, so, for the public use, we've, uh, deployed a full plug and play tool on GitHub called GPT Keylogger.

34:42.480 --> 34:48.560
Um, the tool, uh, has, has, uh, two main models, the attacker model and the trainer model.

34:48.560 --> 34:50.560
I will elaborate them in a bit.

34:50.700 --> 34:59.760
And, uh, our model is also publicly available, uh, and it is trained on GPT4 responses from February 2024.

35:00.540 --> 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.

35:14.100 --> 35:21.620
The tool will basically, uh, tokenize the text, calculate the token length sequence, and, uh, try to predict.

35:22.280 --> 35:25.100
And, uh, you can use it with this simple command.

35:26.140 --> 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.

35:37.920 --> 35:43.220
So, if you want to, uh, target a model, uh, like Llama, you should train.

35:43.240 --> 35:49.000
And, uh, we offer this for you to make life much more easier, uh, with those commands.

35:49.060 --> 35:55.420
Uh, also the configuration file is also available in the GitHub, uh, page, uh, which is nice.

35:55.500 --> 35:58.400
And, uh, all right, so let's talk some defenses.

35:59.420 --> 36:05.600
We have contacted all of the vendors that we found vulnerable up to, uh, February 8th this year.

36:05.680 --> 36:13.160
Uh, all of the major vendors were really responsive and they patched the problem really quickly, uh, until March 1st.

36:13.160 --> 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.

36:22.240 --> 36:29.660
Out of the vendors, those five had bug bounty programs, which awarded us a small reward, which was really nice.

36:30.060 --> 36:32.080
Um, all right.

36:32.080 --> 36:39.160
So, although this side channel is really difficult to exploit, as we saw, the defenses are really easy to make.

36:39.160 --> 36:46.820
After, uh, consulting with the engineers on the, of the different vendors, we came up with three solutions.

36:47.340 --> 36:55.020
Random padding to the packets, padding to the nearest value, like nearest 100 size, or applying more buffering.

36:55.360 --> 37:00.340
Here is the mapping between the different vendors and the deployed defenses.

37:00.900 --> 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.

37:14.340 --> 37:17.820
And as we can see on Wireshark, the size is a line.

37:18.580 --> 37:26.700
And CloudFlare, for example, uh, deployed random pa- padding and, uh, we can see that the sizes are all messed up.

37:27.100 --> 37:28.360
All right.

37:28.580 --> 37:28.960
Let's run the demo.

37:28.980 --> 37:30.180
Let's wrap things up.

37:30.740 --> 37:32.920
So, what did we discover?

37:32.920 --> 37:37.740
We've identified a new side channel vulnerability based on token lengths.

37:37.760 --> 37:47.440
This is significant because, as we saw, it impacts multiple vendors expo- exposing sensitive information through their AI systems.

37:48.040 --> 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.

37:57.920 --> 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.

38:08.260 --> 38:10.580
Now on to the key takeaways.

38:10.580 --> 38:15.120
First off, it is crucial to use encryption schemes correctly.

38:15.220 --> 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.

38:25.020 --> 38:33.780
Similarly, in modern times, even subtle details like token lengths can leak sensitive data if not properly protected.

38:33.980 --> 38:37.000
AI services are no exception to this rule.

38:37.000 --> 38:43.840
They must be designed and implemented up to the highest security measures as any other software domains.

38:44.240 --> 38:46.540
Remember, AI is your friend.

38:46.540 --> 38:50.600
It is a powerful tool both for offensive and defensive applications.

38:50.600 --> 38:55.280
We should harness its potential to identify and mitigate vulnerabilities.

38:55.280 --> 39:00.080
What seemed impossible is now possible thanks to advancements in AI.

39:00.620 --> 39:04.560
Finally, our discovery raises an important question.

39:04.560 --> 39:07.460
What other side channels are vulnerable?

39:07.460 --> 39:11.840
We encourage the community to explore and secure these potential weak points.

39:11.840 --> 39:19.100
To sum it up, we have joined throughout the process of identifying, exploiting and defending against this new side channel.

39:19.100 --> 39:27.680
This research highlights the importance of considering even the smallest details in data transmission within AI systems.

39:27.680 --> 39:36.580
I hope this inspires you to think creatively about both offensive and defensive capabilities of AI in cyber security.

39:37.100 --> 39:39.780
Thank you all for your attention.

39:39.780 --> 39:45.860
Uh, check out our tool GPTKeylogger and our labs page when we update on more research.

39:45.860 --> 39:51.500
Stay secure, stay curious and enjoy the rest short bit of DEF CON.

39:51.500 --> 39:52.160
Thank you.

