1 00:00:00,000 --> 00:00:04,380 All right, so if you can tell, if you follow me on Twitter, I have a terrible cold. 2 00:00:04,420 --> 00:00:05,820 I've had awful DEFCON. 3 00:00:06,200 --> 00:00:07,840 I've been sick the whole time. 4 00:00:07,860 --> 00:00:09,040 I didn't get to play soccer. 5 00:00:09,360 --> 00:00:14,060 I haven't, you know, I've been sober for 72 hours, and I can barely talk. 6 00:00:14,420 --> 00:00:17,540 So I'm going to do my best and, you know, bear with me. 7 00:00:17,580 --> 00:00:18,700 But I do have a backup plan. 8 00:00:19,040 --> 00:00:21,060 So here's my backup plan. 9 00:00:21,180 --> 00:00:22,000 Let me see here. 10 00:00:22,980 --> 00:00:26,000 If I start to phase out here, you'll hear this. 11 00:00:26,280 --> 00:00:28,480 Welcome to my battery hacking talk. 12 00:00:29,280 --> 00:00:29,940 Is that good? 13 00:00:30,220 --> 00:00:31,160 Should I do that instead? 14 00:00:32,420 --> 00:00:33,660 All right, I'll try it. 15 00:00:33,720 --> 00:00:35,880 If I get too nasally, I'm going to go back to the computer. 16 00:00:36,040 --> 00:00:37,120 So hopefully that won't happen. 17 00:00:37,560 --> 00:00:39,340 All right, so who am I? 18 00:00:40,060 --> 00:00:41,220 And sorry about the screen. 19 00:00:41,340 --> 00:00:43,520 I guess they had to move it up so people in the front could see. 20 00:00:44,300 --> 00:00:47,600 So I used to work at the NSA for five years doing secret stuff. 21 00:00:48,160 --> 00:00:50,740 And then when the iPhone came out, I hacked it. 22 00:00:50,820 --> 00:00:53,820 And when the Android phone came out, the G1 phone, I hacked that. 23 00:00:54,140 --> 00:00:56,820 One point in the last four years, I've been sporting the stylist jacket. 24 00:00:57,300 --> 00:00:58,180 So if you see a guy. 25 00:00:58,480 --> 00:01:01,480 You know, wearing a white jacket for some reason, that's probably me. 26 00:01:03,340 --> 00:01:06,260 So everyone who won this year got the jacket. 27 00:01:06,320 --> 00:01:07,540 For some reason, I'm the only one who wears it. 28 00:01:08,440 --> 00:01:09,980 Written a couple of books and that sort of stuff. 29 00:01:10,360 --> 00:01:13,760 And then the most important thing is there's an InfoSug comic that has my name in it. 30 00:01:13,860 --> 00:01:15,240 So I feel pretty cool about that. 31 00:01:15,600 --> 00:01:19,180 Although I don't understand this particular comic, but maybe that's because it's about me. 32 00:01:20,220 --> 00:01:22,220 OK, so why am I here? 33 00:01:22,400 --> 00:01:24,100 Why did I decide to do battery firmware hacking? 34 00:01:25,080 --> 00:01:28,080 So last year I came to Black Hat and DEF CON. 35 00:01:28,080 --> 00:01:31,860 And I saw Barney Jack's talk, and I thought it was really awesome. 36 00:01:32,160 --> 00:01:35,820 So I was like, this is cool that, you know, it's easy to explain to someone. 37 00:01:36,160 --> 00:01:38,920 You walk up to an ATM and it gives you money, right? 38 00:01:39,040 --> 00:01:40,860 This is what it's all about. 39 00:01:40,980 --> 00:01:44,720 It's not like, hey, I can make calculator pop up on your computer. 40 00:01:44,920 --> 00:01:46,300 Like, it's just not impressive. 41 00:01:46,740 --> 00:01:48,260 And, you know, that's what I usually do. 42 00:01:48,340 --> 00:01:49,980 I usually do less impressive stuff than that. 43 00:01:50,080 --> 00:01:52,220 It's like I can make this bit change or something, right? 44 00:01:53,400 --> 00:01:56,060 So then I was like, I need to do something cool like Barnaby. 45 00:01:56,200 --> 00:01:57,820 So I came across this YouTube video. 46 00:01:57,820 --> 00:02:02,780 This, you know, computer, like, catching on fire and, like, the flames just going feet high. 47 00:02:02,980 --> 00:02:04,480 And I was like, I want to do that. 48 00:02:06,580 --> 00:02:10,680 So I set out, like, in September last year, like, right after Black Hat. 49 00:02:10,800 --> 00:02:13,620 And I was like, I'm going to see if someone remotely could blow up my computer. 50 00:02:14,380 --> 00:02:18,140 And you're going to find out I actually didn't do that, but I made a lot of progress. 51 00:02:18,280 --> 00:02:20,020 And so it's sort of interesting anyway. 52 00:02:20,300 --> 00:02:23,880 And maybe someone who's a little smarter than me can actually finish it up for me. 53 00:02:23,960 --> 00:02:27,340 And also, I'm kind of a chicken, so you'll see about that, too. 54 00:02:28,320 --> 00:02:29,440 All right, so this is the spoilers. 55 00:02:29,740 --> 00:02:32,260 You know, despite what you might have read in the paper, I actually didn't blow up anything. 56 00:02:33,480 --> 00:02:35,340 Mostly, well, you'll see. 57 00:02:35,400 --> 00:02:36,340 So there's a lot of layers of security. 58 00:02:36,520 --> 00:02:40,740 I totally bust one of them, and then I got kind of scared. 59 00:02:40,940 --> 00:02:43,700 So there's, like, all these parameters you can switch, 60 00:02:43,800 --> 00:02:46,300 and you've got to charge it and discharge it, and maybe overnight. 61 00:02:46,600 --> 00:02:50,180 And I work out of my home, and, you know, so anyway, I was kind of a chicken shit. 62 00:02:50,300 --> 00:02:52,020 But you'll see that it's kind of cool. 63 00:02:54,420 --> 00:02:55,600 So what's the talk about? 64 00:02:55,860 --> 00:02:57,800 So mostly, I'll start out with a little bit of a story. 65 00:02:57,800 --> 00:03:00,740 A little sort of intro on how batteries work and that sort of thing. 66 00:03:00,920 --> 00:03:05,340 And then I'm going to basically tell you the story of, like, seven months of my life looking into this. 67 00:03:07,600 --> 00:03:12,240 And, you know, it's mostly a story about a guy who's good at software hacking 68 00:03:12,240 --> 00:03:13,560 who tried to do hardware hacking. 69 00:03:13,840 --> 00:03:18,720 So the good thing about that is, you know, probably not you guys who are in Hardware Hacking Village, 70 00:03:18,860 --> 00:03:20,640 which I should actually go to and hang out. 71 00:03:21,400 --> 00:03:24,340 But the guys who do software, you'll probably learn some stuff, hopefully, 72 00:03:24,360 --> 00:03:26,080 about how to do hardware because that's what I had to learn. 73 00:03:26,300 --> 00:03:27,720 And then at the end, I'll talk about, like, 74 00:03:27,720 --> 00:03:28,740 you know, the so what question. 75 00:03:28,980 --> 00:03:32,140 Since I didn't blow up something, what did I do, and what could I do? 76 00:03:33,640 --> 00:03:35,920 All right, so when I started this whole thing, 77 00:03:36,000 --> 00:03:39,840 I didn't know anything about batteries or, you know, chargers or really anything about hardware. 78 00:03:40,140 --> 00:03:43,040 So I'm giving you a little bit of a spoiler here 79 00:03:43,040 --> 00:03:46,500 because just to sort of make sense of where I'm going. 80 00:03:46,940 --> 00:03:48,300 But I didn't know this when I started. 81 00:03:48,480 --> 00:03:51,760 So there's this document called the Smart Battery Specification. 82 00:03:52,340 --> 00:03:57,520 And what it does is it outlines exactly how batteries and chargers and computers are supposed to communicate. 83 00:03:58,280 --> 00:04:02,840 And so this sort of justifies, you know, what I went after. 84 00:04:03,020 --> 00:04:05,580 So it says, you know, safety is the primary concern. 85 00:04:07,220 --> 00:04:07,780 It's great. 86 00:04:08,980 --> 00:04:14,620 The primary concept is that the primary intelligence is supposed to be in the battery itself. 87 00:04:14,900 --> 00:04:17,140 So, you know, the computer is smart. 88 00:04:17,580 --> 00:04:18,560 It doesn't have to be. 89 00:04:18,660 --> 00:04:19,900 The charger doesn't have to be smart. 90 00:04:20,000 --> 00:04:21,880 What's supposed to be smart in this whole thing is the battery. 91 00:04:22,160 --> 00:04:23,660 So the brains are supposed to be in the battery. 92 00:04:24,720 --> 00:04:27,700 And the reason is because when the battery is in the battery, 93 00:04:27,700 --> 00:04:29,340 the battery knows the most about the battery. 94 00:04:29,500 --> 00:04:31,040 So it knows how much charge it's gotten. 95 00:04:31,160 --> 00:04:34,200 It knows how much, you know, how much it's got stored in it. 96 00:04:34,260 --> 00:04:35,420 It knows what its temperature is. 97 00:04:35,540 --> 00:04:37,220 It knows what kind of chemistry it has. 98 00:04:37,560 --> 00:04:41,920 So the battery is supposed to be the brains of the operation. 99 00:04:42,140 --> 00:04:43,600 And everything else is supposed to rely on that. 100 00:04:43,800 --> 00:04:45,680 And so that's why I attack the brains. 101 00:04:47,040 --> 00:04:49,720 So I'm going to go after the little chip on the battery. 102 00:04:51,800 --> 00:04:54,640 Okay, so what are smart batteries, right? 103 00:04:54,680 --> 00:04:56,240 I just thought these were like Duracells. 104 00:04:56,340 --> 00:04:57,680 Well, they're Duracells. 105 00:04:57,700 --> 00:05:00,820 They're Duracells with a chip, or actually more than one chip you'll see. 106 00:05:01,100 --> 00:05:06,820 So there's just, you know, there's chemistry cells and then there's some chips. 107 00:05:07,200 --> 00:05:11,420 And its main job is to make sure that it gets charged and it doesn't blow up. 108 00:05:12,180 --> 00:05:15,280 And if you have a MacBook like me and you hit, you know, 109 00:05:15,280 --> 00:05:17,260 the more information about your system, 110 00:05:17,420 --> 00:05:20,600 you end up with a screen that looks like that if you can read it. 111 00:05:20,840 --> 00:05:23,160 And on this one, when I started it, it didn't say this. 112 00:05:23,240 --> 00:05:27,240 But on this one, actually, if you look, it says device name BQ20Z451. 113 00:05:27,240 --> 00:05:30,740 That's the model of the chip from Texas Instruments that's on this battery. 114 00:05:30,940 --> 00:05:34,500 But anyway, this information is obtained from the battery 115 00:05:34,500 --> 00:05:37,820 by the operating system asking the battery and the battery telling it. 116 00:05:39,600 --> 00:05:44,180 All right, so like, you know, what could go wrong with a battery, right? 117 00:05:44,300 --> 00:05:46,780 So you could make their battery not work anymore. 118 00:05:46,980 --> 00:05:49,320 And this is super easy. I do it all the time. 119 00:05:49,840 --> 00:05:51,140 Never on purpose, though. 120 00:05:53,340 --> 00:05:57,220 And then you could reprogram it to, you know, 121 00:05:57,220 --> 00:05:58,900 why, and this is what I do. 122 00:05:59,720 --> 00:06:03,480 Maybe this would allow what the engineers call thermal runaway, 123 00:06:03,560 --> 00:06:05,020 and I call, like, explosions. 124 00:06:06,660 --> 00:06:08,300 But I didn't do it, so I can't say. 125 00:06:08,740 --> 00:06:12,380 And then the other thing is, you can imagine, like, just talking to, 126 00:06:12,500 --> 00:06:16,600 you know, have the battery talking nonstop to the, you know, OS, 127 00:06:16,680 --> 00:06:18,540 like, you know, a Dan Kaminsky DEF CON talk. 128 00:06:18,740 --> 00:06:20,700 And then eventually the OS is going to get bogged down. 129 00:06:21,820 --> 00:06:23,320 Dang, everyone loves Dan Kaminsky. 130 00:06:23,660 --> 00:06:25,440 At Black Hat, that would have nailed it. 131 00:06:25,720 --> 00:06:27,060 All right. So... 132 00:06:27,580 --> 00:06:30,260 And then you can imagine it also, if there was a bug in the kernel, 133 00:06:30,400 --> 00:06:33,040 it could actually attack the kernel from the battery, 134 00:06:33,160 --> 00:06:36,600 and you figure, like, you know, Apple can barely write secure software 135 00:06:36,600 --> 00:06:38,000 when they know someone's going to attack them, 136 00:06:38,040 --> 00:06:40,700 but when they're, like, you know, reading values from a battery, 137 00:06:40,820 --> 00:06:41,960 they really probably didn't pay attention. 138 00:06:42,280 --> 00:06:46,100 And then you're also on the same bus as, like, a TPM chip or the BIOS. 139 00:06:46,140 --> 00:06:47,940 So you could sniff all sorts of other interesting things 140 00:06:48,520 --> 00:06:50,220 that you wouldn't normally have access to 141 00:06:50,220 --> 00:06:52,320 because you're at this other spot in hardware. 142 00:06:52,880 --> 00:06:54,760 All right, so these are things that you might be able to do with this. 143 00:06:55,920 --> 00:06:59,100 Okay, so, you know, the story was, again, you know, after Black Hat, 144 00:06:59,180 --> 00:07:00,580 I sat around, you know, mopey, 145 00:07:00,600 --> 00:07:02,200 trying to think of something interesting to do, 146 00:07:02,300 --> 00:07:03,320 and eventually I was like, 147 00:07:03,440 --> 00:07:05,020 yeah, let's see if I can blow up a computer. 148 00:07:05,160 --> 00:07:08,260 So I was like, well, you know, I wish I knew something about hardware. 149 00:07:09,080 --> 00:07:11,840 So I know I have a computer and I have a battery. What else? 150 00:07:12,080 --> 00:07:13,440 Well, let's just use Google. 151 00:07:13,780 --> 00:07:14,900 That's what a lot of this talk is. 152 00:07:14,960 --> 00:07:16,120 I don't know what I'm doing, so I Google stuff. 153 00:07:16,680 --> 00:07:19,800 So in this case, I Google MacBook battery firmware. 154 00:07:20,080 --> 00:07:21,640 All right, that seems like a reasonable thing to start. 155 00:07:22,560 --> 00:07:23,860 And sure enough, the very first hit 156 00:07:23,860 --> 00:07:26,520 is about a firmware upgrade 157 00:07:26,520 --> 00:07:29,660 that Apple put out in 2009. 158 00:07:30,180 --> 00:07:31,980 And I was like, sweet, it's software. 159 00:07:32,160 --> 00:07:33,600 I can look at this. I understand this. 160 00:07:33,840 --> 00:07:35,880 So I downloaded it, checked it out, 161 00:07:35,960 --> 00:07:37,160 reverse engineered it, 162 00:07:37,700 --> 00:07:39,340 and I found out a few things. 163 00:07:39,480 --> 00:07:41,140 So one thing is that, you know, 164 00:07:41,180 --> 00:07:43,100 the computer's trying to talk to the battery, 165 00:07:43,180 --> 00:07:44,500 and it just wraps this function, 166 00:07:45,140 --> 00:07:47,320 ioconnect, method structure is structure zero, 167 00:07:47,580 --> 00:07:49,800 function over and over and over. It just keeps calling this. 168 00:07:50,100 --> 00:07:53,600 And it turns out this is a function that you use 169 00:07:53,860 --> 00:07:57,300 in OS X to talk to kernel drivers, like kexts. 170 00:07:58,680 --> 00:08:00,120 So this is the way you do it. 171 00:08:00,180 --> 00:08:01,680 And the particular driver they're talking to 172 00:08:01,680 --> 00:08:03,780 is called Apple Smart Battery Manager. 173 00:08:04,160 --> 00:08:06,420 So the, you know, your user land program, 174 00:08:06,680 --> 00:08:07,600 it has to have root privileges, 175 00:08:08,160 --> 00:08:09,820 but it doesn't have to, like, have, you know, 176 00:08:09,840 --> 00:08:11,060 wires plugged into the hardware or anything. 177 00:08:11,220 --> 00:08:15,160 It can talk to the battery by calling this method. 178 00:08:17,440 --> 00:08:19,960 So then, you know, so I was like, okay, cool. 179 00:08:20,120 --> 00:08:23,840 So I noticed that there's this sort of associated source code bundle, 180 00:08:23,840 --> 00:08:25,840 on the Apple website, called Apple Smart Battery. 181 00:08:26,080 --> 00:08:27,860 Actually, it's called Power Management Package. 182 00:08:27,940 --> 00:08:29,900 You can download it. It has, like, some cool source in it, 183 00:08:29,940 --> 00:08:31,840 but it doesn't build. Like, they don't, they give you enough 184 00:08:31,840 --> 00:08:33,820 just to, like, say that it's open source, 185 00:08:33,940 --> 00:08:35,080 but not enough to actually use it. 186 00:08:36,060 --> 00:08:38,560 So, but the cool thing is they have a bunch of header files, 187 00:08:38,760 --> 00:08:40,660 and you can start to read some interesting stuff 188 00:08:41,040 --> 00:08:43,060 about, like, some of the commands that this, 189 00:08:43,240 --> 00:08:44,440 this firmware upgrade is doing. 190 00:08:48,820 --> 00:08:50,120 So what's the firmware upgrade do? 191 00:08:50,600 --> 00:08:52,200 Well, based on that header file, I can see. 192 00:08:52,200 --> 00:08:55,980 It does things like, um, it looks at the device name 193 00:08:55,980 --> 00:08:58,160 and compares it to a list of things to see whether it, 194 00:08:58,240 --> 00:08:59,540 this is something it should be upgrading. 195 00:08:59,800 --> 00:09:02,400 Looks at the firmware version, looks at the padlock code, 196 00:09:02,460 --> 00:09:03,980 again, making sure it's something, you know, 197 00:09:04,000 --> 00:09:04,820 the right one to upgrade. 198 00:09:05,760 --> 00:09:07,660 And then some things that it's not in the header files, 199 00:09:07,820 --> 00:09:08,700 I don't know what those things are. 200 00:09:09,080 --> 00:09:12,000 And then I came across this, and I was like, that's weird. 201 00:09:12,060 --> 00:09:13,560 It doesn't look like the rest of the program. 202 00:09:14,000 --> 00:09:15,940 Instead of just calling that function over and over, 203 00:09:16,080 --> 00:09:19,480 it's got these, like, weird numbers, like 414 and 3672. 204 00:09:19,920 --> 00:09:21,560 Like, these stick out to me. 205 00:09:22,640 --> 00:09:23,980 You know, like, I wonder what that is. 206 00:09:24,140 --> 00:09:25,820 So I was like, well, you know, I don't know. 207 00:09:25,900 --> 00:09:28,080 I'll Google. So, so you Google that number, 208 00:09:28,640 --> 00:09:30,260 and, and the very first thing is, it's like, 209 00:09:30,280 --> 00:09:32,980 the default is 3672-0414. 210 00:09:33,720 --> 00:09:36,720 And, uh, it's like, this is entered by sending the data, 211 00:09:37,160 --> 00:09:38,180 414, to address 0. 212 00:09:38,380 --> 00:09:39,340 And it's like, look back at here. 213 00:09:39,660 --> 00:09:41,840 Look, that's what it's doing. And then it's like, 214 00:09:41,900 --> 00:09:43,800 and then immediately after sending 3672, 215 00:09:43,940 --> 00:09:45,660 that's exactly what it's doing. So what does it mean? 216 00:09:45,920 --> 00:09:47,660 And then you can look down a little bit, and it's like, 217 00:09:47,760 --> 00:09:50,280 the default code is set to unsealed to full, 218 00:09:50,480 --> 00:09:52,180 and it's like talking about, like, 219 00:09:52,180 --> 00:09:53,680 you know, all sorts of stuff. 220 00:09:53,860 --> 00:09:55,060 And so you Google a little bit more, 221 00:09:55,200 --> 00:09:57,440 and I come across this document from Texas Instruments 222 00:09:57,440 --> 00:10:00,340 that talks about, you know, the unsealed key 223 00:10:00,340 --> 00:10:02,180 is this magical number I see. 224 00:10:02,480 --> 00:10:04,000 I was like, oh, okay. It's like, 225 00:10:04,120 --> 00:10:05,860 you know, unsealing the battery. 226 00:10:06,140 --> 00:10:08,000 And then I was like, oh, look, there's this other thing 227 00:10:08,000 --> 00:10:10,300 called full access key. That sounds even more important. 228 00:10:11,600 --> 00:10:12,120 And, uh, 229 00:10:13,020 --> 00:10:14,300 it's, it's FFFFF. 230 00:10:14,480 --> 00:10:15,480 I was like, well, let me try that. 231 00:10:15,680 --> 00:10:17,380 Hey, it worked. So, uh, 232 00:10:18,360 --> 00:10:19,820 so this is basically the whole talk, 233 00:10:19,840 --> 00:10:21,300 is this slide, is, you know, 234 00:10:22,300 --> 00:10:23,740 they, they use this chip, 235 00:10:23,880 --> 00:10:25,280 and you can download the spec, 236 00:10:25,520 --> 00:10:27,260 and they didn't change the passwords on it. 237 00:10:27,780 --> 00:10:29,940 So, uh, it allows, it allows you to, 238 00:10:30,080 --> 00:10:32,000 and this is on every Apple laptop 239 00:10:32,000 --> 00:10:34,120 I've ever seen. I, I have a bunch of them. 240 00:10:34,500 --> 00:10:36,000 And, uh, apparently there's a bunch 241 00:10:36,000 --> 00:10:37,500 of other computers that use the same chip, 242 00:10:37,540 --> 00:10:39,160 but I don't know if they've actually changed the password. 243 00:10:39,300 --> 00:10:40,760 So, I, I mean, like, the chip's okay, 244 00:10:40,900 --> 00:10:42,660 it's just Apple is stupid and didn't change the password. 245 00:10:43,420 --> 00:10:45,360 Um, so anyway, so now I was, like, sort of in business, 246 00:10:45,400 --> 00:10:48,400 because A, I know it kinda, I know it comes from Texas Instruments, 247 00:10:48,440 --> 00:10:49,700 because that's where I got the dock from. 248 00:10:50,680 --> 00:10:52,160 I know Apple is dumb, but I already kind of 249 00:10:52,180 --> 00:10:53,580 knew that. And then, uh, 250 00:10:54,120 --> 00:10:55,320 that's, that's where I'm at right now. 251 00:10:55,440 --> 00:10:58,180 So I'm feeling pretty good. Um, but I still don't know 252 00:10:58,180 --> 00:11:00,600 exactly what chip, I just know it came from Texas Instruments. 253 00:11:01,000 --> 00:11:02,260 So, uh, I had 254 00:11:02,260 --> 00:11:04,080 to figure out what that was, and you should 255 00:11:04,080 --> 00:11:06,060 know by now that, like, you know, I could have 256 00:11:06,060 --> 00:11:07,640 just, like, opened the battery and looked at the chip, 257 00:11:07,740 --> 00:11:09,300 but I'm totally scared to touch stuff. 258 00:11:09,740 --> 00:11:12,100 So, uh, I still wanted to find a new, a software 259 00:11:12,100 --> 00:11:13,380 way to do it. And so what I did was, 260 00:11:13,720 --> 00:11:15,740 there's a way you could query the battery for particular 261 00:11:15,740 --> 00:11:17,700 types of data with these different, what they call, 262 00:11:17,780 --> 00:11:20,140 subclass IDs. Um, and so 263 00:11:20,140 --> 00:11:22,100 I just did that. I said, okay, give me your data, 264 00:11:22,180 --> 00:11:24,060 for subclass ID 0, 1, 2, 265 00:11:24,160 --> 00:11:26,100 3, 4. And it would give me a certain amount of data 266 00:11:26,100 --> 00:11:28,180 for each one. And all the Texas Instruments chips, 267 00:11:28,700 --> 00:11:29,980 they have documentation 268 00:11:29,980 --> 00:11:32,160 on what that's supposed to return. And each 269 00:11:32,160 --> 00:11:34,100 one returns something a little bit different. And so 270 00:11:34,100 --> 00:11:36,000 I just, you know, saw what mine was, 271 00:11:36,100 --> 00:11:38,240 and I looked at every single dock, um, 272 00:11:38,240 --> 00:11:40,100 to see which one had sort of the same kind 273 00:11:40,100 --> 00:11:42,020 of, it returned the right amount of data. And I found out 274 00:11:42,020 --> 00:11:43,980 what chip it was by doing that. It's, uh, 275 00:11:44,780 --> 00:11:46,160 Texas, oh wait, here, I won't give 276 00:11:46,160 --> 00:11:47,840 away the story yet. So, uh, 277 00:11:47,960 --> 00:11:49,920 anyway, this is what mine returned. Subclass 0 278 00:11:49,920 --> 00:11:51,520 was 22 bytes. 279 00:11:52,180 --> 00:11:53,700 So you can see, like, what kind of stuff this is. 280 00:11:53,900 --> 00:11:56,040 This is the kind of stuff, like, you're messing with now that you probably 281 00:11:56,040 --> 00:11:57,840 shouldn't be. So it says, uh, like, 282 00:11:57,900 --> 00:11:59,740 first level safety is subclass ID 0. 283 00:11:59,860 --> 00:12:01,820 So it returns 22 bytes. Subclass 284 00:12:02,480 --> 00:12:03,560 ID 1 is 285 00:12:04,060 --> 00:12:05,860 first level safety current. The other one was, 286 00:12:05,860 --> 00:12:07,900 was voltage. And then, you keep going, 287 00:12:08,060 --> 00:12:09,580 then you've got, like, second level safety. 288 00:12:09,880 --> 00:12:11,320 And then, uh, 289 00:12:12,620 --> 00:12:14,160 you know, second level safety current, 290 00:12:14,260 --> 00:12:16,100 second level safety voltage, and so on. And it turns out 291 00:12:16,100 --> 00:12:18,020 it matches exactly this, uh, 292 00:12:18,040 --> 00:12:20,180 Texas Instruments chip called TIBQ20Z80. 293 00:12:21,100 --> 00:12:21,920 And so all the 294 00:12:22,180 --> 00:12:23,960 MacBook, and MacBook Airs, and MacBook 295 00:12:23,960 --> 00:12:25,400 Pros, and all these, uh, 296 00:12:26,080 --> 00:12:28,260 have some sort of chip really close to this. 297 00:12:28,380 --> 00:12:30,080 Not, they're not all necessarily the 20Z80, 298 00:12:30,140 --> 00:12:31,980 but all the stuff I'm talking about all works on all, 299 00:12:32,040 --> 00:12:32,540 all of them. 300 00:12:33,980 --> 00:12:35,880 Okay, so that was my, like, totally 301 00:12:36,380 --> 00:12:38,120 weenie way to figure out what it was. And then 302 00:12:38,120 --> 00:12:40,040 eventually, like, I was like, well, I should 303 00:12:40,040 --> 00:12:42,060 at least get my hands a little bit dirty. So I took a battery 304 00:12:42,060 --> 00:12:44,100 and I ripped it apart. And so, uh, 305 00:12:44,220 --> 00:12:46,060 if you take a battery out of your computer, it looks 306 00:12:46,060 --> 00:12:47,380 like this, and there's these little screws. 307 00:12:47,880 --> 00:12:50,120 Uh, so you unscrew it, and then 308 00:12:50,120 --> 00:12:52,100 you just, like, rip off the plastic part 309 00:12:53,800 --> 00:12:54,120 um, 310 00:12:54,320 --> 00:12:55,840 and this is what you see on the inside. 311 00:12:55,960 --> 00:12:58,060 So you got six lithium polymer 312 00:12:58,060 --> 00:13:00,060 cells, um, and then 313 00:13:00,060 --> 00:13:01,680 on the end, like over here, 314 00:13:02,480 --> 00:13:04,200 is, like, where all the electronic stuff is. 315 00:13:04,700 --> 00:13:05,860 So then you rip that off, 316 00:13:06,280 --> 00:13:08,120 and, uh, it's like, whoa, there's lights on 317 00:13:08,120 --> 00:13:10,060 and I'm touching it. It's like, for a software guy, it's really just 318 00:13:10,060 --> 00:13:12,140 creepy. So, there's, like, 319 00:13:12,140 --> 00:13:14,120 chips and stuff, and then you can open it up even 320 00:13:14,120 --> 00:13:16,100 more, and then you can start to read the labels 321 00:13:16,100 --> 00:13:16,580 on the chips. 322 00:13:18,120 --> 00:13:19,960 So, uh, there's one that's called 323 00:13:21,120 --> 00:13:22,100 BQ29312. You can download it 324 00:13:22,180 --> 00:13:23,860 and get information about that. This job is basically, 325 00:13:23,960 --> 00:13:24,900 it does safety stuff. 326 00:13:26,480 --> 00:13:27,800 And then, uh, so, 327 00:13:28,720 --> 00:13:29,880 you know, this talk, 328 00:13:30,060 --> 00:13:32,080 you know, that was in the newspaper and all that stuff, and, uh, 329 00:13:32,120 --> 00:13:33,880 Travis Goodspeed, who's, like, a total hardware nut, 330 00:13:35,000 --> 00:13:36,260 just because he's, he's, 331 00:13:36,260 --> 00:13:38,020 he's curious, he takes one of his 332 00:13:38,020 --> 00:13:39,940 batteries, and he, you know, 333 00:13:39,980 --> 00:13:41,960 rips apart the, the chips, he 334 00:13:41,960 --> 00:13:44,020 puts an acid bath and x-rays it, 335 00:13:44,100 --> 00:13:46,220 and this is, this is some pictures he did, just because he's, 336 00:13:46,240 --> 00:13:48,100 he's a super curious guy. So this is 337 00:13:48,100 --> 00:13:49,440 what the chip looks like under x-ray. 338 00:13:50,980 --> 00:13:52,160 Um, and then, uh, 339 00:13:52,180 --> 00:13:54,160 on the other side of that, that board, you've got 340 00:13:54,160 --> 00:13:56,220 the BQ20Z80, which is the brains of the operation, 341 00:13:56,460 --> 00:13:57,400 and then this other chip, 342 00:13:58,140 --> 00:14:00,000 29412, which is another one of these 343 00:14:00,000 --> 00:14:01,400 chips that, that does, uh, 344 00:14:01,980 --> 00:14:03,900 safety checks. So, uh, 345 00:14:04,000 --> 00:14:05,580 and then here is the BQ20Z80, 346 00:14:06,060 --> 00:14:07,660 thanks to, to Travis for these pictures. 347 00:14:08,720 --> 00:14:09,320 Pretty cool. 348 00:14:09,980 --> 00:14:11,160 Um, so anyway, uh, 349 00:14:11,780 --> 00:14:14,240 so the, the BQ20Z80 is the main brains, 350 00:14:14,280 --> 00:14:16,120 that's the chip you can talk to through that 351 00:14:16,120 --> 00:14:18,280 driver. The other two chips, you can't 352 00:14:18,280 --> 00:14:20,180 talk to directly. They're in charge of, 353 00:14:20,320 --> 00:14:22,160 uh, some safety stuff. But what you 354 00:14:22,180 --> 00:14:24,160 can do is, you can set the 355 00:14:24,160 --> 00:14:26,100 parameters in the BQ20Z80, and it 356 00:14:26,100 --> 00:14:28,060 will push out those parameters to the other chips. So you can 357 00:14:28,060 --> 00:14:30,000 configure those other chips, you just can't talk to them directly. 358 00:14:30,300 --> 00:14:32,060 But that's all you really need. So like, you can say, 359 00:14:32,100 --> 00:14:33,960 oh yeah, you're in charge of the second level safety? 360 00:14:34,120 --> 00:14:36,060 Sweet. Uh, yeah, yeah, don't go off 361 00:14:36,060 --> 00:14:37,900 until you're at like, you know, five million 362 00:14:37,900 --> 00:14:40,200 degrees, and then, then everything's bad. 363 00:14:40,420 --> 00:14:42,100 But until then, it's cool. So it, 364 00:14:42,140 --> 00:14:44,020 so you can still mess with those, those other chips. 365 00:14:45,520 --> 00:14:46,200 Um, oops, 366 00:14:46,220 --> 00:14:48,120 I skipped this slide. Uh, so, so 367 00:14:48,120 --> 00:14:50,140 this is, so again, like, it took me that long 368 00:14:50,140 --> 00:14:52,100 to figure out what kind of chip it was. Actually, if I were to pay attention 369 00:14:52,180 --> 00:14:54,200 to the actual header file, they'd tell me exactly what it was. 370 00:14:56,460 --> 00:14:58,060 Oh well. That's why, you know, 371 00:14:58,140 --> 00:15:00,160 that's why we, we do it. And that's why it took me seven 372 00:15:00,160 --> 00:15:01,940 months instead of my normal project, which is like 373 00:15:01,940 --> 00:15:04,140 two weeks. Alright, so, so 374 00:15:04,140 --> 00:15:06,200 where am I at now? So I know, you know, I, I actually 375 00:15:06,200 --> 00:15:08,200 took it apart, so I, I know what kind of hardware it is. 376 00:15:08,260 --> 00:15:09,740 I can download information about it. 377 00:15:10,140 --> 00:15:12,060 Um, I know, sort of, I can see 378 00:15:12,060 --> 00:15:14,120 how the, this firmware updater talks 379 00:15:14,120 --> 00:15:16,300 to it, so I can, you know, probably figure out how to talk to it. 380 00:15:16,760 --> 00:15:18,060 Um, but I don't really know, like, 381 00:15:18,100 --> 00:15:19,700 what, what kind of things to say to it. 382 00:15:20,960 --> 00:15:21,960 So, back to this 383 00:15:22,180 --> 00:15:23,380 document, the smart battery specification. 384 00:15:24,100 --> 00:15:26,180 Um, it, it describes exactly how this sort 385 00:15:26,180 --> 00:15:28,240 of communication works. So there, there's three components. 386 00:15:28,400 --> 00:15:30,160 There's the, the battery, which is in the 387 00:15:30,160 --> 00:15:31,920 middle, and that's what we've, we've talked about so far. 388 00:15:32,140 --> 00:15:34,100 There's the charger, which is this thing that, 389 00:15:34,140 --> 00:15:35,600 that, you know, decides 390 00:15:36,300 --> 00:15:38,140 somehow how much charge to deliver 391 00:15:38,140 --> 00:15:40,040 to the battery, or not to charge it. 392 00:15:40,640 --> 00:15:42,000 And, and then there's the host, 393 00:15:42,080 --> 00:15:44,220 which is like the computer, or the thing that needs 394 00:15:44,220 --> 00:15:45,160 to, to get power. 395 00:15:47,520 --> 00:15:48,160 So, uh, 396 00:15:48,300 --> 00:15:49,920 basically this is the way they can commun- 397 00:15:49,920 --> 00:15:52,060 they can communicate. It's on this bus, the SN bus. 398 00:15:52,840 --> 00:15:54,200 And, uh, the SN bus is based 399 00:15:54,200 --> 00:15:56,080 on I2C, which, uh, 400 00:15:56,120 --> 00:15:58,020 Steven Ridley gave this, like, really cool talk about. 401 00:15:58,180 --> 00:15:59,960 There's lots of things in, in the electronics 402 00:15:59,960 --> 00:16:02,100 world based on I2C. Anyway, uh, 403 00:16:03,320 --> 00:16:04,360 so they talk to each other. 404 00:16:04,760 --> 00:16:06,240 And, uh, it's sort of 405 00:16:06,240 --> 00:16:08,160 complicated, but, but I, I, uh, 406 00:16:10,080 --> 00:16:10,560 I, I 407 00:16:10,560 --> 00:16:12,140 wrote this API that makes it easy 408 00:16:12,140 --> 00:16:14,260 to talk to the battery. So, and I'm, and I released 409 00:16:14,260 --> 00:16:15,880 it. You can download it and play with your battery. 410 00:16:16,240 --> 00:16:18,260 Um, but just be careful that you 411 00:16:18,260 --> 00:16:20,160 don't break it. Or at least don't blame me. 412 00:16:20,220 --> 00:16:22,160 You can break it if you want. Um, so anyway, 413 00:16:22,180 --> 00:16:24,060 so you can do things now, like read a word, like 414 00:16:24,060 --> 00:16:25,720 read the serial number from the thing. 415 00:16:25,920 --> 00:16:28,140 You can, uh, unseal it if you know the 416 00:16:28,140 --> 00:16:30,060 password, which we do. You 417 00:16:30,060 --> 00:16:32,040 can, uh, write a word so you can change 418 00:16:32,040 --> 00:16:33,920 what the manufacturer date was. You can 419 00:16:33,920 --> 00:16:36,220 change the device name, which is what I'm doing here. 420 00:16:36,640 --> 00:16:37,920 And then you can read data flash, 421 00:16:38,180 --> 00:16:40,240 which is like all that, that stuff I was talking about 422 00:16:40,240 --> 00:16:42,260 about getting the ID and stuff. So here I'm reading, 423 00:16:43,080 --> 00:16:44,200 um, some data flash, 424 00:16:44,420 --> 00:16:46,120 uh, 50, whatever 57 was. 425 00:16:46,220 --> 00:16:47,780 I don't know which one that is off the top of my head. 426 00:16:48,020 --> 00:16:50,060 Then you can get full access, which I'll talk about in a minute, 427 00:16:50,100 --> 00:16:52,060 which is like the, it's the equivalent of, like, 428 00:16:52,180 --> 00:16:53,920 you know, root or whatever on the battery. 429 00:16:54,180 --> 00:16:56,100 And then you can seal things back up when you're done. 430 00:16:57,660 --> 00:16:58,020 Okay. 431 00:16:58,520 --> 00:17:00,120 So, so what kind of things 432 00:17:00,120 --> 00:17:01,840 can you, can, you know, 433 00:17:01,860 --> 00:17:04,000 uh, computer or can we say 434 00:17:04,000 --> 00:17:06,020 to the battery? So there's this 435 00:17:06,020 --> 00:17:08,040 document that says exactly what to do. So there's these 436 00:17:08,040 --> 00:17:10,200 things called standard commands, which is the first column. 437 00:17:10,320 --> 00:17:12,140 You can do things like ask 438 00:17:12,140 --> 00:17:14,040 it what its temperature is, what its voltage is, 439 00:17:14,100 --> 00:17:15,520 how much charge it wants, stuff like that. 440 00:17:17,960 --> 00:17:20,000 And then there's, uh, in the next column, extended 441 00:17:20,000 --> 00:17:21,780 commands. So these are things like, uh, 442 00:17:22,220 --> 00:17:24,060 a little more complicated. These are the things you need more 443 00:17:24,060 --> 00:17:25,980 privileges to do. So, like, you can set passwords. 444 00:17:26,360 --> 00:17:28,240 You can control the FETs, which is the little 445 00:17:28,240 --> 00:17:30,140 thing that, that decide, you know, 446 00:17:30,160 --> 00:17:32,260 that, that physically closes to make electricity 447 00:17:32,260 --> 00:17:33,100 run into the battery. 448 00:17:34,300 --> 00:17:36,240 And then, uh, you know, keys and all that kind of stuff. 449 00:17:36,460 --> 00:17:38,280 Then there's this data flash. This is all just, like, 450 00:17:38,280 --> 00:17:40,320 data, like, that you can configure the device with. 451 00:17:42,800 --> 00:17:43,080 Um, 452 00:17:43,120 --> 00:17:44,340 so there's lots of, like, interesting things 453 00:17:44,340 --> 00:17:45,780 you can imagine playing with, right? 454 00:17:46,160 --> 00:17:47,940 So, uh, you can, you know, change the, 455 00:17:47,940 --> 00:17:50,100 the chemistry. You can change the, you know, 456 00:17:50,120 --> 00:17:52,160 all these thresholds where, like, bad things are supposed to be 457 00:17:52,180 --> 00:17:52,460 happening. 458 00:17:54,920 --> 00:17:55,940 And so I did that. 459 00:17:56,200 --> 00:17:58,100 Right? Uh, you know, the first thing 460 00:17:58,100 --> 00:17:59,780 I do is, like, you know, hmm, how about 461 00:17:59,780 --> 00:18:02,180 no over-voltage protection? Let's change that. 462 00:18:02,720 --> 00:18:04,360 Uh, but what happens is the battery 463 00:18:04,360 --> 00:18:06,120 still just, you know, it, it 464 00:18:06,120 --> 00:18:08,140 gets its charge and it, it knows when it's done 465 00:18:08,140 --> 00:18:10,220 and it stops. Um, so just changing 466 00:18:10,220 --> 00:18:11,840 those thresholds, those are, like, safety features 467 00:18:11,840 --> 00:18:14,180 when things go wrong. But if you don't make 468 00:18:14,180 --> 00:18:15,820 things go wrong somehow, then, then 469 00:18:15,820 --> 00:18:18,080 you don't need those thresholds. They're not ever, they're not 470 00:18:18,080 --> 00:18:19,620 ever hit. So you have to do something more. 471 00:18:20,200 --> 00:18:22,060 Um, so, uh, 472 00:18:22,180 --> 00:18:24,220 so, you know, we, we talked about how we can 473 00:18:24,220 --> 00:18:26,020 un-seal it and then we can get full access. 474 00:18:26,420 --> 00:18:28,260 But there's, there's other modes that are even more 475 00:18:28,260 --> 00:18:30,120 powerful. So there's, like, boot-run mode, 476 00:18:30,240 --> 00:18:31,240 which I'll talk about in a second. 477 00:18:31,800 --> 00:18:33,920 And that gives you, like, very low-level access 478 00:18:33,920 --> 00:18:36,100 like you're sitting, you're the TI guy sitting in the 479 00:18:36,100 --> 00:18:36,400 factory. 480 00:18:39,000 --> 00:18:40,260 So these are all the different modes 481 00:18:40,260 --> 00:18:42,100 that you can put the battery in. So sealed, 482 00:18:42,160 --> 00:18:43,840 that's how it's supposed to ship from the, from the 483 00:18:44,200 --> 00:18:46,100 factory. Let me see if I have slides. Yeah, I'll just 484 00:18:46,100 --> 00:18:47,940 go in. So, couldn't remember, cause, 485 00:18:48,040 --> 00:18:50,340 so the, the problem with this talk is it was, at Black Hat 486 00:18:50,340 --> 00:18:52,160 it was 75 minutes and now it's 50 minutes. 487 00:18:52,180 --> 00:18:54,060 And I can't remember for sure what I cut. So, 488 00:18:54,140 --> 00:18:55,960 uh, bear with me. 489 00:18:56,260 --> 00:18:58,020 Okay, so sealed, I guess I thought this was really important 490 00:18:58,020 --> 00:18:58,640 cause I didn't cut it. 491 00:18:59,660 --> 00:19:01,700 So it comes from the factory, you're not supposed to mess with it. 492 00:19:01,780 --> 00:19:03,360 This is how your batteries are supposed to behave. 493 00:19:03,620 --> 00:19:05,540 You can't change anything, you can't configure it, 494 00:19:05,580 --> 00:19:06,100 you can't do anything. 495 00:19:07,520 --> 00:19:10,160 Um, so you can only do the standard commands, which was that first column. 496 00:19:10,540 --> 00:19:11,440 And even there, 497 00:19:11,820 --> 00:19:13,920 you can, uh, only read them. 498 00:19:14,000 --> 00:19:15,960 You can't write to those. So you can't set anything. 499 00:19:16,420 --> 00:19:18,120 If you un-seal it, which is what the, 500 00:19:18,560 --> 00:19:19,820 the former upgrade did. 501 00:19:20,440 --> 00:19:22,060 So in, in a sense it wasn't bad, 502 00:19:22,180 --> 00:19:24,060 that they used the default un-seal command, 503 00:19:24,220 --> 00:19:26,180 because I could have just reverse engineered anything they chose. 504 00:19:26,280 --> 00:19:28,360 The bad thing is that they, they sort of gave me the idea 505 00:19:28,360 --> 00:19:29,860 to try the default for the full access. 506 00:19:30,000 --> 00:19:31,840 And then they did change that. Anyway, so, 507 00:19:31,920 --> 00:19:34,240 in the un-sealed mode, you can then 508 00:19:34,240 --> 00:19:36,140 access the, some of the extended 509 00:19:36,140 --> 00:19:38,160 commands, you can read the data flash and write the 510 00:19:38,160 --> 00:19:40,220 data flash. At that point you can start to do some, some 511 00:19:40,220 --> 00:19:41,500 real configuration of the thing. 512 00:19:43,140 --> 00:19:44,120 And this is again what 513 00:19:44,120 --> 00:19:45,480 the battery firmware upgrades go to. 514 00:19:46,180 --> 00:19:46,540 Uh, 515 00:19:47,780 --> 00:19:50,100 so full access mode, then you have all SPS commands. 516 00:19:50,200 --> 00:19:51,020 So again, this is like root. 517 00:19:52,180 --> 00:19:54,240 All SPS commands. You can write to any of them that allow you 518 00:19:54,240 --> 00:19:56,160 to write. You can enter these other, like, 519 00:19:56,180 --> 00:19:58,080 super privileged access modes, boot ROM and 520 00:19:58,080 --> 00:20:00,240 configuration mode. And, uh, the, the, 521 00:20:00,320 --> 00:20:02,260 the Apple firmware upgrades don't even need to, 522 00:20:02,300 --> 00:20:04,180 to access that. So one of the modes is 523 00:20:04,180 --> 00:20:06,220 called configuration mode. And this is basically 524 00:20:06,220 --> 00:20:08,240 the way that you can configure 525 00:20:08,240 --> 00:20:09,880 all the little internal sensors and stuff. 526 00:20:10,260 --> 00:20:12,340 So, you know, the little internal sensor might think 527 00:20:12,340 --> 00:20:14,260 your sen-, it has, you know, 528 00:20:14,720 --> 00:20:15,080 2000, 529 00:20:17,060 --> 00:20:18,020 uh, I don't know. 530 00:20:18,100 --> 00:20:20,080 So it, it, it measures, you know, the amount of current 531 00:20:20,080 --> 00:20:22,160 passing into it. And it thinks it's 20 miles 532 00:20:22,180 --> 00:20:24,120 amps, but really it's 22. And so 533 00:20:24,120 --> 00:20:25,960 you tell it that, and then it reconfigures itself 534 00:20:25,960 --> 00:20:27,460 to know that, oh, yeah, that was 22. 535 00:20:27,860 --> 00:20:30,140 And so you can imagine definitely screwing with it in this mode. 536 00:20:30,240 --> 00:20:31,000 But I didn't mess with that mode. 537 00:20:32,460 --> 00:20:33,900 So the things you can configure are 538 00:20:33,900 --> 00:20:36,140 number of cells. So that means, like, 539 00:20:36,140 --> 00:20:37,920 six in this case. Current, how much current 540 00:20:37,920 --> 00:20:40,140 you're giving it, how much voltage it has, and what its temperature is. 541 00:20:40,200 --> 00:20:42,140 So these are the things that this document I found 542 00:20:42,140 --> 00:20:44,240 tells you to do. I was like, gee, I wonder 543 00:20:44,240 --> 00:20:46,180 if there's any other calibrations you can do besides 544 00:20:46,180 --> 00:20:47,580 those, because this sounds, like, really fun. 545 00:20:48,360 --> 00:20:50,140 And, uh, you know, I don't know. And, 546 00:20:50,160 --> 00:20:51,960 you know, it turns out if you Google, like, 547 00:20:52,180 --> 00:20:54,280 what other calibrations for BQ20Z80 548 00:20:54,280 --> 00:20:56,240 besides temperature, voltage, you know, 549 00:20:56,280 --> 00:20:57,720 like, Google actually doesn't help in that case. 550 00:20:58,820 --> 00:21:00,180 Um, so I just went to the store. 551 00:21:00,260 --> 00:21:01,500 So I asked the Texas Instruments people. 552 00:21:02,100 --> 00:21:03,320 Um, so I said, uh, 553 00:21:04,180 --> 00:21:06,180 so I get on the board, and I'm 554 00:21:06,180 --> 00:21:07,660 like, hi, yes, uh, 555 00:21:07,860 --> 00:21:09,900 you know, can I do anything besides this? 556 00:21:10,000 --> 00:21:11,920 And this, like, really nice employee named Jackie 557 00:21:11,920 --> 00:21:14,080 writes back. And she's like, no, only current 558 00:21:14,080 --> 00:21:16,160 voltage and temperature. And I'm like, okay, 559 00:21:16,200 --> 00:21:18,080 thanks. And the only reason I put this up is I think it's 560 00:21:18,080 --> 00:21:20,180 really cool because they have these message 561 00:21:20,180 --> 00:21:22,160 boards there, and you earn points, and it's, like, a 562 00:21:22,180 --> 00:21:24,080 video game, and, like, I have 105 563 00:21:24,080 --> 00:21:26,140 points at this point in this game, and 564 00:21:26,140 --> 00:21:28,180 it says I'm a prodigy. And I like 565 00:21:28,180 --> 00:21:30,000 that the game realized that, 566 00:21:30,160 --> 00:21:32,160 you know, while I don't know 567 00:21:32,160 --> 00:21:34,020 much about batteries, I have a lot of 568 00:21:34,020 --> 00:21:36,000 potential. So I felt 569 00:21:36,000 --> 00:21:36,740 really good about that. 570 00:21:38,160 --> 00:21:39,160 Okay, so, uh, 571 00:21:39,980 --> 00:21:41,940 so then the other mode that I 572 00:21:41,940 --> 00:21:43,800 deal with a lot is called boot round mode. 573 00:21:44,200 --> 00:21:45,880 And, uh, this allows low-level access, 574 00:21:46,320 --> 00:21:48,200 and in the regular document that talks 575 00:21:48,200 --> 00:21:50,200 about SPS, it doesn't talk about 576 00:21:50,200 --> 00:21:52,120 this at all because, really, you're not supposed to be doing 577 00:21:52,180 --> 00:21:53,900 this unless you know what you're doing, and 578 00:21:54,300 --> 00:21:55,160 obviously I don't. 579 00:21:56,240 --> 00:21:57,920 So I had to buy some hardware to help me out. 580 00:21:58,380 --> 00:22:00,200 So, and again, this is something I bought 581 00:22:00,200 --> 00:22:02,120 just to help figure out things. You don't actually need this to 582 00:22:02,120 --> 00:22:04,040 do all the sort of attacks I talk about. 583 00:22:05,420 --> 00:22:06,180 So anyway, I bought this 584 00:22:06,180 --> 00:22:08,100 evaluation module, and, uh, 585 00:22:08,220 --> 00:22:10,100 it's basically the same exact thing that's on the 586 00:22:10,100 --> 00:22:12,140 battery, except it's, like, a big board. You can look 587 00:22:12,140 --> 00:22:14,040 at it, and you can play with it. And the most important 588 00:22:14,040 --> 00:22:16,080 thing is it comes with Windows software that 589 00:22:16,080 --> 00:22:17,820 talks over USB to the chip, 590 00:22:17,960 --> 00:22:20,180 and, you know, will, like, program 591 00:22:20,180 --> 00:22:22,160 it and stuff. And so I can just sort of edit 592 00:22:22,180 --> 00:22:24,000 and emulate what it does. So this is what it looked like 593 00:22:24,000 --> 00:22:26,060 at my house, um, sitting on my, like, 594 00:22:26,060 --> 00:22:26,560 dusty floor. 595 00:22:27,800 --> 00:22:29,880 And then you'll also notice there's this RadioShack, 596 00:22:29,980 --> 00:22:32,180 uh, you know, device that I 597 00:22:32,180 --> 00:22:34,000 bought there, and I was like, well, 598 00:22:34,120 --> 00:22:36,160 I'm a child of the 80s 599 00:22:36,160 --> 00:22:38,040 or whatever, so I was like, those dudes at RadioShack, 600 00:22:38,080 --> 00:22:40,040 they know a lot. So I went in there, and I was like, 601 00:22:40,160 --> 00:22:42,180 so I would sort of hint around at my project, you know, 602 00:22:42,180 --> 00:22:44,160 I'm like, well, you know, I work for a consulting 603 00:22:44,160 --> 00:22:46,140 company, and we're evaluating the safety 604 00:22:46,140 --> 00:22:48,040 of batteries, and, uh, 605 00:22:48,060 --> 00:22:50,140 tell me about batteries, and what do I need to test 606 00:22:50,140 --> 00:22:51,440 batteries? And the guy was like, 607 00:22:52,900 --> 00:22:53,560 I don't know, 608 00:22:53,580 --> 00:22:56,080 can I interest you in a mobile phone, you know? 609 00:22:57,120 --> 00:22:57,860 So it was, 610 00:22:57,860 --> 00:22:59,420 it was not helpful at all. 611 00:23:00,760 --> 00:23:02,020 So, uh, yeah. And then, 612 00:23:02,080 --> 00:23:04,180 yeah, it was amazing. But there's a lot of people who still shop there, 613 00:23:04,220 --> 00:23:04,500 surprisingly. 614 00:23:05,700 --> 00:23:08,200 So anyway, this is what the software looks like, and this is where I got 615 00:23:08,200 --> 00:23:10,020 the little guy for the title screen. I think it's really 616 00:23:10,020 --> 00:23:11,960 cool, they have, they have, like, a, you know, 617 00:23:11,960 --> 00:23:13,720 mascot for battery technology. 618 00:23:14,440 --> 00:23:15,940 It's like a, it's like Clippy 619 00:23:15,940 --> 00:23:16,960 with a backpack on. 620 00:23:22,180 --> 00:23:23,960 So, uh, this is what the screen looks like, 621 00:23:24,060 --> 00:23:26,120 and this allows you, like, through a GUI 622 00:23:26,120 --> 00:23:28,080 to change all the SPS commands, and it shows 623 00:23:28,080 --> 00:23:30,120 you all the, you know, bit fields, and what 624 00:23:30,120 --> 00:23:30,860 they mean, and stuff. 625 00:23:32,080 --> 00:23:33,880 And, uh, you know, so here's the data flash, 626 00:23:34,200 --> 00:23:36,240 and, you know, again, it tells you what each one means, 627 00:23:36,340 --> 00:23:37,920 what they, what the value is, what to change it to. 628 00:23:38,100 --> 00:23:40,300 But of course, the first button that I push when I, 629 00:23:40,340 --> 00:23:42,160 when I see it is the Pro button. 630 00:23:42,540 --> 00:23:44,160 Right? So, uh, 631 00:23:44,340 --> 00:23:45,500 it says, like, this, 632 00:23:45,880 --> 00:23:48,060 this screen is only for advanced users, 633 00:23:48,260 --> 00:23:50,060 and, you know, I'm certainly an advanced user. 634 00:23:51,060 --> 00:23:52,020 So, it lets you 635 00:23:52,020 --> 00:23:53,380 do things like send raw commands, 636 00:23:53,840 --> 00:23:55,900 uh, and then the best thing is it lets you, 637 00:23:55,960 --> 00:23:58,080 uh, flash the firmware, which is something I really 638 00:23:58,080 --> 00:23:59,720 want to do. So, uh, 639 00:24:00,480 --> 00:24:02,180 so then what I, what I wanted to do 640 00:24:02,180 --> 00:24:04,060 is see how it's doing all these things, and then 641 00:24:04,060 --> 00:24:05,920 write some, you know, write a driver 642 00:24:05,920 --> 00:24:07,380 or something for OS X to let me do it. 643 00:24:08,640 --> 00:24:09,760 Unfortunately, it's a Windows program, 644 00:24:10,420 --> 00:24:11,960 and I'm trying to do things on Macs. 645 00:24:12,300 --> 00:24:14,060 Um, but anyway, the, the 646 00:24:14,060 --> 00:24:16,180 evaluation kit comes with this SREC file, 647 00:24:16,560 --> 00:24:18,180 which is, has the firmware on it, 648 00:24:18,240 --> 00:24:20,040 and so I want to, I want to read 649 00:24:20,060 --> 00:24:21,560 and reprogram the thing and sniff what it does 650 00:24:21,560 --> 00:24:23,700 to know how to, how to talk to it on this little level. 651 00:24:24,020 --> 00:24:26,060 Because there's no documentation I've seen yet 652 00:24:26,060 --> 00:24:26,960 that tells you that. 653 00:24:27,980 --> 00:24:29,980 So, I, I Google, I look around, and there's this 654 00:24:29,980 --> 00:24:31,740 SREC file, it says it's an encrypted, 655 00:24:32,300 --> 00:24:33,320 or the sync file, 656 00:24:33,540 --> 00:24:35,180 that's what the ENC is for, encrypted. 657 00:24:35,840 --> 00:24:37,700 Um, so it's an encrypted SREC file, 658 00:24:37,880 --> 00:24:39,600 and so, like, I reverse engineered the encryption, 659 00:24:39,820 --> 00:24:41,460 it's like XOR. Um, 660 00:24:42,300 --> 00:24:43,380 but, you know, to give it, 661 00:24:43,880 --> 00:24:45,840 you know, some, some, some credit, it's not 662 00:24:45,840 --> 00:24:47,960 just XOR with a byte, it's like XOR with a byte 663 00:24:47,960 --> 00:24:49,860 and the previous byte, so it's like, 664 00:24:50,060 --> 00:24:51,100 you know, sort of fancy. 665 00:24:51,600 --> 00:24:54,100 Anyway, the, the firmware file has 666 00:24:54,500 --> 00:24:55,480 header, header stuff, 667 00:24:55,960 --> 00:24:57,580 uh, it has all the data flash, 668 00:24:57,820 --> 00:24:59,060 so those are all the configuration parameters, 669 00:24:59,260 --> 00:25:01,540 it has all the instructions, and then a bunch of checksums and stuff. 670 00:25:03,160 --> 00:25:04,000 Um, so I wrote a 671 00:25:04,000 --> 00:25:05,900 PyDebug script to, uh, 672 00:25:06,020 --> 00:25:07,080 intercept the USB traffic, 673 00:25:07,680 --> 00:25:09,420 and then I could see exactly the sorts, 674 00:25:09,580 --> 00:25:11,480 and then by comparing it to the things I saw 675 00:25:11,480 --> 00:25:14,100 when I would just do a single byte write and all that kind of things 676 00:25:14,100 --> 00:25:16,120 in the GUI, I could, I could figure out 677 00:25:16,120 --> 00:25:17,580 sort of what was going on. 678 00:25:19,060 --> 00:25:19,800 So, like, for example, 679 00:25:20,060 --> 00:25:21,840 I figured out, like, oh, to read a word, apparently 680 00:25:21,840 --> 00:25:24,160 you send the command 8, to write a word, you send the command 4, 681 00:25:24,240 --> 00:25:24,660 and so on. 682 00:25:26,300 --> 00:25:26,860 So, uh, 683 00:25:27,700 --> 00:25:29,220 so then I'm back to Google, right? 684 00:25:29,480 --> 00:25:31,920 So I, so I Google SMBus boot ROM 685 00:25:31,920 --> 00:25:33,400 read 8, write 4. 686 00:25:33,580 --> 00:25:35,780 So that's like, I don't know how anyone did any research 687 00:25:35,780 --> 00:25:36,420 before Google. 688 00:25:37,420 --> 00:25:39,200 And no, Google did not pay me for this talk. 689 00:25:39,440 --> 00:25:42,280 I should have, you know, had Microsoft 690 00:25:42,280 --> 00:25:43,600 pay me, I could say, yeah, I used Bing. 691 00:25:44,300 --> 00:25:45,300 Bing did it for me. 692 00:25:46,960 --> 00:25:47,660 So, anyway, 693 00:25:47,760 --> 00:25:50,040 I, I came across this document that talked about, 694 00:25:50,040 --> 00:25:51,720 talks exactly about, like, how to do, 695 00:25:51,740 --> 00:25:53,600 uh, talk in the boot ROM level. 696 00:25:55,980 --> 00:25:57,920 And also it talked about how the firmware, 697 00:25:58,080 --> 00:25:59,080 the instructions were laid out. 698 00:25:59,180 --> 00:26:00,200 So that was, like, really useful, too. 699 00:26:01,800 --> 00:26:04,400 So, uh, now when I sniff the reprogramming, 700 00:26:04,400 --> 00:26:05,700 I see this, these are the steps it does. 701 00:26:05,800 --> 00:26:08,120 So it erases everything, the instructions and the data, 702 00:26:08,240 --> 00:26:10,220 and then I can see, like, how much data it expects. 703 00:26:10,600 --> 00:26:12,920 And then it reprograms row by row the data, 704 00:26:13,060 --> 00:26:14,620 and then it reprograms the instructions. 705 00:26:14,940 --> 00:26:17,740 So there's 300, hex 300 rows of instructions. 706 00:26:18,280 --> 00:26:18,680 Cool. 707 00:26:20,040 --> 00:26:21,400 And then I can see the data, too. 708 00:26:21,620 --> 00:26:23,780 So, like, I could piece together by the data it's sending 709 00:26:23,780 --> 00:26:26,000 what, uh, the firmware looks like. 710 00:26:27,520 --> 00:26:29,360 Um, so I, I pretty much understand now 711 00:26:29,360 --> 00:26:30,880 how to write in boot ROM to, 712 00:26:30,980 --> 00:26:32,540 to reprogram it just by sniffing. 713 00:26:32,900 --> 00:26:34,500 Uh, I could probably figure out how to read, 714 00:26:34,560 --> 00:26:35,660 you know, how to dump the firmware. 715 00:26:35,880 --> 00:26:38,280 Uh, but I, at this point in the story, I haven't. 716 00:26:38,760 --> 00:26:40,120 Uh, I could get the data flash. 717 00:26:42,640 --> 00:26:43,840 And, uh, but the problem is, 718 00:26:43,900 --> 00:26:45,340 so I, I could, I either have the firm, 719 00:26:45,360 --> 00:26:46,600 I could either probably dump the firmware, 720 00:26:46,600 --> 00:26:49,060 or I could just watch the firmware being uploaded 721 00:26:49,060 --> 00:26:49,920 from the SREC file, 722 00:26:50,060 --> 00:26:51,500 but I don't know, like, what the hell is in there. 723 00:26:53,280 --> 00:26:54,620 So that's the next thing I want to do. 724 00:26:55,120 --> 00:26:56,840 So I, I want to disassemble it and, like, 725 00:26:56,860 --> 00:26:58,100 reverse engineer it, see how it works. 726 00:26:58,500 --> 00:27:00,320 Uh, but the problem is I don't know what kind of chip it is. 727 00:27:00,380 --> 00:27:01,640 All right, I know Texas Instruments makes it, 728 00:27:01,660 --> 00:27:03,300 but I don't know what kind of, like, you know, assembly it takes. 729 00:27:04,060 --> 00:27:06,320 So, uh, you know, I do this stupid thing, 730 00:27:06,380 --> 00:27:07,500 which is I load it into IdaPro, 731 00:27:07,640 --> 00:27:10,300 and I select each processor one by one and see what happens. 732 00:27:10,660 --> 00:27:11,520 And they all suck. 733 00:27:12,160 --> 00:27:14,540 So it, it, it's none of the ones that are in IdaPro. 734 00:27:16,280 --> 00:27:18,120 So I'm back to asking Texas Instruments. 735 00:27:19,340 --> 00:27:20,820 So, uh, I'm like, 736 00:27:20,900 --> 00:27:22,540 hey, does anyone know what kind of, uh, 737 00:27:22,680 --> 00:27:25,060 you know, what kind of processor this is? 738 00:27:25,160 --> 00:27:26,020 You know, thank you. 739 00:27:26,160 --> 00:27:27,460 And I try to be, like, really nice. 740 00:27:28,020 --> 00:27:29,920 Um, and I'm like, you know, and I'm not lying, 741 00:27:29,940 --> 00:27:30,760 I'm saying I'm Charlie Miller. 742 00:27:31,200 --> 00:27:32,940 You know, if they Google, they'll see who I am, 743 00:27:33,020 --> 00:27:34,480 and, uh, you know, so I'm just, 744 00:27:34,880 --> 00:27:36,080 my approach is just to be nice, 745 00:27:36,080 --> 00:27:37,760 and hopefully Jackie will give me a nice answer. 746 00:27:38,200 --> 00:27:40,700 Um, but instead of Jackie, this time I get this asshole 747 00:27:40,700 --> 00:27:41,520 named Doug Williams. 748 00:27:44,540 --> 00:27:45,980 He's a secretary. That's it. One-word answer. 749 00:27:46,600 --> 00:27:48,980 Um, I'm like, don't you know I'm a prodigy? 750 00:27:51,060 --> 00:27:52,600 So, so anyway, I'm like, 751 00:27:52,640 --> 00:27:54,900 I'm like, oh, thank you for your kind response. 752 00:27:55,880 --> 00:27:57,860 Um, can you give me a little more information? 753 00:27:57,980 --> 00:27:59,580 Like, do you mean this is something 754 00:27:59,580 --> 00:28:00,660 you just don't want to tell me, 755 00:28:00,740 --> 00:28:03,080 or do you mean, like, you made this in your basement, 756 00:28:03,140 --> 00:28:04,800 and, like, no one knows what the hell it is? 757 00:28:05,760 --> 00:28:07,080 And, uh, he says, 758 00:28:07,380 --> 00:28:08,600 he says, this is the first thing. 759 00:28:08,960 --> 00:28:09,880 We have customers, 760 00:28:10,400 --> 00:28:11,640 you know, Apple probably, 761 00:28:11,800 --> 00:28:14,520 who create their own firmware, um, but we don't know 762 00:28:14,520 --> 00:28:16,380 we don't disclose this data because we want to protect 763 00:28:16,380 --> 00:28:17,220 our intellectual property. 764 00:28:19,300 --> 00:28:20,560 Sorry. So, uh, I'm like, 765 00:28:20,620 --> 00:28:22,760 well, okay, I'll just steal your intellectual property. 766 00:28:23,600 --> 00:28:23,920 . 767 00:28:24,940 --> 00:28:26,020 So, uh, so, 768 00:28:26,100 --> 00:28:28,480 I, I just take the binary, I stick it into, 769 00:28:28,560 --> 00:28:31,060 uh, Hex Editor, and I just start staring at it. 770 00:28:31,100 --> 00:28:31,280 Right? 771 00:28:32,120 --> 00:28:33,780 Like, this is the worst job in the world. 772 00:28:34,780 --> 00:28:36,480 And actually, someone asked me about this 773 00:28:36,480 --> 00:28:38,440 part in, when I gave this talk in Black Hat, 774 00:28:38,520 --> 00:28:39,940 and they were like, they were like, wow, 775 00:28:40,080 --> 00:28:41,920 are you, like, some kind of genius for looking at this? 776 00:28:41,980 --> 00:28:44,440 I'm like, no, this is the beauty of, like, you know, 777 00:28:44,520 --> 00:28:46,720 the cooking show, where the guy, 778 00:28:46,720 --> 00:28:48,320 like, throws a bunch of stuff, sticks it in the oven, 779 00:28:48,340 --> 00:28:50,500 they're like, hey, it's done, right? So, like, this was, like, 780 00:28:50,500 --> 00:28:52,420 really hard, but in the slide deck, it's like, 781 00:28:52,500 --> 00:28:54,400 oh, yeah, it was this, this, oh, it was so obvious, right? 782 00:28:54,500 --> 00:28:56,600 But this was actually, like, took me, like, a week, it was really hard. 783 00:28:56,800 --> 00:28:58,320 But, you know, for, for your benefit, 784 00:28:58,380 --> 00:28:59,900 it looks, like, really cool, like, I'm awesome. 785 00:29:00,280 --> 00:29:02,420 So, anyway, so, so, what do you notice 786 00:29:02,420 --> 00:29:04,500 in this? Anyone want to, want to beat me to the punch? 787 00:29:04,580 --> 00:29:06,400 So, is there anything special? Can you read the, 788 00:29:06,420 --> 00:29:08,340 the, the bytes at all? Anything 789 00:29:08,340 --> 00:29:10,700 stick out? Oh, I already said, 790 00:29:10,820 --> 00:29:12,440 in the, don't look at that bullet, if you 791 00:29:12,440 --> 00:29:13,200 want to play my game. 792 00:29:14,100 --> 00:29:15,480 All right, so, so you'll notice, 793 00:29:16,220 --> 00:29:18,260 there's, there's threes, right? That's the only 794 00:29:18,260 --> 00:29:19,900 thing that you really notice, is there's some threes. 795 00:29:20,540 --> 00:29:22,460 Okay, cool, threes. And, and 796 00:29:22,460 --> 00:29:24,080 anyone notice the, like, you know, 797 00:29:24,100 --> 00:29:25,680 something special about the threes? 798 00:29:29,020 --> 00:29:30,240 They're, they're, oh, sorry, well, 799 00:29:30,320 --> 00:29:32,380 they're spread out a certain amount. 800 00:29:32,480 --> 00:29:34,300 So, it turns out that the threes are separated 801 00:29:34,300 --> 00:29:36,220 by two bytes each. So, it's like, oh, well, that's 802 00:29:36,220 --> 00:29:38,160 sort of interesting. So, 803 00:29:38,340 --> 00:29:40,240 so that's, like, well, maybe then it's aligned 804 00:29:40,240 --> 00:29:42,340 somehow on, you know, three 805 00:29:42,440 --> 00:29:44,320 byte widths. So, you know, 806 00:29:44,340 --> 00:29:46,420 adjust the, the, the hex editor 807 00:29:46,420 --> 00:29:48,180 a little bit, and then you start to look. 808 00:29:48,240 --> 00:29:50,420 Hey, look, sure enough, if you 809 00:29:50,420 --> 00:29:51,640 look down those columns, 810 00:29:53,140 --> 00:29:54,500 uh, there's, there's this, 811 00:29:54,500 --> 00:29:55,940 this feature that 812 00:29:56,380 --> 00:29:58,360 the, the high nibble of the third byte is 813 00:29:58,360 --> 00:29:59,780 always zero, one, two, or three. 814 00:30:00,320 --> 00:30:02,280 Okay. So, 815 00:30:02,340 --> 00:30:04,340 maybe, and then you can see this is true for all the 816 00:30:04,340 --> 00:30:06,400 columns. So, maybe this is a 817 00:30:06,400 --> 00:30:08,520 22-bit word. So, there's, 818 00:30:08,520 --> 00:30:09,880 so I gotta find some sort of chip 819 00:30:10,340 --> 00:30:11,720 that has 22-bit 820 00:30:12,580 --> 00:30:14,360 length instructions, and maybe 821 00:30:14,360 --> 00:30:16,280 I'm in good shape. And, you know, that's probably pretty rare. 822 00:30:18,160 --> 00:30:18,520 Okay. 823 00:30:18,580 --> 00:30:20,480 And then the, the final clue was I looked at the end 824 00:30:20,480 --> 00:30:22,440 of the firmware. And so, what you see 825 00:30:22,440 --> 00:30:24,440 here is the very last, 826 00:30:24,660 --> 00:30:26,420 so there's lots of these things at the end that say 827 00:30:27,580 --> 00:30:28,460 3FFFF, and the 828 00:30:28,460 --> 00:30:30,440 very last thing before that is 23FFFF. 829 00:30:31,560 --> 00:30:32,260 So, here's the 830 00:30:33,240 --> 00:30:34,140 23FFFF. Can anyone, 831 00:30:34,320 --> 00:30:36,520 like, what would you think would be the very 832 00:30:36,520 --> 00:30:38,340 last instruction in 833 00:30:38,340 --> 00:30:40,020 something that you disassembled? 834 00:30:41,520 --> 00:30:41,880 . 835 00:30:45,340 --> 00:30:45,700 . 836 00:30:47,280 --> 00:30:47,640 . 837 00:30:47,640 --> 00:30:49,880 Ah, see, I am smart. I knew the 838 00:30:49,880 --> 00:30:51,360 answer, and I don't think I've heard the right answer yet. 839 00:30:51,540 --> 00:30:52,140 Keep, keep going. 840 00:30:53,440 --> 00:30:55,600 What's at the end of, like, big 841 00:30:55,600 --> 00:30:57,160 functions, little functions? 842 00:30:58,160 --> 00:30:59,920 Return, right. So, I'm like, well, maybe 843 00:30:59,920 --> 00:31:01,940 this is a return, because, you know, that's 844 00:31:01,940 --> 00:31:02,820 how I end my functions. 845 00:31:03,840 --> 00:31:05,800 And then, any guesses what 3FFF 846 00:31:05,800 --> 00:31:06,140 is? 847 00:31:08,080 --> 00:31:08,900 . What's that? 848 00:31:11,020 --> 00:31:11,300 . 849 00:31:12,020 --> 00:31:14,080 Ah, I heard it. So, like, what do you put 850 00:31:14,520 --> 00:31:16,020 at the end when you don't want to do 851 00:31:16,020 --> 00:31:17,820 anything? No ops. So, that's what I'm thinking. 852 00:31:18,040 --> 00:31:20,140 Right? So, no op, no op, no op, 853 00:31:20,140 --> 00:31:22,020 no op, no op, no op, no op. So, let's see if I'm right. 854 00:31:23,020 --> 00:31:24,040 So, the first thing 855 00:31:24,040 --> 00:31:25,840 to see if I have, if I'm, maybe I'm just, like, 856 00:31:25,860 --> 00:31:27,840 totally crazy. So, I was like, well, let's search 857 00:31:27,840 --> 00:31:30,000 for this thing that might be a return in the whole 858 00:31:30,000 --> 00:31:31,700 file. Okay. 859 00:31:31,880 --> 00:31:34,000 So, there's 410 times it shows up. Cool. 860 00:31:34,400 --> 00:31:36,000 And they're all sort of, like, randomly spread 861 00:31:36,000 --> 00:31:37,060 about, also cool. 862 00:31:38,280 --> 00:31:38,980 And, uh, 863 00:31:39,200 --> 00:31:41,200 and also, I'm very happy to say that they 864 00:31:41,200 --> 00:31:43,100 didn't, like, encode or encrypt the firmware. That would have 865 00:31:43,100 --> 00:31:45,160 really made this sort of analyzing 866 00:31:45,160 --> 00:31:46,620 in a hex editor harder. 867 00:31:47,440 --> 00:31:49,260 Um, so, anyway, you know, I'm pretty sure 868 00:31:49,260 --> 00:31:50,960 this thing's a return by now, and those other things are no 869 00:31:50,960 --> 00:31:52,900 ops. And I know it's 23-bit instruction, 870 00:31:53,120 --> 00:31:55,080 so, probably, that might be enough to go 871 00:31:55,080 --> 00:31:56,200 back to my best friend, Google. 872 00:31:57,960 --> 00:31:58,940 But, my Google 873 00:31:58,940 --> 00:32:00,980 foo was weak. I could not find it. 874 00:32:01,340 --> 00:32:03,060 Uh, but, my co-worker, Deon 875 00:32:03,060 --> 00:32:05,060 Lozakis, he came up with a 876 00:32:05,060 --> 00:32:06,900 Google search that did work. So, he started 877 00:32:07,060 --> 00:32:08,320 a search for 23-FFFF, 878 00:32:08,600 --> 00:32:11,040 3-FFFF, 22-bit. I don't know why I didn't 879 00:32:11,040 --> 00:32:12,560 think of that. So, uh, 880 00:32:13,500 --> 00:32:14,960 anyway, I come across this document, 881 00:32:15,120 --> 00:32:17,040 you know, to be fair, to show how hard this 882 00:32:17,040 --> 00:32:18,940 research was, it wasn't the top hit, it was the 883 00:32:18,940 --> 00:32:19,420 second hit. 884 00:32:21,000 --> 00:32:22,860 So, you see things, like, it says, blah, blah, 885 00:32:22,940 --> 00:32:25,040 3-FFFF is a no-op, you know, 886 00:32:25,140 --> 00:32:27,140 return is 23-FFFF, so, like, 887 00:32:27,160 --> 00:32:28,700 this is, this is pretty much business. So, 888 00:32:28,720 --> 00:32:30,840 you look in there, and it says something about cool risk, 889 00:32:31,380 --> 00:32:33,000 and then you Google for that, and you 890 00:32:33,000 --> 00:32:35,000 come across the document, and you find out that 891 00:32:35,000 --> 00:32:36,820 the BQ20Z80 is a cool risk C, 892 00:32:37,060 --> 00:32:39,000 816 chip, or at 893 00:32:39,000 --> 00:32:40,940 least something so close that it doesn't matter. 894 00:32:43,280 --> 00:32:44,900 So, at this point, we're in, we're in good, 895 00:32:44,940 --> 00:32:45,440 good shape. 896 00:32:46,920 --> 00:32:48,820 So, uh, I can read all about it, 897 00:32:49,360 --> 00:32:51,020 and, yeah, so, who, who saw 898 00:32:51,020 --> 00:32:53,140 Hackers last night? It's a great 899 00:32:53,140 --> 00:32:55,020 movie, and, uh, you know, 900 00:32:55,060 --> 00:32:56,300 this is the best line, I think, from it. 901 00:32:57,460 --> 00:32:59,180 Angelina Jolie talking about risk architecture 902 00:32:59,180 --> 00:33:00,600 is, like, a total, uh, 903 00:33:01,420 --> 00:33:02,080 awesome thing. 904 00:33:03,640 --> 00:33:05,000 So, anyway, uh, so this 905 00:33:05,000 --> 00:33:06,640 particular chip, it's 8-bit, 906 00:33:07,160 --> 00:33:09,060 uh, it has, has this Harvard 907 00:33:09,060 --> 00:33:10,280 risk architecture, 908 00:33:10,800 --> 00:33:13,140 uh, the, you can see the data flash, 64K, 909 00:33:14,220 --> 00:33:14,860 64K flash 910 00:33:14,860 --> 00:33:16,620 instructions, each 22 bits. 911 00:33:17,320 --> 00:33:18,720 Um, there's 8-bit registers, 912 00:33:19,160 --> 00:33:21,060 and, of course, IDAPRO doesn't support 913 00:33:21,060 --> 00:33:21,240 it. 914 00:33:22,900 --> 00:33:24,720 So, you know, this is what the registers look like, 915 00:33:25,840 --> 00:33:26,820 uh, and luckily, 916 00:33:26,900 --> 00:33:28,820 since it's RISC, and RISC is gonna change everything, 917 00:33:29,580 --> 00:33:30,960 that, uh, there's not too many 918 00:33:30,960 --> 00:33:33,040 instructions, and so there's, this is what there are, 919 00:33:33,080 --> 00:33:35,080 there's, like, you know, 40 or something. And so, basically, 920 00:33:35,160 --> 00:33:37,040 all you have to do, if you like IDAPRO, like, 921 00:33:37,040 --> 00:33:38,960 me, is go in, and you can, 922 00:33:38,960 --> 00:33:40,760 you can write in Python, uh, 923 00:33:41,340 --> 00:33:42,460 IDAPRO processor script, 924 00:33:43,440 --> 00:33:45,160 and tell it what each of these instructions 925 00:33:45,160 --> 00:33:47,240 means, and, and what it looks like, and then, 926 00:33:47,300 --> 00:33:48,700 uh, it can disassemble it. 927 00:33:48,940 --> 00:33:50,700 That's what I did. So this, you know, 928 00:33:50,700 --> 00:33:52,420 another two weeks of my life in one slide. 929 00:33:53,940 --> 00:33:55,100 So you just go in this table 930 00:33:55,100 --> 00:33:57,000 in the document, it explains exactly what the bits are, 931 00:33:57,160 --> 00:33:58,280 you translate it into Python, 932 00:33:59,640 --> 00:34:01,120 and then you've got a new setting on your 933 00:34:01,120 --> 00:34:03,200 IDAPRO that says, Texas Instruments 934 00:34:03,200 --> 00:34:04,480 Cascades BQ20C80. 935 00:34:05,800 --> 00:34:07,020 And I'm really, this is all really, uh, 936 00:34:07,020 --> 00:34:08,840 released to, so you can download it and, and disassemble 937 00:34:08,840 --> 00:34:10,100 and see how these things work now. 938 00:34:10,700 --> 00:34:12,420 Um, oh, I, uh, sorry, you can't, they're proprietary. 939 00:34:14,320 --> 00:34:14,640 Um, 940 00:34:15,600 --> 00:34:16,880 so, uh, so anyway, 941 00:34:16,940 --> 00:34:18,480 now, if you, if you pop in IDAPRO, 942 00:34:18,660 --> 00:34:20,840 you, you, you, it's RISC, so you have to, 943 00:34:20,860 --> 00:34:22,920 you know, make a separate data section for it, 944 00:34:22,940 --> 00:34:24,200 and then, uh, 945 00:34:24,700 --> 00:34:26,100 and then you're good to go, it'll disassemble. 946 00:34:27,020 --> 00:34:29,000 But the problem is that it didn't do that great 947 00:34:29,000 --> 00:34:30,900 a job. But I 948 00:34:30,900 --> 00:34:33,040 just can help it out. So I know that it's, 949 00:34:33,040 --> 00:34:34,980 you know, the instructions are fixed length, they're all gonna be, 950 00:34:35,040 --> 00:34:36,820 you know, three by a line, so I just wrote a 951 00:34:37,020 --> 00:34:38,900 script to go through and disassemble every single instruction. 952 00:34:39,180 --> 00:34:40,680 Cause I, and I know there's not gonna be any data 953 00:34:40,680 --> 00:34:41,820 because of the RISC architecture. 954 00:34:43,200 --> 00:34:44,880 So then, uh, now I'm in business. 955 00:34:44,980 --> 00:34:46,840 It disassembled the whole thing pretty much, uh, 956 00:34:47,340 --> 00:34:49,160 and, and I can start reading it and seeing 957 00:34:49,160 --> 00:34:50,980 what, how this, how this is, you know, code on 958 00:34:50,980 --> 00:34:52,760 the battery, what it does. 959 00:34:53,700 --> 00:34:55,160 So, if you can, if you 960 00:34:55,160 --> 00:34:56,720 can see that, uh, so, so basically, 961 00:34:56,840 --> 00:34:58,940 this is some, some function that takes 962 00:34:58,940 --> 00:35:00,840 in those SPS commands that you can ask 963 00:35:00,840 --> 00:35:03,060 for the temperature and stuff. It does the operation 964 00:35:03,060 --> 00:35:05,000 and it sends it back to the computer. So this is 965 00:35:05,000 --> 00:35:06,520 exactly what we would kind of expect to see. 966 00:35:07,020 --> 00:35:09,100 So this one, if you, if you can see it, so on the one 967 00:35:09,100 --> 00:35:10,700 on the left it says, uh, 968 00:35:11,060 --> 00:35:13,180 you know, so it's SPS command 21, 969 00:35:13,460 --> 00:35:15,120 so which is the device name, so it does 970 00:35:15,120 --> 00:35:16,860 some calculations and then sends it back. 971 00:35:17,020 --> 00:35:18,860 This one is 20, 972 00:35:19,060 --> 00:35:20,800 which is like the manufacturer name, sends it back 973 00:35:20,800 --> 00:35:21,260 and so forth. 974 00:35:22,880 --> 00:35:25,240 Okay, cool. So, so where are we now? 975 00:35:25,320 --> 00:35:27,080 I can, I can disassemble the firmware, 976 00:35:27,160 --> 00:35:29,120 I know what's going on in the battery, but it turns 977 00:35:29,120 --> 00:35:30,980 out things are gonna go wrong for me 978 00:35:30,980 --> 00:35:31,500 very soon. 979 00:35:32,660 --> 00:35:35,000 So I can disassemble it, I can, uh, 980 00:35:35,140 --> 00:35:36,940 I can dump the, the, the flash, 981 00:35:37,020 --> 00:35:38,300 cool, um, 982 00:35:39,860 --> 00:35:40,800 what else can I do? 983 00:35:40,960 --> 00:35:43,040 Oh, so then I start to dump the flash, right? 984 00:35:43,340 --> 00:35:44,800 And I notice that I'm not getting identical 985 00:35:44,800 --> 00:35:47,120 results when I flat, when I dump the flash each time. 986 00:35:47,200 --> 00:35:48,940 And, you know, that's sort of weird, but, eh, whatever. 987 00:35:49,820 --> 00:35:50,100 Uh, 988 00:35:50,760 --> 00:35:52,840 and then the bad things start to happen, right? 989 00:35:52,920 --> 00:35:55,020 So then I was like, well, let's, let's make some changes 990 00:35:55,020 --> 00:35:56,780 to the firmware, that's really what I want to do. I do it, 991 00:35:56,820 --> 00:35:58,420 uh, the battery doesn't work anymore. 992 00:35:59,040 --> 00:36:00,120 So, uh, that's bad. 993 00:36:00,620 --> 00:36:02,900 The other thing wasn't so bad, but this is bad. If I try it, 994 00:36:02,920 --> 00:36:05,020 so I was like, well, maybe you have to do exactly what the Texas 995 00:36:05,020 --> 00:36:06,900 Instruments, like, GUI does. So I do it 996 00:36:07,020 --> 00:36:08,340 exactly what it does, bricked. 997 00:36:08,800 --> 00:36:11,020 So, uh, you know, I'm, I'm sort of stuck. 998 00:36:12,260 --> 00:36:12,840 And so, 999 00:36:12,880 --> 00:36:14,960 I start to, you know, I get on the 1000 00:36:14,960 --> 00:36:16,680 Apple store and I start ordering these batteries 1001 00:36:16,680 --> 00:36:18,620 because I'm going through them so quick, like, 1002 00:36:19,360 --> 00:36:20,880 faster than they can ship them to me, 1003 00:36:20,920 --> 00:36:21,440 I'm bricking them. 1004 00:36:22,920 --> 00:36:24,620 So, uh, and they're like $129, 1005 00:36:24,860 --> 00:36:27,020 they're pretty expensive. So I, so I have a ton 1006 00:36:27,020 --> 00:36:28,860 of these things, and this, I have just 1007 00:36:28,860 --> 00:36:30,980 piles of them in my house that don't work 1008 00:36:30,980 --> 00:36:32,760 anymore. So it's a very expensive 1009 00:36:32,760 --> 00:36:35,120 hobby. Lucky I have 1010 00:36:35,120 --> 00:36:35,980 a corporate credit card. 1011 00:36:37,980 --> 00:36:39,080 So I had one idea. 1012 00:36:39,140 --> 00:36:40,880 I was like, hey, I got an idea. They have, like, 1013 00:36:40,920 --> 00:36:42,860 on eBay, they have, they sell these batteries 1014 00:36:42,860 --> 00:36:44,960 that, you know, some dude in China makes in his basement. 1015 00:36:45,100 --> 00:36:46,600 And, uh, you know, they, 1016 00:36:47,160 --> 00:36:48,840 let's buy one. Maybe it's the same thing. 1017 00:36:48,900 --> 00:36:50,500 And then it'll be cheaper. So I bought it. 1018 00:36:50,860 --> 00:36:52,900 And, yeah, I looked at it. It's got the Texas 1019 00:36:52,900 --> 00:36:54,840 Instruments chip. As far as I could tell, it's pretty much 1020 00:36:54,840 --> 00:36:57,020 the same. But, he changed 1021 00:36:57,020 --> 00:36:58,340 the password on it. So, 1022 00:37:00,360 --> 00:37:00,920 I couldn't, 1023 00:37:00,920 --> 00:37:01,620 I couldn't hack it. 1024 00:37:06,340 --> 00:37:06,620 Yeah. 1025 00:37:06,620 --> 00:37:08,420 So anyway, so the $40 battery was, 1026 00:37:08,460 --> 00:37:10,220 was, like, super safe. I was like, well, well. 1027 00:37:14,720 --> 00:37:16,640 Okay. So, so, so to start to fix 1028 00:37:16,640 --> 00:37:18,500 my problems and stop buying batteries, 1029 00:37:19,080 --> 00:37:20,760 um, I, like, I wondered if, like, 1030 00:37:20,760 --> 00:37:22,220 the Apple store, like, tracks this. It's like, 1031 00:37:22,280 --> 00:37:24,640 this guy has bought, like, ten batteries. What's he doing? 1032 00:37:25,620 --> 00:37:26,580 And then, like, you should 1033 00:37:26,580 --> 00:37:27,840 have a special, like, and he's Charlie Miller. 1034 00:37:28,200 --> 00:37:29,540 You know, he, he hates Apple. 1035 00:37:31,580 --> 00:37:32,440 He's up to something. 1036 00:37:32,900 --> 00:37:34,540 So, uh, so anyway, 1037 00:37:34,700 --> 00:37:36,600 uh, it turns out, by experience, 1038 00:37:36,600 --> 00:37:38,540 by experimentation, I found out that when I do the reads 1039 00:37:38,540 --> 00:37:40,580 from the firmware, they're not always reliable. 1040 00:37:40,820 --> 00:37:42,440 And they don't error out or anything. They just return, like, 1041 00:37:42,460 --> 00:37:44,300 random crap sometimes. And so, 1042 00:37:44,360 --> 00:37:46,260 what I did is now I just have, I changed the API 1043 00:37:46,260 --> 00:37:48,520 that I wrote to, like, it reads it a few 1044 00:37:48,520 --> 00:37:50,100 times and it makes sure that it always agrees. 1045 00:37:50,260 --> 00:37:52,500 And then it's okay. And so once I do 1046 00:37:52,500 --> 00:37:54,560 that, then everything starts to go much better for me. 1047 00:37:54,840 --> 00:37:56,380 So I can, I can, you know, 1048 00:37:57,020 --> 00:37:58,540 consecutive dumps of the firmware, like, 1049 00:37:58,600 --> 00:38:00,500 agree. So this is, this is good. 1050 00:38:02,080 --> 00:38:02,400 Alright. 1051 00:38:02,460 --> 00:38:04,180 So then the next problem. Oh, by the way, 1052 00:38:04,280 --> 00:38:06,420 this is, like, the worst thing that ever 1053 00:38:06,420 --> 00:38:08,220 happens to me in my research, if you can see it. 1054 00:38:08,500 --> 00:38:10,100 The little X on the battery. 1055 00:38:10,320 --> 00:38:12,200 So when you see that, that means you're screwed. 1056 00:38:14,120 --> 00:38:14,480 So, 1057 00:38:14,540 --> 00:38:16,480 so that means, uh, you, you bricked your, 1058 00:38:16,540 --> 00:38:17,480 your, your battery. 1059 00:38:18,100 --> 00:38:20,380 Um, well, if you're doing my stuff. Otherwise, it just 1060 00:38:20,380 --> 00:38:22,320 means you probably don't have it plugged in quite 1061 00:38:22,320 --> 00:38:24,140 tight enough. Oh, the other thing, so 1062 00:38:24,140 --> 00:38:25,800 speaking of the Apple Store before, uh, 1063 00:38:26,800 --> 00:38:27,500 I, uh, 1064 00:38:29,300 --> 00:38:30,460 so the one thing you can do 1065 00:38:30,460 --> 00:38:32,380 from this research, so I didn't blow up batteries, but I know 1066 00:38:32,380 --> 00:38:34,320 how to, like, manipulate them. So if ever anyone has 1067 00:38:34,320 --> 00:38:36,260 a battery that isn't covered under warranty anymore, 1068 00:38:36,420 --> 00:38:37,960 I can hook you up. So I can, 1069 00:38:38,020 --> 00:38:40,220 you can go in and you can change when it was manufactured, 1070 00:38:40,460 --> 00:38:42,040 you can change how many cycles it's ever seen. 1071 00:38:42,520 --> 00:38:43,100 So you can, 1072 00:38:44,420 --> 00:38:46,420 you can make it look like it's, like, five days 1073 00:38:46,420 --> 00:38:48,380 old. You're like, dude, I just bought this battery, 1074 00:38:48,420 --> 00:38:50,320 like, five days ago and it's not working. I don't know what the 1075 00:38:50,320 --> 00:38:52,160 problem is. Well, it's gonna, 1076 00:38:52,260 --> 00:38:54,280 it's good. So I help out 1077 00:38:54,280 --> 00:38:55,260 the community when I can. 1078 00:38:57,260 --> 00:38:58,120 Alright, so, uh, 1079 00:38:58,280 --> 00:39:00,500 so then I start, so now I'm confident 1080 00:39:00,500 --> 00:39:02,280 I can read firmware and I can write firmware, 1081 00:39:02,400 --> 00:39:04,540 but still it's not working. I'm getting this stupid X 1082 00:39:04,540 --> 00:39:06,160 that says I've, I've done something wrong. 1083 00:39:06,420 --> 00:39:08,400 And so I, I look at the traffic and I 1084 00:39:08,400 --> 00:39:10,220 figure out what it is and it turns 1085 00:39:10,220 --> 00:39:12,240 out that it's this particular 1086 00:39:12,240 --> 00:39:14,240 flag is set. The data flash 1087 00:39:14,240 --> 00:39:16,460 failure flag. Total failure. 1088 00:39:16,640 --> 00:39:18,480 So it, so you read it, blah, blah, blah, and it's like, 1089 00:39:18,540 --> 00:39:20,460 number one, after a full reset, 1090 00:39:20,680 --> 00:39:22,340 the instruction flash checksum does 1091 00:39:22,340 --> 00:39:24,180 not verify. Ah, crap, there's a checksum. 1092 00:39:24,340 --> 00:39:25,260 I've messed it up. 1093 00:39:26,460 --> 00:39:28,080 So I need to figure that out, but 1094 00:39:28,080 --> 00:39:30,380 luckily I have the firmware so I 1095 00:39:30,380 --> 00:39:31,660 can reverse engineer how they do that. 1096 00:39:32,020 --> 00:39:34,500 So it turns out that there's these particular functions 1097 00:39:34,500 --> 00:39:36,300 that I can't change that are in the 1098 00:39:36,420 --> 00:39:38,220 ROM, um, and one of them is in 1099 00:39:38,220 --> 00:39:39,740 charge of, of computing, 1100 00:39:40,240 --> 00:39:42,380 uh, the checksum. So I just need to figure out 1101 00:39:42,380 --> 00:39:43,500 who's using that function. 1102 00:39:44,480 --> 00:39:46,540 And in IdaPro there's only two references to it. 1103 00:39:46,680 --> 00:39:48,280 One is to some SPS command 1104 00:39:48,280 --> 00:39:50,500 that Google will tell you has something to do with 1105 00:39:50,500 --> 00:39:52,300 checksumming, and the other one is 1106 00:39:52,300 --> 00:39:54,360 some function I haven't seen yet. So that's, 1107 00:39:54,360 --> 00:39:56,540 that's my candidate. So I, I check that out. 1108 00:39:56,840 --> 00:39:58,220 And if you look at the 1109 00:39:58,220 --> 00:40:00,420 IdaPro dump of that, it does something like 1110 00:40:00,420 --> 00:40:02,640 it reads in, uh, you know, 1111 00:40:02,660 --> 00:40:04,280 four bytes from data flash, 1112 00:40:04,960 --> 00:40:06,400 and then it compares it, and if it's, uh, 1113 00:40:06,420 --> 00:40:08,240 if it's zero, these four bytes are zero, then it just 1114 00:40:08,240 --> 00:40:10,240 goes to the end of the function. Otherwise 1115 00:40:10,240 --> 00:40:12,280 it switches the end in this, calls, 1116 00:40:13,180 --> 00:40:14,440 uh, the checksum, 1117 00:40:14,540 --> 00:40:16,420 and then compares byte for byte if it's true. 1118 00:40:16,560 --> 00:40:18,280 And if it's not true, it goes to the 1119 00:40:18,280 --> 00:40:20,100 bad code. And if it is true, 1120 00:40:20,140 --> 00:40:22,260 if they do agree, then it goes to the end of the function. 1121 00:40:22,840 --> 00:40:24,020 So, uh, anyone 1122 00:40:24,620 --> 00:40:26,280 have, have an idea what we should set 1123 00:40:26,280 --> 00:40:28,420 the, those four bytes in memory to? 1124 00:40:29,220 --> 00:40:30,120 Zero. Right. 1125 00:40:30,240 --> 00:40:31,880 So if you set it to zero, then, 1126 00:40:32,320 --> 00:40:34,400 uh, it doesn't compute the checksum anymore. 1127 00:40:34,580 --> 00:40:35,760 And you can make any changes you want. 1128 00:40:36,780 --> 00:40:38,440 Um, but then, so that was the older 1129 00:40:38,440 --> 00:40:40,080 version of firmware, some of the newer version of firmware, 1130 00:40:40,680 --> 00:40:42,060 like, they, they got tricky, 1131 00:40:42,160 --> 00:40:44,420 and they, they, uh, encode, or they 1132 00:40:44,420 --> 00:40:46,080 probably would say they encrypt the checksum. 1133 00:40:47,120 --> 00:40:48,440 And really, I, I think 1134 00:40:48,440 --> 00:40:50,420 they just did this because you might accidentally get zeros 1135 00:40:50,420 --> 00:40:52,060 there someday, but you wouldn't actually get this weird value. 1136 00:40:52,240 --> 00:40:54,240 So they do some encoding of the thing, but the same 1137 00:40:54,240 --> 00:40:56,360 basic principle applies, that if you, if you set 1138 00:40:56,360 --> 00:40:58,300 these four bytes instead of the zero to an 1139 00:40:58,300 --> 00:41:00,100 encoded zero, then, uh, 1140 00:41:00,540 --> 00:41:01,920 it won't check the checksum anymore. 1141 00:41:03,200 --> 00:41:04,240 So you can just, 1142 00:41:04,260 --> 00:41:06,160 uh, do a raw data flash 1143 00:41:06,160 --> 00:41:08,380 right to the device to, to, 1144 00:41:08,380 --> 00:41:10,320 of zeros for those four bytes, 1145 00:41:10,420 --> 00:41:11,800 and it won't check, the checksum anymore. 1146 00:41:12,260 --> 00:41:14,080 And, but since I'm totally scared to go into 1147 00:41:14,080 --> 00:41:15,860 boot run mode with all my dead batteries, 1148 00:41:16,040 --> 00:41:18,080 I figured out a way to do it without going to the boot run mode. 1149 00:41:18,360 --> 00:41:20,040 You can just figure out 1150 00:41:20,040 --> 00:41:21,780 that, uh, there's, there's this 1151 00:41:21,780 --> 00:41:23,820 undocumented subclass 57 1152 00:41:23,820 --> 00:41:25,940 you can read, and the checksum is actually 1153 00:41:25,940 --> 00:41:27,500 in there. So you can change those four bytes, 1154 00:41:28,040 --> 00:41:30,200 um, just with using extended SPS 1155 00:41:30,200 --> 00:41:30,480 commands. 1156 00:41:32,220 --> 00:41:34,120 Um, so now I can just freely patch, 1157 00:41:34,920 --> 00:41:35,640 um, the, 1158 00:41:36,160 --> 00:41:38,240 the firmware, and do whatever I want. 1159 00:41:38,420 --> 00:41:39,520 So what do I want to do? 1160 00:41:39,900 --> 00:41:40,260 Well, 1161 00:41:41,760 --> 00:41:43,720 I can make it lie. 1162 00:41:44,100 --> 00:41:46,040 So now when you ask for the temperature, I can make it 1163 00:41:46,040 --> 00:41:46,900 return anything I want. 1164 00:41:47,840 --> 00:41:49,400 But what I need to do is understand 1165 00:41:50,080 --> 00:41:52,120 what things are, are asked of the battery, 1166 00:41:52,240 --> 00:41:54,000 and what things, you know, so those are, I 1167 00:41:54,000 --> 00:41:55,020 don't even know what to lie about. 1168 00:41:55,820 --> 00:41:58,080 So I bought some more stuff, plugged 1169 00:41:58,080 --> 00:42:00,000 it in, and I was like, okay, now I'm gonna sniff the 1170 00:42:00,000 --> 00:42:02,160 traffic. The battery 1171 00:42:02,160 --> 00:42:04,020 has these six little grooves, and then maybe 1172 00:42:04,020 --> 00:42:06,100 a couple other little spots where there's wires. Two of 1173 00:42:06,100 --> 00:42:07,840 these have got to be SMBus. I don't know which two. 1174 00:42:08,520 --> 00:42:09,980 So I just, I was like, well, I know. 1175 00:42:10,760 --> 00:42:12,220 Uh, I'll buy these little probes, 1176 00:42:12,240 --> 00:42:14,060 I'll hook them up between the things, and, uh, 1177 00:42:14,200 --> 00:42:15,440 you know, I'll monitor what's going on. 1178 00:42:15,960 --> 00:42:17,160 Uh, this was a disaster. 1179 00:42:18,260 --> 00:42:20,060 So, uh, I did this, and I 1180 00:42:20,060 --> 00:42:22,000 must have touched the wrong thing 1181 00:42:22,000 --> 00:42:24,060 at some time. Uh, the computer just didn't 1182 00:42:24,060 --> 00:42:25,980 work anymore. So, apparently I 1183 00:42:25,980 --> 00:42:27,860 short, shorted something on, on the main, 1184 00:42:27,940 --> 00:42:29,960 uh, logic board, and so 1185 00:42:29,960 --> 00:42:31,920 I had to take it into the Apple store. 1186 00:42:32,660 --> 00:42:32,980 . 1187 00:42:34,160 --> 00:42:36,080 Which I, I do this a lot. I go to the Apple store, 1188 00:42:36,080 --> 00:42:38,060 and, uh, uh, I'm like, yeah, 1189 00:42:38,160 --> 00:42:39,220 this isn't working anymore. 1190 00:42:39,720 --> 00:42:41,840 And they're like, they're like, what'd you do? I was like, 1191 00:42:41,940 --> 00:42:44,120 I don't know, I just turned it on, and it doesn't work. 1192 00:42:44,540 --> 00:42:44,900 . 1193 00:42:45,380 --> 00:42:47,660 So, uh, they replaced the logic board. 1194 00:42:48,700 --> 00:42:50,000 And then everything was good again. 1195 00:42:50,820 --> 00:42:51,180 So... 1196 00:42:52,980 --> 00:42:54,260 Yeah, I never tell them what I do. 1197 00:42:54,740 --> 00:42:54,840 . 1198 00:42:56,220 --> 00:42:57,760 Okay, so then I had, I said, well, 1199 00:42:57,880 --> 00:43:00,060 the problem was, you know, all these loose wires 1200 00:43:00,060 --> 00:43:01,740 and stuff. So I'm gonna build my own special 1201 00:43:01,740 --> 00:43:03,600 cable that connects the battery to the computer. 1202 00:43:03,900 --> 00:43:05,920 And so, you know, for someone who doesn't do any hardware, 1203 00:43:05,920 --> 00:43:07,720 this is, like, a big deal. It took me, like, five days 1204 00:43:08,240 --> 00:43:09,620 soldering and, you know, all this stuff. 1205 00:43:09,880 --> 00:43:12,000 I plugged in, it didn't work. It's a piece, piece of crap. 1206 00:43:12,220 --> 00:43:13,960 . So, that didn't work. 1207 00:43:14,100 --> 00:43:15,980 So finally I figured out the right way to do it, is you just 1208 00:43:15,980 --> 00:43:17,860 move the keyboard a little bit. The battery 1209 00:43:17,860 --> 00:43:19,980 can be sitting where it's supposed to sit. You can still 1210 00:43:19,980 --> 00:43:21,880 see the wires, and you can hook little, you know, probes 1211 00:43:21,880 --> 00:43:23,280 to it. This is the, this is the right way to go. 1212 00:43:24,660 --> 00:43:26,020 So then I hook up this, this 1213 00:43:26,020 --> 00:43:27,800 logic analyzer, and I can see exactly which 1214 00:43:27,800 --> 00:43:29,760 cables have the SM bus traffic. 1215 00:43:30,580 --> 00:43:32,120 And then you can actually have, ask 1216 00:43:32,120 --> 00:43:32,860 it to decode it. 1217 00:43:34,360 --> 00:43:35,900 And you can see the actual SM bus 1218 00:43:35,900 --> 00:43:37,680 right. So it's, like, a right of eight, 1219 00:43:37,760 --> 00:43:39,820 which is temperature. And then it reads the 1220 00:43:39,820 --> 00:43:41,840 values, so B73, so I can see what 1221 00:43:41,840 --> 00:43:43,020 the, the temperature response is. 1222 00:43:44,140 --> 00:43:45,860 And then, you know, that's cool for just, like, 1223 00:43:45,900 --> 00:43:47,720 show, but then there's this other thing called a Beagle 1224 00:43:47,720 --> 00:43:49,820 that will, will record all this information for a 1225 00:43:49,820 --> 00:43:51,760 long time. You get, like, cool GUI 1226 00:43:51,760 --> 00:43:53,700 like this, and you can see still the SM bus traffic. 1227 00:43:53,960 --> 00:43:55,820 You can record it for, like, an hour while you're charging 1228 00:43:55,820 --> 00:43:57,520 your battery and see all the things that are ever asked 1229 00:43:57,520 --> 00:43:57,980 of the battery. 1230 00:43:59,780 --> 00:44:01,600 And so these are the exact things that the, 1231 00:44:01,600 --> 00:44:03,940 the, with the computer off and it charging 1232 00:44:03,940 --> 00:44:05,820 it asks for. Battery status. Temperature. 1233 00:44:05,900 --> 00:44:07,460 Charging current. Current. Voltage. 1234 00:44:07,800 --> 00:44:09,200 Battery mode. Relative state of change. 1235 00:44:09,640 --> 00:44:10,980 Remaining capacity. Full charge capacity. 1236 00:44:11,380 --> 00:44:13,660 And of those, only five ever change. 1237 00:44:13,880 --> 00:44:15,620 So the rest of them are just, like, yeah, everything's cool 1238 00:44:15,620 --> 00:44:17,660 or whatever. So temperature changes, but 1239 00:44:17,660 --> 00:44:19,660 probably that's not so important. Current, 1240 00:44:19,720 --> 00:44:21,820 which is the amount of current it's delivering. Well, okay. 1241 00:44:22,100 --> 00:44:22,900 Then voltage. 1242 00:44:24,020 --> 00:44:25,660 Remaining char, or remaining capacity 1243 00:44:25,660 --> 00:44:27,520 and relative state of charge. So these are the things 1244 00:44:27,520 --> 00:44:29,820 that you could guess the charger's asking for 1245 00:44:29,820 --> 00:44:31,860 in order to figure out how much charge to deliver it. 1246 00:44:32,920 --> 00:44:33,620 So, uh, 1247 00:44:33,780 --> 00:44:35,820 I'm gonna lie about those things. So, 1248 00:44:35,900 --> 00:44:37,060 I gotta wrap this up quick, but 1249 00:44:38,040 --> 00:44:39,620 basically these are the things I can imagine 1250 00:44:39,620 --> 00:44:41,940 doing now. I mean, so where am I at? I can make 1251 00:44:41,940 --> 00:44:43,380 the battery do anything I want. 1252 00:44:43,980 --> 00:44:45,680 Uh, so, so what 1253 00:44:45,680 --> 00:44:47,520 could, what, you know, so what, right? 1254 00:44:47,840 --> 00:44:49,820 So, bricking the battery is 1255 00:44:49,820 --> 00:44:51,920 super easy. I'm an expert at it. 1256 00:44:52,080 --> 00:44:53,860 I'm, I'm, I'm not even just 1257 00:44:53,860 --> 00:44:55,420 a prodgy. I'm a full-blown expert. 1258 00:44:55,740 --> 00:44:57,780 So here is, uh, some code that 1259 00:44:57,780 --> 00:44:59,780 with my API you can do. All this 1260 00:44:59,780 --> 00:45:01,440 does is erases all flash. 1261 00:45:01,700 --> 00:45:03,840 You're definitely not gonna recover from that. 1262 00:45:04,920 --> 00:45:05,360 Um, 1263 00:45:05,900 --> 00:45:07,860 so you can make firmware changes like we've been talking about. 1264 00:45:08,060 --> 00:45:09,880 So you can change all the things that are queried to 1265 00:45:09,880 --> 00:45:11,860 lie. So, like, no matter how much charge it gets, 1266 00:45:11,900 --> 00:45:13,680 you're always like, hey, I'm 50% full. 1267 00:45:13,780 --> 00:45:15,780 Keep it coming. And maybe 1268 00:45:15,780 --> 00:45:16,640 something bad would happen there. 1269 00:45:17,880 --> 00:45:19,900 Um, so this is, uh, basically, like, 1270 00:45:20,060 --> 00:45:21,700 a function that deals with SPS 1271 00:45:21,700 --> 00:45:23,900 commands, and I wanna 1272 00:45:23,900 --> 00:45:25,660 change the ones, like, so, like, remaining 1273 00:45:25,660 --> 00:45:27,740 capacity, which is SPS command F. Instead 1274 00:45:27,740 --> 00:45:29,900 of F, I'm gonna say, you, you wanna know F? 1275 00:45:30,240 --> 00:45:32,040 I'll tell you 1B. That's manufacturer 1276 00:45:32,040 --> 00:45:33,940 date. And same thing. If you, you ask 1277 00:45:33,940 --> 00:45:35,880 me for full charge capacity, I'll tell you the serial number. 1278 00:45:35,900 --> 00:45:37,400 So you just make changes to the firmware. 1279 00:45:37,680 --> 00:45:39,740 And the reason is because manufacturer date 1280 00:45:39,740 --> 00:45:41,780 and serial number are both words, which is the 1281 00:45:41,780 --> 00:45:43,700 same thing as capacity, full charge 1282 00:45:43,700 --> 00:45:45,960 capacity. But, uh, they're never queried. 1283 00:45:46,060 --> 00:45:47,460 And you can set them to any value you want. 1284 00:45:47,660 --> 00:45:49,880 So then you can control exactly what the battery's 1285 00:45:49,880 --> 00:45:51,960 reporting. And you can do this live while the battery's 1286 00:45:51,960 --> 00:45:53,820 charging. You know, without any wires or anything. 1287 00:45:53,900 --> 00:45:55,260 Just remotely with root access. 1288 00:45:57,040 --> 00:45:57,840 Um, so 1289 00:45:57,840 --> 00:45:59,780 this is, uh, what the code looked like that 1290 00:45:59,780 --> 00:46:01,860 handles that case. And then here's the, 1291 00:46:01,860 --> 00:46:03,620 the API call to patch the 1292 00:46:03,620 --> 00:46:05,720 firmware. And then it just all, it changes that 1293 00:46:05,900 --> 00:46:07,300 code to this code, which just changes, 1294 00:46:07,860 --> 00:46:09,760 uh, the SPS command and then jumps to 1295 00:46:09,760 --> 00:46:10,280 the other case. 1296 00:46:11,420 --> 00:46:13,160 So now when I query remaining capacity, 1297 00:46:13,500 --> 00:46:15,680 you know, surprisingly, it's exactly the same as the 1298 00:46:15,680 --> 00:46:17,880 manufacturer date. And same thing, full charge 1299 00:46:17,880 --> 00:46:19,740 capacity, you know, coincidentally is exactly the same 1300 00:46:19,740 --> 00:46:20,240 as the serial number. 1301 00:46:21,660 --> 00:46:23,860 Okay, so now, I, I don't show it here, 1302 00:46:23,940 --> 00:46:25,640 but I go through and I have a white paper that, that goes 1303 00:46:25,640 --> 00:46:27,620 in way more detail than I can here. But, uh, 1304 00:46:27,800 --> 00:46:29,660 I go and I, I change the firmware 1305 00:46:29,660 --> 00:46:31,540 to lie about every single thing that's queried. 1306 00:46:31,720 --> 00:46:34,060 So now, over time, it, uh, 1307 00:46:34,120 --> 00:46:35,680 doesn't, it doesn't change if I don't want to. 1308 00:46:35,900 --> 00:46:37,900 I can change it on the fly. And I 1309 00:46:37,900 --> 00:46:39,720 did verify that, you know, these 1310 00:46:39,720 --> 00:46:41,880 changes that I make do affect 1311 00:46:41,880 --> 00:46:43,880 how much current's delivered to the battery, but in, like, 1312 00:46:43,920 --> 00:46:45,780 some sort of weird, non, like, super 1313 00:46:45,780 --> 00:46:47,800 obvious way. So, uh, anyway, this, 1314 00:46:47,840 --> 00:46:49,800 this is where I, like, got, started to get scared. 1315 00:46:50,000 --> 00:46:51,860 And I, you know, I tell this story that, 1316 00:46:52,680 --> 00:46:54,000 um, I, I was driving, 1317 00:46:54,100 --> 00:46:55,900 you know, to a soccer game or something, and 1318 00:46:55,900 --> 00:46:57,860 I saw all these, like, fire trucks and stuff going the other 1319 00:46:57,860 --> 00:46:59,180 direction. I was like, oh, shit. 1320 00:47:00,120 --> 00:47:01,900 Uh, cause I was just, like, messing with this 1321 00:47:01,900 --> 00:47:03,800 stuff when I left. And so, like, I call 1322 00:47:03,800 --> 00:47:05,740 home and, and, you know, my wife answers. I'm like, 1323 00:47:05,900 --> 00:47:07,420 well, that's good. So she answered the phone. 1324 00:47:07,700 --> 00:47:09,620 And then I was like, you know, that computer 1325 00:47:09,620 --> 00:47:11,860 upstairs in my office, can, can you go 1326 00:47:11,860 --> 00:47:13,560 unplug that? So she 1327 00:47:13,560 --> 00:47:15,920 did that. Anyway, so, so, so I mentioned 1328 00:47:15,920 --> 00:47:17,920 that there's, there's various layers of defense 1329 00:47:17,920 --> 00:47:19,780 besides this chip that I'm, like, owning 1330 00:47:19,780 --> 00:47:21,800 is, is the main guy in charge of safety. 1331 00:47:21,880 --> 00:47:23,500 But there's other things that, that may prevent 1332 00:47:23,500 --> 00:47:25,980 the, the big explosion. Um, so there's 1333 00:47:25,980 --> 00:47:27,700 these, like, thermal cut-offs and, that you see. 1334 00:47:27,780 --> 00:47:29,940 So it's, like, these little cells that, they get 1335 00:47:29,940 --> 00:47:31,840 hot, they, they melt, and then you can't get electricity 1336 00:47:31,840 --> 00:47:32,660 to the cells anymore. 1337 00:47:34,280 --> 00:47:35,880 Um, but, uh, the, the, you know, the good 1338 00:47:35,880 --> 00:47:37,920 thing about that battery is I can't mess with it, the off-market one. 1339 00:47:38,140 --> 00:47:39,940 The, the, the bad thing is I didn't see these 1340 00:47:39,940 --> 00:47:41,620 little things on the, the off-market battery. 1341 00:47:43,520 --> 00:47:43,880 Um, 1342 00:47:44,060 --> 00:47:45,920 the other, the other thing you can imagine, again, 1343 00:47:45,960 --> 00:47:47,660 is attacking the kernel from the battery. 1344 00:47:48,000 --> 00:47:49,940 So this would be, like, a way to have persistent malware, 1345 00:47:50,040 --> 00:47:51,880 for example. Uh, I didn't look for 1346 00:47:51,880 --> 00:47:53,980 a particular bug. Again, like, knowing Apple, 1347 00:47:54,100 --> 00:47:55,520 it's hard to imagine there's not a bug there. 1348 00:47:56,680 --> 00:47:57,940 So you can imagine riding a 1349 00:47:57,940 --> 00:47:59,620 fuzzer in cool risk assembly 1350 00:47:59,620 --> 00:48:01,800 and changing the firmware and having the battery literally 1351 00:48:01,800 --> 00:48:04,180 fuzzing the OS. That is crazy. 1352 00:48:04,560 --> 00:48:05,480 But it would be awesome. 1353 00:48:05,880 --> 00:48:07,620 Um, the, the easier way is you can just do it in hardware, 1354 00:48:07,740 --> 00:48:09,660 just hook wires in there and, and emulate the, 1355 00:48:09,720 --> 00:48:11,880 the fuzz. And, uh, Travis 1356 00:48:11,880 --> 00:48:13,860 Goodspeed is talking about it. He already has something that basically 1357 00:48:13,860 --> 00:48:15,700 does that. Um, 1358 00:48:15,760 --> 00:48:17,880 so then if, you know, I don't really think there's much risk 1359 00:48:17,880 --> 00:48:19,800 of, of anything bad happening to 1360 00:48:19,800 --> 00:48:21,840 you, um, from this, uh, without 1361 00:48:21,840 --> 00:48:23,720 someone else doing something, you know, a lot more work. 1362 00:48:24,100 --> 00:48:25,880 Uh, but if you're the super paranoid 1363 00:48:25,880 --> 00:48:27,740 type, which probably 90% of the people in this room 1364 00:48:27,740 --> 00:48:29,700 are pretty paranoid, uh, I did, I 1365 00:48:29,700 --> 00:48:31,760 released a tool called Cockgun, which basically goes in and 1366 00:48:31,760 --> 00:48:33,860 changes the passwords to, to values nobody knows. 1367 00:48:35,000 --> 00:48:35,860 It's a source code-based 1368 00:48:35,880 --> 00:48:37,460 and it basically looks like this. It's just like, yeah, 1369 00:48:37,520 --> 00:48:39,120 it gets full access, changes the password, 1370 00:48:39,520 --> 00:48:41,820 and, and that's it. So, um, here's all 1371 00:48:41,820 --> 00:48:43,420 the people who helped me on this talk. 1372 00:48:43,660 --> 00:48:45,620 Uh, you know, I'm such a hardware noob that 1373 00:48:45,620 --> 00:48:47,780 I, I couldn't get very far. So thanks to all those 1374 00:48:47,780 --> 00:48:49,640 guys. Here's where you can download 1375 00:48:49,640 --> 00:48:51,880 the paper, the slides, the tools. 1376 00:48:52,160 --> 00:48:53,700 I have, uh, IdaPro scripts. 1377 00:48:53,980 --> 00:48:55,740 I have the firmware, IDB files, 1378 00:48:55,920 --> 00:48:57,500 everything you'd want to, like, learn and play with. 1379 00:48:57,700 --> 00:48:59,220 And, and that's it. Thanks a lot.