Hello and welcome. My name is Mike Ryan. I'm the founder of Ice9 Consulting, and in this video, I'll cover a new tool I've developed for Bluetooth sniffing with software-defined radios, as well as some background and theory on how I built it. Before I get into that, I'll introduce my company. Ice9 Consulting is a boutique consulting firm that specializes in Bluetooth, IoT, and embedded security and development. For more info, you can email info at ice9.us, and full contact info will be available in a few slides. I'll open with a question I get asked a lot. How do I sniff Bluetooth? It seems like something that should be easy, right? Like, we've been sniffing Wi-Fi for as long as we've had Wi-Fi. So how about Wireshark? It's certainly my go-to for sniffing Wi-Fi and Ethernet, so what about Bluetooth? As many of you probably know, if you go into Wireshark today and look for Bluetooth, you won't find anything. At most, if you're on Linux, you might find the btmon interface, but that's not true Bluetooth sniffing. But that's all about to change. As of this talk, I'm releasing a new tool that integrates with Wireshark and works with most popular software-defined radios, and here's how it works. You open up Wireshark, scroll down your interface list. For each supported software-defined radio you have attached, you should see an entry for Ice9 Bluetooth. You can click the little gear icon to change some settings, then smash that start button, and voila, you've got Bluetooth packets. Yes, it really is that simple. And the best news yet, if you have a HackRF, a BladeRF, or a Usurp B200 or B210, you can finally use it in Wireshark to sniff some Bluetooth. I'm pleased to release the Ice9 Bluetooth sniffer, available immediately from the URL at the bottom of the slide. Here's what it can do. It can detect BLE advertising packets and decode BLE data packets on any channel promiscuously. It can identify classic Bluetooth laps, and I'm working on adding more features in this space. With the current hardware, you can listen on up to 56 channels simultaneously, though in practice your CPU will probably limit you to fewer. For a benchmark, my M1 Macs can listen to 36 channels in real time. Later in the talk, I'll cover how I'm trying to increase that. It's written in Portable C, its only dependency other than the SDR libraries is LiquidDSP, and it runs on Mac and Linux. In principle, it should build and run fine on Windows, but that's not really my bag. I will gladly accept contributions in this space. I've also included my contact info. And that's it! If you're just here to sniff Bluetooth, follow the instructions to install the software and away you go. For the rest of you who want to dig a little deeper, I will now take this opportunity to segue into the real title of this talk, Everything I Wish I Had Known About Software-Defined Radios Since 2013. I picked 2013 because that's when I got my first real SDR, a HackRF Jawbreaker. I fired up that bad boy and did all the usual things. More or less the Hello World of SDR applications, I fired up GQRX and tuned the SDR to the middle of the Broadcast FM band here in the states. Now, this is pretty nifty. You can watch about 20 stations play on in real time and click on them to listen. Eagle-eyed viewers may even be able to spot some digital sidebands of the in-band on-channel HD radio stations. However, as cool as this is, I knew it was only scratching the surface of what software-defined radios are capable of. So, I took the next logical step and fired up GNU Radio. I made a handful of tame flow graphs similar to the one pictured. However, whenever I really tried to start decoding the signals, I kept running into the same issue. The flow graphs, blog posts, and YouTube tutorials always got a little... intense, I guess is the word I would use. They always started out comprehensible enough, but by the end, they'd always end up looking like this picture of Valent Sieber. Now, I don't mean to denigrate GNU Radio. It's an excellent tool in capable hands. This is almost certainly a me problem, but I find when I have problems, sometimes other people have the same problems. I didn't study digital signal processing in school. I'm not really a radio guy by training. I know enough math to be dangerous, and I can sling code. I was able to figure this stuff out, and I bet you can too. In order to do so, let's start from the very basics. What, exactly, is RF? Borderline philosophical question, right? Well, that's simple enough. It's a burst of energy at a given frequency. That's probably not the most useful definition, so what is it exactly? If you're watching this talk right now, you're looking at it. Literally. Visible light is extremely high frequency RF. We're talking hundreds of terahertz. When visible light hits our optic nerves, they emit signals that our brain uses to create images. We're interested in much lower frequency RF, though. Let's say about 50 megahertz to 6 gigahertz, which just so happens to be the range of our SDRs. Let's build a model of a simple broadcast RF system so we have something to talk about. It all starts with an audio source, like a microphone. That's wired into some kind of broadcast tower that emits tons of RF on a specific frequency. That RF travels through the air to the antenna on some kind of radio, like a boombox, where the signal is picked up, amplified, and converted back into sound. Now let's consider that RF flying through the air. What if, instead of a boombox, we attached our antenna to a software-defined radio? When we capture with the SDR, it spits out digital IQ. What is that exactly? Well, by way of analogy, let's consider another commonly digitized signal, sound. Sound is a compression wave through the air. Air molecules strike a membrane inside a microphone's transducer. The movement of that membrane is converted to a digital signal, sampled periodically, and we're left with a digital audio file. In this regard, you can think of a software-defined radio as a microphone for RF. Armed with that knowledge, how do we interpret the data? One simple way is to look at the signals in the frequency domain. This is a spectrogram of someone saying a few words into a microphone. Time is on the x-axis, and frequency in hertz is on the y-axis. Simply looking at this is enough for us to glean some patterns, such as the low-frequency voice sounds and the high-frequency fricatives. You can immediately imagine approaches you might take to processing this data when presented this way. Let's look at the broadcast FM spectrum, that's 88 megahertz to 108 megahertz, in the frequency domain as well. Once again, time is on the x-axis, and frequency in megahertz, this time, is on the y. Aside from the range on the y-axis, it looks quite similar to the previous spectrogram. Each bright squiggly line is an FM radio station, and in fact, if we zoom in on a few of these, you can see that this frequency domain representation of the RF signal looks an awful lot like a time domain representation of an audio signal. Hmm, I wonder if this is what they meant by frequency modulation. Okay, okay, okay, enough background. This is a talk about sniffing Bluetooth, right? So let's sniff some Bluetooth. Step 0, not depicted here, is to find some software. GQRX or SDR-Sharp are good options depending on your platform. Step 1, tune your radio to somewhere around 2400 megahertz. 2427 is a good choice. Step 2, set your sample rate as high as it'll go. A higher sample rate means you will capture more channels. Finally, smash that capture button and let her rip. Give it a few seconds and stop the capture. Open up your capture and InSpectrum, and there you go. Each one of these red blobs is a Bluetooth packet. What's more is that you can clearly see they're organized into channels. Remember, frequency is on the y-axis in this spectrogram. For the sake of keeping things manageable, let's target a single channel for sniffing. In order to do that, we must do two things. First, in this capture, this particular channel is centered at about 0.5 megahertz, and we need to move it down to 0 megahertz for the rest of our algorithms to work. Once we've moved it down to 0 megahertz, we have to filter out all the other channels that we're not interested in. Cool, so how do we do that? First, moving a radio signal around is very simple. Let's say your signal of interest is at x megahertz. In order to move it down to 0 megahertz, you simply multiply it by a sine wave at negative x megahertz. With that taken care of, we can filter out all the frequencies we're not interested in using a low -pass filter. Typically, at this point, we also decimate the signal to throw away redundant information and make it easier to work with. What we are left with is a single channel, filtered and ready for demodulation. Let's look at our filtered centered channel. Bluetooth is a bursty protocol, which means it doesn't broadcast continuously, but instead sends data in periodic packets. What does this mean for us? This means that we can't leave our demodulator running all the time. Otherwise, 99% of the time we'd be demodulating noise, and that could lead to false detections of packets. Let's zoom in on a single Bluetooth packet. We need a way to detect the presence of this packet against the background noise. One possible way of doing this is to plot the amplitude of the signal over time. What you'll notice is that when a packet is present, the amplitude goes up by a lot. One very simple way of approaching this is to then draw a line at some value. Let's call it squelch. When the amplitude is below the squelch, we know there's probably noise on the channel so we don't even attempt to demodulate. Once the amplitude goes above the squelch, or breaks squelch as the jargon goes, we know some burst of RF energy is present on our channel. Not only that, we can also detect when the amplitude goes below squelch, and after a short timeout we know the burst is over. This gives us bursts as well as burst lengths, which will be important later, so remember that. Neato! We have bursts. Let's dive a step deeper into demodulating them. In Spectrum makes this super easy. Just right click on the spectrogram, point to add derived plot, and click add frequency plot. This will add some lines to the spectrogram that you can move around to center on the burst. Be sure to adjust the bandwidth of the filter by making it taller or shorter as necessary. Once you've done that, in the frequency plot below you'll see what is obviously some kind of digital signal that you could probably decode by eyeball if necessary. But we don't need eyeballs for this, we have computers to do our bidding. Let's look at the raw demodulated data. In Spectrum you can right click on the frequency plot and click export samples to file. Load up the samples in your favorite graphing software. I'm using GNUplot. If you plot them as a time series you get something that, hey, looks exactly like that demodulated signal from in Spectrum. Now the y-axis on this chart is a value in some strange units. I think it might be radians per sample or something, but essentially it's proportional to the frequency offset used in the frequency shift keying modulation. First thing you might notice upon taking a closer look is that the symbols are not centered about zero, they're slightly below zero. This is called the carrier frequency offset, and it exists because there's some very slight offset between the center frequency of my radio and the center frequency of the transmitter's radio. Before demodulating we'll have to correct for that. Next you might notice that the values range from approximately negative 0.2 to 0.2. This is our FSK deviation. For our purposes it would be most convenient if the values range from negative 1 to 1. Let's look into how we correct for carrier frequency offset and frequency deviation. I searched the literature and honestly didn't come up with a lot of good options for how to approach this. Back in 2016 Michael Osman presented a really interesting talk on whole packet clock recovery. As part of this research he published what he calls the median method, and I have taken that and improved upon it. Thus I present to you the improved median method. You take the first n points and bucket them into positive and negative values. If either of those groups is empty reject the packet. We find the max as the median of the positive points and the min as the median of the negative points. Our midpoint is the average of the max and min values. This is our carrier frequency offset. What we call the scaling factor is half the distance from the midpoint to the max, or the half height of our signal. This is our FSK deviation. First we subtract the midpoint from all of the points, centering them about 0. Finally we divide all the points by our scaling factor, which scales them from negative 1 to 1. We are left with a normalized corrected packet. It's centered about 0 and the values swing from roughly negative 1 to 1. This we can work with. Any signal processing textbook will tell you that the next step is clock recovery. This is the process for recovering the original signal clock and phase so that you know exactly when to sample the data so it's in the exact middle of a symbol. There are a bunch of approaches to do this, including the aforementioned talk by Michael Osman. Myself, I decided to completely punt. I finagled things so that the data we process is 2 samples per symbol at this point. This means we can use every other sample as our symbol or bit value. The packets are short enough and the clocks are close enough that this works fine for our use case. That said, if you have a bigger brain than I do, check out the polyphase symbol synchronization method. Okay, bada bing bada boom, we've turned our digitized analog signal into a pile of bits. Here's our real Bluetooth packet turned into 1s and 0s. There's only one slight problem. We don't know exactly where it begins. How do we even interpret this data? For that, we turn to the spec. The Bluetooth core spec gives us this table as the format of a BLE packet. You can see they always begin with an 8-bit preamble, which is 010101 or 101010. Following that is a 32-bit access address. This value is fixed for advertising packets, and for connections, it's a random value shared by the two parties when they establish the connection. Following that is a short header, a data field, and a 24-bit CRC for error protection. If we were building a regular Bluetooth transceiver instead of trying to sniff Bluetooth, our job would be easy. We would know the value of the access address either because we were part of a connection or we were on an advertising channel. This means we could search the bitstream for that 32-bit value and know with high fidelity that the remainder of a packet destined for us would follow. But we're making a promiscuous sniffer. We want to be able to capture all packets even if we don't have a priori knowledge of their access addresses, so this approach won't work for us. You might be looking at the preamble and thinking, why not just search for those 2-bit patterns? Again, this won't work. Those values are very short and susceptible to noise. You'd get a ton of false positives and false negatives with this approach. Instead, I took a novel approach. Let's zoom in on the header. The second half of it is a length field. What if we compare this header field to the length of the burst, since that's a value we know from earlier in the processing chain? Here's an illustration of the approach. Pictured is our packet, and let's say the burst length is 78 bits. First, we assume the packet starts at the beginning of the burst. You can see the 101010 preamble, followed by our candidate 32-bit access address. After this is the header, with an 8-bit candidate length. Let's say our first candidate length is 138 bits. And note that these values are bogus. Don't try to compare them to the packet above, because I just made them up. So our first candidate length is 138 bits. How does that compare to our burst length? It's much longer, so that's probably not correct. This is unlikely to be the start of the packet. Now we move the start of our packet forward one bit. Here again we have our preamble, our candidate 32-bit access address shifted over by one bit, and our candidate length shifted over by one bit. In this case, the candidate length is 74 bits, pretty close to our 78 bits. Let's remember this one. For the sake of completeness, let's move forward one more bit and see what the candidate length is. If we do that, our length comes up as 15. Compared to 78, that's way too short, so this is not the correct offset for our packet. That only leaves us with a second case we considered. This means we know the start of the packet, and our candidate access address is probably valid. We can decode the rest of the packet and stuff it into PCAP. Boom, open that up in Wireshark. Well hold your dang horses, that's not what I showed at the beginning of the talk. I promised interface lists and buttons. Enter extcap. This is a little-known feature of Wireshark that was introduced in 2013 by these two clowns. Mike Kershaw, who you may know as Dragorn of Kismet fame, as well as yours truly, Mike Ryan, the Bluetooth expert. These pictures are what we looked like in 2013. This is what we look like today. In the intervening, oh my god, nine years, the code has been made a core part of Wireshark and has been available for quite some time for anyone who wants to implement custom interfaces. It's extremely simple. You just follow the specification for implementing a handful of command line flags, output PCAP into a pipe, and you get Wireshark support for free. This feature is really well documented, so I won't go into details here. If you have something that produces PCAP that you want to add to Wireshark, give this a look. Anyway, that's that. Bluetooth and Wireshark. Talk over, right? Well, kinda. That's the hardest part done with, but remember earlier, I said we were only going to look at one channel. I promised up to 56. Remember this? We could just do this 56 times in a row, right? Once for each channel. Well, yes we could, but it would be incredibly slow. I hate to break it to you, but this image is a bunch of lies. Very few modern digital communication systems work this way. Let's go back to our image of the Bluetooth spectrum and let me be possibly the first to introduce you to an amazing and incredible tool, the polyphase channelizer. At its most basic level, it splits the spectrum into equally sized channels and allows you to process them in parallel. It's built out of polyphase filters, as the name might suggest, and those are completely bonkers. I can only barely wrap my head around how they work, and they're totally worth looking into further. Check out Fred Harris's lectures and his book on multi-rate signal processing to have your mind blown. This finally allows us to get to the overall architecture of the Ice9 Bluetooth sniffer. It begins with nMHz of RF, where n can be anywhere from 4 to 56. This gets fed into a polyphase channelizer, which I've configured to spit out n streams that are 2MHz wide. Remember how I mentioned two samples per symbol earlier? This is where it comes from. These streams are fed into n burst catchers, each running in its own thread, that watch the signal amplitude and mark the beginning and end of bursts. Those bursts are fed into a queue that is serviced by a single burst processor thread. This is where the FSK demodulation, Bluetooth detection, and PCAP stuffing happen. From there, we got Bluetooth. Now, some comments on this architecture. First, you may be looking at this single burst processor and thinking, why not have a few more of those? I kept an eye on that queue, and even under very heavy load, it never fills up, so that's not our bottleneck. Instead, the issue is over here in the polyphase channelizer, and specifically in there, the FFT. This is not something that trivially paralyzes over threads, so your single core performance will be the limiting factor. The good news is that this is something that is extremely amenable to GPU acceleration, and that's something I've been actively looking into. I'll leave you with some parting thoughts. Remember the carrier frequency offset and FSK deviation that we corrected for? These are physical properties of the transmitter that can be considered a leakage channel. If you plot them on a scatter plot, a few things become obvious. First, if you look at just the purple crosses, the classic Bluetooth packets, you can see near the top there's one cluster, as well as another cluster much lower. This implies that there were at least two distinct classic Bluetooth devices transmitting when this data was collected. Similarly, looking at the BLE packets, you can see one cluster here, another here, and a longer potential cluster over here. There are obvious privacy implications in this, and I'm not the first person to make this observation. A very interesting paper just came out in the IEEE Symposium on Security and Privacy covering this very topic. It's not plumbed out for general use, but if you want to experiment with this, the code is available. Finally, a few pieces of related work. First is Jiaoxian Jun's BLE Sniffer. This one is a single-channel sniffer more akin to an Ubertooth or NRF sniffer. That said, it's very capable and totally worth a look if you have BLE sniffing needs and a HackRF or BladeRF. Next up is the original GR Bluetooth, which isn't very good and I don't recommend. However , it's the first open-source Bluetooth sniffer for SDR that I'm aware of, so it at least deserves a shout. Last up is a paper by Cominelli et al that uses a sniffer architecture very similar to mine and makes use of GPU acceleration in the channelizer. As I said, this is something I really want to do, and if you're interested, contributions are extremely welcome. No work is done in a vacuum, and this work in particular could not have been done without the RFHackers Sanctuary and DEFCON, who put on this event, as well as Michael Ostman, Rob Gilduta, Jared Boone, Tal, and The Liquid DSP Project. Greets, of course, to their eBay Red team, Cousin Nico and all the other cousins, Sammy, Dragorn, Dominic Stupid, and all the other flat ducks. And, of course, thank you, the viewer. Here's the info once again, I'll just recap the features quickly. IceDyne Bluetooth Sniffer can sniff BLE advertising and data packets promiscuously, but it does not yet follow connections. It can recover laps from classic Bluetooth packets and sniff up to 56 channels simultaneously. It's written in Portable C and runs on Linux and macOS. Currently, it supports HackerRF, BladerRF, and Usurp B200 series. If your favorite SDR is not on that list, let me borrow the hardware and we'll make it happen. Find me on Twitter at mpeg4codec, email me at info at ice9.us, and thanks for watching.