1 00:00:00,023 --> 00:00:04,650 - Alright coming up next, we have a talk on the iPhone. 2 00:00:04,650 --> 00:00:07,020 It's called "The Hitchhiker's Guide to iPhone Lightning 3 00:00:07,020 --> 00:00:08,700 and JTAG Hacking." 4 00:00:08,700 --> 00:00:11,908 So please help me welcome to the stage Stacksmashing. 5 00:00:11,908 --> 00:00:15,360 (crowd applauds) 6 00:00:15,360 --> 00:00:18,660 - Hello, let's get started. 7 00:00:18,660 --> 00:00:21,022 This is gonna be a fast paced talk. 8 00:00:21,022 --> 00:00:24,630 So we got to hurry, first off about me, 9 00:00:24,630 --> 00:00:26,910 my name is Thomas Roth, I'm probably better known 10 00:00:26,910 --> 00:00:29,700 as Stacksmashing on Twitter and YouTube. 11 00:00:29,700 --> 00:00:32,820 And yeah, I'm a security researcher, I do hardware, 12 00:00:32,820 --> 00:00:34,920 I do software, all kinds of stuff. 13 00:00:34,920 --> 00:00:37,350 And before we can get started with the actual talk, 14 00:00:37,350 --> 00:00:39,450 we have to say thank you to a couple of people. 15 00:00:39,450 --> 00:00:41,730 So first off, Carlo Maragno, 16 00:00:41,730 --> 00:00:44,220 who is like my partner in crime on this talk, 17 00:00:44,220 --> 00:00:47,160 basically we designed the hardware together, 18 00:00:47,160 --> 00:00:48,540 collaborated on this. 19 00:00:48,540 --> 00:00:51,591 Then Jiska, Caro, and Fabian who just 20 00:00:51,591 --> 00:00:55,440 have been a great support, answered a ton of questions, 21 00:00:55,440 --> 00:00:59,760 listened to my rambling about debugging SWD issues 22 00:00:59,760 --> 00:01:03,120 and so on, then Lily, AKA Bendy Cactus, 23 00:01:03,120 --> 00:01:07,500 who just gave me a lot of hints and tips when I was stuck 24 00:01:07,500 --> 00:01:11,580 and just was contributed some great information. 25 00:01:11,580 --> 00:01:15,630 Then John, AKA Nyan Satan, who basically documented 26 00:01:15,630 --> 00:01:17,310 a lot of this stuff you're about to see 27 00:01:17,310 --> 00:01:19,680 and a lot of the information that I used in this talk is 28 00:01:19,680 --> 00:01:22,590 based on his research and also LambdaConcept 29 00:01:22,590 --> 00:01:25,710 who are the vendors of the Bonobo Cable. 30 00:01:25,710 --> 00:01:28,549 They published a lot of things as open source that have been 31 00:01:28,549 --> 00:01:30,813 really, really helpful for this talk. 32 00:01:32,010 --> 00:01:33,390 Now, Lightning. 33 00:01:33,390 --> 00:01:34,860 What's so special about Lightning? 34 00:01:34,860 --> 00:01:36,570 Lightning is this proprietary connector 35 00:01:36,570 --> 00:01:38,400 by Apple that you can find on iPhones 36 00:01:38,400 --> 00:01:41,940 and it's reversible, so it has eight contacts on both sides. 37 00:01:41,940 --> 00:01:44,430 However, if we look on the device site's side, 38 00:01:44,430 --> 00:01:46,560 it really only has contacts on the bottom. 39 00:01:46,560 --> 00:01:48,480 So it's just eight signals. 40 00:01:48,480 --> 00:01:49,830 If you look at the connector with 41 00:01:49,830 --> 00:01:52,020 the contacts on the bottom, we count them like this, 42 00:01:52,020 --> 00:01:54,518 one to eight, and Lightning normally 43 00:01:54,518 --> 00:01:58,200 is used for audio charging, data transfer, 44 00:01:58,200 --> 00:01:59,970 all that kind of stuff. 45 00:01:59,970 --> 00:02:02,520 So for me, it's not really interesting, however, 46 00:02:02,520 --> 00:02:05,970 if you take a look at some of the 47 00:02:05,970 --> 00:02:08,370 less common iPhone accessories, 48 00:02:08,370 --> 00:02:10,080 you can find that there are actually a couple of 49 00:02:10,080 --> 00:02:12,330 interesting things going on. 50 00:02:12,330 --> 00:02:13,890 So for example, you can get something 51 00:02:13,890 --> 00:02:16,350 called a DCSD or Alex cable, 52 00:02:16,350 --> 00:02:20,460 which basically you plug it into the iPhone and it gives you 53 00:02:20,460 --> 00:02:22,230 a serial console onto the iPhone. 54 00:02:22,230 --> 00:02:23,850 And so if you plug it in, you boot your iPhone, 55 00:02:23,850 --> 00:02:25,350 you get like the boot lock and so on, 56 00:02:25,350 --> 00:02:27,150 especially on a jailbroken iPhone. 57 00:02:27,150 --> 00:02:29,100 So that's pretty interesting. 58 00:02:29,100 --> 00:02:30,690 And there's also something really cool 59 00:02:30,690 --> 00:02:32,160 called the Kanzi Cable, 60 00:02:32,160 --> 00:02:34,590 the Kanzi Cable gives you JTAG on the iPhone, 61 00:02:34,590 --> 00:02:37,230 so it allows you to debug the actual iPhone. 62 00:02:37,230 --> 00:02:39,870 Now the Kanzi Cable is an Apple internal device, 63 00:02:39,870 --> 00:02:42,870 so you can sometimes get them on the gray and black market, 64 00:02:42,870 --> 00:02:45,630 so it's not really an option if you want to do like, 65 00:02:45,630 --> 00:02:47,372 let's say, legit security research cause 66 00:02:47,372 --> 00:02:49,773 you can't start off with a stolen device. 67 00:02:50,670 --> 00:02:53,910 But luckily for us LambdaConcept built a 68 00:02:53,910 --> 00:02:56,460 commercial version of this called the Bonobo Cable. 69 00:02:57,330 --> 00:03:01,080 It's apparently really great, I unfortunately never had one. 70 00:03:01,080 --> 00:03:05,070 The issue is it's been out of stock for the past few years. 71 00:03:05,070 --> 00:03:08,040 And so I have friends who work at universities and do iPhone 72 00:03:08,040 --> 00:03:12,030 security research and they cannot do JTAG research simply 73 00:03:12,030 --> 00:03:14,040 because they can't get the hardware. 74 00:03:14,040 --> 00:03:16,470 Now I'm a hardware hacker, and after 75 00:03:16,470 --> 00:03:19,740 visiting those friends and a couple of drinks in, 76 00:03:19,740 --> 00:03:22,770 the mission was clear, we have to build our own. 77 00:03:22,770 --> 00:03:26,190 To do that, we have to first understand Lightning itself. 78 00:03:26,190 --> 00:03:28,470 If we look at the Lightning connector, we have the pins, 79 00:03:28,470 --> 00:03:31,050 we have obviously a ground signal, 80 00:03:31,050 --> 00:03:33,570 we have power for charging and so on, 81 00:03:33,570 --> 00:03:35,280 and then we have two differential pairs. 82 00:03:35,280 --> 00:03:37,300 So we have L zero, positive and negative, 83 00:03:37,300 --> 00:03:39,480 and L one, positive and negative. 84 00:03:39,480 --> 00:03:41,430 And these two differential pairs can be 85 00:03:41,430 --> 00:03:43,530 configured to different protocols. 86 00:03:43,530 --> 00:03:45,870 So for example, if you have a USB cable, 87 00:03:45,870 --> 00:03:47,550 they will be configured to USB. 88 00:03:47,550 --> 00:03:49,170 If you have a DCSD cable, they will 89 00:03:49,170 --> 00:03:52,410 do UART and so on and so forth. 90 00:03:52,410 --> 00:03:54,420 And we also have two ID pins. 91 00:03:54,420 --> 00:03:56,790 Now normally we only use one of these, 92 00:03:56,790 --> 00:03:58,590 they're basically used by the cable to 93 00:03:58,590 --> 00:04:00,270 tell the iPhone what it should do. 94 00:04:00,270 --> 00:04:03,090 And the reason we have two is that the Lightning cable is 95 00:04:03,090 --> 00:04:05,400 actually not symmetric when you turn it around. 96 00:04:05,400 --> 00:04:08,700 But the ID pin on the actual plug is on a different pin 97 00:04:08,700 --> 00:04:10,470 depending on the orientation you plug it in. 98 00:04:10,470 --> 00:04:12,630 And so when you plug in the Lightning connector, 99 00:04:12,630 --> 00:04:15,530 the iPhone can actually tell which wave you plugged it in. 100 00:04:17,010 --> 00:04:19,590 Now, Lightning cables are always active, like 101 00:04:19,590 --> 00:04:21,420 even if you have a Lightning to USB cable, 102 00:04:21,420 --> 00:04:23,880 it actually, in the plug itself, contains a small 103 00:04:23,880 --> 00:04:26,370 micro controller that talks to the iPhone 104 00:04:26,370 --> 00:04:28,770 and tells it, "Hey, I'm a Lightning cable" 105 00:04:28,770 --> 00:04:30,600 and it even sends over its serial number 106 00:04:30,600 --> 00:04:34,500 to authenticate itself, so it's pretty fancy. 107 00:04:34,500 --> 00:04:37,110 I'm not sure if it's necessary, but it's there. 108 00:04:37,110 --> 00:04:39,480 And the way this authentication is done is via 109 00:04:39,480 --> 00:04:42,330 a protocol called SDQ or IDBUS, 110 00:04:42,330 --> 00:04:44,459 just two words for the same BUS. 111 00:04:44,459 --> 00:04:47,520 And inside the iPhone, there's basically, 112 00:04:47,520 --> 00:04:49,350 directly connected to the Lightning connector, 113 00:04:49,350 --> 00:04:54,030 a small chip called Tristar or Hydra on newer devices. 114 00:04:54,030 --> 00:04:56,100 And this Tristar chip is on the bottom, 115 00:04:56,100 --> 00:04:58,770 connected directly to Lightning and then internally 116 00:04:58,770 --> 00:05:01,800 connected to the internal serial BUSes to USB, 117 00:05:01,800 --> 00:05:05,490 to JTAG and on engineering iPhones, it's even connected to 118 00:05:05,490 --> 00:05:08,223 the basement UART, and so it's pretty interesting. 119 00:05:09,300 --> 00:05:11,370 And when you plug in the Lightning cable, 120 00:05:11,370 --> 00:05:13,297 the iPhone will basically ask the cable, 121 00:05:13,297 --> 00:05:14,760 "Hey, what do you want?" 122 00:05:14,760 --> 00:05:16,477 And then the USB cable will say, 123 00:05:16,477 --> 00:05:18,457 "Hey, please speak USB" or 124 00:05:18,457 --> 00:05:22,050 "please speak" I don't know, serial, JTAG, whatever. 125 00:05:22,050 --> 00:05:25,260 And if the cable says, "please speak USB." 126 00:05:25,260 --> 00:05:27,630 Then the iPhone will basically change, for example, 127 00:05:27,630 --> 00:05:30,600 the differential pair to be USB or 128 00:05:30,600 --> 00:05:32,850 to be UART and so on and so forth. 129 00:05:32,850 --> 00:05:36,270 Now SDQ is pretty well known, it's not really secret. 130 00:05:36,270 --> 00:05:37,440 It's been known for years, 131 00:05:37,440 --> 00:05:39,750 it's based on the one wire standard. 132 00:05:39,750 --> 00:05:43,590 Even I released like an analyzer for it in 2018. 133 00:05:43,590 --> 00:05:45,510 And overall it's pretty well documented. 134 00:05:45,510 --> 00:05:48,540 So I'm not gonna go too deep into the physical details, 135 00:05:48,540 --> 00:05:49,863 but all you have to know is that 136 00:05:49,863 --> 00:05:51,810 it's a simple one wire protocol, 137 00:05:51,810 --> 00:05:54,870 so basically you only have one wire that connects both 138 00:05:54,870 --> 00:05:57,300 accessories, you don't have TX and RX, 139 00:05:57,300 --> 00:05:59,340 it's really just one wire. 140 00:05:59,340 --> 00:06:01,290 And the data looks somewhat like this. 141 00:06:01,290 --> 00:06:03,513 If we zoom in on a single byte here, 142 00:06:04,350 --> 00:06:07,020 basically we encode once as a short, low pulse 143 00:06:07,020 --> 00:06:08,760 and a long, high pulse, and we 144 00:06:08,760 --> 00:06:11,670 encode zeros as a long, low pulse in a short high pulse 145 00:06:11,670 --> 00:06:14,730 and data is transmitted least significant bit first, 146 00:06:14,730 --> 00:06:17,523 and so this would encode to hex zero F. 147 00:06:19,020 --> 00:06:22,050 Now, if we wanna talk to, let's say the Lightning cable, 148 00:06:22,050 --> 00:06:25,200 the iPhone would then for example, send hex zero F, 149 00:06:25,200 --> 00:06:28,140 then it would send a break, then there's a short delay 150 00:06:28,140 --> 00:06:31,860 for the inputs to switch over for the direction. 151 00:06:31,860 --> 00:06:33,420 And then the Lightning cable would answer 152 00:06:33,420 --> 00:06:35,103 on exactly the same data line. 153 00:06:35,970 --> 00:06:40,650 And now a lot of people implement this on FPGAs and so on, 154 00:06:40,650 --> 00:06:43,350 but if you know me, I like to go very cheap on my stuff, 155 00:06:43,350 --> 00:06:45,360 and so there's only one option for me, 156 00:06:45,360 --> 00:06:48,330 the Raspberry Pi Pico, it's just $4, 157 00:06:48,330 --> 00:06:52,620 not $20 or a hundred dollars, and it's super, 158 00:06:52,620 --> 00:06:55,710 super well suited for this because it runs at 3.3 Volts, 159 00:06:55,710 --> 00:06:58,410 which is exactly the voltage we need. 160 00:06:58,410 --> 00:07:00,720 And it has something called programmable IO, 161 00:07:00,720 --> 00:07:05,100 which is this feature that lets you very easily implement 162 00:07:05,100 --> 00:07:06,960 protocols directly in hardware. 163 00:07:06,960 --> 00:07:10,890 It's basically a small state machine CPU core 164 00:07:10,890 --> 00:07:12,330 that has its own instruction set. 165 00:07:12,330 --> 00:07:15,900 And you can just implement SDQ in hardware on this thing. 166 00:07:15,900 --> 00:07:18,300 And the best part is you can actually buy it because it's 167 00:07:18,300 --> 00:07:20,580 not actually affected by the chip shortage. 168 00:07:20,580 --> 00:07:23,820 So yeah, it's pretty good. 169 00:07:23,820 --> 00:07:28,140 The issue is that we need a Lightning connector and as said, 170 00:07:28,140 --> 00:07:30,720 you can't just cut off a USB to Lightning cable because 171 00:07:30,720 --> 00:07:32,760 there's a chip in the plug itself, 172 00:07:32,760 --> 00:07:36,360 and so you can't simply abuse that, 173 00:07:36,360 --> 00:07:39,600 but there are these nice breakouts who, by the way, 174 00:07:39,600 --> 00:07:42,330 Jills over there sent to me this one. 175 00:07:42,330 --> 00:07:44,580 Unfortunately, if you count the number of signals, 176 00:07:44,580 --> 00:07:45,870 it's just five signals, but 177 00:07:45,870 --> 00:07:48,000 Lightning actually has eight signals. 178 00:07:48,000 --> 00:07:50,790 And so those are nice for some basic experimentation. 179 00:07:50,790 --> 00:07:52,830 And we basically did our first steps, 180 00:07:52,830 --> 00:07:55,650 let's say, with a similar one, in this case, 181 00:07:55,650 --> 00:07:57,810 we were sniffing at DCSD cable, 182 00:07:57,810 --> 00:08:02,010 but then Bendy Cactus actually recommended to me that the 183 00:08:02,010 --> 00:08:05,700 Lightning extension cords you can get on Amazon contain all 184 00:08:05,700 --> 00:08:08,575 eight signals and even better, if you cut one apart, 185 00:08:08,575 --> 00:08:10,530 all the cables are nicely colored, 186 00:08:10,530 --> 00:08:12,570 and the color scheme is identical to the 187 00:08:12,570 --> 00:08:14,760 default jumper wire color scheme. 188 00:08:14,760 --> 00:08:18,750 And so you can really easily build one of these and then 189 00:08:18,750 --> 00:08:21,423 plug it into a breakboard or directly into the Pico. 190 00:08:22,740 --> 00:08:25,020 Here's the signal description, this is also on the GitHub, 191 00:08:25,020 --> 00:08:27,030 as you will see, so if you wanna experiment, 192 00:08:27,030 --> 00:08:30,363 this is the layout we found on most cables. 193 00:08:31,500 --> 00:08:32,730 Then you hook it all up, and then 194 00:08:32,730 --> 00:08:35,700 you have a device to explore Lightning. 195 00:08:35,700 --> 00:08:38,070 You will notice that I've marked the Lightning connector, 196 00:08:38,070 --> 00:08:39,780 cause, as said, it's not symmetric, 197 00:08:39,780 --> 00:08:42,480 you actually have to decide for one side 198 00:08:42,480 --> 00:08:44,520 And then you hook it up to the Pico 199 00:08:44,520 --> 00:08:46,740 and you wanna implement SDQ and it turns 200 00:08:46,740 --> 00:08:49,890 out that implementing SDQ is super simple. 201 00:08:49,890 --> 00:08:51,000 You don't have to read this code, 202 00:08:51,000 --> 00:08:53,310 I just wanna show how relatively short it is. 203 00:08:53,310 --> 00:08:55,470 It's just like 40 instructions and you are done. 204 00:08:55,470 --> 00:08:59,133 And then 20 lines of code to start talking SDQ. 205 00:09:00,030 --> 00:09:01,590 To test all this and see whether we 206 00:09:01,590 --> 00:09:03,390 really can talk to the iPhone, 207 00:09:03,390 --> 00:09:06,090 our goal was to build a simple DCSD cable, 208 00:09:06,090 --> 00:09:10,020 as I've mentioned, DCSD is this iPhone to serial cable. 209 00:09:10,020 --> 00:09:12,960 And the basic idea is that we have our iPhone and we have 210 00:09:12,960 --> 00:09:14,900 our Pico and the iPhone, when we plug in 211 00:09:14,900 --> 00:09:17,970 the Lightning cable, will ask, "Hey, who's there?" 212 00:09:17,970 --> 00:09:20,190 And it dusted with a four byte request, 213 00:09:20,190 --> 00:09:21,900 seven four is the command, at the end 214 00:09:21,900 --> 00:09:24,870 we have a CRC eight doesn't really matter too much. 215 00:09:24,870 --> 00:09:28,710 And then we simply respond with this eight byte response, 216 00:09:28,710 --> 00:09:29,887 which just tells the iPhone, 217 00:09:29,887 --> 00:09:33,060 "Hey, please configure Lightning to speak UART." 218 00:09:33,060 --> 00:09:35,910 And the Tristar chip in the iPhone will do exactly 219 00:09:35,910 --> 00:09:38,400 that, it will take one of the differential pairs 220 00:09:38,400 --> 00:09:40,500 and it will switch it to UART. 221 00:09:40,500 --> 00:09:43,735 And then all we have to do really on the Pico is receive 222 00:09:43,735 --> 00:09:46,230 UART signals and turns out this is super simple, 223 00:09:46,230 --> 00:09:49,470 it takes less than 50 lines of code to do this. 224 00:09:49,470 --> 00:09:53,580 And then you have a DCSD cable and we check this out, 225 00:09:53,580 --> 00:09:56,400 we plug in the iPhone, it boots up and 226 00:09:56,400 --> 00:10:00,192 we have a $5 DCSD cable without 227 00:10:00,192 --> 00:10:02,760 having done too much, this is pretty cool, 228 00:10:02,760 --> 00:10:06,193 but DCSD cables can be very easily bought on Ali Express 229 00:10:06,193 --> 00:10:09,090 and so on, and it's not really what we are interested in. 230 00:10:09,090 --> 00:10:11,370 We are here for JTAG. 231 00:10:11,370 --> 00:10:15,360 Now, JTAG on the iPhone is actually not JTAG it's SWD, 232 00:10:15,360 --> 00:10:18,000 which is serial wire debug, it's basically 233 00:10:18,000 --> 00:10:20,970 like JTAG, but only uses two signals. 234 00:10:20,970 --> 00:10:24,060 And the big issue is that production iPhones obviously have 235 00:10:24,060 --> 00:10:25,380 JTAG turned off, cause they don't 236 00:10:25,380 --> 00:10:27,510 want you to debug the iPhone, 237 00:10:27,510 --> 00:10:29,880 but if you have a checkmateable iPhone, 238 00:10:29,880 --> 00:10:32,580 you can actually use a jailbreak to basically first 239 00:10:32,580 --> 00:10:34,710 compromise the iPhone, the boot ROM, 240 00:10:34,710 --> 00:10:36,960 and then we can do something called 241 00:10:36,960 --> 00:10:39,720 demotion where we set an internal register 242 00:10:39,720 --> 00:10:42,090 to a different value and then suddenly 243 00:10:42,090 --> 00:10:45,600 JTAG has re-enabled and this is all done by iPhone DFU. 244 00:10:45,600 --> 00:10:47,190 And this has been known for years, by the way, 245 00:10:47,190 --> 00:10:49,190 this is nothing new, just wanna clarify. 246 00:10:50,070 --> 00:10:54,450 But now we actually wanna start talking JTAG to the iPhone. 247 00:10:54,450 --> 00:10:56,700 And so we need a plan. 248 00:10:56,700 --> 00:10:58,620 The plan is super simple. 249 00:10:58,620 --> 00:11:01,110 First we set Lightning to JTAG via SDQ. 250 00:11:01,110 --> 00:11:03,270 We just set it to UART, so we already 251 00:11:03,270 --> 00:11:05,070 know how to do this, basically. 252 00:11:05,070 --> 00:11:08,789 All we do is we respond to the "who's there" request 253 00:11:08,789 --> 00:11:11,280 with this time a different byte. 254 00:11:11,280 --> 00:11:13,230 And by the way, all these bytes for the responses 255 00:11:13,230 --> 00:11:17,850 are documented by Nyan Cat, sorry, Nyan Satan. 256 00:11:17,850 --> 00:11:20,520 And so you can find a lot of details about this online. 257 00:11:20,520 --> 00:11:23,970 And we also have our own documentation on some more details. 258 00:11:23,970 --> 00:11:26,580 And then the iPhone, the Tristar chip, 259 00:11:26,580 --> 00:11:29,190 will reconfigure all the pins on the iPhone. 260 00:11:29,190 --> 00:11:33,150 And then we actually have directly the SWD clock and IO 261 00:11:33,150 --> 00:11:35,793 signal exposed on the Lightning connector. 262 00:11:36,660 --> 00:11:39,203 And so all we have to do now is we just 263 00:11:39,203 --> 00:11:42,480 connect the debug probe with openocd, right? 264 00:11:42,480 --> 00:11:43,800 What could possibly go wrong? 265 00:11:43,800 --> 00:11:45,420 And even better, LambdaConcept, 266 00:11:45,420 --> 00:11:48,570 who are the vendors of the Bonobo Cable, 267 00:11:48,570 --> 00:11:51,810 they actually published an openocd fork that supports, 268 00:11:51,810 --> 00:11:54,570 has like special support for the iPhone and so on 269 00:11:54,570 --> 00:11:56,970 and even better, they supply us with all 270 00:11:56,970 --> 00:12:00,060 the configuration files we need to actually talk to the chip 271 00:12:00,060 --> 00:12:02,400 because for if you wanna debug a chip, 272 00:12:02,400 --> 00:12:03,930 there are all these definitions on, 273 00:12:03,930 --> 00:12:06,600 whereas which peripheral and so on and so forth. 274 00:12:06,600 --> 00:12:07,980 And they provide us all of this. 275 00:12:07,980 --> 00:12:11,190 And so I decided to hook this up in the 276 00:12:11,190 --> 00:12:13,323 messiest way possible, cause yeah, 277 00:12:14,160 --> 00:12:17,283 basically what I did is I just connected my iPhone, 278 00:12:18,750 --> 00:12:21,300 brought the Lightning stuff out to a breakboard, 279 00:12:21,300 --> 00:12:23,760 connected a logic analyzer so that I can actually see what's 280 00:12:23,760 --> 00:12:26,550 going on, connected the Pico that will actually tell the 281 00:12:26,550 --> 00:12:29,160 iPhone to go into SWD mode, and then 282 00:12:29,160 --> 00:12:32,880 I used a ready to use debug probe just to see, 283 00:12:32,880 --> 00:12:35,040 just to get it working basically. 284 00:12:35,040 --> 00:12:38,040 And so I hooked this all up and so we are ready to go. 285 00:12:38,040 --> 00:12:40,353 And so it doesn't work. 286 00:12:42,420 --> 00:12:46,350 It turns out that switching over to SWD is really easy. 287 00:12:46,350 --> 00:12:48,930 And if we actually connect with the debugger, 288 00:12:48,930 --> 00:12:51,510 we can even see that it finds the debug port. 289 00:12:51,510 --> 00:12:54,480 Like the hex number on the bottom is basically, 290 00:12:54,480 --> 00:12:56,250 if you Google it, that's an iPhone. 291 00:12:56,250 --> 00:12:59,280 And so we do have some kind of debugging connection to the 292 00:12:59,280 --> 00:13:03,120 iPhone, but if we wanna actually debug something, 293 00:13:03,120 --> 00:13:05,043 this is a screenshot from openocd, 294 00:13:05,970 --> 00:13:09,810 it doesn't work, like the state of all CPUs is unknown 295 00:13:09,810 --> 00:13:12,843 and I have zero clue how to turn them on. 296 00:13:14,100 --> 00:13:15,240 And how do you debug this? 297 00:13:15,240 --> 00:13:18,660 Because my issue was I have no clue about SWD. 298 00:13:18,660 --> 00:13:20,940 Like I've used JTAG a million times. 299 00:13:20,940 --> 00:13:25,800 I've used SWD probably even more, but how do you debug, 300 00:13:25,800 --> 00:13:26,970 if you just like, 301 00:13:26,970 --> 00:13:29,940 we didn't even have a working Kanzi or Bonobo Cable, 302 00:13:29,940 --> 00:13:33,150 we didn't have a known working system that we could sniff. 303 00:13:33,150 --> 00:13:36,450 This is all basically partially reverse engineered, 304 00:13:36,450 --> 00:13:39,750 partially combined from public information and so on. 305 00:13:39,750 --> 00:13:41,970 And so, yeah, what do you do? 306 00:13:41,970 --> 00:13:45,450 You get a nice book for the evening called 307 00:13:45,450 --> 00:13:49,380 the SWD specification, you read it twice, 308 00:13:49,380 --> 00:13:53,640 hope you understand at least a quarter of it, and then you 309 00:13:53,640 --> 00:13:58,230 start to logic analyze it and you see what bits are actually 310 00:13:58,230 --> 00:14:01,710 going over the wire, and so on, simple, right? 311 00:14:01,710 --> 00:14:03,720 So I hooked up my logic analyzer, 312 00:14:03,720 --> 00:14:06,510 I debug the signal, didn't make sense to me, 313 00:14:06,510 --> 00:14:08,370 turns out the logic analyzer is broken. 314 00:14:08,370 --> 00:14:12,840 The SWD plugin for the logic analyzer just simply was not 315 00:14:12,840 --> 00:14:14,670 great and so first you get to 316 00:14:14,670 --> 00:14:17,550 fix the logic analyzer, much fun. 317 00:14:17,550 --> 00:14:20,940 Then you see that openocd doesn't 318 00:14:20,940 --> 00:14:24,120 handle some SWD things correctly. 319 00:14:24,120 --> 00:14:28,140 And so basically when you send an SWD command to a chip, 320 00:14:28,140 --> 00:14:32,130 it can respond with acknowledgement or knock or wait. 321 00:14:32,130 --> 00:14:34,020 And it turns out openocd with, 322 00:14:34,020 --> 00:14:36,210 by default doesn't support the wait response 323 00:14:36,210 --> 00:14:38,940 and in the logic analyzer, I could see, 324 00:14:38,940 --> 00:14:41,280 I get wave response, but my debug probe just 325 00:14:41,280 --> 00:14:43,380 ignores it and keeps going. 326 00:14:43,380 --> 00:14:46,380 So obviously you implement SWD by hand. 327 00:14:46,380 --> 00:14:48,790 And so you, again, open the specification 328 00:14:49,728 --> 00:14:52,680 and you write as a completely custom, 329 00:14:52,680 --> 00:14:54,603 partially custom SWD stack. 330 00:14:55,650 --> 00:14:57,480 And at this point it still didn't work. 331 00:14:57,480 --> 00:14:59,460 We handled the wait bits, we handled 332 00:14:59,460 --> 00:15:02,940 everything was looking perfect and it still didn't work. 333 00:15:02,940 --> 00:15:05,160 And now then you're at a point in time where you can 334 00:15:05,160 --> 00:15:08,430 potentially sink 200 hours without success, 335 00:15:08,430 --> 00:15:10,227 cause you simply have no clue what's going on. 336 00:15:10,227 --> 00:15:14,670 And so I just started randomly trying everything I could 337 00:15:14,670 --> 00:15:17,427 find, randomly setting bits, clearing bits and so on. 338 00:15:17,427 --> 00:15:21,210 And I basically built kind of a fuzzer for some parts of 339 00:15:21,210 --> 00:15:25,200 the SWD protocol that tries to just flip bits until maybe 340 00:15:25,200 --> 00:15:27,360 we get successful. 341 00:15:27,360 --> 00:15:29,670 And it turns out a single bit that 342 00:15:29,670 --> 00:15:32,013 resets a certain peripheral was wrong. 343 00:15:34,710 --> 00:15:38,700 That was a tough day because you spend so much time just 344 00:15:38,700 --> 00:15:41,943 wasted, completely wasted on a single bit, 345 00:15:43,290 --> 00:15:45,510 but then you have a great moment, 346 00:15:45,510 --> 00:15:48,870 which is you hook up openocd, you hook up your iPhone, 347 00:15:48,870 --> 00:15:52,950 you hit return, and it connects no errors. 348 00:15:52,950 --> 00:15:54,427 Everything is fine, it tells you 349 00:15:54,427 --> 00:15:56,550 "Yes, I'm listening for a GV connection. 350 00:15:56,550 --> 00:15:58,860 I'm listening for an openocd connection." 351 00:15:58,860 --> 00:16:02,850 And so you hook up openocd and you check what do our CPU 352 00:16:02,850 --> 00:16:06,930 cores do, and this time we can see CPU zero halted, 353 00:16:06,930 --> 00:16:09,360 CPU one power off, no more unknown states, 354 00:16:09,360 --> 00:16:12,030 except for the SCP, which has a different reason. 355 00:16:12,030 --> 00:16:12,900 It's all working, 356 00:16:12,900 --> 00:16:17,900 and to prove that we can hook up gdb, connect to it and 357 00:16:18,990 --> 00:16:21,390 we can actually inspect the registers. 358 00:16:21,390 --> 00:16:24,120 We actually built a $5 Kanzi Cable. 359 00:16:24,120 --> 00:16:26,370 So yes, that was a great moment. 360 00:16:26,370 --> 00:16:29,120 (crowd applauds) 361 00:16:31,950 --> 00:16:35,010 And now at this point in time, 362 00:16:35,010 --> 00:16:38,430 it was all a bit complicated because 363 00:16:38,430 --> 00:16:40,020 I had a big pile of code. 364 00:16:40,020 --> 00:16:42,695 The branch was literally called clusterf**k. 365 00:16:42,695 --> 00:16:44,670 (crowd laughter) 366 00:16:44,670 --> 00:16:46,680 And so now it was time to clean up 367 00:16:46,680 --> 00:16:48,390 and put everything together, 368 00:16:48,390 --> 00:16:50,280 make everything work nicely together. 369 00:16:50,280 --> 00:16:51,600 And in the end we had this 370 00:16:51,600 --> 00:16:53,610 awesome framework for the Raspberry Pi Pico 371 00:16:53,610 --> 00:16:55,773 that can be used as an SDQ bridge, 372 00:16:56,640 --> 00:16:58,680 contains self contains, in the Pico, 373 00:16:58,680 --> 00:17:01,290 a full SWD probe for which 374 00:17:01,290 --> 00:17:03,990 we added support to openocd for. 375 00:17:03,990 --> 00:17:05,550 And it's fully open source. 376 00:17:05,550 --> 00:17:08,790 Now, obviously the cables that are 377 00:17:08,790 --> 00:17:11,280 used for debugging iPhones, they all have very 378 00:17:11,280 --> 00:17:13,200 awesome names based on monkeys. 379 00:17:13,200 --> 00:17:16,530 So you have the Kanzi Cable, the Bonobo, 380 00:17:16,530 --> 00:17:19,440 you have the Chimp Cable and the Kong Cable. 381 00:17:19,440 --> 00:17:22,140 Luckily for us, they didn't select the coolest monkey, 382 00:17:22,140 --> 00:17:23,880 which is the tamarin monkey, 383 00:17:23,880 --> 00:17:28,140 And so our firmware it's called the Tamarin Cable and you 384 00:17:28,140 --> 00:17:32,370 can find it as open source now online, it fully works. 385 00:17:32,370 --> 00:17:34,410 It's pretty simple to use, you plug it in, 386 00:17:34,410 --> 00:17:38,370 it will give you two, actually three, USB devices, 387 00:17:38,370 --> 00:17:40,680 two serial ports, the first serial port just 388 00:17:40,680 --> 00:17:44,789 lets you, you know, select between JTAG, DCSD mode, 389 00:17:44,789 --> 00:17:46,710 you can even reset the device, 390 00:17:46,710 --> 00:17:48,330 which is pretty cool, so it turns out 391 00:17:48,330 --> 00:17:51,390 that there are a couple of, basically, secret 392 00:17:51,390 --> 00:17:55,830 JTAG, sorry, secret SDQ commands that Bendy Cactus found. 393 00:17:55,830 --> 00:17:58,650 And basically just randomly I think posted them on Twitter. 394 00:17:58,650 --> 00:18:01,320 And I was like, "Hey, how did you find those?" 395 00:18:01,320 --> 00:18:03,420 And so it turns out by fuzzing Lightning, 396 00:18:03,420 --> 00:18:07,470 you can actually find some undocumented commands and this 397 00:18:07,470 --> 00:18:10,560 allows you to reset the device and go into DFU mode. 398 00:18:10,560 --> 00:18:14,520 If you've never jailbroken an iPhone before, 399 00:18:14,520 --> 00:18:17,160 you have to hold power and volume down, 400 00:18:17,160 --> 00:18:18,507 and at precisely eight seconds, 401 00:18:18,507 --> 00:18:20,520 you have to release the buttons. 402 00:18:20,520 --> 00:18:24,210 And then checkmate is not really a super stable exploit, 403 00:18:24,210 --> 00:18:25,530 so then you get to do it again, 404 00:18:25,530 --> 00:18:27,810 and again, and again, and again. 405 00:18:27,810 --> 00:18:29,700 With this, it's like a single tap, 406 00:18:29,700 --> 00:18:32,190 you just click reset and enter DFU and it goes into 407 00:18:32,190 --> 00:18:36,540 DFU and you can just try a hundred times, so honestly, 408 00:18:36,540 --> 00:18:39,180 this is the third best feature of this thing. 409 00:18:39,180 --> 00:18:41,610 Now to make this all a bit nicer, 410 00:18:41,610 --> 00:18:43,620 we also developed custom hardware 411 00:18:43,620 --> 00:18:45,060 that we call the Tamarin Cable, 412 00:18:45,060 --> 00:18:48,750 which basically also exposes it has a USB hop on there, 413 00:18:48,750 --> 00:18:50,930 so you can do both JTAG and also 414 00:18:50,930 --> 00:18:53,190 USB data at the same time. 415 00:18:53,190 --> 00:18:57,556 And just as we were ready to order a thousand pieces of this 416 00:18:57,556 --> 00:18:59,760 turns out, there's this thing going on 417 00:18:59,760 --> 00:19:02,410 called the chip shortage, you might have heard of it. 418 00:19:03,420 --> 00:19:07,320 And so all USB hubs we could finger were just out of stock. 419 00:19:07,320 --> 00:19:10,200 And so we had to build the chip shortage edition, 420 00:19:10,200 --> 00:19:14,670 which instead of a hub, simply adds two USB ports and just 421 00:19:14,670 --> 00:19:16,590 makes it a bit cleaner, like, you can make it 422 00:19:16,590 --> 00:19:18,780 a nice short cable, plug it in and so on, 423 00:19:18,780 --> 00:19:22,440 but this has zero advantages except it's less messy over the 424 00:19:22,440 --> 00:19:24,840 cable itself, so this is not a sales pitch, 425 00:19:24,840 --> 00:19:25,710 but this is coming up. 426 00:19:25,710 --> 00:19:28,350 If you're interested, we will probably do a production run, 427 00:19:28,350 --> 00:19:30,870 follow me on Twitter and 428 00:19:30,870 --> 00:19:33,420 you will get notified when it comes out. 429 00:19:33,420 --> 00:19:37,080 And with that, releases, there's a lot of 430 00:19:37,080 --> 00:19:39,420 different things that we've had to build for this. 431 00:19:39,420 --> 00:19:42,990 So first off the Tamarin Cable firmware is now open source. 432 00:19:42,990 --> 00:19:47,190 We forked openocd, added support for our Tamarin SWD probe. 433 00:19:47,190 --> 00:19:50,460 We forked the SWD analyzer of logic analyzer, 434 00:19:50,460 --> 00:19:53,040 and there's also the SDQ analyzer plug in. 435 00:19:53,040 --> 00:19:56,580 And I think some of the repos are still private, 436 00:19:56,580 --> 00:19:58,410 but the Tamarin Cable is open. 437 00:19:58,410 --> 00:20:00,660 As soon as I'm on a wifi that doesn't scare me, 438 00:20:00,660 --> 00:20:03,300 I will change the GitHub visibility. 439 00:20:03,300 --> 00:20:05,430 And with that, thank you very much. 440 00:20:05,430 --> 00:20:06,820 That's all I have for you today. 441 00:20:06,820 --> 00:20:09,570 (crowd applauds)