Okay, so good afternoon, DEF CON. Thank you very much for taking the time to be here, and I hope you'll walk away from this talk having learned something interesting and new. And if you have, please do let me know about it. So what this talk is about. With the introduction of shared bicycles and its rise in popularity all around the world, I've seen bicycles all over the place regularly used by people who pay a token sum to use them. This got me wondering how the lock system worked and how secure it would be. Would it be possible to hack the lock and get free rides? It doesn't cost much to rent a shared bike, but wouldn't it be fun to hack a lock? My name is Vincent. I'm from sunny Singapore. I'm currently a security consultant at MWR, and hacking mobile and wireless is my thing. In this talk, I'll first give a quick overview of the bike sharing economy and the locks used on shared bicycles. I'll do a quick recap of BLE for those of you who aren't familiar. Then I'll move on to walking you through how I analyze communications between my iOS device and the BLE. BLE lock, what worked, what didn't, and how a key can be built from what I've learned, and a small demo of an app I've built to get rides for free. So I'm sure by now, we all know that smart locks are rubbish. The state of security now is terrible because, and I could be wrong, companies only care about features and getting the market as soon as possible. They don't care about designing a scale lock. And they aren't performing any tests to validate the security of their solution. Take for example, tab lock. The latest smart lock to be hacked. It talks about having all these incredible security features such as Enclipter fingerprint reader, EAE 28-bit encryption, and anti-theft alarm. But ultimately it got hacked in two seconds. audience. So what is the situation with these guys? These are the three largest bike sharing companies in Singapore. Ofo and Mobike being companies from China. And Obike, a local Singapore startup, which unfortunately has just filed for bankruptcy not too long ago. These guys have operations all over the world and have pretty high valuations. Across all companies, the cost of renting a bike is $0.50 per half hour, which roughly equates to $0.37 USD. So before all the juicy bits, a quick refresher on what Bluetooth Low Energy, aka BLE, is. There are two key things to know to navigate your way around. The first is GAP, or Generic Access Profile. This is the first thing you need to know to navigate your way around. The first is GAP, or Generic Access Profile. This basically defines what the device is. Devices are split into two categories, a peripheral device and a central device. A peripheral device is a low-powered device. It could be a bicycle lock or a pacemaker. And the central device is your high-powered device such as your mobile phone or your laptop. Then comes the Generic Attribute Profile, or GAP. This defines the way that two Bluetooth Low Energy devices communicate with each other. Each BLE device will have one or more services, and within each service it will have one or more characteristics. Services are a group of characteristics, and a characteristic is a data point, both of which are identified by a 16-bit or 128-bit UUID. In the case of a treadmill, for example, a data point can be the steppe climate data, speed, inclination, or heart rate. And in the case of a Bluetooth Low Energy device, it can be a speed or inclination. So that's a lock, the data could be the battery life or the unlock mechanism. So let me give you an example, an idea of what the bicycle lock is, how it looks like and how it operates. How do you pick a lock when you don't actually own the lock? My first hurdle came when it was time to figure out properly how a bike lock would work. Since I have pretty much zero experience in Bluetooth or lock mechanisms, I decided I should go buy one instead. Quick search on China's beloved shopping site Taobao quickly came upon this. For $30, I could have my own smart bike lock. Appears to operate the same way and apparently the company also OEMs the entire solution to bike sharing companies. Maybe one of my targets would use it. In essence, this is how the entire process of renting a bike works. You download one of the apps, OFO, Mobike, Obike, what have you, enable Bluetooth, find your account, scan the QR code on the bike and the bike will automatically unlock. These bikes have a small solar panel to charge the battery in the lock and most of the locks do not come with built-in GPS. GPS data is provided by the app. Wherever you cycle to and finally lock the bike, the app will record it and send it off to the cloud via HTTPS. There are, of course, more expensive locks which do have inbuilt GPS. So the first thing I did, like any good hacker does, is to tear the part upon receiving it. This is a teardown. The lock with the QR code on the left and the four cell battery inside, this lock charges via USB. This lock charges via USB. This lock charges via USB. This lock charges via USB. This is the logic controller with Bluetooth radio and the motor that releases the lock. So it's a spring-loaded lock and the lock is held in place with a pin in the notch. When the unlock command is received, the motor will then engage to release the lock. So time to actually look at how the lock and app were communicating. Again, I had no idea where to begin, how Bluetooth worked, et cetera. I turned to a great presentation by Sloamir Jazic, sorry if I mispronounced your name, where it was effectively man-in-the-middling the Bluetooth connection, thus allowing the modification of packets. Unfortunately, I wasn't able to get the setup working for that. Unfortunately, I wasn't able to get the setup working for that. Then I've found another fantastic presentation by Anthony Rose and Ben Ramsey from DEFCON 24, where they used an Ubertooth 1 to sniff BLE packets and then used the Wireshark to figure out what was going on. But for the life of me, I couldn't figure out what was happening. So this is an example capture that I took. This shows a capture from the Ubertooth 1 and the BLE write request and response. Again, didn't understand what was going on. But after this packet was sent, the lock opened. So I basically replayed the bytes from this packet with no result. Again, I have no idea what's going on. So back to drawing board. I figured I needed two things to be able to help me figure out what was going on. First, I needed to figure out how the app communicated with the lock. What were the endpoints that it communicated with? What were the services and characteristics that the app communicated with. And second, how I could intercept the BLE to understand what was going on. For the first problem, I needed a way to figure out and understand how the app communicated with the lock via Bluetooth. After doing a little more Googling, I found a tool written by EvilSocket, Blair. You may know EvilSocket as the author of the more famous Bettercap toolkit. So after doing a little more Googling, I found a tool written by EvilSocket, Blair. You may know EvilSocket as the author of the more famous BetterCapped Toolkit. So what Blair does is to influence the lock in the app a bit. After that, I've found a tool written by the more famous BetterCat toolkit. is that it essentially enumerates the services and characteristics of any BLE device. This allows one to see in a practical manner what services there are on the device and what characteristics can be written or read from. In this screenshot, you can see at the bottom the different characteristics that can be read from or written to. For my second problem, since I have the app and I have the lock, it all comes down to understanding the process of what BLE messages are sent to unlock the lock. I turned to Frida and the Frida Trace tool which would allow me to view in real time what the app was processing. For those of you who have not used Frida before, it is a wonderful tool to allow instrumentation of applications across various platforms. In particular, the Frida Trace tool allows you to view the app in real time. The Frida tool used on the iOS platform allows users, in essence, to log in relatively real time on Objective C classes and methods and C functions which are accessed and executed by the application. Since we can use Frida to hook and view methods and messages, we now need a way to ‑‑ we now need to find which ones to hook. In iOS, the core Bluetooth framework is used to perform Bluetooth communication. We can use Frida to hook and view methods and messages. We can use Frida to hook and view methods and messages. We can use Frida to use messages and then import messages from our system with the app. In iOS, the core Bluetooth framework is most commonly used. We can use Frida to hook and view methods and messages via our platform. We can use Frida to hook and view methods and messages via our platform. We can also use Frida to load messages and messages toนะutnk, for example. We can touch something and tyres. This one is used on a lot of our apps and devices. Once we have all of these methods of loading messages and messages, it is difficult to use Frida to hook and view. When we run Frida to a different feature, case a lock to push messages to the application. This is done through the notify property of the characteristic and it can be enabled by the set notify value. We can then capture the push message by tracing the update methods of the CB peripheral delegate class. So after a lot of reversing of the app, processing of traffic and recording of BLE reads and writes, I've come up with the following process to unlock the bicycle lock that I bought from China. Obviously, scan the QR code. The app will then get the lock key for the server. The app makes a the server respond to the lock key. The app makes a request to the lock for an encrypted token by sending the right request. Lock responds with the encrypted token through the notify property. The app decrypts the token with the key from the server. Sends a right request and it unlocks. So this is a challenge and response process where the lock will provide the token and if you have the corresponding key, you'll be able to decrypt the token and send the result back to the lock. By the way, if it isn't already clear, the security of the lock is horrible. If you don't have the key, you can retrieve any key for any lock from the server by just incrementing the lock ID for this company. And they make a whole bunch of locks. So let's try this against the real world. Now we've seen how such a lock could work and the steps needed to understand how it works, what methods to hook and how to use it. So let's get started. Let's see what kind of lock and what kind of operations the app and the lock may perform. How does it compare to an actual lock used by OBIKE? For the most part, the hardware looks pretty much the same. Someone did a YouTube video teardown of the lock. As you can see here, we have a single cell battery, the lock hardware, and a Texas Instruments CC2541 SOC chip. Now let's find the service and characteristics UUIDs that could be of interest. Again, with Blair, we know what could be of interest, but we don't know how they are used. To figure this out, I traced the entire flow of the app to identify which characteristics was most used. And as it turns out, communications went to the FFF6 characteristic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . that I bought off Taobao, it appears to use some sort of challenge and response mechanism. Let's go through all of that in a little bit more detail. Scanning the QR code provides the app with the ID number of the lock, and as seen in point one, the QR code is essentially the URL with the bike ID at the end. Assuming you have used the O-Bike app to scan the QR code, a request is made to the server with the lock ID and the current coordinates of where the lock was scanned. The server responds to the status check with whether the lock is faulty or not based on reports from other users. And if it's not, the app will proceed to the next step. Here, the app requests for a key source from the lock. This can be a little bit confusing, so let me explain. As I mentioned earlier, it is possible for the user to scan the QR code, but it is not possible to scan the QR code. It is also possible for a peripheral device to send push notifications, also known as notify in BLE, back to the app. As shown here, the app is setting the notify flag in the FFF6 characteristic. Next, the app sends a request for the key source to the lock by performing a BLE write. In this case, a dump of the BLE write at the memory location shows that the write command is in the form of the following byte. It is being scanned to the same FFF6 characteristic. The app now waits. If the command sent was correct and accepted by the lock, the lock will respond with the token or the key source. This is the response. Here, we can see the response through the trace of the update value for the locking IP, but it is not visible. As you can see, the lock cannot be sent to the lock by method. And within the response, the app picks out the key source as shown. What the data means, I have no idea. But I don't need to know. Because every time this transaction happens, the key source is always located in the same location. It is always taken from the 9th to the 12th bytes. The key source is then sent to the server through the unlock pass API. And assuming there are no errors, the server responds with a pair of keys. So now we've got the keys. How are they used? The unlock message is constructed and sent to the FFF6 characteristic in two parts. As you can see, the two write value messages. And below is the dump of how the actual message is written. Or what the actual message is. This looks roughly like the message that I tried replaying earlier from the wire shot capture which didn't work. So I dug a little deeper into how the unlock message was constructed and try and piece together what the different values meant. After looking at numerous unlock messages, I found the following. In the first two messages ‑‑ sorry. In the first message, the first two bytes are still in the same location. They are static throughout all messages sent from the app to the lock. Whether it's an unlock message or any other form of message, these two bytes are used. The next byte is the length of the message which is also static for the algorithm. Next byte could be a command byte to unlock the lock. Together with the key index. Then the subsequent six bytes are static. Again, I have no idea what they are used for. And the final five bytes of the message are the date timestamp. Message two contains the key from the server. However, this has been truncated to 12 bytes. Why this has been done, I'm not sure. And the last byte is a checksum. This is done by performing an XOR of each byte across both messages. Now, I had to jump through a couple of hoops along my journey. The first was trying to understand what was sent from the app to the server. And as you can see here, the messages look to be encrypted. Why the programmers would encrypt the messages sent to the server is beyond me. And they're just wasting their time and my time. With Frida, hooking the right messages couldn't be easier. I found that the messages were encrypted using AES. We have a combination of a static string and a version number of the application provided in the HTTP header as seen here. So, okay. Encryption killed. For those of you who have noticed, there is a string tagged to the back of the message sent to the server. What the heck is that? Again, the developers implemented some form of integrity check. For some unknown reason, to waste time, with further assistance from Frida, that string I found was a SHA-1 sum of the following values. The data that's actually to be processed by the server, a static string, and the application version. Now, you must be wondering how users get charged. After the byte is unlocked, the app sends a message to the server. And the server gets the log status to the server. Informing it, it has been unlocked. And to start a timer. Once you're done writing, the app will then send the log status again to the server to stop the timer. Lastly, you're billed for the amount of time that has been used. So, if I actually write my own app, to perform the unlock and halt all further communications with the server, after unlocking the byte, I get free rides. After jumping through the hoops and understanding how the BLE communication works and how the unlock command is built, I built the my own key. Sorry, the video is a little bit dark, but here I am entering the log ID into my app. Waiting for the server. That's the unlock sound. So, if you've no doubt noticed, opening the log depends on the connection to the server. How can you then unlock it offline? Since Obyte has recently gone bankrupt, someone dismantled the log from the byte, retrieved the chip, and sent it over to me. My solution was to try and get the dump of the firmware to figure out how the unlock algorithm works offline. Unfortunately, the readout fuse was set on the TI chip, and it was not possible for me to dump the firmware. If any one of you knows how to get around this, I'd like to hear from you. Okay, it was relatively easy to unlock the log from one bike sharing company. Should be relatively easy to do it for another. No? I tested this process against Mobike. Same thing. We start off by finding the services and characteristic UUIDs that could be of interest. Looks to be a lot simpler here. Only two characteristics. And it is obvious which we need to write to to unlock the bike. Moving on. For Mobike, the process in unlocking the log is much simpler. Same as before. You scan the QR code. You get a bike ID. And then you go to the server. App sends the log status to the server. Also sends your coordinates. So we respond to the log status. However, this time, if the log is good, the server will also send along the unlock key immediately. The app then uses the key to unlock the log. So no challenge as a response mechanism here. It's just a direct unlock. As before, let's go through all of that in a little bit more detail. Similar to Mobike, after the bike is unlocked, log status sent to the server. Timer starts. When you're finished, you lock the bike. Timer stops. User account is charged. Again, if we cut off the messages after the unlock, you don't get charged. Similarly, I encountered various crazy integrity checks implemented by the developer. So I'm going to show you some of the features they've implemented in this. The HTTP messages for the Mobike app, there's a sign parameter, and there's an EP data. How are these formed? In this case, they use RSA encryption to encrypt a user ID string together with the current date time. And the output of that is used in messages sent to the server. The sign parameter is then an MD5 hashed to the server. So you're of the data that's sent to the server. After going through all of that, again, the process starts out the same. User scans the QR code. The QR code contains a URL with the bike ID at the end. Assuming you've used the mobile app to scan the QR code, a request is made to the server with the log ID and the current coordinates of where the log is scanned. However, here's the difference. The application server will respond with the faulty message if the log has been reported faulty by a number of users. Or it will immediately respond with an unlock key if the log is in good condition. This differs from OBIKE in that it doesn't require a challenge and response. So what happens with the key from the server? First, according to the trace, the app tells a log to send it a notification by setting the set notify value to one, as seen here for the FEE0 and FEE1 UUIDs. Then the app breaks up the key into three 9-byte pieces, appends a 2-byte header to each. And writes it to the log via Bluetooth. And it unlocks. Again, to make it clearer, the key response from the server is broken into three 9-byte pieces. And an incremental header is then added. And returned to the log. And it unlocks. Straightforward and simple. In testing, however, I faced one problem. It seemed that the log was able to keep track of time. Because the log was able to keep track of time. Because every key received from the server for the same log is always different. Additionally, if there was a delay in sending a key to the log, it would not work. So after all that trouble, I modified my app. And this time around, I only programmed this specific byte ID. So it would save me time and trouble. Let's play that again. Okay. So there were two types of log schemes across the three logs that I faced. The first was a challenge response scheme. Where a challenge was requested from the log. This day. Data was then sent to the server to process. Or data was processed on the client side. Output from this processing was then sent to unlock the log. The other type was a direct unlock of the log based on a key provided by the server. So when I started this journey, I had no idea how BLE worked and how one would begin looking at BLE devices. There was no process or one that I was aware of when I started. On how to look at BLE stuff. I hope given the following repeatable process. Anyone. Who has wanted to start breaking BLE devices would have an easier time. As we have any project. We first need to intimate our tech surface. And I found this to be done easily with Blair. As shown previously, we can use Blair. to integrate the services and characteristics of any BLE device and understand what we communicate with. Then we find out if the device does send notifications to the app. And if so, we enable notifications by setting the set notify value. Lastly, we hook into the appropriate read and write methods to figure out what messages are being read from and written to the BLE device. And we also hook the did update methods to find out what notifications, if any, the peripheral devices send to the central device. So I didn't make use of any special hardware such as the Ubertooth one or develop any special app. I use a $5 Bluetooth dongle to animate a BLE device. I use my iPhone to help run the app. And Frida to help with understanding the communications between the app and the lock. That's all for me. Thank you for listening. Thank you.