[00:00.000]Hey everyone, welcome to my talk, Ace of the Sleeve, hacking into Apple's new USB-C controller.
[00:06.200]

[00:06.540]First off, who am I? My name is Thomas Roth, aka Stacksmashing. I'm a security researcher for
[00:11.840]

[00:11.840]hardware and firmware, and I'm also a co-founder at this online training platform called Hackstreet.io.
[00:17.240]

[00:17.240]You can find me on Twitter, YouTube, and so on. Now, as always, like any research, it's built on
[00:24.160]

[00:24.160]top of other people's work, right? And so I want to thank, for example, Sigusa, who built a kernel
[00:29.920]

[00:29.920]module we will use, Oli for the Thunderbolt patcher, the Azahi Linux team, without whose
[00:35.800]

[00:35.800]reverse engineering work I couldn't do anything, Carlo Maragni, who just always was there when I
[00:41.520]

[00:41.520]talked and had to rant about fault injection, Biska, Fabian, and Caro, Mark Zingier for the
[00:47.640]

[00:47.640]central scrutinizer, and also the TAD12 dev team, who did some awesome work. Now, a bit on the
[00:54.560]

[00:54.560]backstory. Apple used to have this proprietary connector called Lightning, and it could do, you
[01:00.800]

[01:00.800]know, fairly obvious things such as charging, USB, video, and audio. But it could also do some
[01:06.640]

[01:06.640]really cool stuff, for example, JTAG, UART, SDQ, and so on. And you could buy cables for this on
[01:13.900]

[01:13.900]the black market, and there was also the Bonobo cable, but we decided we want to build an open
[01:18.720]

[01:18.720]source version of this, and we called it the Tamarink cable. And the Tamarink cable is essentially
[01:23.560]

[01:23.780]a $20 Lightning debugging interface that we introduced two years ago at DEF CON,
[01:28.820]

[01:29.240]so it's good to be back. However, Apple decided to throw all of my work away by switching from
[01:34.920]

[01:34.920]Lightning to, you know, this thing here. There was supposed to be audio here, but she's talking
[01:46.860]

[01:46.860]that we can do charging, data, audio, and video. But I think they made a mistake during the keynote
[01:51.640]

[01:51.640]because they forgot, you know, all the cool stuff. Like, who cares about charging? I want JTAG on the
[01:56.280]

[01:56.280]iPhone. And, you know, if you look at the USB-C connector, it has a ton of pins, and so surely we
[02:03.740]

[02:03.740]can somehow get some of these to speak JTAG, UART, or, you know, anything interesting, not just
[02:09.580]

[02:09.580]charging. And then I realized that the iPhone is not the first USB-C device that, you know, Apple
[02:15.880]

[02:15.880]made. And I never looked at any of these, but luckily for me, other people did. And they figured
[02:21.040]

[02:21.040]out that Apple, uh, essentially uses the USB power delivery negotiation to do some cool stuff. And
[02:28.640]

[02:28.640]it turns out that this power delivery negotiation is happening in something called the USB-C port
[02:34.300]

[02:34.300]controller. It's essentially a tiny microcontroller in the, in the MacBook, and that one handles all
[02:40.660]

[02:40.660]of this. And essentially, the charger communicates with it through these two lines, the configuration
[02:46.860]

[02:46.860]lines. And this is all handled by a microcontroller that sits close to the USB-C ports. And, you know,
[02:54.040]

[02:54.160]a microcontroller will have some kind of firmware. And some smart people years ago figured out,
[02:58.760]

[02:59.300]you can just dump that firmware. So you solder a couple of wires into your very expensive MacBook,
[03:05.020]

[03:05.020]dump the firmware, and then they wrote an awesome blog post because they reverse engineered the
[03:09.920]

[03:09.920]firmware. And they figured out that the Apple Type-C port controller, which we call Ace,
[03:15.300]

[03:15.300]actually contains a lot of secret functionality. And they found that Apple uses something called
[03:21.560]

[03:21.560]VDM, or Vendor Defined Messages, to let us change the configuration of certain pins on the USB-C
[03:27.680]

[03:27.680]connector. And so, for example, we can change the SBU, the Sideband Use Pins, to be serial. And so
[03:36.020]

[03:36.020]we can, you know, send the VDM action 306 to the Ace controller, and then we get a serial console
[03:43.360]

[03:43.360]on the MacBook. And it turns out that to this Ace, there's much more connected than just serial. You
[03:49.740]

[03:49.740]can also do JTAG, Thunderbolt, even I2C, or on the iPhone there's SPMI and so on. And so that's
[03:57.800]

[03:57.800]kind of cool. But how can we actually send these Vendor Defined Messages? Because this is not just
[04:02.760]

[04:02.760]like regular USB. Instead, we actually have to use special tooling to be able to send these
[04:08.820]

[04:08.820]messages. And again, some very smart people from the Asahi Linux tool, uh, Linux team found out
[04:14.860]

[04:14.860]that the back left port on the MacBook Pro is special, and can actually send those commands,
[04:20.700]

[04:20.700]and they reverse-engineered all of that stuff. And so there's a nice tool that you can just use
[04:24.940]

[04:24.940]to send these commands from a Mac to another Mac. Also, Marc Zenier built this thing called the
[04:30.640]

[04:30.640]Central Scrutinizer, which is essentially a serial adapter that is able to send all of these things
[04:35.820]

[04:35.820]and can give you, you know, a UART shell on a MacBook, and so on and so forth. Now, I saw this,
[04:43.160]

[04:43.160]it's Pico-based, I love the Pico, and so I ordered a couple of PCBs and started experimenting with
[04:48.100]

[04:48.100]this, um, and essentially all it contains is a small USB-C controller and a couple of level
[04:53.840]

[04:53.840]shifters. Now, I wanted to try to get serial on the iPhone 15 that was freshly released,
[04:59.900]

[04:59.900]because everyone was harassing me that my stuff doesn't work anymore, so, uh, I had to get with
[05:05.240]

[05:05.240]the times. Now, unfortunately, it didn't work on the iPhone 15 out of the box. Uh, I had to
[05:10.620]

[05:10.620]actually solder on a small USB switch and provide power to the iPhone and so on. Now, this might
[05:15.980]

[05:15.980]just be my incompetence, because this is the first time I ever touched USB-C, and so I just tried
[05:21.100]

[05:21.100]random stuff until it happened to work. And so, if you know USB-C better than me, feel free to
[05:27.120]

[05:27.120]tell me what I'm doing right or wrong. Um, but after doing all of this, I essentially had the
[05:34.200]

[05:34.200]central scrutinizer working on the iPhone, and so I can, you know, hit some keys, and suddenly I
[05:39.840]

[05:39.840]get the serial console on the, uh, iPhone 15. That's pretty cool, um, but also pretty useless,
[05:48.200]

[05:48.200]because, you know, like, what do we do with serial output? We want to get JTAG or SPMI or
[05:53.320]

[05:53.320]something interesting, right? And again, the Asahi Linux people did a ton of cool reverse
[05:59.220]

[05:59.220]engineering work on all of that USB PD stuff, and they have a gigantic document where they
[06:04.440]

[06:04.440]document all the actions and so on and so forth, and if you keep scrolling and scrolling and
[06:08.980]

[06:08.980]scrolling, you will find a small note that says, by the way, there's this action called 0206,
[06:15.380]

[06:15.380]and there's a good chance this is SWD, but nobody ever seems to have, like, publicly tried this.
[06:21.040]

[06:21.240]Um, so I took my central scrutinizer, hooked my oscilloscope debugger and so on up to this,
[06:27.700]

[06:27.700]and tried to connect to it. And it didn't work. But, you know, turns out there are two cables,
[06:36.720]

[06:36.720]and so I just reversed them, gave it another try, and suddenly we get a success message. We found
[06:44.080]

[06:44.080]the debug port with the ID 4BA02477. We just got JTAG on the iPhone 15 by just sending 206.
[06:54.060]

[06:54.060]Awesome. Unfortunately, this is a production device, and so JTAG is locked. So essentially,
[07:05.200]

[07:05.200]we can't debug it because it's a production device. On the black market, you can probably
[07:09.660]

[07:09.660]find an iPhone that is not locked, but it will run you like 100k or something, so I can't do that.
[07:15.100]

[07:15.960]But we got JTAG. Useless JTAG. You know. But we can still explore some other buses, and so it
[07:23.800]

[07:23.800]turns out that on the iPhone 15, there's actually more than just UART and so on on this connector,
[07:29.160]

[07:29.160]but also SPMI and other things. And so in December last year, we released a PCB called the Tamron
[07:35.920]

[07:35.920]C adapter, which is essentially a fork of the central scrutinizer with bidirectional level
[07:42.080]

[07:42.080]shifters, a USB power switch so it can actually charge the iPhone if you want to let it run for
[07:46.520]

[07:46.600]a long time for research. And we can use it to explore all the buses on the iPhone 15, including
[07:51.560]

[07:51.560]SPMI, which I think we released the first public analyzer for. And it also runs a full JTAG probe,
[07:58.480]

[07:58.480]and so you can experiment with this. It's fully open source. And if you use it, it looks like
[08:03.740]

[08:03.740]this. Now, this is cool, but again, also kind of useless. However, what's interesting is that
[08:09.860]

[08:09.860]all this stuff is implemented on the iPhone side in this chip called the ACE3. And the ACE3
[08:17.540]

[08:17.540]essentially sits between the USB port and the system on a chip. And it makes for a very
[08:22.240]

[08:22.240]interesting target, because on the iPhone 15, the ACE3 can actually run a full USB port, like it can
[08:29.400]

[08:29.400]come up as a USB device. If you go into recovery and plug your iPhone in, you're actually
[08:34.620]

[08:34.620]communicating with the ACE3. And that makes it an interesting target, because imagine if you
[08:39.540]

[08:39.540]compromise this part of the device, you could do attacks on the system on a chip without
[08:45.100]

[08:45.100]any way for anyone to know. Like there would be essentially zero traces.
[08:49.260]

[08:50.520]So I was interested in this. But I wanted to first understand the predecessor, the ACE2,
[08:56.960]

[08:56.960]because there's a lot of public work on the ACE2 already. And the ACE2 is essentially a Texas
[09:02.120]

[09:02.120]Instruments, a custom Texas Instruments USB-C controller. It's an ARM chip. It's connected
[09:09.340]

[09:09.340]to the SOC via I2C. And you can find it on all MacBooks, starting with the T2 Macs, up to the
[09:15.840]

[09:15.840]M3 Macs. And so very recent Macs even still use this. It turns out that it's just essentially a
[09:21.920]

[09:23.860]re-labeled TPS65986 with a custom, with a custom ROM essentially. Now, I open up my MacBook. I
[09:33.160]

[09:33.160]recreated the work by the TAD12 dev team. I dumped this on an M1 MacBook, and so I got an
[09:37.240]

[09:37.240]up-to-date firmware, started reverse engineering it, and found like the command handling, uh,
[09:42.480]

[09:42.480]built like tooling to talk to it, and so on and so forth. And interestingly, the firmware even
[09:46.900]

[09:46.900]contains like some privileged commands, such as memory, read, write, modify, and so on. It's like
[09:51.860]

[09:51.860]peek and poke. But unfortunately, those are locked on production devices. But if you manage to
[09:56.680]

[09:56.680]change a single bit, you can unlock them. And so, uh, yeah, that's kind of cool. Um, the communi-
[10:04.640]

[10:04.640]the way we communicate from the system on a chip, like from macOS with the ACE, is using a bus
[10:10.260]

[10:10.260]called Apple HPM bus, which stands for Host Port Microcontroller. And we communicate with it by
[10:16.860]

[10:16.860]sending these four-byte commands. They're called 4CC. It's essentially a four-byte integer, but it
[10:22.840]

[10:22.840]happens to be ASCII. And so they're like commands such as, you know, GAID, or, you know, reset,
[10:28.720]

[10:28.720]and so on and so forth. And we built a small tool called ACE tool to communicate with that. And so
[10:33.320]

[10:33.320]we have the full list of commands online. We have a tool online to try them out. So it makes for
[10:39.520]

[10:39.520]fun. But the reason I'm telling you this is that we can do one very important thing. We can read
[10:45.000]

[10:45.000]the status of the chip. We can determine whether it's in application mode or whether it's in boot
[10:49.680]

[10:49.680]mode. And we can also determine whether it's in DFU mode and so on. And so if the chip fails to
[10:54.840]

[10:54.840]boot, we can measure it. If the chip successfully boots, we can also measure this. This will become
[10:59.600]

[10:59.600]important later. So yeah. The ACE2 also has an external flash connected. And this spy flash
[11:06.840]

[11:06.840]does not actually contain the full firmware, but it actually just contains patches for the ROM.
[11:13.340]

[11:13.340]And so essentially you can patch every single function in the ROM using this flash. This makes
[11:19.740]

[11:19.740]reverse engineering terribly annoying. Because when you start reversing the firmware, you have
[11:23.740]

[11:23.740]like a function call. That function call goes to another Segway function, which does like stupid
[11:28.800]

[11:28.800]stuff with the registers. Then it dereferences a pointer list, which will be loaded from the flash.
[11:36.880]

[11:37.800]And then it actually jumps to the function. And so everything has like three layers of
[11:41.900]

[11:41.900]indirection, which breaks all your tooling for cross-referencing and so on and so forth. And so
[11:46.960]

[11:46.960]we built some scripts to make this easier. Um, but there are thousands of these functions and
[11:51.220]

[11:51.220]so it's terribly annoying to reverse without additional tooling. But, because it has an
[11:56.820]

[11:56.820]external flash, this chip is getting updates. And so on macOS, there's a tool called USB-C
[12:02.340]

[12:02.340]firmware flasher. And with this, it gets regular updates and so on. And these updates are
[12:07.880]

[12:07.880]unfortunately protected using RSA 3072. But that signature is only checked during updates. So
[12:15.620]

[12:15.620]there's no secure boot on the chip whatsoever. So if you find code execution and can modify the
[12:21.800]

[12:21.800]external flash contents, you get persistence for free. Like you have, you don't have to do anything.
[12:26.300]

[12:27.020]And so I found a vulnerability in the ACE2. Uh, as you do. Well, it's not actually, you will see.
[12:33.960]

[12:33.960]It's complicated. Um, and I got told it would be fixed in fall. So in the submission report, I can
[12:40.920]

[12:40.920]see fall 2024. However, uh, after I said that at Black Hat, uh, I got told by Apple, oh yeah,
[12:48.360]

[12:48.360]that's a mistake. We are not going to fix it. And so I learned two days ago that I can actually
[12:54.920]

[12:54.920]drop a vulnerability here. So, uh, I'm doing. Thank you. So, uh, so I spent the last two hours
[13:05.480]

[13:05.480]writing slides. So this is going to be a bit of PowerPoint karaoke. Um, but essentially it turns
[13:11.080]

[13:11.080]out that not only does the ACE have SWD to the system on a chip, but the system on a chip also
[13:17.460]

[13:17.460]has SWD to the ACE2. And so the SOC can debug the ACE2. And the way this works is that there are
[13:26.260]

[13:26.260]the two lines that you need for SWD. SWDIO and SWDCLK are general purpose IOs on the, on the SOC.
[13:34.940]

[13:34.980]And GPIO on Apple SOC is basically just a memory range. And if you write to it, you can fiddle
[13:41.500]

[13:41.500]with the IOs. You can put them into read mode, output mode, high, low, and so on and so forth.
[13:46.760]

[13:46.760]And thanks to the Asahi Linux team, we know how to talk to them. And thanks to Sigusa's, Sigusa's
[13:52.420]

[13:52.420]IO kernel read write module, we can actually do writes to those pages using a kernel module,
[13:57.880]

[13:57.880]which requires disabling SIP and so on. And so we can control the pins that talk to the debug port
[14:05.120]

[14:05.120]of the ACE through the kernel. And so let's bitbang SWD through the macOS kernel. Cause, you know,
[14:14.720]

[14:14.720]I don't have enough stuff to debug or something. I don't know. Anyway. And so basically we have our
[14:20.560]

[14:20.560]user space application. That user space application talks to the IO kernel read write module that I
[14:27.020]

[14:27.020]loaded into the macOS kernel, which talks to the memory mapped IO peripherals, which toggles the
[14:32.900]

[14:32.900]physical pins, which then talk to the ACE2. And I implemented a debug probe over this that lets us
[14:40.140]

[14:40.140]dump and modify the ACE2 from user space and looks like this. So you can just essentially call
[14:49.020]

[14:49.020]dot slash ACE2 dump. Assuming you have this kernel module loaded, it will dump the firmware of the
[14:53.340]

[14:53.340]ACE2. Now the problem with this is I wanted to, you know, build some payloads and I want to debug
[14:59.580]

[14:59.580]those payloads and I don't always want to have my MacBook open to debug the payload. And so I want
[15:05.980]

[15:05.980]to debug. So I ported this entire thing into OpenOCD. And so introducing Tamarin Kernel, which
[15:14.380]

[15:14.380]is essentially an OpenOCD driver that bitbanks SWD on Apple SOCs through the IO kernel read write
[15:21.440]

[15:21.440]module. And so you can actually debug more than just the, than just the ACE2. There are other
[15:27.680]

[15:27.680]peripherals that have debug enabled. Thank you. And, and also I found a way to disable the
[15:34.880]

[15:34.880]signature verification because it's, you know, patchable from external. Uh, I can just, if I get
[15:39.680]

[15:39.680]code execution, it turns out that remember how all functions are patched, patchable. Also the
[15:45.800]

[15:45.800]signature verification functions are patchable. And so you can just disable them from the external
[15:50.180]

[15:50.180]flash. And afterwards, afterwards you can actually just load your own firmware through user space
[15:55.340]

[15:55.340]and all modifications survive a full system restore. So even if you wipe your Mac, the ACE2
[16:00.820]

[16:00.820]will still be compromised. And so we can back to the ACE2. Yeah. And I'm gonna like all these
[16:06.300]

[16:06.300]things I have to release like today, as I learned, I can release this two days ago. So I don't have
[16:11.120]

[16:11.120]this packaged nicely. And there's still a lot of swear words in the code, let's say. So I'll fix
[16:16.880]

[16:16.880]that and publish it on GitHub. Um, but we had the ACE2, um, which is on the way out. It's an old
[16:23.800]

[16:23.800]chip. It doesn't do a whole lot. Uh, the iPhone 15 pro uses the successor, which is far cooler.
[16:29.840]

[16:30.480]And so we have checked the ACE3. Um, the ACE3 is actually a Texas Instruments SN25A12.
[16:37.740]

[16:37.740]And when I started this, there was zero public information on this, literally zero. In fact,
[16:42.740]

[16:42.740]I started tweeting about the chip. And afterwards I got emails from like the gray market salespeople
[16:48.120]

[16:48.120]who sell like the stolen chips online. And they were like, Hey, can we pay you to write a product
[16:52.400]

[16:52.400]description for this chip? Because we can't find anyone else who ever talked about it. And so the
[16:58.340]

[16:58.340]ACE3 is used in the iPhone 15 and on the MacBook pro M3 with pro and max processors. And the ACE3
[17:05.560]

[17:05.560]is far more complex than the ACE2. It runs a full USB stack called port DFU. It has access to some
[17:12.140]

[17:12.140]more internal buses. It has very interesting potential because it's so, it, because it can
[17:17.100]

[17:17.100]run full USB. If we managed to, you know, find another checkmate style boot ROM issue, we could
[17:23.200]

[17:23.200]in theory, uh, get persistence for a jailbreak by just putting it in the ACE3 instead of having to
[17:29.000]

[17:29.000]gain persistence in the SOC itself. I haven't done any of that. It's just some of the motivation
[17:34.600]

[17:34.600]that drove me to hack this chip. Um, so I started looking at how is this chip protected? Like what's
[17:41.880]

[17:41.880]different? And it turns out that everything has changed. It doesn't use the USB-C from a flasher
[17:46.840]

[17:46.840]anymore. It uses different upgrade mechanisms between the iPhone 15 and the MacBook.
[17:51.740]

[17:51.740]In fact, I believe on the iPhone 15, it actually uses SWD to update the chip, which is kind of
[17:57.460]

[17:57.460]cool. And the updates are fully personalized. So each chip will get their own firmware.
[18:02.820]

[18:03.400]But you know, I still had this vulnerability that I think, you know, I can theoretically,
[18:07.440]

[18:07.440]I now can debug the ACE3. So I wanted to try it on the ACE3. So I ordered a MacBook M3
[18:12.460]

[18:13.140]and the trick didn't work. So easy select, uh, easy choice, send it back or, you know, I'm a
[18:22.500]

[18:22.500]hardware hacker, open it up. So, uh, I open up the MacBook and remember I had to do this quickly
[18:29.920]

[18:29.920]because the Amazon return window for this machine was just 30 days. And the first thing you will
[18:37.300]

[18:37.300]notice is that there are again, the same debug ports that we already saw on the previous MacBooks
[18:43.860]

[18:43.860]and on the previous MacBooks, we could dump the chip this way. And so just for labeling,
[18:49.300]

[18:49.300]this is the ACE3. It's much bigger than the ACE2 and there's no Texas Instruments chip that looks
[18:54.520]

[18:54.520]similar to this one. And so we really have zero idea what this chip does. There's again,
[18:59.620]

[18:59.620]an external spy flash and these nice debug connectors. Now I started probing these and
[19:05.980]

[19:05.980]in combination with the, uh, kernel, uh, with the Tamarink kernel, I can, I could essentially
[19:11.320]

[19:11.320]see that yes, I'm talking SWD on the right lines, but it seems like the debug port is disabled. So
[19:19.760]

[19:19.760]no, no luck. So instead I decided to dump the external flash. So again, like I couldn't solder
[19:26.020]

[19:26.020]in this because again, Amazon return window. So I use these needle probes to just like probe the
[19:30.480]

[19:30.480]flash lines. And eventually I got a full firmware dump. Reversing time. Turns out it's essentially
[19:38.300]

[19:38.300]the same. Only patches get loaded from the external flash and, um, everything seems to be
[19:43.980]

[19:43.980]different on the hardware side. So for example, the CRC peripheral is a different, at a different
[19:48.320]

[19:48.320]address as far as I can tell. Um, it's just patches and there are some weird regions with
[19:53.460]

[19:53.460]high entropy, which is always a bad sign because that means that there's some cryptography very
[19:57.520]

[19:57.520]likely going on. And, uh, yeah, that will spoil our day if they implemented secret boot. However,
[20:04.360]

[20:04.360]some successful things was that I was able to reverse engineer the firmware header. And so I
[20:08.940]

[20:08.940]found a couple of CRCs and so on. And my naive hope was, okay, I just, you know, patch the firmware,
[20:15.220]

[20:15.220]fix the CRCs and surely this chip will boot. And so let's flip a bit in a $3,000 MacBook.
[20:21.280]

[20:23.040]Unfortunately, uh, I couldn't get it to boot a modified firmware, but at least I didn't fully
[20:28.780]

[20:28.780]brick it. So in the end what I tried, I tried my software vulnerability, I tried physical SWD
[20:34.820]

[20:34.820]access, I tried modifying and switching the flash contents, even like between the different ACE
[20:40.040]

[20:40.040]chips, but they all seem to have a unique signature. Like even you can't take the, the left ACE and
[20:45.540]

[20:45.540]put it on the right ACE and so on and so forth. I tried fuzzing and I actually found a timing
[20:50.900]

[20:50.900]side channel that lets me enumerate the commands that the ACE 3, um, supports, but that doesn't
[20:56.420]

[20:56.420]really give me anything. So yeah, essentially we have a completely undocumented, not documented,
[21:03.240]

[21:03.240]apologies, chip. We have no firmware and only some simple commands. Time to give up or do we
[21:11.540]

[21:11.540]try fault injection? Um, so fault injection is an awesome technique because essentially we can
[21:18.360]

[21:18.360]introduce faults into a chip, which allows us to modify the behavior of the running software.
[21:23.640]

[21:23.860]So for example, we might be able to flip, flip bits and registers and memory. We might be able
[21:28.500]

[21:28.500]to skip instructions and so on. And there are a lot of different techniques for this. There's
[21:32.480]

[21:32.480]voltage glitching, laser, BBI, electromagnetic and so on. Uh, they all have one thing in common,
[21:38.440]

[21:38.440]which is that they very easily break chips. Um, the most common way to do glitching is using
[21:44.660]

[21:44.660]voltage fault injection. And there you essentially drop the power to the chip for a very short
[21:50.360]

[21:50.360]amount of time at just the right point in time. And the problem is this pretty much requires
[21:56.360]

[21:56.360]soldering and removal of a ton of capacitors and so on. And it's best performed if you, if you like,
[22:01.740]

[22:01.740]know what's going on. Like we don't even know the pinout. We don't know what is the core voltage,
[22:05.240]

[22:05.240]what is the main voltage rail. We don't know what other chips are on there and so on and so forth.
[22:10.120]

[22:11.080]But there's an alternative called EMFI, electromagnetic fault injection. The idea is we
[22:17.560]

[22:17.560]create a high voltage pulse into a coil and this lets us inject current directly into precise
[22:23.460]

[22:23.720]locations in the chip. And this again can let us skip instructions, change register values and so
[22:29.500]

[22:29.500]on. And we don't really need target preparation for this. It's just we point our chip shouter at
[22:36.520]

[22:36.520]the chip, we zap it and the chip is hacked. Wonderful in theory. The problem is we need to
[22:45.060]

[22:45.060]know the very precise timing on when we need to glitch because otherwise, you know, we're just
[22:50.500]

[22:50.500]gonna glitch something else. How do we figure out the timing on something that we know nothing
[22:56.440]

[22:56.440]about, right? We just know it doesn't boot, period. Brute force, I thought about it, but it,
[23:03.380]

[23:03.380]the boot is so slow that it would take forever to try. And the more we try to glitch at the
[23:09.240]

[23:09.240]wrong point in time, the more likely we are to break the chip. So we really want to get this
[23:14.140]

[23:14.140]right. But another idea, which are what if we find a side channel? What if we find a side channel to
[23:23.540]

[23:23.540]get this precise timing on when to inject our glitch? Normally, now I decided to use an EM
[23:30.980]

[23:30.980]side channel. So I use an EM probe to measure the chip. And normally you would use a very high
[23:36.860]

[23:36.860]end oscilloscope for this, but I wanted to use a cheap, affordable hacker to make this more
[23:41.560]

[23:41.560]accessible. And I just glued a random coil onto a PC by probe and just dropped it onto the chip.
[23:48.280]

[23:48.280]So this is just held with gravity. And this way we can capture the magic chip waves. And we can
[23:54.060]

[23:54.060]actually see this as we restart the chip, we can actually see that there's activity on the spectrum
[24:00.220]

[24:00.220]at around 48 megahertz. Now this activity could be anything, right? Like this could be the power
[24:05.960]

[24:05.960]rail, this could just be the spy flash line or so, but it's something. And so the idea is simple. We
[24:12.880]

[24:12.880]start recording the spectrum on the hack RF, we reboot the ACE3 using the ACL I showed earlier,
[24:18.760]

[24:18.760]we get the electromagnetic recording, and then we just do some very simple DSP,
[24:24.760]

[24:25.680]which just took the better half of a week to generate, you know, a ton of different measurements
[24:31.920]

[24:31.920]and so on and so forth, filtering this and that. But eventually I had a line that I thought, okay,
[24:36.700]

[24:36.700]this looks like it might tell us something about the chip. And this is completely gut feeling,
[24:41.100]

[24:41.100]like I didn't do any science here, I just tried to play with filters and eventually I got this line.
[24:46.560]

[24:47.720]Now the problem with this recording is that you want to collect a lot of
[24:52.300]

[24:52.300]traces and average them together. The problem is they will all be at different offsets in time
[24:58.540]

[24:58.540]because we don't have a precise way on how to start the recording. And so we could align these
[25:04.380]

[25:04.380]in software. However, the hack RF actually has a nice feature, which is it has hardware trigger
[25:10.240]

[25:10.240]inputs. And so we can actually trigger the recording using a hardware signal. This doesn't
[25:15.720]

[25:15.720]work in the latest hack RF firmware. So it was again like hours of trying different firmwares
[25:20.060]

[25:20.060]until one would actually trigger correctly. And now we just need a trigger. Now remember that we
[25:26.580]

[25:26.580]have access to the flash lines. And the flash lines have a line called chip select. And the
[25:32.760]

[25:32.760]chip select line will go low just as our firmware is being loaded. And so this is perfect to offset
[25:40.780]

[25:41.000]a glitch from if we want to bypass secure boot of what just got loaded from flash.
[25:45.080]

[25:45.780]So, easy plan. We start recording on the chip, on the hack RF. We reboot the ACE3. The hack RF gets
[25:54.260]

[25:54.260]triggered by the chip select line. And we get a perfectly aligned recording. And in theory if you,
[26:00.220]

[26:00.220]you know, it should look like this if you take pictures for presentation. In reality your desk
[26:05.480]

[26:05.480]will look like this and it will just be a gigantic mess. So in the end we have perfectly aligned
[26:12.380]

[26:12.380]recordings and we can actually average them together to get a nice meaningful signal where
[26:17.780]

[26:17.780]if anything else put in noise we can just filter it away essentially. But, you know, now we just
[26:23.940]

[26:23.940]have a fancy line. How do we actually use this to time our glitch? Well, we can change the flash
[26:30.880]

[26:30.880]contents to be invalid so that the boot fails. We reboot the ACE3 and record the EM emissions.
[26:37.720]

[26:37.720]And then we compare the differences. Sounds easy but in reality this takes hours because you have
[26:43.680]

[26:43.680]to set up these needle probes which takes like, you know, 20 minutes. You try to flash the chip
[26:48.960]

[26:48.960]until it works. Then you do the capture and measure and so on. And then you do this again and again and
[26:55.700]

[26:55.700]again to get everything right. And in the end you end up with a trace that might look like this where
[27:00.920]

[27:00.920]you have the original firmware and the modified firmware. And we can see that this trace looks
[27:06.820]

[27:06.820]super different, right? Like there's a clear point in time where they start to differ.
[27:11.040]

[27:11.820]What's even better is we can test our hypothesis by modifying the CRCs. So remember that we have
[27:18.800]

[27:18.800]these three CRCs and so in theory if we fix just some of them we should see a delay in our boot,
[27:26.260]

[27:26.260]in our EM trace. Like we should see that our trace changes at a later point in time.
[27:31.780]

[27:32.460]So I tried this. So I have the original firmware. Then I set one of three CRCs to be correct.
[27:39.200]

[27:39.780]And you can see we have exactly the same signal as before. Then I tried two of three
[27:45.380]

[27:45.380]CRCs to be correct and no change. So I was worried that this might not actually work.
[27:51.080]

[27:51.080]But then when I set the third CRC to be correct we can see that the boot actually goes much further
[27:56.860]

[27:56.860]and that the boot fails at a much later point in time. And so why not just glitch here, right?
[28:05.420]

[28:05.420]So simple enough. We now have some timing. Now we just need to position our chip shoulder. Because
[28:11.320]

[28:11.320]normally for EMFI it's very important where you are glitching. And so if you were doing this
[28:18.760]

[28:18.760]professionally to give a talk at big security conferences you would use a big XY table to scan
[28:24.640]

[28:24.640]the chip. Unfortunately, like literally the week before I did this I had a small accident with my
[28:30.200]

[28:30.200]CNC and I got 230 volts onto the ground line and completely bricked my computer, my screen and my
[28:36.540]

[28:36.540]CNC controller. That was fun. And so I couldn't do this. But I really wanted to try this attack.
[28:44.100]

[28:44.120]So I just did the dumbest thing you probably could have done which is I chose the biggest
[28:49.160]

[28:49.160]tip I had. I just placed it on the chip. So that way I was sure that I was at least hitting
[28:57.400]

[28:57.400]something in there. And so I had this nice setup with the chip shoulder. Then the triggering was
[29:05.660]

[29:05.660]done by a chip whisperer Husky. The trigger connection is just the chip select line using
[29:11.620]

[29:11.840]a PC byte and a connection to ground. What's not shown is the days of debugging this took.
[29:17.920]

[29:17.920]Again, this is a photo op. Reality looked like this. As soon as you bump the table everything
[29:23.760]

[29:23.760]would just drop off. So yeah. So we are ready to glitch essentially. So my first attempt was
[29:32.500]

[29:32.500]I would just change the version string. So from Mac OS I can read out the version of the firmware
[29:37.900]

[29:37.900]that is running on the Ace. And so on my MacBook this was 2.45. So I decided in the flash I would
[29:47.600]

[29:47.600]just change that single byte. Then I fixed all the other CRCs around it. And then I armed the
[29:55.440]

[29:55.440]Husky and the chip shoulder. I reboot the Ace 3 via Ace tool. I wait for the glitch. And then
[30:02.320]

[30:02.820]remember earlier I told you that we can check what the status of the chip is? I just checked
[30:08.120]

[30:08.120]whether it successfully booted. And this worked wonderfully, right? So I just, I can just try
[30:14.200]

[30:14.200]again and again and again. And in theory we should eventually get successful. And so I
[30:19.460]

[30:19.460]built this tiny Jupyter notebook to do all of this. Um, and started it. And you can see we
[30:26.780]

[30:26.780]got like 1.6 attempts per second. So each reboot takes like 1.6 seconds. That's when the trouble
[30:34.760]

[30:34.760]started. The problem is sometimes the Ace completely starts, stops responding and I can't get
[30:40.080]

[30:40.080]it to boot again. I don't get any output. So I need to reboot the machine. The problem is if I
[30:46.320]

[30:46.320]reboot the machine while the charging controller doesn't have a firmware, the MacBook will stop
[30:51.960]

[30:51.960]charging. And essentially I have eight hours of trying to glitch the chip and then the battery
[30:58.340]

[30:58.340]runs out. Then I have to restore the flash which takes hours again with the probes. Restore the
[31:03.460]

[31:03.460]firmware, charge it up and then do the whole thing opposite again. Um, so I did that for a couple of
[31:10.400]

[31:10.400]days. And cause I, like it was like sunken cost fallacy. I started, then I thought like, hey, maybe
[31:17.460]

[31:17.460]I should build a battery emulator and just like feed it externally. But I thought, ah no, I'm so
[31:22.780]

[31:22.780]close. I'm sure it will happen any minute now. So, yeah. So I kept doing this but eventually I got
[31:28.680]

[31:28.680]success. I managed to get into the app mode on the uh Ace 3. And by checking. Thank you. And by
[31:42.860]

[31:42.860]checking, by checking the version number, I can actually see I was successful. I changed it to
[31:47.560]

[31:47.560]version 42 and we glitched the Ace 3. But the problem is we only changed the external patches.
[31:56.940]

[31:56.940]And we don't actually know what these patches patch because we don't know the actual ROM. And so
[32:01.380]

[32:01.380]essentially we have this flash which is full of random functions. But we don't ever know what
[32:06.940]

[32:06.940]they do. Like we don't know how can I trigger them? Will they actually be executed? And then even if
[32:13.180]

[32:13.180]you manage to execute them, we don't have any input or output. Like we don't even have a driver
[32:17.400]

[32:17.400]to wiggle a pin or something. So I was like considering, oh can I do maybe some, some looping
[32:22.260]

[32:22.260]that I can measure via EM or so. Um but yeah, essentially we can replace functions. We don't
[32:27.760]

[32:27.760]know what they do. And even if we execute them, even if we 100% know we get them to execute, we
[32:34.480]

[32:34.480]have no way to get data out. However, I started looking around a lot through the Ace 3 flash and
[32:41.080]

[32:41.080]you can see that there are a lot of 4CC strings here again. Like this, UFPF, DFUF, uh USBW and
[32:47.920]

[32:47.920]this one and so forth. And I thought probably there's some similarities between the Ace 3
[32:53.820]

[32:53.820]firmware and the Ace 2 firmware. And maybe I get lucky and they patched a function in both chips,
[32:58.580]

[32:58.580]the old one and the new one. And so after hours of staring in Binary Ninja, I found a function
[33:04.460]

[33:04.460]that is actually almost identical between the two. And this is the USBW command handler. And USBW
[33:12.640]

[33:12.640]command handler, I have no idea what that does. But it's a command that I can send through the
[33:18.320]

[33:18.320]Ace that will get executed. And remember, and so I can replace it. And remember how earlier I saw
[33:25.260]

[33:25.260]the memory function? I essentially took that implementation from the Ace 2, modified it,
[33:31.340]

[33:31.340]simplified it slightly and then had a function that was by Apple built to give me memory. And
[33:37.120]

[33:37.120]essentially Apple built my exploit payload. So I'm very thankful for that. And so in the end,
[33:44.280]

[33:44.280]I essentially had a very simple payload that is a trivial memory reader that takes in an address
[33:49.120]

[33:49.120]and returns 4 bytes at that address. So again, attempt 2, we replace the USBW command handler
[33:56.280]

[33:57.220]and we start glitching. And we again, you know, wait for the battery to run out,
[34:01.980]

[34:01.980]start over and so on and so forth. The glitch was not very stable at this point in time.
[34:06.300]

[34:06.300]And so, but eventually, I got a success and so I decided I will just send the USBW command with
[34:16.040]

[34:16.040]the address 0 0 0 0. And I got this back. 0 0 0 6 2 0. And you know, this is a little endian
[34:25.100]

[34:25.100]machine so you reverse it and if you do a lot of arm reversing you will immediately spot why
[34:29.920]

[34:29.920]this indicates success. This is the stack pointer reset value. We just read address 0 of the
[34:36.180]

[34:36.180]memory of the chip. And so we can read and also write arbitrary memory on the ACE3. So,
[34:44.120]

[34:49.340]time to dump. Um, and again, like I, my payload was not the greatest and so I could dump 4 bytes
[34:56.100]

[34:56.100]at a time. And so, it took hours and the battery ran out and I had to reflash, restore,
[35:06.160]

[35:06.180]recharge, glitch again, and then dump it again. But eventually, I had the full firmware. A full
[35:13.560]

[35:13.560]dump of the ACE3, ROM and RAM, and so on and so forth. So, awesome. We can actually start
[35:19.300]

[35:19.300]reverse engineering this chip. And the main thing that I learned during this is dumping
[35:25.220]

[35:25.220]unknown silicon is actually possible. Like, I knew almost nothing about this chip, right? And it's
[35:30.340]

[35:30.340]not super difficult, it just takes a lot of persistence and, you know, dealing with annoyances.
[35:35.860]

[35:35.860]And we can actually get code execution without having firmware, even on a microcontroller.
[35:41.340]

[35:41.340]And I thought that was really cool. And now we can actually start researching the ACE3.
[35:46.300]

[35:47.060]Now, the equipment I used with like the chip shoulder, husky, and so on, this is all very
[35:52.160]

[35:52.160]expensive, right? Like, the toll is probably like 8k or something. And, you know, so let's make it
[35:58.180]

[35:58.180]cheaper. So, I imported the entire attack onto the PicoMP, which is like a super low cost, uh,
[36:04.140]

[36:04.140]electromagnetic fault injection tool. And I put a firmware on the chip shoulder that does all the
[36:10.780]

[36:10.780]triggering on the chip select line and so on and so forth automatically. And so you can now attack
[36:15.740]

[36:15.740]the ACE3 and dump it for $60, which I think is pretty fair. And so, yeah. With that said,
[36:27.140]

[36:27.140]that's all I have for you today. I think we have a bit of time for Q&A, but thank you. And also,
[36:32.860]

[36:32.860]if you're interested in actually trying some fault injection, we are running a glitching lab over at
[36:37.060]

[36:37.060]the Embedded Systems Village. And so come by and you can actually bypass some protections on chips
[36:41.980]

[36:42.540]by zapping them or fiddling with the voltage rails and so on. So, yeah. Thank you.
[36:47.260]

