All right, so this is the Unicorn team, 360 technology, and I will let them go. Good afternoon, everyone. Thank you for attending this talk. It's our honor to share our research with you. In this presentation, we are going to talk about one vulnerability we found in NXP associates, and we will show you how to use this vulnerability to implant malware into the peripherals which are made of these chips. Now, let me firstly give a brief self-introduction. My name is Yiwei. I am a security researcher of Unicorn team, and this is Shaokun Cao. He founded this vulnerability and that is my colleague Hao Jishan. Unicom team is a research group within 360 technology. The team was formed in 2014. We focused on the security issues in numerous types of wireless systems. During this talk, firstly, we will introduce why we did this research. Then, we will discuss the secure boot and its different types of implementation. Thirdly, we will reveal the detail of our vulnerability. We provide two exploits. One is to bypass the Unicom ID verification in secure boot. Another is to implant malware in a peripheral. Finally, we will give our recommendations to vendors who use these chips. Secure boot is widely used in personal computer, workstation, server, and the smartphone. It's used to prevent malicious code from being loaded and executed. But in the embedded systems, because its resource is limited, there is no TPM or trust zone within these systems. So how to implement Secure Boot? We want to research the implementation of Secure Boot in closely constrained systems and try to find a common way to implement malware into such systems. Let's have a basic understanding of Secure Boot. As this figure shows, in the system which has Secure Boot support, there is a primary bootloader and I1. And a one-time program of memory in the main chip. In the main chip, the primary bootloader is designed by the chip vendor and permanently banned into its boot room at the chip manufacturing stage. The one-time programmable memory is used to store the root public key. It was banned at the product manufacturing stage. In the external storage, there are secondary bootloader, OS kernel, drivers, applications, corresponding public keys and signatures, etc. When the system is powered up, the primary bootloader will verify the secondary bootloader. If the secondary bootloader is worried, it will be executed. Then, the secondary bootloader will verify the kernel. OK. OK. And so on. Otherwise, the system will be hard. This mechanism ensures all the binary code executed in this system is trusted. We also can see the primary bootloader and the root public key is the root of the whole trust chain. The master cannot be replaced or bypassed. So what can secure the boot be used for? Secure boot can be used to prevent the malicious code from being executed. Here we give two attack examples. One example is a talk of Black Hat Conference US 14. In this talk, the author provided a way to inject malicious features into a 4G modem using the malicious code. And the attack is user. Another example is a research provided by our team in DEF CON 23. We modified the firmware of a femur cell to yield off nearby cellular users. If these products have secure boot, such attacks are hard to perform again. Secure boot also can be used to prevent the malicious code from being executed. It can also be used to protect the copyright of product vendors. In industrial and commercial areas, different types of secure boot have been implemented and used. One example is UEFI Impressional Computer and Server with the support of TPM. Just a trusted operating system is allowed to load and boot. Another example is UEFI Impressional Computer and Server with the support of TPM. Another example is a smartphone with the support of Trusted ROM. Only the trusted OS can boot and the trusted application can be installed and executed. Both the two implementations require hardware support. The specified hardware unit ensures the boot ROM and the public key cannot be replaced. But in the embedded system, due to the limits of cost, there is no hardware unit like Trusted ROM. There is no hardware unit like Trusted ROM. How do we implement secure boot? Many chip vendors design a lot of SoCs for such cost-sensitive usages. These SoCs integrate a lot of components such as Flash, RAM, Timer, etc. which means most of the aimed application scenarios. It only requires very few external components to design a product with this type of chip. So it is widely accepted because it is easy to use and low cost. Chips vendors also design a mechanism of such type of chip. which can be used to protect the firmware from being read out. This mechanism is called as code read protection. If the code read protection function is enabled, the JTAG or in-system programmer interface of these chips will be disabled. Nobody can read out or erase the flash through this interface again. But this also results the firmware cannot be updated anymore. So, as the upfig shows, the product vendor also designed the customized bootloader and implemented them in the application programming features in this bootloader. With the IP support, the application array can be updated again. As the lowerfig shows, if the bootloader array is not allowed to update, the public key can be stored in the bootloader array. This is also fully satisfied the requirements of secure boot. That is the bootloader and the public key. The bootloader array cannot be replaced. To understand how such secure boot can protect the designer's copyright, we have to understand how does the copier clone a hardware product. As this figure shows, firstly, the copier buys the PC of the target product. Then, he recovers the PCB layout and the corresponding components through reverse engineering. Secondly, he corrects the code protecting mechanism to read out the firmware. After that, he buys the same components and reproduces the PCB. Finally, he binds the firmware into the PCB and he can batch clone target products. Now, let's calculate the cost the copier needs to pay in this procedure. The main cost occurs in the PCB reverse and firmware readout steps. According to the complexity of the PCB board, the cost of PCB reverse is from $20 to $200. In the firmware readout steps, depending on the strength of the code read protection, the cost is from $200 to $5,000. The total cost of the copier product is much lower than the designer's one. This brings great damage to business fairness. So, to defend the copier, the chief vendor also designed a so-called unique ID feature. They gave a unique serial number to each of their chips. The unique ID is factory listed into the silicon at the chip manufacturing stage and cannot be modified again. As the left figure shows, the product maker can read out the chip ID and combine it with the application to generate its signature. When the system boots, the bootloader reads the unique ID and works on it. If the signature is valid, the application firmware will be executed and the normal function of the product can be used. Otherwise, the product becomes a brick. So, even the copier buys the same chip and buys the same firmware due to the unique ID, they will get a brick. When the secure boot is binded to the unique ID, besides the costs we calculated before, the copier also needs to patch all corresponding passes to bypass the unique ID and the signature verification in the firmware. Because the embedded firmware is strongly precision-dependent, linked, the cost to reverse and patch the firmware is very high. According to the complexity of the firmware, the cost is from $5,000 to $50,000, and the copier needs to pay again when the firmware is updated. This is not a valuable deal, so the unique ID is a good way to defend the copier. Now let's have an analysis of the strength of such types of secure boot. How to bypass the secure boot verification? As we mentioned before, patching is not a good way. In high-level operating systems, such as Windows or Linux, we can hook the system API to change the behavior of the application, but not to patch the application itself. For example, we can hook the MAC address reader API to give arbitrary MAC address to disable the application. But in the resource-constrained SLCs, is the hook mechanism also effective, and how to implement it? Now let's show Quan and Haoqi to reveal the details of the exploits. OK. The NXP Cortex-M series uses the method to access the UID. There is a function pointer in the fixed position of the ROM. After accessing the function pointer, you can invoke a ROM function. The UID of the ROM can be obtained by calling this function. This subrouting is multifunctional, and different functions can be selected through other parameters. This is the code that accesses the UID, and this function has two parameters. One is the entry parameter, and the first one, the integral of the entry parameter, is the command. When the command is 58, which is to read the UID value, and the UID value will be found in the return parameter. This is the description of the UID function in the NXP document. It's very simple. We just have to forge the same function. That's what we will hook to. As we know, debug systems can change the action of a program. We can set a debug breakpoint, halt a running program, or change the value of a variable or a register. In Cortex-M, we can do this without changing the fresh ROM. It means that if we can write a patch and run it before the bootloader, we can simulate a light debugger. It will work similar to a JTAG debugger. The FPV register is one of the registers of a debugging system. Of course, it can be accessed by the JTAG, but it can also be accessed by the code. If we write code like JTAG do, actually, we are implementing a light version of soft debugger. The FPV is used to provide fresh patch and the breakpoints. Flash patch means that if an instruction accessed by the CPU matches a certain address, the address can be remapped to a different location so that a different value is obtained. Alternatively, the matched address can be used to trigger a breakpoint event. Then the fresh patch feature is very useful for testing, such as adding a diagnosis program code to a device that cannot be used in normal situations unless the FPV is used to change the program control. The FPV unit can be programmed to generate breakpoint events even if the program memory cannot be altered. However, it is limited to six instruction addresses and two literal addresses. The FPV has two functions. One is hardware breakpoint. It can generate a breakpoint event to a processor to invoke debug modes such as HOT or debug monitor. Patch instruction or literal data from code memory space to SRAM. And it has six instruction parameters and two literal comparators. Here is a very simple example to show how to use the FPV. The FPV remap register is set to 0x20001000. It means that once the comparator is matched, the code or the literal data will be replaced by the data in the mapped memory. In this example, we set two variables to replace. One is the instruction. Another is the literal data. The FPV compare 0 indicates the instruction in the offset 0x8001000 will be replaced to another instruction. The FP compare 6 indicates that the data in the offset 0x8001000 is replaced. If we enable the FPV by setting the FPV control register to 3, the action of the code will be totally changed. It should be the data in R4 is 0x8000000. But actually, R4 is skipped and R1 is 0x1000. And the R4 should be 0 but negative 1. In fact, the FPV has a fresh patch control register. That contains an enable bit to enable the FPV. In addition, each comparator comes with a separate enable bit in its comparator control register. Both of the enable bit must be set to 1 for a comparator to operate. The comparators can be programmed to remember addresses from code space to the SRAM memory region. When this function is used, the remap register needs to be programmed to provide the base adjusts of the remap contents. The upper 3 bits of remap register is hardwired to 001, which is limited the remap base adjusts location to be within 0x200000023FFFFF80, which is always within the SRAM memory region. And this is an example to replace the literal data. This constant int data is initial to negative 1. After compiling and linking, it will be stored into the flash. It cannot be changed again at runtime. We program the FPV to set the constant to remap this data to SRAM and try to set its value to 0. After we enable the FPV, all codes that access this constant will get 0. In order to verify this vulnerability in real-world product, we use the J-Link to implement to exploit. Before discussing the detail of this exploit, let me introduce the J-Link. J-Link is a powerful emulator and debug tool for ARM processors. It's very useful for ARM developers to debug their firmware and hardware. This tool is designed by SEGGER. They implement secure boot in their firmware and use the unique ID provided by NXP to verify the license. It has a USB port and under normal use scenarios, it must be plugged in to the computer. So it's also a good carrier for hardware children. Based on the example and the character of NXP's SOC, we can use the FPV to change the entry of ROM API function. There are function pointers in a fixed position. Therefore, find out the function pointer which you want to hook. And remap it to the fake function. That's part of the code. This invokes the FPV funk to remap and go to the entry point of original program. Just run it before the target. And this is the fake IAP, which is the original IAP is redirected to. In this example, we replace the command number 58, which is to access the UID. In other cases, it will jump to the original own entry so that it only modifies the UID but will not change any other function. You should remap the original function to the fake one. Now let me show you the demonstration. In this video, you can see after we burn the J-Link firmware and our exploit code, the development board has the same function as J-Link. OK. Let my partner, Mr. Haoqi, finish this topic. So, thanks for my colleagues' explanation about the details of the attack. So in the following sentence, I will introduce you guys how to really exploit or illegal copy a real product of the XP production. So, in this video, we will show you how to copy a J-Link production one step by step. But before that, I will really apologize for the bad solutions of the video because we kind of like made a mistake. So, in this video, can we make this? Oh, it doesn't matter. It's OK. So, I just click it. So, before I start this video, I want to, as we mentioned in the previous discussion, we need the firmware of the J-Link to do our patch stuff because we didn't actually modify the firmware. We actually patch some kind of code sections, some kind of data sections inside of the firmware and do our stuff such like to bypass the anti-clone mechanisms. And so, in this video, we kind of like, before that, we need the firmware of this J-Link production. But, as we discussed before, the J-Link production has kind of like code read protections. With these protections, you can't read the firmware outside. You can't extract the firmware because there, I mean, if this code read protection is enabled, then you can't access this production with the J-Link nor with the ISP programming system. I mean, you can actually erase the data, you can actually erase the code, but you can't read them out. So, but there is a very simple way you can get the firmware. And they basically store this firmware in the desktop applications. Remember J-Link has some software on your PC, on your Mac, so you can just upgrade your, upgrade the firmware of the J-Link hardware. So, basically they just store this firmware in plain text, so you can just x-ray it, or you can just copy it on that. With the x-rayed firmware, so we can do the critical copy. So, let's start. So, in the right side bottom corner, so you can see we actually have a computer, we actually have a J-Link, we have a development board. On the development board, evaluation board, so you can just see, there is exactly the same chip we were using on the, I'm sorry, my bad. Yeah, we were using the exactly same chip, same microprocessors on the evaluation board, and this is exactly the same with the J-Link hardware production. So, with the hardware, we can just, we can just download this hardware into the evaluation board, and my colleague is just doing this stuff. So, you can see, oh, because the error here is, means we actually forgot to power it up. So, you can see, so with the firmware and with the same chip, basically, if there is no license verification, there is, if there is no signature, basically, they are just the same products, right? Same hardware, same software, but the truth is, so right here, if you flash it, you can see there is two JLinks in the, in the hardware list. Now, we launch the JLink software command line to verify if all of those are working or not. So, this is the first one. This is the legal copy. And, and right now, we are trying to confirm the second one. This is the illegal copy, which is also the evaluation board. See, it's totally different because the verification procedure is not passed. I mean, it's failed. So, after this, we are trying to deploy our, uh, our patch by, uh, leveraging the FVB unit. So, before that, remember we just talked about there is a code protection mechanism inside of the burn this formula and we run it, then the evaluation board is dead because you can't actually, you can't actually erase it. You can't actually program it by the JTAG, right? But, there is also another way, just use the ISP programming mechanism to erase all these code sections. I'm sorry. Oh, this is really my bad. So, right now, my colleagues is trying to erase the evaluation board and make this, make it as brand new and so we can do the patch stuff after that. And, uh, there is another way It's a tool called flash magic. You can do things like this. Okay. Then, this evaluation board is blank. So, we can do the next step. Connect it. Okay. So, we So, this is actually the code we clone the unique ID and we do the hook functions. So, basically, while compilation we can just use the original formula as a section of our new formula. So, we can just put our bypass code and patch code inside of the another region of the flash and combine all of this together as a new formula and download into the hardware. And try to flash it and verify. And now we launch a new jet ink terminal to verify if our work is doable or not. So, this is the original one. This is the legal copy. And the evaluation board. So, right now you can see there is totally the same. And the serial number, if our solution is better, I mean, if our radio solution is better, then you can see the unique ID or the serial number is exactly the same. You can just use exactly the same production. So, we all basically request a legal copy. But, I mean, we just do this for phones, not for profit. So, we were trying to say, oh, is there any way we can just exploit this, you know, do something more interesting? So, then we were thinking about how about the hardware charging? I mean, imagine this scenario. There is, so, like, the U.S. is trying to attack the Iraq, right? There was a case that the FBI, I can't remember, but they kind of like they intercept a bunch of printers which was intercepted, they patched the firmware, and those kind of printers just was their boat, their boat net, and those kind of printers just steal a lot of stuff for them. So, we were thinking about, can we do that? I mean, patch the firmware, patch the firmware of embedded system is not quite easy. It's not like a computer. You can do this easily. You have a lot of whole platform to do this. But, with the FPP function, we can do this very easily. I mean, the FPP function, it's just, it's very simple. You can just hook a function, or you can just hook a snip of code to do some other stuff. It won't, it won't infect the integrity of this firmware. And you don't have to actually analysis the firmware. And so, you can just put your code and invoke this function. That's all. So, we were thinking about how to inject hardware children inside of the G-Link production. And the G-Link is using the NXP chip, right? So, which is also based on the core and it has a giant flash. It's very, I mean, it's pretty enough for us. So, the G-Link firmware is also So, if we want, we can just inject the hardware children inside of the firmware before some other people purchased this hardware. So, how about add a better USB into a G-Link, right? You purchased a G-Link, it's huge, expensive, and you said it can accelerate your development procedure, but turns out it's a better USB. It can just do all of this stuff from your computer because you just connected this hardware into your computer and into your laptop and you think, okay, this is safe enough. I can do my stuff. So, in the, so, I mean, if you were trying to bypass the anti-clone mechanism, we were talking about the unique ID verification function, but in this one, we can just hook another, we can just hook another system function call. So, in this case, we were hooking the CST handler, so this is basically an exception handler. I mean, there is a bunch of function inside of the hardware, inside of the system, and in it, it's kind of like a time slice, so this one will just help you to count the time, right? So, this is, I mean, all of these computers, all of these embedded systems, we just use a function like this. So, this is our main target. And, after we do that, I mean, the normal function we just keep is original, I mean, we didn't harm the integrity of this formula. So, how to trigger this charging? I mean, you can, it can be just considered that we have two parts of the charging. It can do the debug probe, it can do all of this things. This is what you do for the 800 bucks. But, if we, and another part is the beta USB. This part of the function, it will be executed in some times and it will just inject a bunch of code into your computer and act like a USB, USB, like a USB device, like, like your keyboard, like your mouse, it can do everything, right? This is basically human. So, we have two parts of the formula and we hook the time interrupted entry. So, we do this by hooking the function formula that, uh, that, which is the, uh, which is the cystic handler with, it's a previous slice. So, the, the rest of the thing is, uh, I mean, the rest of the thing we need to do is, like, the first step is we try to compile this beta USB code. The second step is we try to hook this critical function. And, uh, once this critical function is executed, okay, then we can just execute our firmware. I mean, it's a beta USB stuff. And, also, we just act as pretty normal. You can just use this to download, to debug everything else. And, uh, so you can see, so you can see the first step is, of course, the power up, right? Of course, this is after we, uh, download our firmware into this hardware. So, the first thing, I mean, it's a, it's just a power up. And, uh, we also, we, we don't want to make our code wrong, but execute it, you know, in the beginning of this power up procedure. I mean, we want to be executed, we want it to be executed in some certain time. So, nobody will just be noticed. So, we put the attack flag inside. I mean, remember the cystic? So, this is basically some, like, the time counter. So, we set up, uh, we set up a time counter, and, uh, we told them, okay, when this, uh, if this, uh, jet ink is powered, like, five minutes, then our, then our charging will be executed. This sounds like more reliable when, when we just put a jump inside of the, I mean, in the beginning of the firmware and to do all this better stuff, I mean, it's too obvious. Somebody will just notice, okay, I just plug in this and, uh, my computer is, my computer is doomed. Nobody will like that. So, that's why we choose this critical func, system, uh, system function as our hook function, and, uh, we choose, uh, time counter as our, uh, attack method. So, so, in this video, we can show you, uh, this is a demo of a beta USB. And, uh, so this is a code, this is a, uh, this is original code of the beta USB, and, uh, you can see, right now, we are trying to compile all of this into a firmware, and we download it into the, uh, Jetink, official Jetink stuff. So, all right. Download. And, uh, we, uh, left our computer right over there. And, uh, leave it wrong. So, you can see, now, this is no man touching the, touching our computer. And you just open a Defcon website. So, imagine that it can just open everything. It just, uh, steals stuff like, uh, like a personal account or download the firmware into your, into your computer and execute it. And it will just, it can be noticed. So, actually, uh, as we mentioned before, this is, uh, not actually, uh, NXP chip. This is, uh, NXP chip's fault. I mean, this is because we have, uh, debug function inside of our production. So, this is basically, uh, this is basically accelerate some hackers trying to attack, uh, trying to attack your production. This is to help them to lower the, lower the difficult. So, all, basically, all this Cortex-M3, Cortex-M4 of NXP chip, uh, FPV function, uh, I'm sorry, same FPV unit. So, you can just, uh, uh, leveraging or you can say, or you can say, you just exploit this into, uh, malicious function. So, uh, but also, there is, uh, some other vendors also have the team that provide the UID features. So, you can also clone their product, or you can also implement, uh, hardware trojins out of their production. we need to analyze, uh, the hardware, we need to analyze the firmware, and we try to implement all of this inside. But, uh, with this, we can just, uh, use FPV to hook a function to patch some stuff. This will be much easier. And, uh, uh, somebody was, I just want to say, is there any mitigation measure? And, of course, the first step is never leak your firmware. If you don't have a, if some, if nobody can get your firmware, of course, they can't, they, they, they can't do this. I mean, what's the point, right? You have, you don't have the firmware, and you give them a bunch of hardware, and told them, uh, you can, okay, you're gonna do this. Nobody will, will use that. So, uh, also, the second one is what we in, suggest for the AXP chip. So, uh, basically, I'm sorry, for the JLink, uh, enterprise. So, basically, they were just, uh, disable the FPV function before they call the critical, uh, API. So, I, I mean, it's, it's not, uh, sufficient, it's actually not a sufficient, kind of, measure, but it's, but it's much harder for the hackers to try to do stuff like what we've done before. Also, we, also, you can just, uh, pass the, uh, firmware to, you know, there's a blank, there's a bunch of blank flash regions, uh, in, of the firmware. So, you can just pass this firmware to set all this blank, uh, flash area to a specific value. So, for example, you can just, uh, use instruction, like the BL reset handler. That means if the, uh, if the code, uh, if the blank flash region was, uh, was being excluded, then you just directly jump back into the, uh, back into the beginning. So, it's not usable anymore. So, also, you should always verify the signature of the entire flash instead of just, uh, just a piece of code. It's, it's totally not secure, right? It's, it's, uh, I mean, it's just leave a giant blank hole into, and let us, uh, and told us, okay, you can take it. It's, uh, I mean, so, we also received the advice from the P3 of the NXP. I mean, it's, uh, it's, uh, it's also a security group of the NXP. So, there was just the, uh, the enterprise who, all the companies who were willing to use the NXP chip that is, uh, enables the code read protection. I mean, the code read, read protection setting has, uh, three levels. Uh, there is, uh, level one, level two, and level three. I mean, level one and level two, there is only, they, they just disable the JTAG. You can also use the, leverage the ISP to do the better stuff like the way, what we have done before. But, uh, if you enable the level three, yes, you can't use JTAG. You can't use ISP. I mean, you can't, this chip is, uh, it's not reprogrammable. But, uh, but, that also means if your production has something wrong, and it ships a ton of thousands of stuff like, to the, uh, to the users, to the endpoint, and if something wrong, then you are doomed. All of this will be refunded, and the, your company will be broke. So, the condom errors is like, it's not, uh, good idea to put the, in critical, to, to put a critical API into the address region that can be remapped. I mean, uh, it's just, the name is called like, Flash, Patch, and Breakpoint. That, that also means, it can only, I mean, the, Flash region can be remapped. So, nothing else. So, you can just put this in some critical register, or some higher, uh, address. That, that'll be, that'll be much better. So, we can recommend that SOC vendors just prohibit reading, remapping all of these ROM API in, uh, subsequent product. I mean, if you just ship it, if you ship it before, it can be recalled, right? So, it's much harder. So, this is a reference of our product, uh, I mean, our work. So, you can see, the principle is much, it's pretty easy, but, uh, you can do a lot of better stuff to do this. So, thanks, and, uh, thanks, thanks guys. So, if you have any questions, you can just ask me right now.