Hello? Is this thing on? Hi, everyone. Welcome to our talk, Bites in Disguise. If you happen to watch this as it's being released by DEF CON, we want to thank you for tuning in on a Sunday morning. You brave souls. If you're watching this on YouTube at some point later on, well, thank you, you lazy f**ks. My name is Mickey. And I'm Jesse. I'm on the left. Jesse's on the right, just so you'd know to associate our faces with our voices now. We're both principal security researchers at Eclipseum, and we deal with hardware and firmware on a daily basis. Now that we have all the formalities out of the way, we can start with the actual talk. We'd like to start with a little bit of structure. What are we going to talk about? The agenda and high level. We want you to understand the background and the why, because it's very important for you to see things from a different viewpoint, our own viewpoint. We hope that by showing you what motivated us to look into this research, you'll be able to understand and maybe go out on your own and explore this yourselves. Once we've established that, we can show you what we did from an attack surface perspective, how we look at things from a hardware firmware perspective. After that, we can continue and walk you through some of the hiding places inside computers, servers, laptops, or any other computer platform. We thought about the best way to do this and we decided that it will be best if we start explaining each hiding spot and immediately after that, go through the attack surface scenarios and examples for that spot. Once that's all done, we'll discuss a little bit of what's in store for these types of threats in the future of the security industry and what can we do to protect against them. In the past, we've seen a lot of research talking about bad devices being abused like bad USB, rubber duckies, OMG cables, which are the best cables, all these malicious devices, dropping code, executing it from a separate device, hiding things off the platform. But the main issue is persistence. If your payload has to be plugged into the target to replay every time, even if it still stays undetectable, having a thumb drive stick out of your computer would be noticed by a user. You can't really hide that. So what if you could have your loader persistent and just have the payload itself, that's the malicious code, stored somewhere in your device. The easiest things to find about this type of research that was done in the past is fileless malware and fileless exploits and in-memory execution and anything that doesn't touch disk. And remember, don't touch disk. And one of those examples is a talk that was done last year at DEF CON by Topher and Mike that discussed about abusing this exact thing in UEFI variable. We usually describe this in the slide and say, look, past research done this and that. But since we know these guys, we thought we'd just ask them and record them and just replay it for you guys. So here's Topher and Mike. Topher is the left in the picture and Mike is on the right. So I hope you enjoy and help us embarrass them. Hey, I'm Topher Timson. Hey, I'm Michael Lebowitz. Last year at DEF CON, Mike and I gave a talk entitled EDR is coming, hide your shit. The reason that we did this research and gave this presentation is because we've been red teaming for a number of years now, and we were running into the problem that a lot of our malicious payloads and our malware were being eaten up by whether it be AV solutions or EDR solutions. And the blue team was discovering us and ruining our engagements. And, you know, when your lovingly crafted payload becomes some analyst sample, everyone's going to have a bad evening. So in looking at new areas in which we could hide our shit, we effectively wanted to get off of disk. The rationale for this was because having things on disk leaves it vulnerable to AV scanning it. It allows analysts to look at hashes of the binaries. The EDR solution sees that they're executing these binaries and all the activity that they're doing is shown to the analyst in whatever EDR platforms console they're using. In looking at ways to hide our shit, we looked into UEFI. So I used to do some UEFI security research. So I was already somewhat familiar with how UEFI worked as this firmware platform. And variables are something that were exposed after boot services. So they were available at runtime and actually booting the platform. Windows 10 re-added a UEFI API that allowed you to read and write UEFI firmware variables. And I had already known, or at least I had suspected, that EDR platforms were not at all scanning the UEFI firmware variable space in NVRAM. Everything that we had seen, it was all about what's on the hard drive, what's being executed from the hard drive, and we saw no notion of anything having to do with firmware. So we put our payload there, and lo and behold, analysts were completely blind and the EDR solution and AV solutions never saw our actual malicious payloads. They would see the binaries that we dropped on disk that would execute the payloads out of the UEFI variable, but those are seemingly benign and they're like four kilobyte binaries. In our talk, I handled the Windows platform piece, and my C-sharp binary to do reflective loading of a UEFI variable is like 15 lines of code, and nobody sees it at all in their UEFI platforms at the time. A couple of vendors have added some mitigations to this and are seemingly less blind, but it's still a problem facing a lot of these security solutions where if you hide stuff off of disk, they're not seen. As ever said, we want to muddy the water for analysis, and the analysis is highly correlated to the process image that you're running, and UEFI is an area that we're both familiar with, and UEFI access is available in Ring 3, and anytime you have delegated access in Ring 3 to something that is like a system firmware component, you're in for a good time. And I had previously done some research where I put malicious content into a RAM disk, and so now I had done this such that the malicious content was essentially benign and a very simple loader that could load the end payload from UEFI and then persist across the RAM disk boundary and then infect the EDR platform on the host system. So in total, a three-stage payload system with only one part, the tiniest loader on disk, but in a sort of awkward place in disk that's hard to find. And the whole rationale behind this was making it easier for offensive security practitioners and people on red teams to evade detection, because anytime you execute something to get that initial access, that will leave a lot of traces, particularly in EDR. But we were all about reducing that threat to detection for us after the fact, and by hiding your shit in places that these platforms are blind to, you can persist for longer. And in reality, what we're really trying to do is bring net happiness to the world, because we're now happy that we can persist for longer and run our engagements for longer, but the blue team's also happy because they don't have to work till midnight hunting us down. It's true as it is now, it was then, we need to flatten the curve, the curve of risk of you being detected over time. But no good thing lasts forever, and eventually your breach is going to get detected. But we just want that to go a little bit longer. Thank you Topher and Mike for that amazing summary. Just to recap some of the things that we want to emphasize here is, we want to avoid detection, we want to make it harder for forensic analysts to find our payload, we want to have code caves that we can abuse later on. Basically storing anything in non-conventional storage that the analysts are not looking at, hiding their blind spots. A little bit about UEFI variables. We've seen last year, we know EDR and AV have started looking into these and now we've seen Microsoft adding capabilities, we'll talk about them later. But using get and set variable is something that an attacker uses that is exposed by the Windows API, which is nice and handy if you get that coveted admin privilege, but it's not that handy when you are worried about AV and EDR hooking and monitoring your behavior. So think about it like this, these API calls are not commonly used and if you call them, you will raise so many red flags, you just want to hide under a rock. But under the hood, these API calls are basically a Windows wrapper to something called Runtime Services. UEFI-based BIOS has these function calls in memory, which are called Runtime Services that are obviously, well, as the name suggests, they're available during runtime, but they're only in ring zero, which means the Windows API calls those Runtime Services from a ring zero context. However, if you as an attacker can get code executing in ring zero, you can call those Runtime Services directly. The trick is they have a magic header in memory that you can search for and then you can find the Runtime Services table and then from there extrapolate the calls for setting a variable and getting a variable. All that's nice and dandy in theory, but to get that running in ring zero with modern protections that Windows is incorporating is going to be tricky. Okay, first step in understanding what we have at our disposal is do a proper attack surface enumeration or proper scoping. Let's talk about some of the ways that you can do that. First and most obvious way is to get your hands on your machine and pop open the box and look at what you're attacking. It can be a laptop, desktop, server, industrial controller, whatever you think falls under the definition of the word computer. But whatever you do, for the love of God, remember to unplug it from power before you take it apart. Some of the key things to remember when you take things apart. Remember where you put the screws you took out. Don't lose them. Remember which screw goes to which hole because some of them are longer than the others. And for some diabolical reason, vendors tend to not adhere to the same standard across devices. So while Dell laptops tend to have the same length of screws holding their chassis in, some other third-party vendors would have, and I shit you not, 14 different screws that have six different lengths in the bottom of the laptop. Also remember to group them and label them. And if you have any static electricity, remember to dispose of it. If you don't have any static electricity, you know, wristbands or anything, just YOLO and hope that you don't break your machine. Once you got it open, you need to get a magnifying glass or a jeweler's loop. You can pick these up at like a couple of bucks on Amazon or eBay. Many computers have a lot of chips that look similar and have some very similar markings. For example, spy chips made by Windbond will have very, very similar labels on them, but you'd find a couple of them on the same computer and when you won't be sure what's what, we recommend that you take a picture. Use your phone. You have this device that gives you access to all the cat images on the internet. Use it to take pictures. If you can label the pictures, label them, but just take a picture of it with your phone and save it for later. I know this sounds basic. Everything I say sounds super basic, but these are things that you'd wish you'd thought of at some point. I myself had written these down and it's lessons learned in blood. If you're afraid to open your $1,500 laptop, don't worry. Someone on the internet has probably done it for you. So you need to google the shit out of teardown images. Seriously, start googling the words teardown or memory upgrade or SSD upgrade or any of those and you'd find a lot of repair shops or repair tutorials or upgrade tutorials online that have HD videos and images of the computers you're looking at. You might not be able to go down to the very low resolution of what chip is what in what capacity, but you'll be able to get a sense of how many exist or how many you can risk opening your laptop for. If you open it and it's only like a BIOS chip and one more versus six others that you suspect might be holding firmware, then your risk assessment about opening it might change. One more option is look for schematics. Now, it's a bit of a weird adventure and you'll find yourself entering the world of repair shops and schematics websites in Vietnam, but you'd be able to find a lot of PDFs that describe how devices interconnect including non-volatile and firmware storage devices. You might be finding a lot of EEPROMs that are on the board and the schematics will tell you exactly what address you need to communicate with to read or write from, which SMBus line has what controller allows you. It will basically allow you to understand which device does what and how. I wouldn't put too much effort into this attack surface scoping method because schematics tend to be confidential and secret and if you happen to find one of a more recent platform, it's going to be really rare. But if you want to practice on an old one, buy a laptop from eBay and see if you can find its schematics. Go ahead, go for it. You could spend like 100, 200 bucks on this. My favorite part is looking for official documentation. And the biggest tip we could give you for looking for those is statement of volatilities or declarations of volatilities. The best way to do this is just google in quotes of volatility and just add the file type pdf and include the words flash or cmos or spy or whatever from keywords that you can find from other documents you will find in the process. These documents basically state what volatile and non-volatile components are in a platform. Now, not every computer has this type of document associated with it, but from finding these documents online, you can understand what is in most common platforms. Some of these documents contain hilarities like this one saying 128 bytes are protected by intel. The other 128 bytes are not right protected. So what the shit? Why would you put this in a document that tells me I have 256 bytes of non-volatile storage? Half of it's protected. The other half's not. Go have fun. Okay, we have a demo about that. Now, I wanted to put a picture of the pdf here, but I couldn't find a good enough resolution so I had to crop a snippet of the table. And the table that you see here is somewhat a representation of what you'll see in a statement of volatility document. You'll see a breaking down by type, size, if it's volatile, non-volatile, what's it used for, how to clear it. Sometimes it's not going to be documented on how to clear it or not. Sometimes it will be. There's sometimes in some platforms jumpers you need to remove and and put back. But the key point that I want to tell you here is even though you see documents saying is this user modifiable? Yes and no. You never know if it means is it user space modifiable or is it modifiable from a user at all. And whatever you do, as a rule to live by, always challenge the basic assumptions that you encounter in official documentation. Especially some that you can prove easily wrong. I can tell you that even though some of these are not saying it's not user modifiable, you will see in a few minutes a demo saying that it is. Yeah, to follow up on that a little, user modifiable in this case means that it's intended to be presented to the user to be demodifiable like the BIOS password. The user is intended to be able to modify this. But system software or other software running on this on the device could be modifying these components. It just is not making that directly accessible to the customer. It doesn't mean that it's not modifiable at all. Now that we showed you a way or multiple ways to find information and explore it by yourself, we can go ahead and start diving a little bit deeper into some individual components that we talked about before. We'll go through them one at a time and we'll describe them. And then we'll later proceed into explaining what the pros and cons are from an attacker's perspective. And hopefully we can have fun while doing it. First things first, remember that 128 byte that we saw before? If we looked at the CMOS example in the previous slide, it said it's not user modifiable. And I know Jesse explained that it's what the user can modify sometimes by using a GUI like the BIOS password. But I wanted to emphasize that whatever the document says doesn't literally mean what you think it means. You need to go double check. So basically, back to the CMOS topic. If you are young and you have no idea what CMOS stands for, I am jealous. If you are somewhat old and you had to remove a battery from your computer motherboard, my heart's with you. It's really a relic that's used to have settings set for BIOS bring up, for the system bring up. It's a tiny bit of non-volatile RAM that is only non-volatile as long as their current and that current is supplied by the little lithium battery on the motherboard. The main thing I've seen this used is the real-time clock. So you know how you have a power surge and the microwave clock goes out, but your computer has the same clock afterwards? Probably because it keeps that real-time clock timer going internally. In modern platforms, the CMOS is located inside the chipset. So you really can't see it. It's it's itty-bitty. Not like other chips that we're going to talk about later. The pros of CMOS is that it has a few unused bytes. You can access it through IO ports. You can do in-and-out instructions to get to it. It exists almost everywhere. The cons are that it's super tiny. It only contains 256 bytes separated to two regions, lower CMOS and upper CMOS. If you mess up the wrong bytes, you might cause yourself some trouble and you might need to reset the CMOS or fuck up the platform. We don't know exactly what each modification of each bit might might do, but it's well documented. And then if you want to go to explore what you can do with it, it's all over Wikipedia. One other thing that we we think might happen is that if there are certain PCR measurements done by TPM, modifying CMOS might trigger an alert. For example, BitLocker has PCRs it's monitoring and if those PCR change, then it goes into BitLocker recovery mode. In short, we're pretty sure you can you can have fun with this, but don't mess up bytes that are not zero. So you don't think we're full of shit? Here's a short demo of how to abuse CMOS. In the demo you're about to see, we have the steps written on the right. Basically, we read the CMOS, we write a random payload to the lower part of CMOS, you read it, so we show you that there is a change there. We restore it back and then we read it again to show that we changed it back. Let's go and run the demo. We're going to have the code for this demo up on GitHub after the talk is published and keep an eye on that GitHub because we're going to keep adding more and more code to it as we go on. So let's take a look at SpyFlash. In order to know where to start executing code from in the first place, that code is stored in the SpyFlash and when the system turns on it starts executing instructions from there. Traditionally that was known as BIOS, but these days almost all systems have transitioned over to using a UEFI firmware instead and this firmware is stored in the SpyFlash. There's a few different regions within the SpyFlash. If you have an Intel platform, you'll have a region for the manageability engine or the ME. It's also known as the CSME. AMD platforms will have a PSP region for the platform security controller. There's also a flash descriptor which contains essentially a map for how the contents of the SpyFlash are organized as well as access permissions for these regions. So taking a look at the the contents of the SpyFlash itself, there's a couple constraints that determine the location of a couple of the regions in there. First, when the system boots up, the top of that SpyFlash is mapped to the top of the four gigabyte address space in order for the x86 reset vector to start executing code from there. Because of this, the top of the BIOS region needs to correspond to the top of the SpyFlash. It can vary in size. So you can have a eight meg BIOS region or a four meg BIOS region. The size can vary, but the top of that region needs to correspond to the top of the spy chip itself. Additionally, the flash descriptor region, which is essentially the map and permissions and what is actually stored throughout the spy chip, that starts at the beginning of of the SpyFlash. It contains some platform configuration for the device as well as the map determining where these regions are stored within the SpyFlash itself. There can be some additional regions like the ME region. Some platforms will have a GigE region or an embedded controller region. There can be a platform data region which is for OEM specific additional components. The region mapping in the flash descriptor also doesn't need to include all of the contents of the spy region. So there can be some padding regions or padding areas that aren't actually included in the map as well. To take a look at the flash descriptor itself, starting at the very beginning of the spy contents, there's a signature at 10 hex, offset 10 hex, that is used to determine if there is a flash descriptor in this area. And then there's a mapping, there's a variety of different components and access control lists to determine if the CPU has access to read and write of a particular spy region, or the ME has access to read and write to a particular spy region, or the NIC, the GigE controller has access to read and write directly to that spy region. So those access controls are stored in the flash descriptor. So there are a lot of cases where the CPU can't directly read and write to the ME region. And most systems these days will have that BIOS region protected via hardware mechanisms in the chipset. Occasionally we run into systems where that is still not protected properly and you can just directly write to the spy and BIOS region from code running on the CPU. But even in the case that that BIOS region is properly protected, there can be bugs in the BIOS update mechanism itself. Sometimes that doesn't provide signature verification. Sometimes it will do signature verification for part of the region but still copy data into that spy flash for you. However, the gigabit region itself is generally unprotected and you have full read and write access to that from the CPU. We also sometimes run into cases where the flash descriptor itself has incorrect permissions and that can be rewritten via software to modify the existing region definitions or even define new regions in the spy flash layout and change the permissions for those regions. So if you have that issue, there's a lot of ways that you can take advantage of that. Another interesting storage location is the SPD or Serial Presence Detect chip in DRAM memory modules. Although some recent devices like laptops and tablets only have soldered down memory which is not replaceable, the vast majority of systems include replaceable memory. There are a lot of different types of memory. There's a DRAM2, DRAM3, DRAM4. Each of these different memory modules have different parameters or configuration that needs to be done in order to be used. And the SPD has been created as a standard way for a replaceable memory module to provide this information to the system so that the system knows how to talk to the memory module and use it. So the SPD is essentially a tiny EEPROM on those DRAM memory modules. It includes both the memory module type, like if it's DDR2, DDR3, DDR4, as well as the size of the module itself. There's information about the layout of the memory module as well, including the number of banks, if it includes features like ECC, as well as timing and voltage requirements that are necessary for the system to understand, to know how to talk to and use this memory module. When the system is booting up, it reads this SPD EEPROM in order to determine this information so that it knows how to configure the memory controller. Modifying certain parts of this configuration data can cause the system to not boot up anymore and the system just will be bricked until this module is physically removed from the system. In some systems, this SPD, the lower half of the SPD, which contains this critical data, is locked. Sometimes that's not protected though, and modifying that region can can brick the system or cause other unexpected behavior. But generally, the upper half of that SPD is writable and we can use that to store small amounts of data for payloads, such as encryption keys or other interesting data. So for accessing the SPD, we need to have it unlocked. It's essentially an SPD EEPROM that is connected over an SMBus interface. So there's an SMBus controller in the chipset that is used to talk to this SMBus device in the memory module. That includes a protection mechanism to prevent writes to it. And if that bit is set, we can't write to the SPD itself, but we've run into systems where that bit is not set properly. It is a very small amount of data that you can store things in, but there are some usage scenarios where that actually makes sense and you don't need a lot of data. And there are also attack scenarios where maybe bricking a device makes sense in the attack class. And we want to make sure that people understand that that is also a concern, that if you can write to this SPD, there are bricking scenarios that can come into play here. Next, we have USB controllers. Now, these USB controllers that could be found on your motherboard or part of an external PCI card that is plugged into your motherboard or part of an external USB-C device that is connected to your computer or M.2 modules inside your laptop. Some of these have updatable firmware and it's depressingly common how many of these have unsigned firmware updates. And you as an attacker can store whatever payload you want on them. For example, we can have not just USB controllers that exist as USB bridges or on your motherboard. It doesn't have to be a USB controller. It will be actually a PCI device that exposes a USB 3.1 interface. If you have USB-C ports on your desktop, most likely you'll have one of these PCI to USB components. Not necessarily all of them are PCI to USB. Some of them are USB to SATA. For example, there is an external hard drive enclosure that has this exact, well I won't say issue, but exact design which has a controller that talks over USB 3.1 on one end. On the other end, it talks to a SATA hard disk drive and it has updatable firmware and you can update that firmware from from the computer. The next demo we have is one of these USB controllers embedded in your motherboard that we update the firmware to include a malicious payload, in this case a Metasploit shellcode. So what you're going to see is a program that we have adapted to read the firmware from this USB controller, load it into memory and execute it. And I know it's going to look dumb, but we're basically we're clicking on a file that's running as admin and then we get a connect back in Kali. It's not dumb, I promise you. I'll show you the code right after. Okay, breaking down the video you just saw, on the right side that the we have a binary visualization of the firmware image we're writing to the device to save our payload. What's circled in red is the actual Metasploit code that we have in the firmware. What's colored black is empty space. Everything else is actual code. So you'd see there is about a third of it, almost half of the image. It's 128 kilobytes. Out of that, so much space is is empty for us to use as attackers. The fact that I put a few hundred bytes as payload for a demo looks tiny. If we look at the the code that we have loading this exploit, the first part gets the hidden bytes looking for a magic header, which is leetleet, because obviously. And once we find the leetleet, we fill up a buffer with the bytes from the firmware. After we have the payload, we're loading their payload from UEFI. But in this case, we use interoperability and marshalling, so there's no p invokes. Topher helped us speak this up. And we load them in memory and we execute them. Simple as that. All this code is going to be available on GitHub. Generally speaking, as an attacker, you'd break this attack into two distinct steps. One is hiding the payload. The second is retrieving and running it. When you hide it, you have to get the firmware image, incorporate your payload in the firmware image in bytes that will not disrupt normal behavior or functionality, and upload that new image to your target device or firmware. When you retrieve it, you have to read the firmware like any other mechanism or use the built-in mechanisms or known tools, extract your hidden bytes, and then do the malicious. Let's review a little bit of the attack surface from an internal asset perspective. You have USB controllers that are embedded in your devices that have their own firmware. You have PCI bridges that act as PCI to USB devices. You have trackpads and touch points and touchpads. If you have a ThinkPad Lenovo, it's a point. I don't know what it's called. You have one of those trackpads. It can have sometimes its own internal flash. The monitors you're using, if you ever plugged in a USB cable from your laptop to your monitor, just so you can use the little USB hub on the side of the monitor, if you're one of those blessed few that do that, then you should know that that monitor has a USB hub in it, and it has firmware. Most likely you can modify it from your computer. Webcams tend to have firmware related to them. Fingerprint readers, accelerometers, integrated sensor hubs, power delivery systems, power management ICs, everything you can think of that's inside your computer not necessarily has a separate component to hold firmware, but it most likely has some internal firmware either on the integrated controller or off it. You like to add something, Jesse? In addition to these controllers, there's also all of the endpoint devices themselves. There can be a wireless network card or a cellular modem, and these are often PCI or USB devices themselves that also have updatable firmware. In addition to the controllers, there's generally USB devices or PCI devices in the system itself, and then all of the other fun stuff that Mickey just talked about. Speaking of wireless devices and external assets, there is also all the stuff that you have that you can possibly plug into your computer. Think of all the ports you have on your machine, if it's your laptop or if it's your desktop or whatever device you're looking at. Whatever ports you can use, Thunderbolt 3, USB-C 3.1, whatever USB format it is. Proprietary connectors for docking stations. Docking stations have a lot of parts in them that have their own firmware. So, ask yourself, how often do you check the firmware on the dock that you plug your laptop to at work? And then, obviously, the over-the-air updates. In addition to the Bluetooth controller in the motherboard itself, you might have Bluetooth devices that are commonly paired with your system, like keyboards and mice and wireless headsets. Sometimes those have firmware as well. That's probably less likely to be an attack scenario because they're less universal than some of these other things that we're talking about, but it is something to be aware of and keep in mind. Another example that we think is something that we should all pay attention to is the Gigabit Ethernet. If you have a LAN port on your laptop, congratulations, you have a code cave. In most, I think, the almost every instance that I've encountered of a Gigabit region in SpyFlash on a system, it was read-write capable. I have yet to encounter one instance where it's, if it exists, it is read-only. This region in in SpyFlash usually contains the configuration data for the device. Stuff like MAC address or any other setup configuration that was initially set up by the vendor manufacturing the computer or selling it. Usually, there are two images. One is the one being used, the other one is a backup, and there are so many unused bytes in that region that we'll show you in a second, but it's really open for abuse. Now, some systems are mandated to have such things like servers, for example. There's no server without a network adapter connected to it, and if it's an Intel platform, you will find a GigE region in Spy that you can read and write from. If you have a desktop computer and you bought a Gigabit Ethernet card that you plug in, sometimes these devices will expose their internal non-volatile memory to the user over memory access. So, you would query the PCI device, get the PCI config space, find the base address register where the flash is mapped to, and then you can read and write directly to the flash over memory. There's also other discrete PCI devices, but we'll not talk about them right now. Let's look at an example of the GigE region in a HEX editor. First region would have the main data, and then we scroll past all the unused bytes and empty bytes, and then we get to the backup region that has the backup data, and then we keep looking and there's a whole bunch of other empty bytes. If we take a closer look at this example, which we have eight kilobytes of data, 72 and a half percent of it is not used, which is quite a lot of space. And if I were an attacker and I had a known point to hide payload or data on every common platform on the market, this would be a very, very good piece of information to have. But how do we access it? I mean, it's great. It's in SPI Flash, but how do we read and write from it? The easiest way to do this on Intel platforms is using the Flash programming tool. It's an internal tool that it's not supposed to be public, but you can find it on the internet. I'm not going to say where, but you can use it to update your BIOS and update your ME. Some vendors might have it in their update packages, some don't. There are other utilities. If you have a card made by a different brand manufacturer and you look for firmware updates, for example, if you have like a Broadcom card or an Intel card or any device whatsoever, any card that you find the firmware updates for, always, always look for the same updates for the same hardware on a different OEM. If Lenovo has an update for a Broadcom-based card and Dell has an update for the same Broadcom-based card, you would see two different software implementations. One of them might include a pre-existing tool that you can abuse or use to your advantage. Now, the best part of this, in my eyes, it's the Confused Deputy. Now, last year, we gave a talk about how drivers in Windows are screwed, basically, and you can abuse a lot of these firmware updating drivers to gain access to lower levels of the platform. And a lot, a big number of those would have access to IO ports. And given access to IO ports, arbitrary IO might not seem like a big deal at first, but once you think that, once you remember that arbitrary IO can give you legacy PCI access, and with legacy PCI access, you can do a lot of things like hardware sequencing into the SPI controller on Intel platforms, and that some of these drivers, if they are loaded on the system, some of these don't require you to be an admin to send them IOctals, this becomes more and more realistic as an attacker, from an attacker's perspective. Let's see a demo of how we can read and write to the GIGI region on an actual computer with a custom payload, or just a demo payload that we have. Here we see PowerShell prompt where we dump the GIGI region, and then we clear the screen, we show that the end of it has nothing but Fs. Now we're going to flash a malicious version, well, so-called malicious, just for demo purposes. At the end of it, we put the ICAR test string and just explanation of this might be malicious code or shellcode. Now we flash it. Now it's flashed, that data is on the computer now. We dump the new content, we're checking what's in the new content, to be sure we're not checking the same one we wrote, and we find our malicious payload there. So just to recap, we dumped the GIGI region from Spy using existing tools, modified it, added our own malicious payload, flashed it back onto Spy, and read it back again to make sure that we have the changes persist. A few tips and tricks of how you can hide your payload in firmware. If you have empty regions like we showed you, you can just add your payload there, you won't touch the firmware. Usually what happens when firmware is signed or validated, it will only verify the block of code, it won't verify the whole image. So if you have, let's say you have 128 kilobytes of SpyFlash for your controller, and the firmware image is 60 kilobytes, the image would have a header defining where it starts, where it ends, what parts it includes, what segments, and it would also include all the verification fields like signature or cryptographic signature or CRCs or whatever is included. But past that, there is empty space that is not included or not defined. But when you read and write the firmware from the controller, it would read and write the whole chip. Another way is if you have unverified firmware, you can put your payload inside segments of the that are empty. So if someone built a firmware with a lot of padding in it, or there's different segments that they kept a lot of padding in there, you can abuse that if it's big enough. If it's not big enough, and you need a lot of small segments, you can easily break it down to multiple parts with magic bytes. Like we've seen in the demo before, you can load your shellcode with a magic byte and magic sequence of bytes and then a length to read from, and then you can all concatenate it later into your own shellcode and execute. For this talk, we're going to release some code on GitHub, and it will give you the capability of doing a lot of things low-level again, but with specifically reading and writing firmware. The practicality is that a lot of people are probably saying, well, what's the point? You got to be admin. This is all bullshit, but not necessarily. Like we said before, some drivers, if they exist on the system, they can be accessed from user space. So all you have to do is just see if the device exists and send it iOctals. Another point to mention is this scenario is relevant if you already have execution on the target. There's no point of gaining persistence or hiding your payload if you're just getting into the system. A big focus on the confused deputy angle is where we have a lot of signed drivers and signed tools and existing tools that allow you to do a bunch of actions that you normally wouldn't be able to. There is a lot to explore there. There are a lot of, for example, Dell has .NET tools that are used to communicate with the monitor and update firmware on it. It's not necessarily admin privileged access, but you can literally go and see how your code can interact with some other vendor code to communicate over USB to a device and read the EEPROM content on it or write to it. We are going to release some code on GitHub to use some existing code that we found that might help everyone to play with this even further, specifically in C-sharp because C-sharp is the new Java. I guess it's easier to understand. It's managed code. Why the hell not? In our example, we're releasing code that uses the PMX driver, which is included in a lot of Intel utilities. It is dating back to 1998. It can read and write physical memory. It can read and write debug registers, control registers, model-specific registers, IOs, and so much more. You can load it. If you're admin, you can load it in Windows and play with it. Imagine read, write everything, but not read, write everything that was blocked by Windows. It's confusing, I know, but its name was read, write everything. We will also release code that's using AceMedia tools. There is a tool made by, and I hope I'm not butchering your name, Stefano Moioli, and it's a tool released on GitHub that reads the firmware off AceMedia chipsets, very common chipsets that are found in a lot of places. And that code can be used to adapt calls to the driver that you can load, or can be adapted to write the firmware to the device. In the demo we've shown earlier, we've used Stefano's code to read the payload from the firmware and execute it in our own custom program. We also used update tools from AceMedia to write the malicious firmware into the device. Funny story about AceMedia controllers. I bought, for the talk, I bought a couple of devices off Amazon. Both of them are AceMedia controllers, and I have an Intel NUC, it's called Hades Canyon, it's a NUC8. Anyway, I decided to plug in the Thunderbolt controller to PCI adapter that I have, plug in the PCI cards, and connect it to the NUC and work on the demo. And I'm like working, having fun, writing malicious firmware images, reading them back, writing, flashing it, flashing new ones, flashing backups. And then I realized I have two controllers. Yours truly has not noticed that I have a built-in onboard AceMedia controller in the NUC, I've been flashing that the whole time. Talk about a scary moment right there. So yeah, it's a funny story. I don't want to be all doom and gloom, but I have to be all doom and gloom here, because nobody is looking in the firmware. There is so much space in non-volatile memory. I mean, if you look at it in bytes, it's not a lot of bytes, but it's a lot of bytes that are not supervised. Is EDR catching up? Well, yes and no. Microsoft Defender has released a couple months ago, a press release and notification that they are now looking into the UEFI file system, which is awesome. But why just UEFI? There's so many other places on the platform that you can look into. I mean, great. We have EDR is coming, hide your shit talk last year, where Topher and Mike showed that they can hide malicious payloads in UEFI variables. And then less than a year later, all of a sudden EDR is looking in UEFI variables, but that's just the tip of the iceberg, right? We have solutions coming out. Like we know Dell has a BIOS scanner, CrowdStrike scans firmware, HP has their own hardware, the SureStart solution that is literally a hardware root of trust on the platform that scans BIOS, verifies the BIOS image, verifies a lot of parts in it, including all the Intel parts as well, BootGuard, BIOSGuard, all kinds of solutions. We have open source firmware solutions that allow you to update to legitimate images to make sure that you're up to date and check by Richard Hughes. But beyond the BIOS, beyond the firmware on the SPI, big parts of the firmware on the SPI, no one's doing anything. There is external devices firmware and internal devices firmware, and a lot of stuff that you can see in the volatility reports that do not fall into the SPI BIOS regions that are not verified. And also like this, like Microsoft's, it is Defender ATP, so it's not rolled out everywhere. It's only that the premium version so that you need to pay more for. What can we do about it? We can use OEM tools or vendor tools to read the storage, to access whatever non-volatile components we have on the platform. If they exist, some tools exist, we can hack some sort of interface to vendor tools or we can adapt existing tools like open source code from Stefano and the SASM tool on GitHub or Chipset that allows us to access the CMOS, GIGI, SPI, SPD, a lot of things that we can do there. And maybe we can add open source tools that check for everyone's safety and help notify vendors that not only do you have to verify the firmware image, but you also need to check all the unused space on firmware on your non-volatile device just to see that you're not being abused here. And with that, we've reached the end of our presentation. Thank you for bearing with us and watching the slides while we talk. If you have any further questions that you'd like to ask us, feel free to reach out on Twitter, Discord, Slack, whatever will be available to answer questions for this talk on the DEF CON Discord server. But feel free to ping us later on social media if you have any questions.