00:00:00.100-->00:00:05.105 >> Let’s give Zenofex a round of applause. [Applause] Alright, Hi everyone, uh I guess we’re gonna 00:00:10.577-->00:00:13.780 get started a 2 minutes early which is great because I packed in a lot of content into this 00:00:13.780-->00:00:19.453 period. So, um my talk is dissecting the Teddy Ruxpin reverse engineering smart bear. 00:00:19.453-->00:00:26.293 It’s essentially my experience taking my child’s toy and trying to see if it was going to cause 00:00:26.293-->00:00:31.331 any security nightmares for me. Um, but uh, we’ll get into some fun things here on this 00:00:31.331-->00:00:36.236 presentation. So, a little bit about me, first of all, my Twitter handle is at Zenofex, I 00:00:36.236-->00:00:41.241 go by Zenofex. I’m a security researcher at Cylance. Um, I’m a founding member of the hardware 00:00:41.241-->00:00:47.614 hacking group called the Exploitee.rs uh, and uh, I’m a contributing member to a local 00:00:47.614-->00:00:53.053 community that we have called Austin Hackers. A little bit about Exploitee.rs, um, we have 00:00:53.053-->00:00:58.458 roughly 10 members give or take a few that, uh, don’t officially associate with us but they are 00:00:58.458-->00:01:03.397 pretty much part of the group. Um, we have Agent HH, CJ, Cody, Gynophage, Maximus, MBM, Saurik, 00:01:05.732-->00:01:10.737 Tdweng and, uh, 0x00string or null string, and of course, me. So, our general goal is to just 00:01:14.007-->00:01:18.612 hack things; anything, anywhere. We originally started hacking Google TVs and then Google 00:01:18.612-->00:01:22.583 killed off the Google TVs so then we just started hacking anything we could get our hands 00:01:22.583-->00:01:28.422 on. Um, we have a pretty decent community and we’re all very helpful so, uh, check out our 00:01:28.422-->00:01:34.194 Exploitee.rs site. We have like 60 plus embedded devices that have roots and other hacks. Um, 00:01:34.194-->00:01:38.699 we also have an IRC network that I’ll talk about at the end. So, a little disclaimer first of 00:01:38.699-->00:01:44.004 all, um, the data within this presentation was all stuff that I reverse engineered. I didn’t 00:01:44.004-->00:01:48.642 have official documentation or anything else, um, so a lot of my attempts were just 00:01:48.642-->00:01:53.647 essentially trial and error and reversing what I could, when I could. Um, I literally have been 00:01:58.518-->00:02:04.858 working on this for a very long time. Um, and uh, I, you’ll see why, it’s essentially a RTOS 00:02:04.858-->00:02:09.930 environment, um, which can be a little bit more difficult because after root you wanna 00:02:09.930-->00:02:13.967 interface with the peripherals. So, terminology. Um, you teddyophyles will uh, [laughter] 00:02:13.967-->00:02:18.205 will uh, will not or will already know this but an iliop is a brown bear like creature 00:02:18.205-->00:02:25.078 with a kind disposition. You might think Teddy Ruxpin is a bear but he’s actually an iliop. 00:02:25.078-->00:02:30.083 So, the OG iliop. This was the 1980’s, uh, Teddy Ruxpin, I think a lot of us are familiar 00:02:32.586-->00:02:37.991 with. Um, it used cassette tapes on, uh, on its back that you replaced and you had physical 00:02:37.991-->00:02:43.764 books that read along with the cassette tapes. His mouth moved and his eyed opened and closed 00:02:43.764-->00:02:48.335 but it was a physical movement not an LCD screen like the newest revision. So the new 00:02:48.335-->00:02:53.340 iliop, um, the new iliop is this guy. Essentially, oops, uh, essentially he has animated 00:02:55.709-->00:03:00.647 eyes, a moving mouth, speaker, a Bluetooth low energy, a USB mass storage that is, uh, used via an 00:03:03.116-->00:03:09.322 internal microSD card, and a companion mobile app. Getting inside Teddy. So, I’m about to 00:03:09.322-->00:03:14.361 show you all what, [laughter] what this looks like, it’s terrifying [laughter]. Um, so, 00:03:14.361-->00:03:19.366 uh, a little, [laughter] so a little about Teddy, uh, this particular revision comes with 00:03:21.635-->00:03:26.673 a, uh, mask that you put on him so he doesn’t scare your kids when he’s off [laughter]. It’s 00:03:26.673-->00:03:33.013 needed too because, like I said, it’s crazy, uh, but let’s take his jacket off and uh, get him 00:03:33.013-->00:03:39.653 out of here. This is essentially Teddy Ruxpin. This is Teddy’s skin [laughter]. So, it’s, it’s 00:03:39.653-->00:03:44.658 pretty enjoyable and here’s Teddy on. >> Hi, my name is Teddy Ruxpin. Can you and I be 00:03:52.566-->00:03:57.571 friends? [laughter] >> No. No. I actually tried to wear his skin it doesn’t fit on my face. 00:04:02.342-->00:04:06.913 [laughter] Um, so, inside of Teddy we have a logic board and this is the top of the logic 00:04:06.913-->00:04:10.317 board. It’s actually stored right in his eye area here. Um, there’s this chip called the 00:04:10.317-->00:04:12.319 Sonix, uh it’s the Sonix MCU I don’t remember what the, uh, physical or the, uh actual name 00:04:12.319-->00:04:14.321 of it was but, uh, there’s a speaker driver, the Bluetooth low energy, there’s an SPI flash 00:04:14.321-->00:04:19.326 and then there’s this, uh, uh, SD card slot that actually ends up holding, um, the story books 00:04:31.872-->00:04:37.611 that are, uh, stored on Teddy Ruxpin. Um, this is the logic board’s bottom. You can see that 00:04:37.611-->00:04:42.616 there are 2 128 by 128 LCDs that are used for each individual eye. Um, and then on that 00:04:46.019-->00:04:50.924 previous picture we’ll go 2 slides back. You can see that there’s, uh, on the, I guess 00:04:50.924-->00:04:56.163 right side there is a module that says Teddy firmware 1 point 1. That module is an MYN822BLE 00:04:56.163-->00:05:02.068 module which is essentially just a module for the, uh, Nordic nRF51822 chip. Um, so here is 00:05:02.068-->00:05:07.073 the diagram for interfacing with its SWD port and also all the other different GPIO pins that 00:05:12.846-->00:05:17.851 are used uh within Teddy. They only have, um, roughly 11 GPIO pins in use of the, uh, 22 or so 00:05:24.257-->00:05:29.563 that are available. Um, or, the 26 that are available. Uh, and then of course they have SWDIO 00:05:29.563-->00:05:36.436 and SW clock hooked up, uh, which is the d-bug pin out for software debugging, uh, Cordex 00:05:36.436-->00:05:41.441 M0 chips. So, with that particular pin out we were able to dump, uh, the firmware for 00:05:44.878-->00:05:51.151 Teddy, um, and also the ram. Um, you can dump it with OpenOCD but I had a SEGGER J-Link based on 00:05:51.151-->00:05:57.624 doing some badge development for the whole badge life project and, uh, I just used that with 00:05:57.624-->00:06:03.196 NRFJProg to dump the firmware and ram. Um, like I said, you can use OpenOCD and if you pay 00:06:03.196-->00:06:08.802 me I can get you a config to make that work. Um, so, this particular Teddy, instead of 00:06:08.802-->00:06:13.440 having physical books he uses a mobile app. And so, you can see in the mobile app picture they 00:06:13.440-->00:06:18.945 have a little cartoon picture of Teddy and his best friend Grubby. Um, so uh, the mobile 00:06:18.945-->00:06:23.950 app works essentially by using a BLE to communicate, um, when each page is turned and when the 00:06:27.187-->00:06:33.793 next story should be ready. So I took that and I threw it, I took the APK and I threw it in a JADX 00:06:33.793-->00:06:38.798 GUI and, uh, it was really nothing more than a wrapper for a bunch of Adobe AIR content. 00:06:41.668-->00:06:46.673 Um, so, within the, uh, APK was a SWF file, um, and I took that SWF file and then I threw into 00:06:49.709-->00:06:54.714 JPEXS. Um, essentially this is a flash decompiler, um, and all the BLE stuff was within this 00:06:58.151-->00:07:03.089 SWF. So, uh, if you are poking at your own Teddy, um, [laughter] you can uh, you’re 00:07:06.626-->00:07:11.865 better off not even looking at the APK, just unzip it, grab the SWF and throw it into a, um, 00:07:11.865-->00:07:16.870 JPEXS. So, I went ahead and I listed all the BLE info. The receive and transmit UUID 00:07:20.006-->00:07:25.945 characteristics and, uh, all the commands to jump between storybooks, um, and uh, to 00:07:25.945-->00:07:31.284 choose individual storybooks. I didn’t – I don’t plan on reading you all that. You can look and 00:07:31.284-->00:07:34.888 uh, reference the slides. Uh, at the bottom of the presentation, I didn’t mention this at the 00:07:34.888-->00:07:39.492 beginning, but at the bottom of the presentation is, uh, a web address for our website. If you 00:07:39.492-->00:07:43.596 go to that website here after the talk I’ll have slides and some of my research content but, 00:07:43.596-->00:07:48.068 uh, I’ve been having trouble updating it, uh, and I really don’t want to on the hotel 00:07:48.068-->00:07:54.874 Wi-Fi. So, uh, just check it when you get home. So, you take the firmware, uh, that you 00:07:54.874-->00:08:00.580 dumped with SWD and you can throw it into IDA and, uh, it shows up as just binary data but 00:08:00.580-->00:08:07.287 then if you, uh, choose ARMv7, um, LE, and enter in these settings you can actually go and 00:08:07.287-->00:08:12.092 look at, uh, the disassembly and try to reverse some of it yourself. But, uh, realistically 00:08:12.092-->00:08:17.731 most of my stuff was done through visual analysis of the storybook files and a ton of 00:08:17.731-->00:08:24.704 trial and error. So, I-I got it in IDA, a little too late for me to spend too much time in 00:08:24.704-->00:08:30.677 that-in this particular section. So, uh, the Teddy Ruxpin book – so, um, I showed you all Teddy’s 00:08:30.677-->00:08:36.983 face and body. Um, on the back there’s a microSD pin-pin out or header and you can essentially 00:08:36.983-->00:08:42.522 connect into that and it pops up with mass storage device and it has all the books on it which 00:08:42.522-->00:08:48.294 are and intro file, an idle file and then the 10 storybooks that, uh, they provide. The – I’m 00:08:48.294-->00:08:52.899 thinking the idea was that they would release books at a later point for purchase and you would 00:08:52.899-->00:08:56.603 just copy them over to the bear because they don’t provide functionality to transfer it 00:08:56.603-->00:09:03.143 over, um, through BLE. So, within the storybooks, um, the files that are the container 00:09:03.143-->00:09:08.681 format, um, for the storybooks are these SNX ROM files. Um, since I don’t have the 00:09:08.681-->00:09:13.253 documentation they could be called something else but, um, the-the magic string at the top 00:09:13.253-->00:09:18.691 of each file is SNX ROM, um, in white character so each one is individually null terminated. 00:09:18.691-->00:09:23.496 Um, the Target exclusive contains 2 extra stories but it was always a little more 00:09:23.496-->00:09:28.902 expensive than I wanted to pay and uh, I bought 6 of these, uh, [laughter] so, I-I have way too 00:09:28.902-->00:09:33.907 many Teddy’s. Um, so the SNX ROM files. I had mentioned that they start with a magic string at the 00:09:37.744-->00:09:41.915 top but then there is also the header format. The header format starts with the record stop and 00:09:41.915-->00:09:46.920 record end. Um, and then the table itself ends with FFFF. The data after you use that to 00:09:49.122-->00:09:54.127 extract the files within, you end with, uh, the raw image data first and then the audio files. 00:09:56.362-->00:10:01.801 The audio files always start with AU and the raw image files are all the rest of them. If you 00:10:01.801-->00:10:05.438 take the image files and you throw them into GIMP-GIMP has a feature that you can import raw 00:10:05.438-->00:10:09.809 data and then you can kind of play with the settings to see what the data is, um, which is 00:10:09.809-->00:10:14.214 on the left. You see the picture there. Um, you can see that there RGB656 and then they are 00:10:14.214-->00:10:19.219 128 by 128, um, sizing. Uh, and-yeah. So, then the audio files. This is where things get 00:10:22.655-->00:10:28.461 a little bit crazier and this where I spent a ton of my time. Um, it’s a proprietary file 00:10:28.461-->00:10:33.466 format used by Sonix, um, and it actually uses, uh, it uses this thing called a mark table to 00:10:36.436-->00:10:41.441 store, um, the triggers for the data that shows on the eyes, and then also for, um, the, uh, 00:10:45.311-->00:10:52.218 mouth movement. Essentially, and I’ll get on that on the next slide, but, uh, we’ll get there 00:10:52.218-->00:10:57.223 now. Uh, so, the header structure for this format, um, is essentially the AU string, 2 00:10:59.459-->00:11:03.830 bytes, uh, a unknown constant value since I was using a lot of trial and error and I didn’t 00:11:03.830-->00:11:10.069 have the documentation or anything for this format, um, it, uh – I – there was a bunch 00:11:10.069-->00:11:14.240 of values that didn’t seem to impact my tests and I couldn’t figure out what they were 00:11:14.240-->00:11:19.979 actually used for. So, the unknown constant value is the 2 bytes. That seems like – it’s on 00:11:19.979-->00:11:24.851 almost like every single file and never changes. Um, there’s – then the sample right, which is 00:11:24.851-->00:11:31.324 2 bytes, the channel, which is always 1, um but is also 2 bytes. Another unknown value, 00:11:31.324-->00:11:36.329 another unknown value, and then some, uh, then, uh a 0 or 1 to dictate if there is a mark 00:11:38.831-->00:11:43.536 table, a silence table, another unknown value, and then the mark table data, sounds table data 00:11:43.536-->00:11:49.108 and audio data. The actual data structure – when I say audio data, mark table data a silence 00:11:49.108-->00:11:54.113 table data, um, is the mark table is defined by, uh, 2 to 4 bytes to signify the position, 2 00:11:56.516-->00:12:01.454 bytes to signify the value of the data at that position and then, um, that particular table 00:12:03.590-->00:12:08.595 ends with OXFFF. It also, if the, uh, position value is over 8000, uh, hex, um, it takes that 00:12:13.299-->00:12:19.706 and uses the next 2 bytes, adds them together and uses that as the position value. Um, the 00:12:19.706-->00:12:24.711 silence table, uh, it was OX0 on every single Teddy Ruxpin file that I checked and so it may - 00:12:27.213-->00:12:33.419 uh, I - I know - I don’t know too much about that particular table, um, outside of just what 00:12:33.419-->00:12:39.058 I’ve done for some internet sleuth thing which is, uh - uh, which I’ll talk about soon. And 00:12:39.058-->00:12:44.063 then the audio data, which is 16 bits signed little Indian. The mark table, so, when - when 00:12:46.132-->00:12:51.137 you’re looking at the mark table, how this thing actually works is, uh, the mark table has 00:12:53.339-->00:12:57.110 the position value, uh, the position value and then the actual value. If the value is a 00:12:57.110-->00:13:00.680 0 the mouth is closed. If the value’s 1 the mouth is half open. The value’s 2 the mouth is 00:13:00.680-->00:13:05.685 full open. Now, anything after that that you specify will sit - will correlate to, uh, image 00:13:08.855-->00:13:15.428 frames that are within the storybooks. So, um, if you want to make, let’s say, a special 00:13:15.428-->00:13:21.868 logo pop up or his eyes blink or something you would essentially, uh, put the value - put the 00:13:21.868-->00:13:27.540 value of, uh, that image data and then you would set up multiples to essentially make it 00:13:27.540-->00:13:33.479 a moving image or whatever you’re trying to do. Um, but, everything you do, let’s say, 00:13:33.479-->00:13:38.351 your image file is, um, you know, number 1, well, you’re still going to have to be offset 00:13:38.351-->00:13:44.824 by the mouth open, mouth closed, um, and full mouth open, um, values. So, whatever it is you 00:13:44.824-->00:13:49.829 have to offset it by 3. Um, so then let’s look at the silence table. So I talked about it a 00:13:53.032-->00:13:56.769 little earlier but I didn’t actually mention what it’s for. The only thing this is here for 00:13:56.769-->00:14:01.074 is compression. Um, they don’t use it. I guess the stories weren’t big enough or it wasn’t 00:14:01.074-->00:14:06.913 needed but, um, it essentially just references silent data and marks the position in the table 00:14:06.913-->00:14:13.252 and, um, the only reason I knew that is because of just, random internet searches on the 00:14:13.252-->00:14:19.392 subject. Uh, unfortunately Teddy doesn’t use it. I just know that the files themselves have that 00:14:19.392-->00:14:26.165 field, um, and in my tests the completely broke anytime I tried to enable it. So, um, then we go 00:14:26.165-->00:14:33.139 to the audio data. Uh, it is 16 bit little Indian stored, uh, signed, uh, data that’s stored 00:14:33.139-->00:14:38.044 after the mark table and silence detection table. It only supports 16 kilohertz, uh, 00:14:38.044-->00:14:43.516 sample rates and then it supports bit rates from 16, 20, 24, 28 and 32 kilobits per 00:14:43.516-->00:14:49.155 second. So, what I’ve done for people who want to hack their own Teddy Ruxpin is I created 00:14:49.155-->00:14:53.192 this Teddy Rux Pwn, and, uh, [laughter] essentially there’s - there’s no 0-day in this 00:14:53.192-->00:14:58.631 presentation it’s simply just reverse engineering stuff. So, um, I threw together, uh, some 00:14:58.631-->00:15:04.003 Python code that essentially takes an input file, it breaks it down into a folder structure 00:15:04.003-->00:15:09.742 that contains an eye folder, uh, an audio folder and it throws all the eyes and all the audio 00:15:09.742-->00:15:14.213 into the, uh, folders. You modify what you want and then you use that folder as an input 00:15:14.213-->00:15:19.218 to recreate a new file. Um, so if you take your Teddy, connect him to USB, take one of the 00:15:21.287-->00:15:27.994 files, decompress it or extract all the portions, modify it, rebuild it, then you can put 00:15:27.994-->00:15:34.100 that on the bear’s mass storage drive, or device and, uh, be able to see the new content that 00:15:34.100-->00:15:39.906 you created. This is an example of said content. Um, it’s been the background for all of the 00:15:39.906-->00:15:44.911 slides but I felt like for Def Con it was important to throw the Def Con logo into the eyes. 00:15:47.146-->00:15:51.784 Um, so let me show you a little demo that I created, [laughter] which is generally all the fun. 00:15:51.784-->00:15:56.789 I hope you don’t mind, I know there’s like a no video photography, uh, rule or used to 00:16:09.135-->00:16:14.874 be but I got this 3d camera that is awesome and I really want to use it so everyone can just, uh, 00:16:14.874-->00:16:19.879 deal with me breaking that rule. Ok, cool. So, let’s make sure that it’s nice and zoomed in. 00:16:26.152-->00:16:31.157 Put this guy right there. Let me get this mic. Hello? Ok, cool. [soft music starts to play from 00:16:49.775-->00:16:54.780 bear] [tv static sounds play from bear] [laughter][applause] >>woo! >>Yeah. And that’s the 00:17:24.977-->00:17:31.317 outcome of months of work. [laughter] So, uh, I hope you guys enjoyed that. Uh, let me 00:17:31.317-->00:17:36.455 give thanks to the Expoitee.rs, uh, one of my ex colleagues Ryan Smith, the Def Con staff for 00:17:36.455-->00:17:42.762 helping me on every presentation I’ve ever done, um, my family, especially my kid and wife for 00:17:42.762-->00:17:46.999 tolerating me destroying all of my kid’s toys [laughter] and then filling the kitchen with 00:17:46.999-->00:17:50.236 tons of hardware hacking gear. By the way if you’re leaving I’ve got tons of free stuff to 00:17:50.236-->00:17:54.440 give out so you may not want to. Uh, [laughter] hack all the things, uh, we have an IRC, uh, 00:17:54.440-->00:17:59.478 server where people just jump in and they tell us what they’re hacking on and if they have 00:17:59.478-->00:18:03.349 problems then we help them so if you are hacking on something, you’re new, you just want to 00:18:03.349-->00:18:06.652 chat with like-minded people jump on Freenode channel Exploitee.rs. There shouldn’t be 00:18:06.652-->00:18:11.757 a dot in that channel name, my bad. Um, so just Exploitee.rs without the dot. Um, and, yeah, 00:18:11.757-->00:18:16.762 uh, if you go to the last 3 - the back 3 doors, uh, I got some of my, uh, my Exploitee.rs 00:18:18.931-->00:18:24.036 friends, um, they’re going to be handing out these SD breakouts that we created, um, based on a 00:18:24.036-->00:18:28.774 previous talk but you can grab one of those. We’ve got some stickers, um, we have some SAO’s 00:18:28.774-->00:18:35.481 for your badges, um, the don’t work but you can just tape them on or something, who cares. 00:18:35.481-->00:18:38.751 [laughter] And yeah, thank you everyone for coming out, uh, and braving the heat to get here. 00:18:38.751-->00:18:40.753 [applause]