WEBVTT

00:00.000 --> 00:06.200
Hey everyone, welcome to my talk, Ace of the Sleeve, hacking into Apple's new USB-C controller.

00:06.540 --> 00:07.820
First off, who am I?

00:07.820 --> 00:10.320
My name is Thomas Roth, aka Stacksmashing.

00:10.320 --> 00:17.240
I'm a security researcher for hardware and firmware, and I'm also a co-founder at this online training platform called Hackstreet.io.

00:17.240 --> 00:20.400
You can find me on Twitter, YouTube, and so on.

00:21.400 --> 00:25.880
Now, as always, like any research, it's built on top of other people's work, right?

00:25.880 --> 00:44.460
And so I want to thank, for example, Sigusa, who built a kernel module we will use, Oli for the Thunderbolt patcher, the Azahi Linux team, without whose reverse engineering work I couldn't do anything, Carlo Maragni, who just always was there when I talked and had to rant about fault injection,

00:44.460 --> 00:53.380
Biska, Fabian, and Caro, Mark Zingier for the central scrutinizer, and also the TAD12 dev team, who did some awesome work.

00:53.920 --> 00:55.360
Now, a bit on the backstory.

00:55.640 --> 01:04.640
Apple used to have this proprietary connector called Lightning, and it could do, you know, fairly obvious things such as charging, USB, video, and audio.

01:05.320 --> 01:10.720
But it could also do some really cool stuff, for example, JTAG, UART, SDQ, and so on.

01:10.720 --> 01:21.920
And you could buy cables for this on the black market, and there was also the Bonobo cable, but we decided we want to build an open source version of this, and we called it the Tamarink cable.

01:21.980 --> 01:30.720
And the Tamarink cable is essentially a $20 Lightning debugging interface that we introduced two years ago at DEF CON, so it's good to be back.

01:30.800 --> 01:38.500
However, Apple decided to throw all of my work away by switching from Lightning to, you know, this thing here.

01:44.140 --> 01:49.480
There was supposed to be audio here, but she's talking that we can do charging, data, audio, and video.

01:49.480 --> 01:54.320
But I think they made a mistake during the keynote because they forgot, you know, all the cool stuff.

01:54.320 --> 01:55.420
Like, who cares about charging?

01:55.420 --> 01:57.080
I want JTAG on the iPhone.

01:57.840 --> 02:10.400
And, you know, if you look at the USB-C connector, it has a ton of pins, and so surely we can somehow get some of these to speak JTAG, UART, or, you know, anything interesting, not just charging.

02:10.860 --> 02:16.280
And then I realized that the iPhone is not the first USB-C device that, you know, Apple made.

02:16.280 --> 02:20.200
And I never looked at any of these, but luckily for me, other people did.

02:20.260 --> 02:28.160
And they figured out that Apple, uh, essentially uses the USB power delivery negotiation to do some cool stuff.

02:28.160 --> 02:35.180
And it turns out that this power delivery negotiation is happening in something called the USB-C port controller.

02:35.180 --> 02:41.660
It's essentially a tiny microcontroller in the, in the MacBook, and that one handles all of this.

02:41.740 --> 02:47.840
And essentially, the charger communicates with it through these two lines, the configuration lines.

02:48.500 --> 02:53.200
And this is all handled by a microcontroller that sits close to the USB-C ports.

02:53.380 --> 02:56.440
And, you know, a microcontroller will have some kind of firmware.

02:56.440 --> 03:00.900
And some smart people years ago figured out, you can just dump that firmware.

03:00.900 --> 03:10.440
So you solder a couple of wires into your very expensive MacBook, dump the firmware, and then they wrote an awesome blog post because they reverse engineered the firmware.

03:10.440 --> 03:18.920
And they figured out that the Apple Type-C port controller, which we call Ace, actually contains a lot of secret functionality.

03:19.220 --> 03:28.620
And they found that Apple uses something called VDM, or Vendor Defined Messages, to let us change the configuration of certain pins on the USB-C connector.

03:28.800 --> 03:35.560
And so, for example, we can change the SBU, the Sideband Use Pins, to be serial.

03:35.560 --> 03:44.860
And so we can, you know, send the VDM action 306 to the Ace controller, and then we get a serial console on the MacBook.

03:45.580 --> 03:49.680
And it turns out that to this Ace, there's much more connected than just serial.

03:49.680 --> 03:55.920
You can also do JTAG, Thunderbolt, even I2C, or on the iPhone there's SPMI and so on.

03:56.460 --> 03:58.600
And so that's kind of cool.

03:58.600 --> 04:01.680
But how can we actually send these Vendor Defined Messages?

04:01.680 --> 04:04.240
Because this is not just like regular USB.

04:04.560 --> 04:09.660
Instead, we actually have to use special tooling to be able to send these messages.

04:10.280 --> 04:23.040
And again, some very smart people from the Asahi Linux tool, uh, Linux team found out that the back left port on the MacBook Pro is special, and can actually send those commands, and they reverse-engineered all of that stuff.

04:23.040 --> 04:28.040
And so there's a nice tool that you can just use to send these commands from a Mac to another Mac.

04:28.500 --> 04:41.460
Also, Marc Zenier built this thing called the Central Scrutinizer, which is essentially a serial adapter that is able to send all of these things and can give you, you know, a UART shell on a MacBook, and so on and so forth.

04:42.140 --> 04:54.780
Now, I saw this, it's Pico-based, I love the Pico, and so I ordered a couple of PCBs and started experimenting with this, um, and essentially all it contains is a small USB-C controller and a couple of level shifters.

04:54.960 --> 05:06.020
Now, I wanted to try to get serial on the iPhone 15 that was freshly released, because everyone was harassing me that my stuff doesn't work anymore, so, uh, I had to get with the times.

05:06.500 --> 05:09.920
Now, unfortunately, it didn't work on the iPhone 15 out of the box.

05:09.920 --> 05:15.020
Uh, I had to actually solder on a small USB switch and provide power to the iPhone and so on.

05:15.100 --> 05:23.060
Now, this might just be my incompetence, because this is the first time I ever touched USB-C, and so I just tried random stuff until it happened to work.

05:23.060 --> 05:29.680
And so, if you know USB-C better than me, feel free to tell me what I'm doing right or wrong.

05:29.880 --> 05:43.820
Um, but after doing all of this, I essentially had the central scrutinizer working on the iPhone, and so I can, you know, hit some keys, and suddenly I get the serial console on the, uh, iPhone 15.

05:44.800 --> 05:51.160
That's pretty cool, um, but also pretty useless, because, you know, like, what do we do with serial output?

05:51.160 --> 05:55.000
We want to get JTAG or SPMI or something interesting, right?

05:55.340 --> 06:09.740
And again, the Asahi Linux people did a ton of cool reverse engineering work on all of that USB PD stuff, and they have a gigantic document where they document all the actions and so on and so forth, and if you keep scrolling and scrolling and scrolling,

06:09.740 --> 06:21.040
you will find a small note that says, by the way, there's this action called 0206, and there's a good chance this is SWD, but nobody ever seems to have, like, publicly tried this.

06:21.240 --> 06:29.600
Um, so I took my central scrutinizer, hooked my oscilloscope debugger and so on up to this, and tried to connect to it.

06:30.160 --> 06:31.540
And it didn't work.

06:33.420 --> 06:43.500
But, you know, turns out there are two cables, and so I just reversed them, gave it another try, and suddenly we get a success message.

06:43.500 --> 06:48.820
We found the debug port with the ID 4BA02477.

06:49.500 --> 06:54.060
We just got JTAG on the iPhone 15 by just sending 206.

06:54.060 --> 06:54.840
Awesome.

06:58.520 --> 07:03.980
Unfortunately, this is a production device, and so JTAG is locked.

07:04.180 --> 07:07.900
So essentially, we can't debug it because it's a production device.

07:07.980 --> 07:15.100
On the black market, you can probably find an iPhone that is not locked, but it will run you like 100k or something, so I can't do that.

07:15.960 --> 07:17.700
But we got JTAG.

07:18.220 --> 07:19.560
Useless JTAG.

07:20.680 --> 07:21.500
You know.

07:21.500 --> 07:31.400
But we can still explore some other buses, and so it turns out that on the iPhone 15, there's actually more than just UART and so on on this connector, but also SPMI and other things.

07:31.400 --> 07:47.780
And so in December last year, we released a PCB called the Tamron C adapter, which is essentially a fork of the central scrutinizer with bidirectional level shifters, a USB power switch so it can actually charge the iPhone if you want to let it run for a long time for research.

07:47.780 --> 07:56.340
And we can use it to explore all the buses on the iPhone 15, including SPMI, which I think we released the first public analyzer for.

07:56.340 --> 08:00.240
And it also runs a full JTAG probe, and so you can experiment with this.

08:00.240 --> 08:01.680
It's fully open source.

08:02.160 --> 08:04.520
And if you use it, it looks like this.

08:04.660 --> 08:07.860
Now, this is cool, but again, also kind of useless.

08:07.860 --> 08:16.240
However, what's interesting is that all this stuff is implemented on the iPhone side in this chip called the ACE3.

08:16.460 --> 08:20.960
And the ACE3 essentially sits between the USB port and the system on a chip.

08:21.280 --> 08:30.940
And it makes for a very interesting target, because on the iPhone 15, the ACE3 can actually run a full USB port, like it can come up as a USB device.

08:30.940 --> 08:37.080
If you go into recovery and plug your iPhone in, you're actually communicating with the ACE3.

08:37.120 --> 08:47.100
And that makes it an interesting target, because imagine if you compromise this part of the device, you could do attacks on the system on a chip without any way for anyone to know.

08:47.100 --> 08:49.260
Like there would be essentially zero traces.

08:50.520 --> 08:52.780
So I was interested in this.

08:52.900 --> 08:59.820
But I wanted to first understand the predecessor, the ACE2, because there's a lot of public work on the ACE2 already.

08:59.820 --> 09:06.700
And the ACE2 is essentially a Texas Instruments, a custom Texas Instruments USB-C controller.

09:06.780 --> 09:08.580
It's an ARM chip.

09:08.580 --> 09:11.020
It's connected to the SOC via I2C.

09:11.020 --> 09:16.840
And you can find it on all MacBooks, starting with the T2 Macs, up to the M3 Macs.

09:16.840 --> 09:19.600
And so very recent Macs even still use this.

09:19.720 --> 09:28.380
It turns out that it's just essentially a re -labeled TPS65986 with a custom, with a custom ROM essentially.

09:28.800 --> 09:32.040
Now, I open up my MacBook.

09:32.040 --> 09:35.080
I recreated the work by the TAD12 dev team.

09:35.080 --> 09:44.920
I dumped this on an M1 MacBook, and so I got an up-to-date firmware, started reverse engineering it, and found like the command handling, uh, built like tooling to talk to it, and so on and so forth.

09:44.920 --> 09:51.480
And interestingly, the firmware even contains like some privileged commands, such as memory, read, write, modify, and so on.

09:51.480 --> 09:52.780
It's like peek and poke.

09:52.780 --> 09:55.780
But unfortunately, those are locked on production devices.

09:55.780 --> 09:59.160
But if you manage to change a single bit, you can unlock them.

09:59.160 --> 10:02.020
And so, uh, yeah, that's kind of cool.

10:03.100 --> 10:14.400
Um, the communi- the way we communicate from the system on a chip, like from macOS with the ACE, is using a bus called Apple HPM bus, which stands for Host Port Microcontroller.

10:14.760 --> 10:18.920
And we communicate with it by sending these four-byte commands.

10:18.920 --> 10:20.160
They're called 4CC.

10:20.160 --> 10:24.120
It's essentially a four-byte integer, but it happens to be ASCII.

10:24.120 --> 10:29.940
And so they're like commands such as, you know, GAID, or, you know, reset, and so on and so forth.

10:29.940 --> 10:33.120
And we built a small tool called ACE tool to communicate with that.

10:33.120 --> 10:36.040
And so we have the full list of commands online.

10:36.040 --> 10:38.440
We have a tool online to try them out.

10:38.480 --> 10:40.020
So it makes for fun.

10:40.020 --> 10:44.040
But the reason I'm telling you this is that we can do one very important thing.

10:44.080 --> 10:46.320
We can read the status of the chip.

10:46.320 --> 10:50.220
We can determine whether it's in application mode or whether it's in boot mode.

10:50.220 --> 10:53.380
And we can also determine whether it's in DFU mode and so on.

10:53.380 --> 10:56.080
And so if the chip fails to boot, we can measure it.

10:56.080 --> 10:59.000
If the chip successfully boots, we can also measure this.

10:59.000 --> 11:00.700
This will become important later.

11:00.700 --> 11:01.680
So yeah.

11:02.620 --> 11:05.820
The ACE2 also has an external flash connected.

11:05.820 --> 11:13.340
And this spy flash does not actually contain the full firmware, but it actually just contains patches for the ROM.

11:13.340 --> 11:19.120
And so essentially you can patch every single function in the ROM using this flash.

11:19.300 --> 11:21.700
This makes reverse engineering terribly annoying.

11:21.700 --> 11:25.220
Because when you start reversing the firmware, you have like a function call.

11:25.220 --> 11:30.380
That function call goes to another Segway function, which does like stupid stuff with the registers.

11:30.880 --> 11:36.880
Then it dereferences a pointer list, which will be loaded from the flash.

11:37.800 --> 11:40.080
And then it actually jumps to the function.

11:40.080 --> 11:46.740
And so everything has like three layers of indirection, which breaks all your tooling for cross-referencing and so on and so forth.

11:46.740 --> 11:48.920
And so we built some scripts to make this easier.

11:48.960 --> 11:54.380
Um, but there are thousands of these functions and so it's terribly annoying to reverse without additional tooling.

11:55.540 --> 11:59.380
But, because it has an external flash, this chip is getting updates.

11:59.380 --> 12:03.640
And so on macOS, there's a tool called USB-C firmware flasher.

12:03.640 --> 12:07.000
And with this, it gets regular updates and so on.

12:07.000 --> 12:12.140
And these updates are unfortunately protected using RSA 3072.

12:12.460 --> 12:15.340
But that signature is only checked during updates.

12:15.340 --> 12:18.460
So there's no secure boot on the chip whatsoever.

12:18.740 --> 12:24.380
So if you find code execution and can modify the external flash contents, you get persistence for free.

12:24.380 --> 12:26.300
Like you have, you don't have to do anything.

12:27.020 --> 12:30.980
And so I found a vulnerability in the ACE2.

12:30.980 --> 12:32.020
Uh, as you do.

12:32.020 --> 12:33.960
Well, it's not actually, you will see.

12:33.960 --> 12:35.280
It's complicated.

12:35.420 --> 12:38.420
Um, and I got told it would be fixed in fall.

12:38.420 --> 12:42.460
So in the submission report, I can see fall 2024.

12:43.020 --> 12:49.560
However, uh, after I said that at Black Hat, uh, I got told by Apple, oh yeah, that's a mistake.

12:49.980 --> 12:51.800
We are not going to fix it.

12:51.980 --> 12:56.540
And so I learned two days ago that I can actually drop a vulnerability here.

12:57.040 --> 12:58.780
So, uh, I'm doing.

13:01.840 --> 13:02.920
Thank you.

13:02.920 --> 13:06.360
So, uh, so I spent the last two hours writing slides.

13:06.360 --> 13:08.760
So this is going to be a bit of PowerPoint karaoke.

13:08.760 --> 13:19.660
Um, but essentially it turns out that not only does the ACE have SWD to the system on a chip, but the system on a chip also has SWD to the ACE2.

13:19.900 --> 13:23.440
And so the SOC can debug the ACE2.

13:24.440 --> 13:28.080
And the way this works is that there are the two lines that you need for SWD.

13:28.320 --> 13:34.940
SWDIO and SWDCLK are general purpose IOs on the, on the SOC.

13:34.980 --> 13:39.220
And GPIO on Apple SOC is basically just a memory range.

13:39.220 --> 13:42.300
And if you write to it, you can fiddle with the IOs.

13:42.300 --> 13:46.760
You can put them into read mode, output mode, high, low, and so on and so forth.

13:46.760 --> 13:50.380
And thanks to the Asahi Linux team, we know how to talk to them.

13:50.460 --> 14:01.040
And thanks to Sigusa's, Sigusa's IO kernel read write module, we can actually do writes to those pages using a kernel module, which requires disabling SIP and so on.

14:01.040 --> 14:08.600
And so we can control the pins that talk to the debug port of the ACE through the kernel.

14:08.600 --> 14:13.280
And so let's bitbang SWD through the macOS kernel.

14:13.280 --> 14:17.260
Cause, you know, I don't have enough stuff to debug or something.

14:17.260 --> 14:18.220
I don't know.

14:18.220 --> 14:18.740
Anyway.

14:18.740 --> 14:22.240
And so basically we have our user space application.

14:22.240 --> 14:36.700
That user space application talks to the IO kernel read write module that I loaded into the macOS kernel, which talks to the memory mapped IO peripherals, which toggles the physical pins, which then talk to the ACE2.

14:36.940 --> 14:45.660
And I implemented a debug probe over this that lets us dump and modify the ACE2 from user space and looks like this.

14:45.660 --> 14:50.180
So you can just essentially call dot slash ACE2 dump.

14:50.180 --> 14:54.200
Assuming you have this kernel module loaded, it will dump the firmware of the ACE2.

14:54.480 --> 15:03.920
Now the problem with this is I wanted to, you know, build some payloads and I want to debug those payloads and I don't always want to have my MacBook open to debug the payload.

15:03.960 --> 15:06.980
And so I want to debug.

15:07.120 --> 15:10.180
So I ported this entire thing into OpenOCD.

15:10.400 --> 15:21.940
And so introducing Tamarin Kernel, which is essentially an OpenOCD driver that bitbanks SWD on Apple SOCs through the IO kernel read write module.

15:21.940 --> 15:27.140
And so you can actually debug more than just the, than just the ACE2.

15:27.140 --> 15:30.720
There are other peripherals that have debug enabled.

15:30.720 --> 15:31.480
Thank you.

15:31.720 --> 15:38.640
And, and also I found a way to disable the signature verification because it's, you know, patchable from external.

15:38.640 --> 15:44.680
Uh, I can just, if I get code execution, it turns out that remember how all functions are patched, patchable.

15:45.060 --> 15:48.140
Also the signature verification functions are patchable.

15:48.140 --> 15:50.640
And so you can just disable them from the external flash.

15:50.640 --> 15:58.320
And afterwards, afterwards you can actually just load your own firmware through user space and all modifications survive a full system restore.

15:58.320 --> 16:02.220
So even if you wipe your Mac, the ACE2 will still be compromised.

16:02.480 --> 16:04.520
And so we can back to the ACE2.

16:04.520 --> 16:04.820
Yeah.

16:04.820 --> 16:10.540
And I'm gonna like all these things I have to release like today, as I learned, I can release this two days ago.

16:10.540 --> 16:12.740
So I don't have this packaged nicely.

16:12.740 --> 16:15.460
And there's still a lot of swear words in the code, let's say.

16:15.460 --> 16:18.600
So I'll fix that and publish it on GitHub.

16:19.040 --> 16:23.320
Um, but we had the ACE2, um, which is on the way out.

16:23.320 --> 16:24.140
It's an old chip.

16:24.140 --> 16:25.620
It doesn't do a whole lot.

16:25.620 --> 16:29.840
Uh, the iPhone 15 pro uses the successor, which is far cooler.

16:30.480 --> 16:32.580
And so we have checked the ACE3.

16:32.580 --> 16:37.740
Um, the ACE3 is actually a Texas Instruments SN25A12.

16:37.740 --> 16:42.440
And when I started this, there was zero public information on this, literally zero.

16:42.440 --> 16:44.340
In fact, I started tweeting about the chip.

16:44.420 --> 16:50.240
And afterwards I got emails from like the gray market salespeople who sell like the stolen chips online.

16:50.240 --> 16:53.960
And they were like, Hey, can we pay you to write a product description for this chip?

16:53.960 --> 16:57.360
Because we can't find anyone else who ever talked about it.

16:57.560 --> 17:04.440
And so the ACE3 is used in the iPhone 15 and on the MacBook pro M3 with pro and max processors.

17:04.440 --> 17:08.200
And the ACE3 is far more complex than the ACE2.

17:08.200 --> 17:11.060
It runs a full USB stack called port DFU.

17:11.060 --> 17:13.560
It has access to some more internal buses.

17:13.560 --> 17:18.360
It has very interesting potential because it's so, it, because it can run full USB.

17:18.680 --> 17:31.480
If we managed to, you know, find another checkmate style boot ROM issue, we could in theory, uh, get persistence for a jailbreak by just putting it in the ACE3 instead of having to gain persistence in the SOC itself.

17:31.480 --> 17:33.200
I haven't done any of that.

17:33.200 --> 17:36.480
It's just some of the motivation that drove me to hack this chip.

17:37.600 --> 17:41.500
Um, so I started looking at how is this chip protected?

17:41.500 --> 17:42.340
Like what's different?

17:42.340 --> 17:44.400
And it turns out that everything has changed.

17:44.400 --> 17:47.520
It doesn't use the USB-C from a flasher anymore.

17:47.520 --> 17:51.740
It uses different upgrade mechanisms between the iPhone 15 and the MacBook.

17:51.740 --> 17:58.140
In fact, I believe on the iPhone 15, it actually uses SWD to update the chip, which is kind of cool.

17:58.140 --> 18:00.280
And the updates are fully personalized.

18:00.280 --> 18:02.820
So each chip will get their own firmware.

18:03.400 --> 18:09.180
But you know, I still had this vulnerability that I think, you know, I can theoretically, I now can debug the ACE3.

18:09.180 --> 18:11.060
So I wanted to try it on the ACE3.

18:11.060 --> 18:15.960
So I ordered a MacBook M3 and the trick didn't work.

18:16.860 --> 18:25.060
So easy select, uh, easy choice, send it back or, you know, I'm a hardware hacker, open it up.

18:25.620 --> 18:33.940
So, uh, I open up the MacBook and remember I had to do this quickly because the Amazon return window for this machine was just 30 days.

18:35.680 --> 18:48.100
And the first thing you will notice is that there are again, the same debug ports that we already saw on the previous MacBooks and on the previous MacBooks, we could dump the chip this way.

18:48.180 --> 18:50.300
And so just for labeling, this is the ACE3.

18:50.300 --> 18:55.520
It's much bigger than the ACE2 and there's no Texas Instruments chip that looks similar to this one.

18:55.520 --> 18:59.040
And so we really have zero idea what this chip does.

18:59.040 --> 19:03.260
There's again, an external spy flash and these nice debug connectors.

19:03.620 --> 19:19.460
Now I started probing these and in combination with the, uh, kernel, uh, with the Tamarink kernel, I can, I could essentially see that yes, I'm talking SWD on the right lines, but it seems like the debug port is disabled.

19:19.460 --> 19:21.500
So no, no luck.

19:21.780 --> 19:24.500
So instead I decided to dump the external flash.

19:24.500 --> 19:27.840
So again, like I couldn't solder in this because again, Amazon return window.

19:27.840 --> 19:31.500
So I use these needle probes to just like probe the flash lines.

19:31.780 --> 19:34.820
And eventually I got a full firmware dump.

19:36.000 --> 19:37.100
Reversing time.

19:37.100 --> 19:38.920
Turns out it's essentially the same.

19:38.920 --> 19:45.480
Only patches get loaded from the external flash and, um, everything seems to be different on the hardware side.

19:45.480 --> 19:50.180
So for example, the CRC peripheral is a different, at a different address as far as I can tell.

19:50.220 --> 19:58.820
Um, it's just patches and there are some weird regions with high entropy, which is always a bad sign because that means that there's some cryptography very likely going on.

19:59.040 --> 20:03.380
And, uh, yeah, that will spoil our day if they implemented secret boot.

20:03.840 --> 20:08.560
However, some successful things was that I was able to reverse engineer the firmware header.

20:08.560 --> 20:11.620
And so I found a couple of CRCs and so on.

20:11.620 --> 20:18.020
And my naive hope was, okay, I just, you know, patch the firmware, fix the CRCs and surely this chip will boot.

20:18.160 --> 20:21.280
And so let's flip a bit in a $3,000 MacBook.

20:23.040 --> 20:29.580
Unfortunately, uh, I couldn't get it to boot a modified firmware, but at least I didn't fully brick it.

20:29.580 --> 20:43.280
So in the end what I tried, I tried my software vulnerability, I tried physical SWD access, I tried modifying and switching the flash contents, even like between the different ACE chips, but they all seem to have a unique signature.

20:43.280 --> 20:48.240
Like even you can't take the, the left ACE and put it on the right ACE and so on and so forth.

20:48.640 --> 20:57.500
I tried fuzzing and I actually found a timing side channel that lets me enumerate the commands that the ACE 3, um, supports, but that doesn't really give me anything.

20:57.500 --> 21:04.940
So yeah, essentially we have a completely undocumented, not documented, apologies, chip.

21:04.940 --> 21:08.000
We have no firmware and only some simple commands.

21:08.720 --> 21:13.060
Time to give up or do we try fault injection?

21:13.260 --> 21:23.640
Um, so fault injection is an awesome technique because essentially we can introduce faults into a chip, which allows us to modify the behavior of the running software.

21:23.860 --> 21:28.060
So for example, we might be able to flip, flip bits and registers and memory.

21:28.060 --> 21:30.280
We might be able to skip instructions and so on.

21:30.280 --> 21:32.300
And there are a lot of different techniques for this.

21:32.300 --> 21:36.660
There's voltage glitching, laser, BBI, electromagnetic and so on.

21:36.760 --> 21:41.360
Uh, they all have one thing in common, which is that they very easily break chips.

21:42.020 --> 21:46.160
Um, the most common way to do glitching is using voltage fault injection.

21:46.260 --> 21:53.760
And there you essentially drop the power to the chip for a very short amount of time at just the right point in time.

21:54.020 --> 21:59.440
And the problem is this pretty much requires soldering and removal of a ton of capacitors and so on.

21:59.500 --> 22:02.620
And it's best performed if you, if you like, know what's going on.

22:02.620 --> 22:03.840
Like we don't even know the pinout.

22:03.840 --> 22:07.020
We don't know what is the core voltage, what is the main voltage rail.

22:07.020 --> 22:10.120
We don't know what other chips are on there and so on and so forth.

22:11.080 --> 22:16.640
But there's an alternative called EMFI, electromagnetic fault injection.

22:16.640 --> 22:25.400
The idea is we create a high voltage pulse into a coil and this lets us inject current directly into precise locations in the chip.

22:25.400 --> 22:30.320
And this again can let us skip instructions, change register values and so on.

22:30.360 --> 22:33.580
And we don't really need target preparation for this.

22:33.580 --> 22:40.620
It's just we point our chip shouter at the chip, we zap it and the chip is hacked.

22:40.920 --> 22:43.140
Wonderful in theory.

22:43.140 --> 22:52.980
The problem is we need to know the very precise timing on when we need to glitch because otherwise, you know, we're just gonna glitch something else.

22:53.400 --> 22:57.080
How do we figure out the timing on something that we know nothing about, right?

22:57.080 --> 22:59.380
We just know it doesn't boot, period.

22:59.980 --> 23:07.060
Brute force, I thought about it, but it, the boot is so slow that it would take forever to try.

23:07.080 --> 23:12.560
And the more we try to glitch at the wrong point in time, the more likely we are to break the chip.

23:12.560 --> 23:14.940
So we really want to get this right.

23:15.640 --> 23:20.780
But another idea, which are what if we find a side channel?

23:21.520 --> 23:28.200
What if we find a side channel to get this precise timing on when to inject our glitch?

23:28.420 --> 23:31.680
Normally, now I decided to use an EM side channel.

23:31.680 --> 23:35.400
So I use an EM probe to measure the chip.

23:35.480 --> 23:42.280
And normally you would use a very high end oscilloscope for this, but I wanted to use a cheap, affordable hacker to make this more accessible.

23:42.280 --> 23:48.280
And I just glued a random coil onto a PC by probe and just dropped it onto the chip.

23:48.280 --> 23:49.960
So this is just held with gravity.

23:50.320 --> 23:53.280
And this way we can capture the magic chip waves.

23:53.320 --> 24:02.240
And we can actually see this as we restart the chip, we can actually see that there's activity on the spectrum at around 48 megahertz.

24:02.480 --> 24:04.480
Now this activity could be anything, right?

24:04.480 --> 24:10.260
Like this could be the power rail, this could just be the spy flash line or so, but it's something.

24:10.520 --> 24:12.660
And so the idea is simple.

24:12.660 --> 24:33.040
We start recording the spectrum on the hack RF, we reboot the ACE3 using the ACL I showed earlier, we get the electromagnetic recording, and then we just do some very simple DSP, which just took the better half of a week to generate, you know, a ton of different measurements and so on and so forth,

24:33.040 --> 24:34.440
filtering this and that.

24:34.440 --> 24:39.540
But eventually I had a line that I thought, okay, this looks like it might tell us something about the chip.

24:39.580 --> 24:46.560
And this is completely gut feeling, like I didn't do any science here, I just tried to play with filters and eventually I got this line.

24:47.720 --> 24:54.640
Now the problem with this recording is that you want to collect a lot of traces and average them together.

24:54.880 --> 25:02.040
The problem is they will all be at different offsets in time because we don't have a precise way on how to start the recording.

25:02.820 --> 25:05.460
And so we could align these in software.

25:05.500 --> 25:10.940
However, the hack RF actually has a nice feature, which is it has hardware trigger inputs.

25:10.940 --> 25:14.600
And so we can actually trigger the recording using a hardware signal.

25:14.940 --> 25:17.820
This doesn't work in the latest hack RF firmware.

25:17.820 --> 25:22.380
So it was again like hours of trying different firmwares until one would actually trigger correctly.

25:23.180 --> 25:25.200
And now we just need a trigger.

25:25.560 --> 25:28.940
Now remember that we have access to the flash lines.

25:28.940 --> 25:32.160
And the flash lines have a line called chip select.

25:32.260 --> 25:38.920
And the chip select line will go low just as our firmware is being loaded.

25:38.920 --> 25:45.080
And so this is perfect to offset a glitch from if we want to bypass secure boot of what just got loaded from flash.

25:45.780 --> 25:47.780
So, easy plan.

25:47.780 --> 25:51.460
We start recording on the chip, on the hack RF.

25:51.460 --> 25:53.120
We reboot the ACE3.

25:53.120 --> 25:56.180
The hack RF gets triggered by the chip select line.

25:56.300 --> 25:58.560
And we get a perfectly aligned recording.

25:58.640 --> 26:04.120
And in theory if you, you know, it should look like this if you take pictures for presentation.

26:04.180 --> 26:08.300
In reality your desk will look like this and it will just be a gigantic mess.

26:09.680 --> 26:21.780
So in the end we have perfectly aligned recordings and we can actually average them together to get a nice meaningful signal where if anything else put in noise we can just filter it away essentially.

26:22.360 --> 26:24.840
But, you know, now we just have a fancy line.

26:24.840 --> 26:27.940
How do we actually use this to time our glitch?

26:28.560 --> 26:33.580
Well, we can change the flash contents to be invalid so that the boot fails.

26:33.840 --> 26:37.720
We reboot the ACE3 and record the EM emissions.

26:37.720 --> 26:39.800
And then we compare the differences.

26:39.940 --> 26:47.280
Sounds easy but in reality this takes hours because you have to set up these needle probes which takes like, you know, 20 minutes.

26:47.600 --> 26:50.320
You try to flash the chip until it works.

26:50.400 --> 26:53.800
Then you do the capture and measure and so on.

26:54.000 --> 26:57.540
And then you do this again and again and again to get everything right.

26:57.540 --> 27:04.980
And in the end you end up with a trace that might look like this where you have the original firmware and the modified firmware.

27:05.040 --> 27:07.900
And we can see that this trace looks super different, right?

27:07.900 --> 27:11.040
Like there's a clear point in time where they start to differ.

27:11.820 --> 27:17.860
What's even better is we can test our hypothesis by modifying the CRCs.

27:17.860 --> 27:27.340
So remember that we have these three CRCs and so in theory if we fix just some of them we should see a delay in our boot, in our EM trace.

27:27.340 --> 27:31.780
Like we should see that our trace changes at a later point in time.

27:32.460 --> 27:33.820
So I tried this.

27:33.820 --> 27:35.400
So I have the original firmware.

27:35.400 --> 27:39.200
Then I set one of three CRCs to be correct.

27:39.780 --> 27:43.100
And you can see we have exactly the same signal as before.

27:43.260 --> 27:48.660
Then I tried two of three CRCs to be correct and no change.

27:48.660 --> 27:51.080
So I was worried that this might not actually work.

27:51.080 --> 28:01.280
But then when I set the third CRC to be correct we can see that the boot actually goes much further and that the boot fails at a much later point in time.

28:02.020 --> 28:05.420
And so why not just glitch here, right?

28:05.420 --> 28:07.020
So simple enough.

28:07.120 --> 28:08.640
We now have some timing.

28:08.640 --> 28:11.120
Now we just need to position our chip shoulder.

28:11.120 --> 28:16.480
Because normally for EMFI it's very important where you are glitching.

28:16.540 --> 28:25.480
And so if you were doing this professionally to give a talk at big security conferences you would use a big XY table to scan the chip.

28:26.100 --> 28:37.920
Unfortunately, like literally the week before I did this I had a small accident with my CNC and I got 230 volts onto the ground line and completely bricked my computer, my screen and my CNC controller.

28:39.560 --> 28:40.860
That was fun.

28:40.860 --> 28:41.920
And so I couldn't do this.

28:41.920 --> 28:44.100
But I really wanted to try this attack.

28:44.120 --> 28:50.300
So I just did the dumbest thing you probably could have done which is I chose the biggest tip I had.

28:50.300 --> 28:52.840
I just placed it on the chip.

28:54.060 --> 28:58.740
So that way I was sure that I was at least hitting something in there.

28:59.780 --> 29:03.280
And so I had this nice setup with the chip shoulder.

29:03.940 --> 29:07.860
Then the triggering was done by a chip whisperer Husky.

29:08.400 --> 29:14.540
The trigger connection is just the chip select line using a PC byte and a connection to ground.

29:14.580 --> 29:17.920
What's not shown is the days of debugging this took.

29:17.920 --> 29:19.360
Again, this is a photo op.

29:19.360 --> 29:21.240
Reality looked like this.

29:21.240 --> 29:25.440
As soon as you bump the table everything would just drop off.

29:26.600 --> 29:27.220
So yeah.

29:28.460 --> 29:31.020
So we are ready to glitch essentially.

29:31.020 --> 29:35.100
So my first attempt was I would just change the version string.

29:35.100 --> 29:39.820
So from Mac OS I can read out the version of the firmware that is running on the Ace.

29:40.200 --> 29:44.720
And so on my MacBook this was 2.45.

29:45.120 --> 29:49.940
So I decided in the flash I would just change that single byte.

29:50.100 --> 29:53.180
Then I fixed all the other CRCs around it.

29:53.900 --> 29:57.000
And then I armed the Husky and the chip shoulder.

29:57.000 --> 29:59.680
I reboot the Ace 3 via Ace tool.

30:00.020 --> 30:01.980
I wait for the glitch.

30:02.020 --> 30:07.200
And then remember earlier I told you that we can check what the status of the chip is?

30:07.260 --> 30:10.060
I just checked whether it successfully booted.

30:10.180 --> 30:12.820
And this worked wonderfully, right?

30:12.820 --> 30:15.720
So I just, I can just try again and again and again.

30:15.780 --> 30:18.480
And in theory we should eventually get successful.

30:19.000 --> 30:22.420
And so I built this tiny Jupyter notebook to do all of this.

30:22.420 --> 30:24.720
Um, and started it.

30:25.700 --> 30:29.080
And you can see we got like 1.6 attempts per second.

30:29.080 --> 30:32.040
So each reboot takes like 1.6 seconds.

30:33.740 --> 30:35.620
That's when the trouble started.

30:35.800 --> 30:40.860
The problem is sometimes the Ace completely starts, stops responding and I can't get it to boot again.

30:40.860 --> 30:42.360
I don't get any output.

30:42.540 --> 30:44.440
So I need to reboot the machine.

30:44.980 --> 30:52.840
The problem is if I reboot the machine while the charging controller doesn't have a firmware, the MacBook will stop charging.

30:53.460 --> 30:59.040
And essentially I have eight hours of trying to glitch the chip and then the battery runs out.

30:59.040 --> 31:02.800
Then I have to restore the flash which takes hours again with the probes.

31:02.840 --> 31:07.160
Restore the firmware, charge it up and then do the whole thing opposite again.

31:07.260 --> 31:10.880
Um, so I did that for a couple of days.

31:12.320 --> 31:15.040
And cause I, like it was like sunken cost fallacy.

31:15.040 --> 31:21.320
I started, then I thought like, hey, maybe I should build a battery emulator and just like feed it externally.

31:21.320 --> 31:23.280
But I thought, ah no, I'm so close.

31:23.280 --> 31:25.140
I'm sure it will happen any minute now.

31:25.140 --> 31:26.520
So, yeah.

31:26.520 --> 31:29.540
So I kept doing this but eventually I got success.

31:29.540 --> 31:35.880
I managed to get into the app mode on the uh Ace 3.

31:36.060 --> 31:37.840
And by checking.

31:39.420 --> 31:41.080
Thank you.

31:41.980 --> 31:46.980
And by checking, by checking the version number, I can actually see I was successful.

31:46.980 --> 31:50.760
I changed it to version 42 and we glitched the Ace 3.

31:50.760 --> 31:56.940
But the problem is we only changed the external patches.

31:56.940 --> 32:01.180
And we don't actually know what these patches patch because we don't know the actual ROM.

32:01.180 --> 32:04.580
And so essentially we have this flash which is full of random functions.

32:05.000 --> 32:07.400
But we don't ever know what they do.

32:07.400 --> 32:10.380
Like we don't know how can I trigger them?

32:10.380 --> 32:12.080
Will they actually be executed?

32:12.140 --> 32:16.260
And then even if you manage to execute them, we don't have any input or output.

32:16.260 --> 32:19.040
Like we don't even have a driver to wiggle a pin or something.

32:19.040 --> 32:24.400
So I was like considering, oh can I do maybe some, some looping that I can measure via EM or so.

32:24.760 --> 32:27.560
Um but yeah, essentially we can replace functions.

32:27.560 --> 32:28.680
We don't know what they do.

32:28.680 --> 32:36.320
And even if we execute them, even if we 100% know we get them to execute, we have no way to get data out.

32:37.160 --> 32:44.080
However, I started looking around a lot through the Ace 3 flash and you can see that there are a lot of 4CC strings here again.

32:44.080 --> 32:49.200
Like this, UFPF, DFUF, uh USBW and this one and so forth.

32:49.640 --> 32:55.440
And I thought probably there's some similarities between the Ace 3 firmware and the Ace 2 firmware.

32:55.440 --> 33:00.100
And maybe I get lucky and they patched a function in both chips, the old one and the new one.

33:00.200 --> 33:08.780
And so after hours of staring in Binary Ninja, I found a function that is actually almost identical between the two.

33:09.460 --> 33:11.900
And this is the USBW command handler.

33:11.900 --> 33:15.360
And USBW command handler, I have no idea what that does.

33:15.540 --> 33:20.100
But it's a command that I can send through the Ace that will get executed.

33:20.640 --> 33:23.460
And remember, and so I can replace it.

33:23.460 --> 33:27.000
And remember how earlier I saw the memory function?

33:27.100 --> 33:37.060
I essentially took that implementation from the Ace 2, modified it, simplified it slightly and then had a function that was by Apple built to give me memory.

33:37.060 --> 33:40.460
And essentially Apple built my exploit payload.

33:40.460 --> 33:42.260
So I'm very thankful for that.

33:42.920 --> 33:51.560
And so in the end, I essentially had a very simple payload that is a trivial memory reader that takes in an address and returns 4 bytes at that address.

33:52.200 --> 33:59.020
So again, attempt 2, we replace the USBW command handler and we start glitching.

33:59.020 --> 34:03.380
And we again, you know, wait for the battery to run out, start over and so on and so forth.

34:03.380 --> 34:06.300
The glitch was not very stable at this point in time.

34:06.300 --> 34:18.140
And so, but eventually, I got a success and so I decided I will just send the USBW command with the address 0 0 0 0.

34:18.260 --> 34:20.140
And I got this back.

34:20.140 --> 34:23.400
0 0 0 6 2 0.

34:23.520 --> 34:31.580
And you know, this is a little endian machine so you reverse it and if you do a lot of arm reversing you will immediately spot why this indicates success.

34:32.300 --> 34:34.140
This is the stack pointer reset value.

34:34.140 --> 34:37.980
We just read address 0 of the memory of the chip.

34:37.980 --> 34:42.620
And so we can read and also write arbitrary memory on the ACE3.

34:43.300 --> 34:44.120
So,

34:49.340 --> 34:51.260
time to dump.

34:51.260 --> 34:57.060
Um, and again, like I, my payload was not the greatest and so I could dump 4 bytes at a time.

34:57.180 --> 35:09.980
And so, it took hours and the battery ran out and I had to reflash, restore, recharge, glitch again, and then dump it again.

35:09.980 --> 35:13.080
But eventually, I had the full firmware.

35:13.180 --> 35:16.880
A full dump of the ACE3, ROM and RAM, and so on and so forth.

35:17.040 --> 35:18.220
So, awesome.

35:18.220 --> 35:20.900
We can actually start reverse engineering this chip.

35:21.940 --> 35:27.480
And the main thing that I learned during this is dumping unknown silicon is actually possible.

35:27.480 --> 35:29.880
Like, I knew almost nothing about this chip, right?

35:29.880 --> 35:35.860
And it's not super difficult, it just takes a lot of persistence and, you know, dealing with annoyances.

35:35.860 --> 35:41.340
And we can actually get code execution without having firmware, even on a microcontroller.

35:41.340 --> 35:42.960
And I thought that was really cool.

35:43.040 --> 35:46.300
And now we can actually start researching the ACE3.

35:47.060 --> 35:53.100
Now, the equipment I used with like the chip shoulder, husky, and so on, this is all very expensive, right?

35:53.100 --> 35:55.700
Like, the toll is probably like 8k or something.

35:56.320 --> 35:58.640
And, you know, so let's make it cheaper.

35:58.640 --> 36:06.220
So, I imported the entire attack onto the PicoMP, which is like a super low cost, uh, electromagnetic fault injection tool.

36:06.600 --> 36:14.120
And I put a firmware on the chip shoulder that does all the triggering on the chip select line and so on and so forth automatically.

36:14.120 --> 36:20.580
And so you can now attack the ACE3 and dump it for $60, which I think is pretty fair.

36:20.580 --> 36:22.160
And so, yeah.

36:25.600 --> 36:29.060
With that said, that's all I have for you today.

36:29.060 --> 36:32.240
I think we have a bit of time for Q&A, but thank you.

36:32.240 --> 36:38.360
And also, if you're interested in actually trying some fault injection, we are running a glitching lab over at the Embedded Systems Village.

36:38.360 --> 36:45.960
And so come by and you can actually bypass some protections on chips by zapping them or fiddling with the voltage rails and so on.

36:45.960 --> 36:46.320
So, yeah.

36:46.320 --> 36:47.260
Thank you.

