Good afternoon everybody. So my name is John Heisman. I work for NGS Software in the UK. If you've seen any of my other presentations over the last year, you'll know I've been focusing on rootkits and specifically rootkit persistence. And today I'm going to talk about EFI, which is Intel's replacement for the BIOS. It's currently available in MacBooks and likely to be available on most systems. Most operating systems are likely to support it within the next year. So this is what I want to get through today. To give you some background on EFI, I'm actually going to start by talking about a legacy BIOS. So I've got quite a lot of slides to get through, so I'm going to move quickly through the early ones, where I'm going to talk about what the BIOS actually has to accomplish. How we can attack a traditional BIOS. The limitations and basically the motivation for Intel developing EFI. And then we'll talk about some EFI-specific attacks and also the relevance of the attacks against legacy BIOSes. Then I want to talk about UEFI, which is the kind of successor to EFI. It's the next version that the consortium is working on. I'll summarize and draw some conclusions. Firstly, I want to make a few caveats here. As I said, I'm interested in talking about rootkit persistence. I'm not really interested in what the rootkit does. So essentially, I want to persist a rootkit on some device, in some firmware. I don't want the rootkit to be on disk. However, I do want it to be able to load automatically. So my rootkits have no bootstrap component on disk. They persist in firmware. And they're able to load themselves into the kernel, typically before the operating system has finished booting up. And so I'll show you a few ways of doing that. I'm not going to talk a great deal about trusted computing in this talk. When we talk about UEFI, I'll mention it. But the EFI spec certainly doesn't mandate that you have a TPM, for example. And many MacBooks, some do have a TPM, some don't. Some of these attacks require physical access. Depending on whether you're able to flash the firmware. For example, whether you need to flip a jumper. And all of the attacks are likely to require root access and or kernel access. And the kind of threat I see for this is a blended attack. Whereby stage one is we compromise the user system. We then carry out some information gathering to work out exactly what chipset they have. And then we actually... Go ahead and deploy our rootkit and firmware. And I'd also say that parts of this work are definitely very much work in progress. So moving on. The role of the BIOS. So the BIOS is probably one of the least understood parts of the system today. We know a great deal about how... You guys know a great deal about how the bootloader works. How the operating system works. But the BIOS is kind of a bit of a... Grey area. So when you turn your system on. The CPU starts executing from a fixed address. And ultimately it knows pretty much nothing about the hardware in your system. It actually doesn't even know how to access RAM on your system. So one of the first things it will do is start issuing read cycles for the reset vector. The firmware address. And those will go to the north bridge. Which will basically direct it to the firmware device in your system. So for example the firmware hub. The first few instructions executed by the CPU. Will actually set up the north bridge. So that we can then access memory. Will then go ahead and set up the south bridge. So that we can then start querying devices. And see what hardware we have in the system. Another key part of the BIOS is to set up PCI devices. And in this talk when I talk... When I mention PCI. I'm actually talking about PCI, AGP and PCI Express. Because essentially the area I'm interested in. The expansion ROM mechanism is common to them all. So the BIOS will scan the PCI bus. And will attempt to locate option ROMs. Option ROMs are simply x86 code that needs to be executed during the power on self test. In order to configure the device. The BIOS also provides the familiar setup screen. So we can configure the boot device priority. And we can persist those settings to non-volatile RAM. And finally the BIOS will then hand off to the bootloader. So here are four ways we can attack a legacy BIOS. Here are four ways we can persist a root cap. Firstly we can reflash the firmware device itself. We can just reflash the BIOS. I'm going to go into these in detail on the next slide. So I'll just run through them quickly now. A second attack is that we can modify the option ROMs on PCI devices themselves. And then reflash the device. The third attack is different to the first two. In that we're not interested in modifying code as such. We're interested in modifying some of the data modules that are stored in the BIOS. And this attack modifies the advanced configuration and power interface tables. And then the fourth attack I want to talk about is kind of different to the first three. In that though the majority of my talk is about persisting in firmware. This attack shows how we can persist in memory and survive across reboots without touching firmware or disk. So the first attack, patching the BIOS. We have a huge amount of freedom in what we can do. But ultimately the job of the BIOS is to get the bootloader going. So if we can subvert the bootloader which loads the kernel then we can likely deploy our root cap. The bootloader has to rely on a set of services exposed by the BIOS. And these are exposed through the interrupt vector table. And you'll probably know that when we're executing the BIOS code this is 16 bit real mode assembler. So if we can subvert the interrupt vector table. If we can hook an interrupt that the bootloader will rely on. Then ultimately we can get our code executing in the bootloader. And then we can basically patch the kernel as it loads it. So quite simply we find where the BIOS calls in 19 hex to pass off control to the bootloader. And before this call the IVT has hopefully been constructed at this point. And then we can go back to the bootloader. And we can simply hook the required interrupt. I'll talk more about which interrupt we might go for on my next slide. Some caveats. We may require physical access as I talked about. And some vendors Intel and Phoenix for example have secure flash these days. Which means that we can't necessarily update the firmware with an unsigned update. And of course if we have TPM in the system. And it's linked into a secure boot process. For example BitLocker on Vista. Then we may not be able to update the firmware and get the machine to still boot correctly. Simply having a TPM in your machine but not using any of the secure boot process. Then we can go ahead and flash the firmware. The TPM is simply a device to measure things like the hash of the BIOS for example. So simply having a TPM in your machine doesn't offer you any protection. You have to have the whole secure boot process. The second attack is option ROMs. As I mentioned briefly earlier. Option ROMs are simply ROMs on a PCI card that hold some initialization code. They can actually be for any architecture. But ultimately they're likely to contain x86 code. Option ROMs are copied to RAM during the system post. And then simply executed. So they're just blobs of x86 code that are taken straight off your card. Put into memory and executed. And they'll be stored in a storage. So it's either an EEPROM or an EEPROM. The difference being whether we have to actually remove the chip off the card to flash it. And here's an example. If you have a PCI express graphics card. It will likely have an EEPROM. And the initialization code will basically install a handler for int10 hex video. And that handler will implement the VGA and the VBE functionality. So to attack an option ROM. Ultimately we need to dump the option ROM off the card. Alternatively we can go to the vendor's website. So for example if we're talking about a graphics card. And you've updated the BIOS on your graphics card. You know how easy it is to download a tool to do it. And the BIOS from the website. We patch the option ROM. Again we're interested in subverting the bootloader. So we simply hook an interrupt. Which interrupt to hook? Well. EI released a proof of concept boot sector rootkit in 2005. And they demonstrated that if you hook int13 hex. As in the disk interrupt. When the bootloader starts loading some of the key device drivers in the kernel itself. Then essentially we can see that flow of data. And we can look for a byte stream and patch it on the fly. The approach I took when I was investigating putting rootkits on PCI cards. Was actually to hook int10. The video interrupt. Though this was a Windows specific technique. I noticed that the Windows kernel actually called int10 hex during the boot. And it's a relatively involved process. Because the Windows kernel is obviously 32 bit protected mode. And these are 16 bit real mode interrupts. So I found that the Windows kernel actually switched the processor into V8086 mode. And I was able to influence how it returned back to 32 bit protected mode. I guess my point here is that there are likely other candidates. The key takeaway is that the bootloader in a legacy BIOS. Relies on services exposed by the interrupt vector table. And if we're able to execute code during the power on self test. During the running of the BIOS. Then we can simply hook one of those interrupts that it depends upon. Pros and cons of option ROM attacks. Most PCI cards don't have any jumpers. So we can flash them pretty easily. The flashing process itself simply is doing IO to the card. So we just need root access. In both Linux, Windows, OSX for example. We don't actually need to get into kernel. Network cards also have option ROMs. And the option ROMs and network cards implement PICC. So the network booting. And this was a kind of nice idea. That we could make use of their network stack. So that we could actually do things like pre-boot updates. Of our rootkit. Before the bootloader kicks in. On phone, home, covert channels. Plenty of opportunity. One of the disadvantages is that we're limited by space on an option ROM. We can't simply dump the code that's there. Because your graphics card probably won't work. At least it won't work while the bootloader is working. By the time the operating system is loaded. We no longer rely on things like. The 10 handler. So the graphics card will work. But ultimately we want to shoehorn our code into some slack space. And I played with distributing my rootkit across multiple cards. But then obviously we're increasing the chances of detection. Or somebody removing a card. And us losing some code. And detection is fairly easy. It's very well documented. How to dump option ROMs off the PCI cards. In the PCI spec. And then we just apply some heuristics to analyze the ROM. And if for example we see that it has protected mode code. And as I said we're interested in. We're expecting the option ROM to have real mode code. That's a giveaway. Though I have come up with some ways of detecting the. Of subverting the detection process. As I'll talk about later. Using system management mode. It's possible to trap IO access. And basically give wrong results back. Okay moving on to the third attack against a legacy BIOS. And as I said many of these attacks are going to be applicable to EFI. Which is why I'm going into them now. This attack targets the advanced configuration and power interface. Which is basically a standard that replaces the advanced power management. And this handles all the power management. In everything from your notebook to a big server. And the way ACPE works. Is ultimately the BIOS contains some data tables. And these data tables hold. Virtual instructions. That are interpreted by the operating system. ACPE device driver. And ACPE is a standard. And consequently. There's ACPE implementations for pretty much every operating system. So the kind of nice thing here is that we're. Because we're using these virtual. Virtual instructions. We can actually make a root kit that's. Seemingly platform independent. So the way an attack would work again. Is to implement the ACPE. As I said the BIOS holds these tables. Containing ACPE machine language. The device driver interprets these instructions. So for example. If you press one of the hot keys on your laptop. Then ultimately that will result in. The ACPE device driver. Interpreting some of the AML instructions. That tell it what to do when you press that button. And the key thing is we can. Take the existing ACPE tables for a system. And we can append our own virtual instructions. Into these tables. And this allows us to pretty much. Exert full control over the system. So for example from the ACPE machine language. We can modify system memory. So we can patch the kernel. We can. We have full access to the IO space as well. So ultimately we would take a BIOS. Crack it open into its code modules. Its data modules. Locate the ACPE tables. Disassemble them. Into the ACPE source language. The high level language. That the platform designers use to make them. Modify them. To put our rootkit in there. Recompile them. Put the BIOS back together. And reflash it. Benefits as I said. The ACPE machine language is platform independent. It's these virtual instructions. That are implemented by the. Interpreted by the device driver. And as I said the ACPE source language. Is a high level language. And it's easy to disassemble. Between the ACPE machine language. That you find in the BIOS. And the ACPE source language. The ACPE device driver. By the time it's kicked in. Obviously the kernel is loaded. So this attack allows us to. Very easily patch the kernel. And also the fact that. We've got this virtual machine. Gives us an abstraction. So we can make some smart decisions. And we can future proof our rootkit. So at Black Hat DC. In 2006. I talked about a cross platform rootkit. That had some logic. That said are we running on Windows. Are we running on Linux. And did a series of tests. And made absolutely sure. It knew what the target was. Before then actually patching the kernel. Limitations. We need to modify the system BIOS. So again. If we have to have a signed update. Then this attack. Is mitigated. Also the operating system. Must have an ACPE device driver. Basically. If we can get hold of the raw ACPE tables. To then perform some analysis on them. Then we can spot our rootkit. So if we can stop the ACPE device driver. From interpreting our instructions. We can stop the rootkit deploying. And if you turn off ACPE. Your system performance is likely to suffer. But your operating system will work. And finally. This is one thing I noted. When I did this on Windows. Ultimately I was getting a load of event log messages. That were warning me. That the ACPE device driver was doing things. That could compromise stability. Because I was patching the kernel. And so ultimately. You could come up with some mitigations. In the ACPE device driver. That sandboxed what the interpreter was allowed to do. Because quite frankly. You shouldn't be patching certain areas of memory. You shouldn't be patching kernel code pages. For example. Okay. One of the privacy biases. Is warm reboot attacks. So the last three attacks. Require us to make modifications to firmware. Which kind of makes detection easier. And if we think about it. If you take the case of say a web server. Or a database server. They probably have SLAs. That mean that these things aren't turned off very often. They might be warm rebooted. Say once a month to install some patches. But the only time you might actually. Remove the power is to. Replace some hardware for example. So it may be sufficient for us to. Try and persist in memory alone. Without touching disk. Or firmware. So it's pretty easy to do this. Because what we actually find. Is that when the CPUs. When you first cold boot the system. Those first few memory accesses. That go to the firmware hub. Get cached in RAM. For speed. And when we warm reboot. Ultimately will actually just execute out of RAM. So basically all we need to do. Is modify this shadow RAM. It's called shadow RAM. Because it's obviously shadowing. The contents of the firmware device. So ultimately we can. Remove the right protection on the shadow RAM. Modify it. We can carry out a similar attack. To the other attacks by. We'll look to patch the interrupt vector table. And I guess. The only unfortunate thing is. It's kind of chipset dependent. So Intel have a concept of. PAMs. Programmable attribute maps. And AMD has MTRRs. Memory type range registers. But it's actually fairly easy to do this. Just download the specs. And if you have some code running in. Actually I was going to say ring zero. But again you don't need to be. You don't need to be ring zero. You just need to be root. To be able to remove the right protection. And modify these pages. Okay. So why do we need to replace the BIOS. With a new technology. Well the BIOS is written in 16 bit. Realmed assembler. Who writes that code these days. Not very many people. And the BIOS just doesn't. Expose clean interfaces. An example of this is. Interrupt 15 hex. The so called miscellaneous interrupt. And you'll find that the sub functions. For this interrupt. Just totally vary from vendor to vendor. And the few interfaces. That there are defined. Are pretty clunky. For example. I'll show you some documentation. From the post memory manager spec. Which is a spec for if your code. From another code module. For example an option ROM. Wants to allocate some memory. We have to jump through a load of hoops. To actually get there. We have to scan for a particular. Four byte string. Then we have to check some structure. To make sure we've found it. Some optional stability checks. And then finally we're allowed. To actually call through a function pointer. So it's basically a lot of work. So one of the key. Move on to it. Some of the key design principles of EFI. Were extensibility. One of the other things. The designers of EFI kept in mind. Is that they didn't want to implement. A whole new host of technology. So they want to use existing technologies. There's EFI system partition. Any people that have a MacBook. Will probably know about that. I believe it's about 200 megabytes. And it's just an empty partition. And it's a fat partition. That's the EFI system partition. That could potentially contain. Extra EFI modules. Executable images. In EFI. Are basically PE files. And EFI. Essentially doesn't mess. With any of the existing. Interfaces. That the operating system might use. So ACPE. And SMBIOS for retrieving information. About your system. Both of those are there. And by and large untouched. Another key design principle. Was modularity. So the core EFI implementation. Is stored in firmware. But the idea being. And this is really the key idea. That we can have third party device drivers. So we have just enough to. Implementation in the firmware itself. To be able to read the EFI system partition. For example. And then third parties can drop drivers in. To actually bootstrap other hardware. You can create EFI code. In C. And you can compile it. You can download a development kit. That will let you compile it. On any mainstream compiler. And EFI. Is a spec. It's not an implementation. It simply defines some interfaces. To solve the option ROM problem. Of option ROMs. Simply containing XX6 code. The Intel came up with. A concept of EFI bytecode. So essentially. Their own virtual instruction set. So that we can now create cards. That have option ROMs. Containing bytecode. That's then interpreted by the EFI driver. So here's a high level diagram. Of what EFI really looks like. Ultimately. We start with. Firmware platform initialization. Which as I said. Is just enough to get the thing going. And then we iteratively load drivers. And you can kind of think of EFI. As almost like an operating system. In that we have the concept of drivers. And we have the concept of applications. And eventually. We end up choosing a bootloader. Which is simply an EFI application. And. There's plenty of. Tools out there for. Investigating the EFI environment. So for example. I suspect many of you. That dual boot on a MacBook. Use something like Refit. Or R-E-F-I-T. Basically. A tool that will also let you drop to a shell. And type commands as if you're at a prompt. And actually. Refit is pretty flexible. Even uses network stacks. So that we can actually. Connect to sites on the internet. For example. So some EFI definitions. The concept of a protocol. Protocol is basically an interface. Exposes some functions. Contained in a driver. Each protocol has a GUID. Which ties in with the extensibility. Unlike the interrupt 15 hex. In a legacy BIOS. Where vendors have just kind of. Redefines sub functions. But hopefully with a GUID. There'll be no collisions. So everyone. Each vendor generates a GUID. And embeds it in the driver. And the driver can implement multiple protocols. When you launch an EFI application. Or driver. It's passed the pointer to an EFI system table. Or the EFI system table. And this is a pretty. Key data structure. That basically allows. An EFI application. To locate protocols. And therefore. Functions within them. The EFI environment. Is actually a protective mode. But it's a flat memory model. So we can simply pass around. Function pointers to things. In other drivers or applications. EFI defines boot services. And these are services. That are available for any application. Or driver to use. And they cover the kind of handy things. That you might need. For example. How to locate other protocols. That we can actually. Get stuff done. And how to actually query. EFI images themselves. So we can find out. File paths to things. That kind of thing. We also have the concept of runtime services. And this is quite interesting. These services are available. After EFI has. After the environment has finished. So once the bootloader is executing. Runtime services. Are still available. And the kind of idea of this. Is that ultimately. EFI can provide device drivers. That the operating system can also use. Right now. People aren't really using this. But it's an interesting idea. That you could expose some services. In the EFI environment. That are still available. When the operating system is booted up. The final definition. Is the framework. And this is Intel's reference implementation. And this is what's actually used by OS X. And the interesting thing. Is that it's actually partially open source. So if you're interested. Go to tianocore.org. And have a look at it. And perhaps unsurprisingly. Intel views the framework. As the implementation of choice. If you're looking for an EFI implementation. So what about. EFI and security. Well the 1.10 spec. Isn't really focused on security. The framework itself. The framework spec docs. Remember that's Intel's implementation. Actually starts to elaborate. And says you should have a security phase. The security phase. Is where you. Set your core roots of trust. And basically. You should make sure it's secure. So the security phase. In Intel's implementation. Is responsible for handling. Restarts. As I said. Of trust. And it's responsible for handing off. To the pre EFI phase. The pre EFI phase. Is basically. The phase in which the environments brought up. So. We have to get the hardware going. So for example. This is where the north bridge would be configured. And the south bridge would be configured. And the PEI phase. Invokes the driver execution environment. Which then means we can load drivers. And load our applications. So this is kind of what it looks like. With the various phases. So. How can we abuse EFI? The first objective is. We need to get our code running in the EFI environment. There's a few different ways of doing this. We could. Modify the bootloader itself. The bootloader for SX. Is just simply an EFI binary on disk. We can simply patch that binary. And then. The next stack I'm going to talk about. And I'll go through these in detail. On the next few slides. Is modifying NVRAM variables. So if you're familiar with open firmware. And the way that worked. Ultimately you have some global variables. Stored in some non-volatile RAM. That basically tell you. What bootloader you want to use. Thirdly. We could patch the framework itself. And reflash. Fourthly. We could go for an implementation floor. In one of the EFI drivers. Once we've actually got code. Running in the EFI environment. Then. How do we subvert the bootloader? We could. Hook one of the runtime services. Or a boot service. That we know the bootloader will rely on. We could modify the ACPE tables. As I said. EFI basically. Doesn't really mess with them. And it needs to keep them there. In the existing spec. We could load a system management mode driver. And that's probably. The most interesting attack. So I'll spend time on that. Or we could carry out an attack. That's kind of similar to attacks. Against the legacy BIOS. If we know that there's a compatibility. Support module. Boot camp for example. Okay. The first attack. And the simplest is. We modify the bootloader. OSX doesn't actually use. The EFI system partition. But carrying out this attack. Is kind of unstealthy. Simply because. We could detect it pretty easily. With anything like tripwire. Unless our rootkit is aware. That those tools are going to be looking for it. And if you're patching a file on disk. Why don't you just patch the kernel directly instead. This last point. Is not really applicable to OSX implementation. Sorry. Intel's implementation of EFI. Is not really applicable to the UEFI. Implementations. Where basically we can enforce driver signing. And so. Simply trying to get an unsigned. Bootloader working. Won't work. Modifying the. Non-volatile RAM variables. As I said. These specify which bootloader we want to use. There's an interface for us to do this. From EFI. If you run the MVRAM tool. From OSX. It lets you dump and modify. The variables. We can create a. Custom bootloader. We can set the EFI boot device. And tell the system to use that. And what we actually. Do in this bootloader. We'll typically do. One of the attacks. That I'm going to come on to shortly. Where we will shim one of the services. That's available. The boot services of the runtime service. And then simply call the original bootloader. Is this stealthier. Than the previous one. Well probably not. Because we are modifying MVRAM. And if I was doing forensics on OSX. I would definitely be interested in what's in MVRAM. Code injection attacks. These are going to be pretty important. When. When people actually implement. UEFI properly. Ultimately. For some kind of. Overflow. Or some kind of bug. In verifying digital signatures. And when we talk about. The possibility for this. And people might ask well. What kind of user. What kind of data do we control in this environment. There's actually some good targets. So we could target the file system drivers. We could. Malform the file system in some way. So that we cause an overflow. PE parsing code. Is always a good one. In my work as a security consultant. Looking at antivirus vendor software. For example. The number of bugs I've found in their code. Relating to PE parsing. That ultimately lead to code execution is huge. So I'd be really surprised. If there aren't any bugs like that. Crypto code. Again we'll obviously be verifying. Digital signatures on binaries. So we've got some good targets here. We can modify the data in the certs. The data itself in the certs. Or we could go for ASM1 decoding. And any data coming off the network. So how might we actually. Subvert the bootloader. Once we've got code running in EFI. Well. The spec says that when the bootloader exits. Sorry. When the bootloader is ready to transfer control to the kernel. It must notify the EFI environment. By calling exit boot services. So. This is a great place to hook. Because. We know at this point the kernel is going to be loaded. So if we hook exit boot services. When the bootloader actually. Calls exit boot services. We get control. And we can patch the kernel. It's fairly easy to actually carry out this attack. We can create a runtime driver. That simply locates the EFI system table. And replaces the function pointer for exit boot services. I also looked at shimming runtime services. But. Not many of them are actually called. By far the exit boot services. Seem the best place to hook. This is what. Elilo booting Linux looks like. So we see that. It loads the kernel. Free some resources. And then calls boot services. And then calls the. Sorry exit boot services. And then it calls the start kernel function. So you can see that. When we get in control. When it calls exit boot services. It's pretty easy for us to locate the kernel. In memory. Okay this is. This is probably the most interesting attack. Against EFI. System management mode. Has been on most processors. Since the 386. And. I know virtualization rootkits. Are getting a lot of press these days. But actually I think. System management mode. Has been on virtualization. And it's been on most people's processors. System management mode. Is a kind of get out of jail free card. For platform designers. So pretty much any time they need to do something. That the hardware doesn't let them. They can probably do it in system management mode. So. Basically things like the century rollover bug. Was fixed with. By vendors putting some code in system management mode. And ultimately system management mode. Is very similar to virtualization. In that the operating system. Doesn't know. That we've gone into system management mode. So in the same way that. In virtualization. The operating system shouldn't really know. That hypervisor even exists. In this scenario. The operating system won't know. That we've executed code in system management mode. And we can get into system management mode. A number of ways. Ultimately we need to get a system management interrupt fired. And these can be triggered by external events. So for example. Plugging a USB device into your laptop. Probably generates an SMI. We can also set these up. To be triggered periodically. Every few seconds. And we can also trigger SMIs. On IO access. So this is quite interesting. If we do IO access to a particular port. Then we can track that. And jump straight into system management mode. How might we abuse system management mode. Well. The only presentation I've seen. That actually discussed this. Was Luc Deflois at CanSec. And he used it for subverting BSD secure levels. And in his paper. He hinted that system management mode. Would be pretty bad for malware. Why is that exactly? Well. Things like hardware breakpoints. Just don't work in system management mode. So if we had some detection software. And we were using hardware breakpoints. To try and detect a rootkit. It would be pretty bad. The operating system cannot get access. To the RAM allocated. For system management mode. If the system management. The SMRAM config register. Has been set. To not allow it access. So there's a lock bit. That some vendors set. Some don't. In fact Luc Deflois talk. Basically. Only concerns systems. Where the lock bit wasn't set. So once we've actually set that lock bit. The operating system cannot see. System management RAM. SMIs can't be interrupted. By anything. Even non-maskable interrupts. And as I said. SMM can also trap IO reads and writes. Which is kind of scary. So this is the kind of perfect fodder. For a rootkit. That is seemingly undetectable. I say seemingly. Because ultimately. If you're looking for it. You could probably find it. Timing attacks for example. But why haven't we actually seen. A SMM rootkit. Considering that it's been on processors. Since 386 SL. Well the barrier is pretty high for entry. Ultimately. To debug system management mode. You need a logic analyzer. So it's not going to be too easy to develop. And there's actually not much code out there. That shows you. How to get into system management mode. How to write a system management mode handler. There's limited opportunity. If the vendor has set the lock bit. For malware to use it. Ultimately if we compromise somebody. And the. Buyer has set the lock bit. Then we'll have to wait for the next reboot. To actually. We'll have to carry out the. One of the warm reboot attacks for example. To then try and get our code into system management mode. And also. System dependencies make it less attractive. That's to say that. You don't really know. What your vendor is using. System management mode for. So you probably don't want to go blindly. Trashing system management RAM. With your own code. Because you're probably likely to make something stop working. So why do I mention system management mode. In the context of EFI. Well EFI actually. Provides some very clean. Very easy to use interfaces. For system management mode. They actually take. All of the hard work out of. Creating a system. Management mode driver. They provide us with a protocol. For registering our driver. An access protocol. So we can toggle the lock bit. They provide protocol for triggering. System management interrupts. And the child dispatch protocol for. Setting up things like periodic callbacks. They even go further. They give us some functionality. To use when we're in system management mode. So the SMST. Allows us to allocate memory. It also gives us. Access to the CPU context. Through a nice interface. So for example. The way it might work is. We'll load our driver into system management mode. We'll set up a periodic interrupt. And every time our callback. In system management mode gets executed. We might want to use one of these protocols. To examine the state of the CPU. So we have a context structure. When we can see exactly what code. We can modify things appropriately. The only kind of warning about. The power of system management mode. In the specs that I read. Basically said that you have to preserve the chain of trust. That you've already set up. Which is kind of a pretty vague statement. If you don't have a chain of trust. Set up then ultimately. We can trivially write a driver. And get it into system management mode. Which is what I've been able to do. On OSX actually. And if anyone's interested. I'll show them. Just the amount of code required to do this. It's actually pretty small. Next thing I want to talk about. Is compatibility support modules. And these provide legacy compatibility. So for example. You want to install an operating system. On an EFI system. That requires a BIOS. Basically all you need to do. Is the compatibility support module. Which is simply an EFI application. Or it could be a driver. The majority of the work is. You need to implement the interrupt vector table. So that when the bootloader. Fires an interrupt. Ultimately you. You can actually. Carry out the same functionality. So most compatibility support modules. The two I've looked at. XP on Mac and Boot Camp. Will thunk to. 32 bit protective mode. So they'll execute the. Bootloader in 16 bit real mode. And then. When it calls the interrupt. There'll be a thunk into 32 bit protective mode. It will then carry out the equivalent EFI function. And then thunk back. So really. If we have code execution at this point. All we need to do is hit the interrupt vector table. Or we can patch the handlers. UFI. UFI. UFI. Is basically the next version of EFI. So Intel developed EFI. And. Version 1.10 is theirs. They then gave that to the UEFI consortium. Which has all the major players. You'd expect in it. And they're up to version 2.1 of the spec. And they've started to. Flesh out security now. So for example. The trusted computing group. Have also released specs to say. How EFI is supposed to link in with. The TPM. And how we can actually start. Doing a secure boot process for EFI. Kind of. I put this in just to. Demonstrate the point about complexity. This is what the UEFI spec says. This is how you have a PE file that you have to sign. And ultimately. I'm sure there's going to be code execution bugs. In. As I talked about implementation flaws. So. Some summary and conclusions here. EFI is interesting. It offers a pretty large attack surface. Versus a legacy BIOS. The fact that these high level. Development tools are available. The fact that you just need to be able to write C code. Is basically now making it a target for. Much more of a target. Than the original BIOS was. I will expect that in the next few years. We will see some attempt at malware. That runs in the EFI environment. And. The third party driver model. Presents an easy target. You can download the development kit. And write your own EFI application or driver. Pretty easily. The EFI spec is pretty vague on security. It's an interface. It's the interface. It's not the implementation. But I guess I would have preferred to see some more. Concrete information on what they're expecting. For example. The actual framework. So Intel's implementation. Doesn't go into a great deal of detail. About how the sec phase should be implemented. UEFI is starting to make things a lot clearer. But I really believe. There will be code injection attacks. So that's pretty much. As far as I've got on EFI right now. If I was to say. The key kind of take away from this talk. I think it would be that. We should all be concerned about system management mode. I don't necessarily think. It's a threat that. We're going to see any malware. Like run of the mill malware. That tries to get into system management mode. But it's something to keep in mind. When people are talking about virtualized rootkits. I'd actually be more concerned. About system management mode. Because that's probably on your processor. Whereas virtualization. It's obviously not on all processors right now. So thanks very much.