So, I'm going to talk about Bluetooth Low Energy 5 PRNG today for fun and jamming and maybe more. So, for those who don't know me, I am a security evangelist and also a senior security researcher at Digital Security, a French IT security company specialized in the, um, IOT. And I'm also the main developer of BTAD Jack or BTAD Jack, uh, which is a BAD Swiss Army Knife. So, we are going to talk about, uh, BAD5 and, uh, especially what's new in BAD5 specifications and I will go through some specific features and also some, uh, some interesting stuff in this, uh, in this protocol. So, first of all, I'm going to recap what BAD is for those who are not familiar with this protocol. So, this protocol has been introduced in 2010 as a Bluetooth Smart. So, this is the first name of this protocol in Bluetooth Core Specifications version 4.0. And it has evolved since then. Uh, version 4.1 in 2013, 4.2 in 2014, version 5 in 2016 and last version 5.1, uh, this year, uh, in, uh, at the beginning of this year. So, it's, um, evolving very quickly, uh, as a protocol and, uh, it's, um, it's designed to, to, to be, uh, very effective, so people behind this protocol produces a lot of, uh, produce a lot of, uh, ver- different versions. But the, uh, industry, um, uh, it's difficult for the industry to, to keep up with this, uh, evolution. This protocol provides some security mechanisms, uh, such as pairing, so you can exchange keys between two devices before to, to be able to encrypt communications. And this, uh, pairing mechanism, uh, can be done with a pin code. So, this is, uh, some thing, uh, very easy. You just exchange a six-digit pin code between two devices and you derive some keys from this. Also, from, uh, from out-of-wind data and also, uh, edit some, edit the curve negotiation. So, this is, uh, something provided by this protocol and it's cool. Some version of this pairing, uh, are not very secure, uh, as it was demonstrated before, uh, years before, uh, before, but, uh, some of them are pretty strong, such as the elliptic curves. This protocol also provides secure connections, so that means you can secure a connection between two devices. And this is, uh, very interesting because this, uh, secure connections, BAD secure connection is, uh, uh, pretty strong when, when it's correctly implemented, uh, in the, uh, in the applications. And this secure connection provides encryption and authentication. That means nobody can tap into an existing connection or even inject some malicious packets in this, uh, in the, in a, a specific connection. So, uh, this, uh, this protocol also provides secure connections. And last but not least, there is also what we call the channel selection algorithm. So, to make things clear, clear, uh, this Bluetooth low energy protocol uses channel hopping to ensure, to, to, to make these connections, uh, reliable. And this channel hopping mechanism is very simple. When two devices create a connection, they're going to jump from one channel to another, uh, in order to avoid packet collisions. So, this, uh, allows the connection to be, uh, stable. BAD, you know, even if there are a lot of devices in the same room. Um, this channel selection algorithm is not a security mechanism when it, um, but when it comes to sniffing, when you are trying to sniff, uh, uh, a BAD connection, this can make, this can be an issue because you, for, um, you need to know what this, uh, algorithm is and how to recover this, uh, hopping sequence in order to follow an existing connection. So, this makes sniffing completely complicated. There are also well-known attacks, uh, especially on BAD4, uh, which is the first one, sniffing. You can easily sniff BAD connections. So, this is, uh, pretty straightforward. Even secure BAD connection when the pairing is not so secure. You can also jam an existing connection. This is what, uh, I showed last year at DevCon with BTAD Jack. So, it's possible to disconnect two devices and once, uh, uh, the, uh, device is disconnected, then it advertises, uh, again, and you can connect to it and take control of it. But, uh, you can also hijack a connection. That means you can force a disconnection from, uh, uh, one device to another and then exploit this, uh, connection without the other device noticing the disconnection. So, it's, uh, possible to take complete control over, uh, a device this way. So, again, um, you can do this with, uh, a lot of different virus hardware. So, um, on the left of the screen, there is the uber-tooth. Uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh. Which is a well-known device used to, to sniff BAD connections. In the middle, the Adafruit Bluefront LH sniffer which is the, one of the, one of the first alien Bluetooth load. Uh, this sniffer available in the market. Uh, it costs around, uh, 40 bucks. And, uh, on the right of the screen there is the, uh, the microbit which is a British broadcasting company uh, uh, sponsored, but developed to, uh, or designed to, to teach UK students how to code. this last board, this micro bit to allow attackers to, to sniff, jam, and hijack, uh, some connections. Let's go back to the new features introduced in B85. B85 introduces, uh, uh, a bit of throughput up to 2 megabits per second, a bit of range up to 800 feet or 240 meters, and an improved coexistence. I will go very, very shortly, uh, for these, uh, the first two, better throughput, a better range. Basically, it had, it adds two new files, uh, to the, uh, Bluetooth low energy protocol. The 2 megabit per seconds, uh, uncoded file that doubles the speed of, uh, uh, the, uh, any BID connection, so you can send more data in the same amount of time. And, uh, also the 80 coded file, which here, uh, improves the range, uh, times, uh, 4 times the actual range for B84, but at 125 kilobit per second speed, and 2 times the, the same range at 500 kilobit per second. So this, this is some kind of trade-off, your, your, your redo between range and speed. If you have a look at the packets sent over this, uh, two new files, uh, there is the 80 coded file, which is, uh, a new file introduced in B85, and there is the 80 uncoded file, which is the actual, uh, the B84 file. And in these packets, you will find, uh, an access address, which is a 32-bit value, um, identifying a connection between two devices. But the problem is that the hardware we are using, see, um, such as the microbit, or even the Adafruit blue, blue friend 80 sniffer, this hardware cannot cope with these new files. And that's pretty much the issue. The, the issue here. So, our hardware may be useful, but for this new files, this can be a problem. So we're going to cover this later. The main point here is that the B85 co- protocol introduces a new channel selection algorithm. So the old one is mentioned here, this is, uh, a very simple, uh, sequence generator, based on some modulo. And the new channel selection algorithm, produces a PRNG based random generator PRNG based channel selection algorithm. So this is based on the random number generator. This is a a problem for us because uh as Mike Ryan showed uh in 2013 it was very easy to recover uh a very uh a key value of the first channel selection algorithm which is the uh op-inc value mentioned in this slide. But with the PRNG the the task is uh much harder because you you need to break this uh random number generator to to be able to to sniff and hijack and jam an existing connection. Luckily the device is implementing this channel channel selection algorithm uh advertise the uh a very specific bit and if this bit is set it's a CH cell bit then this device supports this new channel selection algorithm. So based on the PRNG based algorithm PRNG based on the PRNG based algorithm basically what are the consequences regarding known attacks on B85? First of all there is a completely different new hopping pattern used uh so basically the old version the first channel selection algorithm generates a 37 channel sequence and this new channel selection algorithm generates a 65,536 channel sequence. And basically the device will loop over the sequence. So this is uh uh more complicated and uh it's uh it's uh it's uh it's our first approach we we got when we were developing the uh B84 tools uh couldn't work here. So sniffing new connection is still possible because you only need some software able to to follow the this uh new channel secu- channel selection algorithm. Because at the beginning of a connection you get everything you need to synchronize with this connection and and follow packets. But as an attacker we won't be able to jam or hijack B85 devices. We won't be able to jam devices because the connection is always the already established and we don't have these values used to to compute the uh sequence uh of channels. The we need to go uh to synchronize and follow a connection. So we also need a new hardware that supports supports B85 new files, but that's uh another question. It's uh just like some guys at BTSEC decided to introduce this PRNG uh in order to mess up with the uh value of the uh distribution of uh, the actual tools. Well, this is what I believed when I started this, uh, this research. So, let's see. Let's have a look at the random number generator. First of all, it uses a channel identifier value, some kind of value as a seed, which is a 16 bit value. Uh, this, uh, random number generator relies on basic operations, some, uh, add, multiply, XOR, bit permutation, and so on. And it also, uh, uses some, uh, channel remapping, but this was the same with BLE4. This channel identifier value is computed from access address. So, uh, this, uh, this is a 32 bit value identifying your link between two devices. So, basically, identifying your connection. And the, the, the computation is the following. You take the, um, access address, bit 0 to 15, and your XOR, this value, 16 bit value with the, the, the, the access address, bit 16 to 31. So, you got a 16, 16 bit value. And then, we are going to use, uh, a lot of, uh, uh, computation and, uh, a specific working code, MAM, for multiply add mod. And, basically, this waiting to perform some computations. And takes two values, A and B, 16 bit values, and produces a 16 bit output. And this is just three times in a row. Uh, these are some other computations in between. To create a random number. Based on this random number, then we compute the actual channel for a given counter, or given value of the, of the counter used here. So, when this, uh, when this channel selection algorithm generates a sequence, it goes from, uh, a counter from zero to 4K. And then generates every possible channel. And this, this creates, uh, uh, uh, a, a, uh, uh, sequence of, of channels and the devices will go over, loop over this sequence. So when I saw this, uh, I was like, uh, wow, what's this stuff? What, what the fuck? And I wasn't alone. I found some people on Twitter also complaining about this, uh, specification and especially this PRNG. Well, maybe there's something to do. Uh, if you have a, a look at this, uh, generator, then you may have noticed that the channel identifier, which is a 16-bit value, is computed from the access address, which is basically public. So, we need this to sniff in connection. So, this is a non-value. And also, the next value, uh, is generated from a counter, next random value, generated from a counter. So, not from some kind of internal state that usually PRNG is used to, um, to, to create, uh, another random value. So, this is a non-value. So, since access address is public, then we can go from 32 anon bits to 16 anon bits. So, this is, uh, quite easy. And this PRNG, well, is it really a PRNG? If, if you, if you look at the, uh, specification, then we know that the channel identifier is constant since it's derived from the access address. And what this, uh, function does, it, that it generates a fixed sequence of six ifs and one ifs. So, this is, this is, this is, this is, this is, this is, the, uh, they usually carry five, 75, pattern a殿 values, indexed by a counter. Normally, this counter bears random number generators AOA to parallelize, parallelize, , sorry in French, uh, this is a very easy excuse, but anyway . Uh, yeah. For this, uh, this generates a fixed sequence of values. And then, um, this is very interesting for us for, you know, uh, but, what does function does, in fact, just runs in one of these, uh, monomize some kind of channels and that's it. So what do we need to break it? If we consider the channel uh no just consider the channel identifier as known you know since it's derived from the access address we are left with a 16 bit unknown value which is a counter and if we can figure out where we are in the sequence of uh this uh 65,566 values then we would find out what this counter value is and once we get this value it's done you can synchronize with a connection and then follow a connection and then jam, hijack and do whatever you want. So how to get the counter value? As an attacker we can only monitor uh some events uh and these events are the following. We can determine when the packet is received on a specific channel and based on this you can also determine when the packet is received on a specific channel. So basically we can deduce something from uh some measures we can do on this uh on a specific connection. If all 37 data channels are used then the uh channel selection algorithm uses a very simple equation or simple computation to to derive the channel for a specific counter. Uh if these channels are not all used then this is a more complex but in fact this uh it m- it doesn't make things more complica uh more complicated uh in the uh in this way. But uh I will focus on the first case uh the first case is that we are going to use all the 37 data channels to make se- things simpler. My first approach was to uh use a sieve. Uh I'm quite sure you're you know about erasathins sieve you know used to find prime numbers. Uh you can see that as a are basically doing the same. Our goal is to eliminate every possible candidate in multiple rounds and in the smallest number of rounds to be more precise. The prerequisites here to do this is to be able to uh to is to know the hop interval value which is basically the time between two hops in the uh hopping mechanism. So how it works, we are going to consider a counter of zero, so just say that it's zero, it's uh hypothetical, it's not the real value we are looking for. And we compute uh channel C zero from this uh p-rng function with this candidate counter and uh based on the uh channel identifier of course. And we wait for a valid packet. So we get a packet at time T zero on channel zero. On channel C zero. And we do the same on the next channel. So we increase the the counter with the counter of one. We compute the next channel and then we wait for a valid packet. And we get a packet at time T one. So we then we measure the the time spent in between. So data T equals T one minus T zero. And since we know the hop interval, the time between two hops, then we can deduce the number of hops between these two packets. So by doing this we can create a pattern that uh will be very useful to to sieve the sequence. So we can see that the uh the uh the uh the uh the uh the uh the uh values have been showed. So basically we are just uh going through the sequence and looking for uh a specific pattern composed of two channels. Channel C zero at uh uh say index uh 200 for instance. And at index 200 plus N, channel C one. By doing this you will get uh between 200 and 400 candidate values for this counter. So remember we are we are looking for the uh counter used at T0. And we do it uh we repeat the operations we take the first candidate out of the uh the remaining candidates and we compute C0 C1. We write a packet on channel C0 then C1. We deduce the number of hops and then we apply our sieve again. We are going to filter these uh the all these candidates and keep only the matching ones. And you do this until one candidate left. And this candidate is the your the value of the counter at T0. So since uh I had no BLE5 devices at this time I decided to implement uh to simulate this uh this attack. So I will show you the result of this uh simulation. So I uh wrote my uh everything in Python, Python 3 and I create this script CSA2 simulation. So I uh I wrote my uh everything in Python and I simulate the pi. So basically at the start there is a uh a counter randomly generated which is a 13,600. And I will go through every candidates uh each one reducing the number of candidates. So it's here 21, 11, 6, 3, 2 until we get uh a single candidate. And this candidate is 13,600 which is in fact the value we are looking for for T0. So that's good. Yeah I, I love when a plan comes together. The problem here is that we need to know the what this Hop Inteller value is uh. I suppose this uh this value was known during my first simulation but in fact I don't know this value. So how to guess this value? Well it's uh some basic math you have to do, since we are going to measure stressed values because uhh on the guess wha, machine uh, time differences between packets received on various channels, then we can, uh, do so, we can compute the GCD, the greatest common divisor of all these measures, and since these mes- these times are normally multiples of the value we are looking for, we will get this value. So, again, I simulated this, uh, this computation. Well, it's, uh, very quick, so I have no video for this one. But, uh, um, by doing only ten measures, I was able to recover the open interval. And I performed a lot of tests, and this test showed that, uh, um, if you perform only five measures, if you compute, uh, five measures, then you get, uh, this approximative success rate of 95% of success. So this is pretty good. If you're gonna issue- get ten measures, then you are quite sure to get the required value. So, uh, so, uh, uh, I'm gonna do this. But that's cool. So, basically, what I got here is that a way to recover the open interval value and another way to get the, uh, counter value, uh, the value of the counter, sorry, uh, at, uh, a specific time. So, let's do it in practice with a real device. Uh, there was a problem, in fact, is that this, uh, version of the protocol has been released, uh, in 2016 and still there is no compatible devices, uh, uh, running on the it's in the market. So I wasn't able to find something to buy that implements this uh this uh this protocol so uh I'm sorry there is uh there is no video of a sex toy hack this time or a drone hack uh but anyway. So um based on my um first research uh I decided to to try to to apply this uh uh this attacks on uh some B85 devices so since there are no B85 devices I'm going to make some. Uh I ordered uh on the uh on the site on the website on the internet the two development boards from Nordic uh which support this new protocol with uh the correct SDK and the correct stack and uh I just programmed this uh this uh board with very basic examples uh one making a LED blink and providing a B85 compatible device and another uh able to connect to the first one. So basically two devices that can create a connection in between and transfer data. And I also decided to improve my beta jack tool by uh implementing some uh some features new features for B85. So um beta beta jack can do the job but only for the legacy file which is the 1 megabit per second uncoded file but doesn't matter my development boards uh are compatible with this file so it's okay. And I modified beta jack to compute this op interval while uh this uh this tool was mapping channels because usually when you're uh attacking uh an existing B80 connection you need to know what channels are unused. You remember I suppose that all 37 channels are used but this is not always the case. So by doing this uh I modified the code to to be able to to get this uh uh this open uh this uh open path. I modified this code to be able to uh to get the uh this uh uh this up in interval while mapping but I first uh first problem um this problem is that normally when you are using CSA number one the first channel selection algorithm this is a 37 channel sequence and you loop over this this sequence but there is no doubles you know the uh each channel only appears once in this sequence so it's very easy to determine this open interval value and you measure the time spent between two packets received on the same channel and then you divide it by 37 and it gives you the the value you want. But this is not the case with this random number generator since uh um a channel can appear twice or maybe more during the sequence. So I had to compute automatically the uh a time out to be sure that uh uh a channel is correctly used. Anyway and I I tested this uh GCD based technique for recovering the open interval and it it works pretty well. In fact once you're uh smash uh when when once you solve all the all the issues based on time out. So um this is an example output of uh what I gave what uh what I get um when I uh uh tried this open interval recovery system on this uh this connection. So I got a open interval of 160 which is uh uh pretty much it. So that's good. Great success for first time. But the main part is to be able to uh at a specific time during the connection. So I implemented this algorithm. The sieve algorithm. And I started trying this uh this algorithm. So the first round uh went pretty well. Uh I I went from 65,000 uh candidates to about 250 candidates which is which is what I showed you uh a few minutes ago. So that was pretty cool. But the next round's completely messed up. Uh I wasn't able to get any data. So I was a bit puzzled. I was a bit confused. Uh I was a bit puzzled. And it turns out that my filter routine took a hell of a time to execute and it induces a delay and I uh I get lost in the connection. So uh this is a uh simple algorithm problem. So uh yeah I was a bit pissed at this time. Uh so uh I decided to redesign my attack and to solve this problem I move from a sieve to a potential motion algorithm which is basically what I was also using. So I started testing it. I had a lot of um um problems with the uh the broken thing. So, normally during my save attack, um, perform a meas- um, a measure and then, um, I filter all the candidates. This time I'm going to do all the measures in, uh, during the first part of the attack and then filter all the candidates just at the end. And by doing this, I get, um, a more complex pattern, but in fact, uh, I'm quite sure to get the correct value. And by doing this, you end up with 10 delta T values. So, some times difference between packets received in various channels. And based on this, we look for this hopping pattern in our sequence and we deduce a counter exactly as we did before. And, yeah, that worked. I was able to guess the counter value. Uh, so, uh, we'll show- I will show you, uh, an example of this, uh, later. So, that was pretty cool. So, um, I'm going to show you the counter value. Uh, so, from this, uh, uh, I told myself, yeah, that's good. You get the up interval, you get, uh, the counter value. Now this is easy peasy. Uh, everything you need to- to do is just to synchronize with the existing connection. Well, good. So, I developed my, uh, the firmware in order to- to synchronize with the connection and, um, yeah, there was some kind of issue here. Um, didn't work at all. So, I got the, uh, correct up interval value. I got the correct, uh, serv- but I wasn't able to synchronize. And, uh, I looked at my code a bit, uh, once more, you know, just to be sure that I didn't fuck it up. And I stumbled upon this part of the code. So, this is the filtering routine. What this code does is just going through all the candidates and filter this, uh, this candidate. So, uh, this is the second version of the approach. So, I need to- to go through the 65,000, uh, and filter this, uh, this candidate. So, uh, this is the second third version of the approach. So, what I'll do is I'll type, uh, and it takes, uh, 536 candidates and it takes a hell of a time again. And by doing this, I was just, uh, 13 hops away uh, 13 hops away of the correct value at the moment I was trying to synchronize. So, by doing this, just adding 13 to the, uh, counter value, I was able to synchronize to an existing connection. And that's pretty much it for the- this, uh, recovery. But I will show you, uh, I will show you uh, how we can use this feature with a simple carbon copy. I'll show you now a video of uh everything working with this uh this firmware so uh for the video purpose of the video I just provide the channel map and the hop interval value so as we can see uh this uh uh this uh tool is trying to recover the PRNG internal counter which is the unknown value 16 bit. It takes some time um generally less than a minute to to deduce this uh this value so it's pretty cool because uh if you are trying to attack a a real life device you have to be next near to the device to to to attack it so uh if it takes uh less than a minute it's okay. Should be very short. And once the uh counter has been recovered then we capture data sent over these devices. So by doing this we got the correct value for the hop interval and then we get the correct value for the counter. So that's pretty much it. You you get a a way to see sniff sorry you get a way to sniff uh data over a BD5 connection but remember it's only on the 1M per second uh uncoded file. And you can also try to jam a connection so basically once you you are synchronized with this uh this connection you can you can inject packets as well. And this is what I did last year uh for you know when I was attacking some devices. And this can also be done with uh my BD5 devices where it's uh how to say this is yeah uh something very special because um I got my device on on the screen here so I'm going to to recover the the p-r-n-g internal counter. And you can see some L.E.D.s uh normally at the uh bottom uh bottom right of the screen. Uh this L.E.D. which when it's uh L.E.D.2 that means it's uh it's uh that is is uh uh lit then it means the connection is still active. I'm going to jam this uh this connection and be be pay attention this is this will be very quick there is uh uh uh some LED blinking uh telling the telling us that the connection has been uh lost and disconnected. So here uh uh I successfully jammed uh an existing connection BD5 connection by using BT jack. Uh yup back to the slides. So um since uh everything went smooth with this uh this attack I decided to to release a new version of this tool of BT jack version 2 including this uh all this research I made on this uh channel selection algorithm number 2. So it's uh it's working uh but I tested it on a very few devices I only got 2 of them so uh I don't know what um if this tool would work with with any type of devices BD5 compatible devices. So um I give you the code, I give you all the the tools. Uh this uh version of the software has not been published on pip uh just not to mess with uh the actual version because I I'm not doing it Stand not sure uh since I made a lot of modifications in the firmware I'm not sure that the uh this version may uh alter the you know the behavior of uh the actual BTL BTL eject version. So just to make things clear you can clone this uh repository and then uh install the device by using some uh python automagic installer uh python setup pi and that's it. So uh all the code is available open source as usual. So to uh to conclude um not so quickly but uh anyway um what this talk uh demonstrates is that the B85 CSA number 2 so the second channel selection algorithm PRNG is weak. Um but there is a reason for that. Remember at uh at the beginning of this research I was uh just thinking thinking that uh this PRNG has been uh introduced in this version of BID to piss hackers uh trying to attack uh BID devices. But in fact uh after uh I thought uh um uh I I I had some other thought about this uh this uh this PRNG but um well it's it's not really a PRNG uh as it's used here. And of course 16 bits out of 32 can be easily guessed and the last 16 bit is a counter so this is very easy to to recover. But in fact this PRNG has been designed to improve coexistence not security the goal of the uh guys who designed this protocol uh this protocol this the channel selection algorithm and this PRNG uh in particular was to improve the coexistence of devices in the same say the same space. By doing this yeah it works! You can get a lot of B85 devices and with the system you can get a lot more devices that we are used to, to have in the, with the B84 version. And also the counter based random number generators are easier to implement and consumes form less, uh, power and memory. Uh, so in the, uh, in the IoT world this is something that makes sense. So is it a, a vulnerability? Well I, I don't think so. I, I don't think it's a vulnerability but in fact it doesn't stop, uh, hackers, uh, to jam or hijack, uh, existing connections. Future work will include, uh, some, uh, a lot of development for BDAD jack. Uh, as I said there are two new files introduced in this BID5 version, BID5 protocol. And this, uh, new files are supported by a new Nordic system and chip called the, uh, NRF52840. And this, uh, this chip is, uh, very interesting because it, uh, implements all the, uh, files natively. So we don't have to do some, uh, some, uh, SDR stuff or anything. We can just use the features of this, uh, of this chip to be able to decode and anchor the, uh, data packet over there. So this is, uh, quite interesting. But the fact is it, uh, demands a lot of work to pull BID5 jack to this new platform because, uh, both of them, uh, are made by Nordic. But there are some, some differences in the way these chips handles DBA protocol. But, luckily, someone called Marcus Mencks made some research, uh, recently on Logitech unifying devices. And this, this guy, this dude made made a lot of uh of code compatible with this chip and I talked with the with him uh we exchanged a lot of mails and this uh this guy has uh uh some piece of code ready to use to implement this so uh I think uh I'm if he if he's kind enough to share with me some uh some tricks he did on this uh on this chip I will be able to port beta jack to this new platform and get rid of the micro bit uh stuff. So this is uh this is it um I think uh I said every almost uh everything I wanted to say. Um the resource materials the all the notes scripts I wrote everything I showed you with uh python scripts is also uh also available on the on the github repository which uh which is the following b85-research which is the uh uh uh uh uh on github so you can get everything uh I developed and try it. Insert me if the code is uh you know dirty and uh and I'm not that clear. But in fact you can uh simulate uh everything the way I did and test it against uh some uh I don't know maybe some new attacks you're uh looking for. So thank you very much for attending this talk and uh I hope it was uh yeah cool. Thank you.