I'd like to welcome you on our talk, Nano Enigma, Uncovering the Secrets Within EFUSE Memories. First of all, allow me a brief introduction. My name is Martin and I'm here together with my colleague Michal. We also have a third partner in crime named Hayan, however he couldn't come here with us so we just have a pre-recorded message from him. We all work in the embedded system security testing team that's based in Prague, Czech Republic, which is under Accenture Umbrella, and we all have different fields of focus. So for me that's reverse engineering, so I'm usually that person that wants that firmware image unencrypted. So making me shut up was partial motivation of this talk. I'm pretty sure the other guys will tell you briefly about themselves when their time comes, so I'm just going to jump straight ahead into the overview. We have it in the title, we will be talking about EFUSEs, and EFUSE is an electronic component which is just two points interconnected with a connection that has a property that it burns or terminates when the current flowing through it exceeds certain threshold. This is really useful when you want to protect your home appliances from overcurrent, but it's also really useful when you want to create something called one-time programmable memory. Because if you represent bits with EFUSEs, once you change state of a bit from zero to one, you cannot ever unchange it back to zero. This basically means that you can change the state of the device permanently. This is really useful for security because now you can use these types of memories to, for example, disable debugging interfaces or enable secure boot or put there public keys for secure boot. However, some manufacturers took it one step further and they actually used these EFUSE based memories for storing information that requires confidentiality protection. Meaning that you can find there also flash memory encryption keys or passwords for debugging interfaces. But since I mentioned that that connection burns or terminates, there's actual physical change inside that component. So how do you protect confidentiality of something that could be observed through microscope? Because, for example, if I Google EFUSE microscope, you're going to get all the images like burned and unburned examples. So the protection measure you mainly used in some of the chips we looked at was layering. So layering is normal way of making chips where you stack components on top of each other. However, if you put that EFUSE based memory in the very bottom layer, you can then consider it protection because you can't directly observe it. This is based mainly on an assumption that performing the layering process, so removing carefully the layers from the chip so that you can extract information from it, is very complex and expensive process. But we are here at DEF CON because we have proved this assumption wrong. And we will demonstrate you all these techniques on an ESP32 chip from Espressif. However, keep in mind that all of what we will be presenting here is also generally applicable to just about any chip that is using an EFUSE based memory. And with that, I'd like to pass my word to Michal, who's going to walk you through the details of the attack. Hello, my name is Michal Grigarek and I'm also a part of Accenture Prague. At first, I must say I'm really proud to be here on this stage to present you results of our work. So my colleague Martin just explained what EFUSE is for. And now let's take a look more closely how we can observe these structures in much more detail and what technologies and skills we will need. First, we must decapsulate the chip. Decapsulation is the process when we extract the silicon plate from the epoxy housing. Of course, there exists some other material for housings, but for purposes of this presentation, we only consider only epoxy materials. There we see four basic techniques for decapsulation. Thermal, chemical, laser and plasma. Thermal method, this method uses only a blowtorch or a heat gun, simply to heat up the epoxy housing and then slowly and carefully break it and obtain the epoxy silicon plate. Chemical decapsulation uses concentrated chemicals, concentrated acid to dissolve the epoxy housings. Laser etching uses a strong laser beam to vaporize the epoxy material. But this method is quite risky because it is very easy to burn the silicon plate. And my problem lies in the heat deposition to the sample. And the last, plasma one. This process involves ionized gas or plasma to selective etching of materials. So, due to its availability and good traceability, we decided to use a chemical method of decapsulation. Especially, we used concentrated acid. In our case, concentrated acid means 96% of concentration, which must be heated to approximately 250 degrees Fahrenheit. The chemical methods can be effectively combined with laser ablation. At first, laser removes a large part of the housing and then the remaining can be dissolved in the acid. This shortens the process during the GPS exposure to the acid which is needed. The acid will dissolve the housing residue, leaving only the dye. Of course, we must use appropriate protective equipment. After this process, we obtain a beautiful etched chip suitable for other investigations. Because the chip has typically metallization on its top layers, we do not see any internal layers at the first. So, we must etch the surface to obtain these structures. And this process is called the layering. Again, we have seen on this slide four types of basic methods of the layering. Mechanical is the cheapest and starting at about $100. Chemical, when we consider only chemical, it is also not expensive. Laser ablation uses very short, precise femtoseconds pulses of laser beam to ablate the surface, but it is quite costly, starting at 50k USD. And the last, the plasma, this is simply the nanomachining using an ion beam, offers maximum precision, but comes, of course, with maximum price tag as well. Due to the cost-effectiveness, we choose to do mechanical etching with a wet stone. I just slide a piece of silicon with my finger over the stone. Of course, we must use a grinding stone with the highest possible grit size. In our case, it is 8000 grit. Of course, it requires some skill, and I personally mastered it around 10 samples. Too much pressure quickly obtains the background, and it means we must start again. But with patience and systematic polishing, we can obtain a beautiful etched chip within 30 minutes or one hour. Unfortunately, wet stone etching alone isn't enough. Our stone head grain size is about 2 microns, but for the final stage, it is necessary to use a diamond lapping foil, which grain size is less than 0.5 microns. These foils make a significant difference, providing a much smoother surface and, of course, reducing the number of scratches. I tried to prepare the sample on the industrial machine, costing around 60-65 TSD. And as we see on these pictures, mostly the same results can be achieved when I use wet knife etching stone and the lapping foils purchased on Aliexpress for 100 bucks. Another important task is to locate the eFuse memory bank itself. The largest part of the chip is taken up by logical circuits. It is easily identified and can be skipped. The other radio frequency part is good visible, too, and can be skipped. And the rest will have the rectangular purple areas, and these are memory types such as RAM, flash, and our eFuses. The eFuse memory cell is essentially a fuse, which is a conductive structure with a weak point. In our case, it's looking like some triangle with a line going through it. It's looking like a flag, maybe. And at approximately 500 times magnification, clear, repeating, isolated structures of our eFuses become visible. They are relatively small, and each eFuse represents one bit smaller than one micron. We have successfully located these eFuse banks on ESP32 version S2, S3, and C6. It is positioned slightly differently on the C6, but the construction is the same. And now optical microscopy. Observation with optical microscopy has its limits. Maximum resolution of optical microscopy is around 400 nanometers, which corresponds with 2000 times magnification. That is nearly physical limits. This magnification is suitable for locating our structures, our eFuse bank. And on well-prepared sample, we can even see if the eFuse is burned or not, or programmed or not. The term burned is fitting, because when we program data into the eFuse memory bits, during programmation, current flows through the eFuse and physically change its structures. And these changes are observable by optical or scanning electron microscopy technology. For the size comparison, a human hair is 100 times bigger than our eFuses. In order to read their states correctly and repeatedly, we of course need some much more advanced imaging technique. And it is scanning electron microscopy, which provides much higher resolution. Scanning electron microscopy provides approximately 100 times better resolution. As I said, since optical microscopy has a resolution around 300 nanometers, scanning electron microscopy has a resolution approximately 5 nanometers, which corresponds to magnification 100,000 times. Of course, these parameters can apply specifically to our scanning electron microscope. It is Hitachi FlexSAM. The image compares the level of detail we can achieve with these methods. And the difference is significant. This is what the eFuse looks like at even higher magnification using a large electron microscope. And this image shows their 3D structures, which essentially looks like a printed circuit board. Everything is visible at the nanoscale. On the right image, right bottom, we see detail of unburned eFuse, clear eFuse, representing logical zero. And on the left image, we see burned eFuse, representing logical one. Once we obtain higher resolution images of our eFuses, we can read the data stored in them. In my initial experiments, I manually transcript the data to the Excel bit-by-bit, fuse-by-fuse, which was extremely time-consuming. And it requires intense focus to avoid error because bits look very similar. It takes about 10 hours to read one bit of 4,096 bits. And additionally, mapping the logical memory address to a specific cell on the silicon die was also very, very challenging. I had to carefully read and transcript about 20 kilobytes of data before we had enough for our analysis. It truly feels like a forensic investigation. And now my colleague demonstrates how to assign a logical address to a physical location of a given memory. Please, Martina. Thank you, Michal, for extracting all this data during your vacation. Now that we have the raw data, we have to somewhat put meaning to it so that we have some useful information out of it. The best place to start with is documentation because it actually mentions a lot of information about both logical and physical alignment of the memory. From the logical perspective, it will tell us that there are 11 of eFuse blocks and that 0, 1, and 2 are used for system purposes. These basically store MAC address, chip ID, and chip configuration that you can set. The rest of the blocks are user programmable, meaning you could put whatever you want there. However, their primary purpose is actually to store the secure boot keys or the flash memory encryption keys. From the physical perspective, the information is a little scarce, but it will tell us that there are four backups of block 0, meaning that any single eFuse burned in block 0 will actually result in four actual fuses burned. And blocks 1 to 10 are using Reed-Solomon coding scheme for automatic error correction. This is just 12 bytes added to each of the blocks, but it could prove useful in case we cause some damage during the layering process, so we'll talk about that briefly later. So with that, let's summarize what we want to know. We have a lot of bits. We now need to assign them to the bytes. Then we want to take those bytes, put them in the correct order, and have them assigned in the blocks, and then voila, we will have our flash memory encryption key. To do that, we performed several experiments, and the first one was a really stupid one, and I came up with it. And it was like, let's burn values FF into the first block of an eFuses so that we can locate where it is. However, at that time, we didn't really know how painful it is to actually read them. So we kind of wasted this experiment, because if you burn only FF values, you can very well detect where the first block is, but you really can't detect how the bit assignment works inside these bytes and how the byte order works in the blocks, because that information just doesn't exist in such a memory. So we quickly transitioned to the second experiment. In this case, we were a bit smarter, so we burned in unique patterns into the eFuse blocks, and these unique patterns had something in common, and that is that the most significant bits of all of the bytes in these patterns were set to one, either three or four of them. This was because, just from an overview of the memory, if you look at the middle picture, the big one, you can see a lot of red color in the upper portion, those are the ones, and that the lower portion has a lot of variety in it. You may think there's an ASCII text written at the bottom line, at the bottom of the picture. There are no hidden messages, this is purely coincidence. But if we take the only useful information from the very first experiment and filter out in those Excel files the rows that were associated with the first block, we can clearly see our pattern. So in this case, we now know that the bits are organized in columns with the most significant bits in the upper portion of the memory, and we also know the byte-endianess inside the blocks. This is enough for us to just extract any information we want from these memories. We did several other experiments, mainly to confirm that the memory is working the same way also on the other lines of the chip, so we did on S2, S3, C6, as Michael was saying. And the third one I'm showing you here isn't really interesting from the memory layout evaluation, but it's rather interesting because of those white fields there. Again, I am to blame for that, because when you do the layering on the whetstone and you don't clean the whetstone, you have a debris that's left there, and when you keep scratching with your finger, you create these gigantic canyons in that memory, where the e-fuses are just completely gone. In this case, that Reed-Solomon automatic error correction could actually prove useful to recover the information. However, for future-proofing these methods, we rather spend the time on improving the layering method, because, for example, block 0 here doesn't have any automatic error correction, and the other chips don't have that as well. It was just that in the case of ESP32, if you do some damage to the chip, you can actually recover for it using this automatic error correction. So now, this image will show you the layout of the memory, so the full green row at the top and the bottom of the picture, and six others, full green rows in between, that's block 0, so that's where those four times duplicated values actually go to. For example, if you disable JTAG, that's where four e-fuses will be burned. And the rest of the colorful blocks, and I'm sorry for using too many shades of green, but I'm bad with colors. Anyway, the rest of the blocks here are the user-writable blocks. Most tutorials on the internet will just tell you, please put your encryption key into the purple one here, so that's where we will be focusing the most, but once you know the alignment of the blocks, it doesn't really matter which blocks you extract, you just get the coordinates from the extracted data. The biggest problem at this point was that Michael refused to read that manually anymore, after whatever amount of bits he read, so we had to turn to our machine learning guru to help us automate the process. His name is Hayan and he unfortunately couldn't be here with us, but he pre-recorded the message, pre-recorded his part of the presentation, which I'll try to play now. There's about a 50% chance it's going to play. If it does not, I will still play it and I'll try to comment it, so you will not learn anything useful. So, let's see. Hello, I'm Hayan Ali, security delivery senior analyst in Accenture, and also I'm doing a PhD in using machine learning for violin clubs. I will go through the automation process and show you finally a demo about it. Let's go. Instead of a visual reading of the effuses from the images, we automated the process. We started from the output of microscope, where there are around 200 images for each one. First, we stitched these images to get only one image per bank, then pre-processing before applying the machine learning, then applying the machine learning object detection model, then extracting the effuses values into the arrays. The microscope provides high-resolution images when working in zigzag mode. In zigzag mode, the microscope scans the bank in zigzag line, as we see here in the figure, generating around 200 images for each bank. Each image is 2,560 by 1,920. We can see this image is high-resolution image, as we can distinguish between the off effuse, which is the default state, and the one which is the on case. We keep margin by 35% between images to avoid wasting any pixels. Then we stitch these images to get one image per bank. But when using the embedded stitching tool in the microscope, we get bad stitching. For example, there is misalignment between zero and 1, or 2-1, 2-2, or between first row and second row. The reason behind this misalignment is that the margin is theoretically 35%. But practically speaking, it's something random around this value. That's why we suggested a new stitching method. In this method, to stitch two images, one and two, we define a comparison step in the first image and look for the similar step in a stitching area in the second image. A stitching area is plus-minus 200 pixels around the margin line. When defining the similar step, we determine the margin accurately, and also there is a vertical shift between images. Here we can see the result of stitching image one and two. The advantage of this method is to accurate, but downside is the long time it takes. For example, to stitch 200 images to constitute one bank image, it will take around five hours. Here we can see the result of stitching for one bank image. Its high resolution image is 34000 by 12000 image. To effectively use AI to extract the fuses, we use Jetson SGX Orion from NVIDIA. It has 64 gigabyte RAM and 2048 CUDA cores and 64 tensor cores, which makes it good for the image-based AI projects like object detection projects. We use also MobileNet SSD model, which provides a balance between speed and accuracy. This model is trained to detect effuses in the images in terms of the coordinates of the effuses in the images, and also it's a class whether it is on or off. Here we see the example of on effuse, and this is off effuse, which is the default state of the effuse. What is the optimal input of the model? We read from the MobileNet SSD model documents, the optimal size for training and also for inference is 300 by 300. Also, we should meet another condition, which is the object, which is effuse size to the image size, should be bigger than predefined ratio. This ratio, in our case, is defined using practical experience. It is 0.04. Here we can see the example of the optimal image, and we can see also the size of the effuse regarding to the image size. We meet these two conditions using resizing and tiling. When tiling the stitched image, we keep 100 pixels overlapping between tiles to be sure that the whole size of effuse is exist, at least in one tile. When training the model, we used 3,500 training tiles with balanced number between on and off effuses. We used CVAT tool, which is a web-based AI free tool to annotate effuses. Here we can see an example of annotation. We use different colors when drawing boxes about the on and off effuses. The training results are detection accuracy 99%, classification accuracy 97%, and also we get fake detection where none effuse objects are predicted as effuses, but these fake detections will be resolved during the post-processing after prediction. Now, we have a stitched image. What do we do to extract the effuses? First, we tile this stitched image to 2,500 tiles, then we apply the inference using the trained machine learning model that inference results for each tile have three things. First, the convenience of effuses in the tile and also the classification of the effuses, whether they are on or off, and also the confidence score, which corresponds to how the machine learning model is confident about the classification. These three things, results from all the tiles will be re-aggregated again in the stitched image. Then, the duplicates will be removed with keeping only the highest confidence score. Finally, any effuse with a confidence score less than 95% will be visually checked. Finally, we will use dbScan clustering method to define outliers out of the columns and remove them. Then, we use another clustering method to group the effuses in columns and exporting their values into the arrays 1s and 0s. We repeat the same process for the another bank. As we know, there are lower bank and upper bank. Finally, we will get 64 by 64 array and then we'll go through the next steps as my colleagues explained. We will extract the encryption key from the array and use this key to decrypt the encrypted firmware. We will see these steps in the demo. Let's go. We have a firmware image where the main program prints periodically the sentence Hello Las Vegas. This firmware is encrypted. That's why when we look for Hello World, we can find nothing. Here, we will see the images of lower bank and upper bank of the chip holding the encrypted firmware. Here are the images of lower bank before stitching. Here, the image of stitched lower bank. You can see the high resolution of the stitched image. Now, we will apply the diffuse detection script. This script will go through the stitched lower bank and upper bank, do pre-processing, tiling of the images, and prepare the images to be optimal input for the model. These tiles will be stored in the folder for inference, this folder. Now, the script will run the machine learning model, which is trained. This model will do the inference and detect the diffuses, coordinates, diffuses classes on and off, and also the confidence scores of the classifications. Starting from the upper bank, then the lower bank, the script will store all of these inferences also in folder inference results. Now, the script will ask for visually checking the diffuses where there are different classifications due to tiles overlapping. For the lower bank, we have 11 diffuses should be checked. The checking should be whether the diffuse unbound means off or bound means on or not diffuse. For the upper bank, we have zero diffuses to be checked. Check visually if the diffuse with confidence score is than 95%. We have eight diffuses to be checked in the lower bank, and 13 in the upper bank. After that, the script will show us the distribution of the diffuses in the image. We can note that no all players, and also in the upper bank. As everything is okay, the script will export the values of diffuses as zeros at once. The script also will extract the flush key file which contains the encryption keys from the firmware, and here the 64 by 64 array of ones and zeros. We will use the flush key file to decrypt the encrypted firmware and get the decrypt.bin file which is the decrypted firmware. Here is the decrypted.bin file. We should look for hello world in this file, and we should find something. And here we are. Thanks. I will go back to my colleagues to conclude the presentation. Okay, I know it's 3 a.m in Prague, but Hayan, if you're watching, thanks for the video. Now to conclude real quick. If you have any information that you would like to store if you have an information that you would like to keep secret and you need to store it in a chip and you have a choice to do so, please do not put it in any fuse-based memory. In the case of ESP32 chip, if you want to encrypt the flash memory, and you really should if you want to, you have no other choices. So in this case, you should use countermeasures such as using a unique key per each chip, not just use the same key for every device. If you have a choice to store it in some HSM module, physical unclonable functional protected memory, or anti-fuses, whatever you have, it would be a better way, because an eFuse-based memory is just readable based on its physical properties, and the readability protection methods such as layering, they do increase the effort by putting obstacles in between the malicious actor and the information that you're trying to protect. They don't prevent reading. In this case, we had to destroy the chip in process of recovering this information, but since our goal was to recover an unencrypted firmware image, we didn't really care about that, because we don't need it to run, we just want to read the firmware. The assumption about the delayering being expensive, complex, and whatnot has basically been destroyed, because if you have a sink, a wet stone, and at least two fingers, you could do that in your home conditions, and if you also can rent a microscope on your local university for a couple hours to just scan some location on chip, then you can do the recovery of the information at home. So it's rather easy and cheap if you're willing to sacrifice a bit of your fingers. Are there two things I'd like to point out still? The first one is to thank to Espressif, because they allowed us to have this talk, and the communication with them was really smooth, so thanks for that. And finally, I'd like to admit to a lie, because at the very beginning, I told you that if you burn an eFuse from state 0 to 1, you cannot unburn it. I lied, because you can. But the processes around this are really complex and really expensive, so I'd like to keep this as a separate topic for perhaps next time, and we can transition into the Q&A session, which, as I've heard, we will be doing as we will be going. But wait, we also have a giveaway. We have 20 decapsulated ESP32 chips in a vials that look like that they hold some bacteria, but we promise that they did not. And you could just take them and try the layering process at home if you want to, or just as a souvenir. So thank you for your attention, and we will be answering questions as we go.