Give Xenofx a big round of applause. Alright, hi everyone. I guess we're going to get started two minutes early, which is great because I packed in a lot of content into this period. My talk is Dissecting the Teddy Ruxpin Reverse Engineering the Smart Bear. It's essentially my experience taking my child's toy and trying to see if it was going to cause any security nightmares for me. But we'll get into some fun things here on this presentation. A little bit about me. First of all, my Twitter handle is at Xenofx. I go by Xenofx. I'm a security researcher at Silance. I'm a founding member of a hardware hacking group called The Exploiteers. And I'm a contributing member to a local community that we have called Austin Hackers. A little bit about Exploiteers. We have roughly 10 members, give or take a few, that don't officially associate. But they are pretty much part of the group. We have Agent HH, CJ, Cody, Gynophage, Maximus, MBM, Sarek, TD Wang, and XoO String or Null String, and of course me. So our general goal is to just hack things. Anything, anywhere. We originally started hacking Google TVs, and then Google killed off the Google TV. So then we just started hacking anything we can get our hands on. We have a pretty decent community, and we're all very helpful. So, check out our Exploiteers site where we have like 60 plus embedded devices that have roots and other hacks. We also have an IRC network that I'll talk about at the end. So a little disclaimer, first of all. The data within this presentation was all stuff that I reverse engineered. I didn't have official documentation or anything else. So a lot of my attempts were just essentially trial and error and reversing what I could, when I could. I literally have been working on this for a very long time. And you'll see why. It's essentially an RTOS environment, which can be a little more difficult because after you want to interface with the peripherals. So terminology. You Teddy-ophiles will already know this, but an Iliop is a brown, bear-like creature with a kind disposition. You might think Teddy Ruxpin's a bear, but he's actually an Iliop. So. The OG Iliop. This was the 1980s Teddy Ruxpin I think a lot of us are probably familiar with. It used cassette tapes on its back that you replaced. And you had physical books that read along with the cassette tapes. His mouth moved and his eyes opened and closed. But it was a physical movement, not an LCD screen like the newest revision. So the new Iliop. The new Iliop is this guy. Essentially. Oops. Essentially. It has animated eyes, a moving mouth, speaker, Bluetooth low energy, USB mask storage that is used via an internal micro SD card, and a companion mobile app. Getting inside Teddy. So I'm about to show y'all what this looks like. It's terrifying. So. A little. So a little about Teddy. This particular revision comes with a mask that you put on him so he doesn't scare your kids. When he's off. It's needed too. Because like I said it's crazy. But let's take his jacket off. And get him out of here. This is essentially Teddy Ruxpin. This is Teddy's skin. So. It's pretty enjoyable. And here's Teddy on. Hi. My name is Teddy Ruxpin. Can you and I be friends? No. No. I actually tried to wear his skin. It doesn't fit on my face. So inside of Teddy we have a logic board. And this is the top of the logic board. It's actually stored right in this eye area here. There's this chip called the Sonics MCU. I don't remember what the physical or the actual name of it was. But there's a speaker driver. The Bluetooth low energy. There's an SPI flash. And then there's this SD card slot that actually ends up holding the story books that are stored on Teddy Ruxpin. This is the logic board's bottom. You can see there are two 128 by 128 LCDs that are used for each individual eye. And then on that previous picture. We'll go two slides back. You can see that there's on the. I guess right side. There is a module that says Teddy firmware 1.1. That module is an MYN822BLE module. Which is essentially just a module for the Nordic NRF51822 chip. So here is the diagram for interfacing with its SWD port. And also all the different GPIO pins that are used within Teddy. They only have. Roughly. 11 GPIO pins in use of the 22 or so that are available. Or 26 that are available. And then of course they have SWDIO and SWClock hooked up. Which is the debug pin out for software debugging. Cortex M0 chips. So with that particular pin out. We were able to dump the firmware for Teddy. And also the RAM. You can dump it with OpenOCD. But I had a SEGGER J-Link based on doing some badge development. For the whole badge life project. And I just used that with NRFJPROG. To dump the firmware and RAM. Like I said you can use OpenOCD. And if you ping me I can give you a config to make that work. So this particular Teddy. Instead of having physical books. He uses a mobile app. And so you can see in the mobile app picture. They have a little cartoon picture of Teddy. And his best friend Grubby. So the mobile app works essentially by using BLE. To communicate when each page is turned. And when a next story should be read. So I took that. And I threw it. I took the APK. And I threw it into JADX GUI. And it was really nothing more than a wrapper. For a bunch of Adobe Air content. So within the APK. Was a Swift file. And I took that Swift file. And then I threw it into JPEXs. Essentially this is a flash decompiler. And all the BLE stuff was within this Swift. So if you are poking at your own Teddy. You can. You're better off not even looking at the APK. Just unzip it. Grab the Swift. And throw it into JPEXs. So I went ahead. And I listed all the BLE info. The receive and transmit UUID characteristics. And all the commands to jump between storybooks. And to choose individual storybooks. I don't plan on reading you all that. You can look and reference the slides. At the bottom of the presentation. I didn't mention this at the beginning. But at the bottom of the presentation. Is a web address for our website. If you go to that website. Here after the talk. I'll have slides. And some of my research content. But I've been having trouble updating it. And I really don't want to. On the hotel Wi-Fi. So just check it when you get home. So you take the firmware. That you dumped with SWD. And you can throw it into IDA. And it shows up as just binary data. But then if you choose ARMv7 LE. And enter in these settings. You can actually go and look at the disassembly. And try to reverse some of it yourself. But realistically. Most of my stuff was done through visual analysis. Of the storybook files. And a ton of trial and error. So I got it in IDA. A little too late for me. To spend too much time in that. In this particular section. So the Teddy Ruxpin book. So I showed you all Teddy's face and body. On the back there's a micro SD pin. Pin out or header. And you can essentially connect into that. And it pops up as mass storage device. And has all the books on it. Which are an intro file. An idle file. And then the 10 storybooks. That they provide. I'm thinking the idea was. That they would release books at a later point for purchase. And you just copy them over to the bear. Because they don't provide functionality to transfer it over. Through BLE. So within the storybooks. The files that are the container format. For the storybooks. Are these SNX ROM files. Since I don't have the documentation. Or anything else. But the magic string at the top of each file. Is SNX ROM. In wide character. So each one is individually null terminated. The target exclusive contains two extra stories. But it was always a little more expensive. Than I wanted to pay. And I bought six of these. So. I have way too many Teddy's. So the SNX ROM files. I mentioned that they start with a magic string at the top. But then there's also the header format. The header format starts with a record stop. And a record end. And then the table itself ends with FFFF. The data. After you use that to extract. The files within. You end up with the raw image data first. And then the audio files. The audio files always start with AU. And the raw image files are all the rest of them. If you take the image files. And you throw them into GIMP. GIMP has a feature that you can import raw data. And then you can kind of play with the settings. To see what the data is. You can see the picture there. You can see that they're RGB 565. And then they're 128 by 128. Sizing. And. Yeah. So then the audio files. This is where things get a little bit crazier. And this is where I spend a ton of my time. It's a proprietary file format. Used by Sonix. And it actually uses. It uses this thing called a mark table. To store. The triggers for the. Data that shows on the eyes. And then also for. The mouth movement. Essentially. And I'll get on that in the next slide. But we'll get there now. So the header structure. For this format. Is essentially the AU string. Two bytes. An unknown constant value. Since I was using a lot of trial and error. And I didn't have the documentation or anything. For this format. It. Was a bunch of values. That didn't seem to impact my tests. And I couldn't figure out what they were actually used for. So the unknown constant value. Is the two bytes. That seems like it's on every single file. And never changes. Then the sample rate. Which is two bytes. The channel. Which is always one. But is also two bytes. Another unknown value. Another unknown value. And then some. Another unknown value. And then the mark table data. Silence table data. And audio data. The actual data structure. When I say audio data. Mark table data. And silence table data. Is the mark table is defined by. Two to four bytes that signify the position. Two bytes that signify. The value of the data at that position. And then. That particular table ends with OXFFF. It also. Has a zero zero. Hex. It takes that. And uses the next two bytes. Adds them together. And uses that as the position value. The silence table. It was OX zero in every single Teddy Ruxpin file. That I checked. And so. I don't know. Too much about that particular table. Outside of just what I've done. For some internet sleuthing. Which I'll talk about soon. But it's a 16 bit signed little Indian. The mark table. So. When you're looking at the mark table. How this thing actually works is. If. The mark table has the position value. And then the actual value. If the value is a zero. The mouth is closed. The value is one. The mouth is half open. The value is two. The mouth is full open. Now anything after that. That you specify. Will correlate to image frames. That are within the storybook. So if you want to make. Let's say a special logo pop up. Or his eyes blink or something. You would essentially. Put the value. Put the value of. That image data. And then you would set up multiples. To essentially make it a moving image. Or whatever you're trying to do. But everything that you do. If your image file is. You know number one. Well you're still going to have to be offset. By the mouth open, mouth closed. And full mouth open values. So whatever it is. You have to offset it by three. So then let's look at. The silence table. So I talked about it earlier. But I didn't actually mention what it's for. The only thing this is here for. Is compression. They don't use it. I guess the stories weren't big enough. It essentially just references. Silent data. And marks the position in the table. And the only reason I knew that. Is because of just random internet searches. On the subject. Unfortunately Teddy doesn't use it. I just know that the files themselves. Have that field. And in my tests. They completely broke. Anytime I tried to enable it. So then we go to the audio data. It is 16 bit. Little Indian. Signed data. That's stored after the mark table. And silence detection table. It only supports 16 kilohertz. Sample rates. And then it supports bit rates from 16, 20, 24, 28. And 32 kilobits per second. So. What I've done for people who want to hack their own Teddy Ruxpin. Is I created this Teddy Ruxpone. And essentially. There's no ODE in this presentation. It's simply just reverse engineering stuff. So I threw together. Some Python code. That essentially takes an input file. It breaks it down into a folder structure. That contains an I folder. An audio folder. And it throws all the I's. And all the audio into those folders. You modify what you want. And then you use that folder as an input. To recreate a new file. So if you take your Teddy. Connect them to USB. Take one of the files. Decompress it. Modify it. Rebuild it. Then you can put that on the bear's mass storage drive. Or device. And be able to see the new content that you created. This is an example. Of said content. It's been the background for all the slides. But I felt like for DEF CON. It was important to throw the DEF CON logo into the I's. So let me show you a little demo that I created. Which is generally all the fun. I hope you don't mind. I know there's like a no video photography rule. Or used to be. But I got this 3D camera. That is awesome. And I really want to use it. So everyone can just deal with me breaking that rule. Okay cool. So let's make sure that it's nice and zoomed in. Let's play this guy right there. Let me get this mic. Hello. Okay cool. My best friend is an Iliop. An Iliop. An Iliop is my best friend. Come on. What are you waiting on? They're thrashing on the right. They're thrashing the full agenda. They're thrashing. They're thrashing. They're thrashing. They're thrashing. They're thrashing. They're thrashing. You're thrashing. You're thrashing. And that's the outcome of months of work. So I hope you guys enjoyed that. Let me give thanks to the Exploiteers. One of my ex-colleagues Ryan Smith. The DEF CON staff for helping me on every presentation I've ever done. My family, especially my kid and wife for tolerating me destroying all of my kids toys. And then filling the kitchen with tons of hardware hacking gear. By the way if you're leaving I've got free stuff to give out so you may not want to. Hack all the things. We have an IRC server where people just jump in and they tell us what they're hacking on. And if they have any problems and we help them. So if you are hacking on something, you're new, you just want to chat with like-minded people. Jump on free node, channel Exploiteers. There shouldn't be a dot in that channel name. My bad. So just Exploiteers without the dot. And yeah. Pack three doors. I got some of my Exploiteers friends. They're going to be handing out these SD breakouts that we created. Based on a previous talk. But you can grab one of those. We've got some stickers. We have some SAOs for your badges. They don't work. But you can just tape them on or something. Who cares. And yeah. Thank you everyone for coming out and braving the heat to get here.