1 00:00:00,000 --> 00:00:07,700 Good afternoon everybody. So my name is John Heisman. I work for NGS Software in the UK. 2 00:00:08,940 --> 00:00:17,140 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. 3 00:00:17,740 --> 00:00:24,080 And today I'm going to talk about EFI, which is Intel's replacement for the BIOS. 4 00:00:24,080 --> 00:00:29,940 It's currently available in MacBooks and likely to be available on most systems. 5 00:00:30,060 --> 00:00:33,540 Most operating systems are likely to support it within the next year. 6 00:00:36,140 --> 00:00:38,180 So this is what I want to get through today. 7 00:00:39,300 --> 00:00:44,040 To give you some background on EFI, I'm actually going to start by talking about a legacy BIOS. 8 00:00:44,760 --> 00:00:48,680 So I've got quite a lot of slides to get through, so I'm going to move quickly through the early ones, 9 00:00:49,280 --> 00:00:53,880 where I'm going to talk about what the BIOS actually has to accomplish. 10 00:00:54,840 --> 00:00:58,160 How we can attack a traditional BIOS. 11 00:00:58,700 --> 00:01:03,240 The limitations and basically the motivation for Intel developing EFI. 12 00:01:04,540 --> 00:01:11,960 And then we'll talk about some EFI-specific attacks and also the relevance of the attacks against legacy BIOSes. 13 00:01:12,780 --> 00:01:18,080 Then I want to talk about UEFI, which is the kind of successor to EFI. 14 00:01:18,200 --> 00:01:20,440 It's the next version that the consortium is working on. 15 00:01:21,140 --> 00:01:23,120 I'll summarize and draw some conclusions. 16 00:01:24,900 --> 00:01:28,440 Firstly, I want to make a few caveats here. 17 00:01:29,060 --> 00:01:31,660 As I said, I'm interested in talking about rootkit persistence. 18 00:01:32,780 --> 00:01:34,820 I'm not really interested in what the rootkit does. 19 00:01:35,660 --> 00:01:42,200 So essentially, I want to persist a rootkit on some device, in some firmware. 20 00:01:42,900 --> 00:01:44,540 I don't want the rootkit to be on disk. 21 00:01:45,000 --> 00:01:47,360 However, I do want it to be able to load automatically. 22 00:01:47,760 --> 00:01:51,520 So my rootkits have no bootstrap component on disk. 23 00:01:51,700 --> 00:01:53,080 They persist in firmware. 24 00:01:53,080 --> 00:01:59,440 And they're able to load themselves into the kernel, typically before the operating system has finished booting up. 25 00:01:59,960 --> 00:02:02,040 And so I'll show you a few ways of doing that. 26 00:02:04,080 --> 00:02:07,600 I'm not going to talk a great deal about trusted computing in this talk. 27 00:02:07,840 --> 00:02:10,640 When we talk about UEFI, I'll mention it. 28 00:02:10,820 --> 00:02:15,080 But the EFI spec certainly doesn't mandate that you have a TPM, for example. 29 00:02:15,620 --> 00:02:19,060 And many MacBooks, some do have a TPM, some don't. 30 00:02:20,980 --> 00:02:23,060 Some of these attacks require physical access. 31 00:02:23,060 --> 00:02:26,240 Depending on whether you're able to flash the firmware. 32 00:02:26,880 --> 00:02:28,980 For example, whether you need to flip a jumper. 33 00:02:30,840 --> 00:02:35,460 And all of the attacks are likely to require root access and or kernel access. 34 00:02:37,020 --> 00:02:39,820 And the kind of threat I see for this is a blended attack. 35 00:02:40,320 --> 00:02:44,300 Whereby stage one is we compromise the user system. 36 00:02:45,200 --> 00:02:50,820 We then carry out some information gathering to work out exactly what chipset they have. 37 00:02:51,700 --> 00:02:53,040 And then we actually... 38 00:02:53,060 --> 00:02:54,980 Go ahead and deploy our rootkit and firmware. 39 00:02:56,100 --> 00:03:01,680 And I'd also say that parts of this work are definitely very much work in progress. 40 00:03:04,440 --> 00:03:05,400 So moving on. 41 00:03:05,620 --> 00:03:06,940 The role of the BIOS. 42 00:03:07,780 --> 00:03:12,200 So the BIOS is probably one of the least understood parts of the system today. 43 00:03:12,960 --> 00:03:14,760 We know a great deal about how... 44 00:03:14,760 --> 00:03:17,380 You guys know a great deal about how the bootloader works. 45 00:03:17,440 --> 00:03:18,880 How the operating system works. 46 00:03:19,680 --> 00:03:22,600 But the BIOS is kind of a bit of a... 47 00:03:23,060 --> 00:03:23,980 Grey area. 48 00:03:24,620 --> 00:03:26,160 So when you turn your system on. 49 00:03:26,400 --> 00:03:28,820 The CPU starts executing from a fixed address. 50 00:03:29,180 --> 00:03:32,440 And ultimately it knows pretty much nothing about the hardware in your system. 51 00:03:32,700 --> 00:03:35,840 It actually doesn't even know how to access RAM on your system. 52 00:03:36,160 --> 00:03:44,660 So one of the first things it will do is start issuing read cycles for the reset vector. 53 00:03:44,760 --> 00:03:45,600 The firmware address. 54 00:03:46,020 --> 00:03:47,920 And those will go to the north bridge. 55 00:03:48,280 --> 00:03:51,380 Which will basically direct it to the firmware device in your system. 56 00:03:51,460 --> 00:03:52,720 So for example the firmware hub. 57 00:03:54,300 --> 00:03:58,780 The first few instructions executed by the CPU. 58 00:03:59,040 --> 00:04:01,000 Will actually set up the north bridge. 59 00:04:01,160 --> 00:04:02,480 So that we can then access memory. 60 00:04:02,960 --> 00:04:05,620 Will then go ahead and set up the south bridge. 61 00:04:05,760 --> 00:04:08,120 So that we can then start querying devices. 62 00:04:08,400 --> 00:04:10,200 And see what hardware we have in the system. 63 00:04:12,680 --> 00:04:16,920 Another key part of the BIOS is to set up PCI devices. 64 00:04:18,020 --> 00:04:19,900 And in this talk when I talk... 65 00:04:19,900 --> 00:04:21,080 When I mention PCI. 66 00:04:21,080 --> 00:04:25,460 I'm actually talking about PCI, AGP and PCI Express. 67 00:04:25,780 --> 00:04:28,380 Because essentially the area I'm interested in. 68 00:04:28,420 --> 00:04:31,500 The expansion ROM mechanism is common to them all. 69 00:04:32,460 --> 00:04:34,640 So the BIOS will scan the PCI bus. 70 00:04:34,880 --> 00:04:38,020 And will attempt to locate option ROMs. 71 00:04:38,660 --> 00:04:45,820 Option ROMs are simply x86 code that needs to be executed during the power on self test. 72 00:04:45,900 --> 00:04:47,600 In order to configure the device. 73 00:04:49,240 --> 00:04:53,420 The BIOS also provides the familiar setup screen. 74 00:04:53,660 --> 00:04:55,980 So we can configure the boot device priority. 75 00:04:56,220 --> 00:05:00,300 And we can persist those settings to non-volatile RAM. 76 00:05:01,260 --> 00:05:04,480 And finally the BIOS will then hand off to the bootloader. 77 00:05:07,500 --> 00:05:10,280 So here are four ways we can attack a legacy BIOS. 78 00:05:10,420 --> 00:05:12,840 Here are four ways we can persist a root cap. 79 00:05:13,860 --> 00:05:17,220 Firstly we can reflash the firmware device itself. 80 00:05:17,220 --> 00:05:18,540 We can just reflash the BIOS. 81 00:05:20,120 --> 00:05:22,180 I'm going to go into these in detail on the next slide. 82 00:05:22,240 --> 00:05:23,580 So I'll just run through them quickly now. 83 00:05:25,760 --> 00:05:31,480 A second attack is that we can modify the option ROMs on PCI devices themselves. 84 00:05:32,160 --> 00:05:33,660 And then reflash the device. 85 00:05:35,100 --> 00:05:38,020 The third attack is different to the first two. 86 00:05:38,380 --> 00:05:42,860 In that we're not interested in modifying code as such. 87 00:05:42,880 --> 00:05:46,320 We're interested in modifying some of the data modules that are stored in the BIOS. 88 00:05:46,320 --> 00:05:52,320 And this attack modifies the advanced configuration and power interface tables. 89 00:05:54,360 --> 00:05:58,820 And then the fourth attack I want to talk about is kind of different to the first three. 90 00:05:58,960 --> 00:06:03,760 In that though the majority of my talk is about persisting in firmware. 91 00:06:04,040 --> 00:06:09,840 This attack shows how we can persist in memory and survive across reboots without touching firmware or disk. 92 00:06:13,680 --> 00:06:16,060 So the first attack, patching the BIOS. 93 00:06:16,320 --> 00:06:18,740 We have a huge amount of freedom in what we can do. 94 00:06:19,080 --> 00:06:23,560 But ultimately the job of the BIOS is to get the bootloader going. 95 00:06:24,700 --> 00:06:30,420 So if we can subvert the bootloader which loads the kernel then we can likely deploy our root cap. 96 00:06:31,400 --> 00:06:35,100 The bootloader has to rely on a set of services exposed by the BIOS. 97 00:06:35,180 --> 00:06:38,460 And these are exposed through the interrupt vector table. 98 00:06:40,160 --> 00:06:46,140 And you'll probably know that when we're executing the BIOS code this is 16 bit real mode assembler. 99 00:06:47,460 --> 00:06:50,860 So if we can subvert the interrupt vector table. 100 00:06:50,980 --> 00:06:54,420 If we can hook an interrupt that the bootloader will rely on. 101 00:06:54,560 --> 00:06:57,640 Then ultimately we can get our code executing in the bootloader. 102 00:06:57,660 --> 00:07:01,240 And then we can basically patch the kernel as it loads it. 103 00:07:03,440 --> 00:07:10,500 So quite simply we find where the BIOS calls in 19 hex to pass off control to the bootloader. 104 00:07:10,580 --> 00:07:15,020 And before this call the IVT has hopefully been constructed at this point. 105 00:07:15,740 --> 00:07:16,300 And then we can go back to the bootloader. 106 00:07:16,320 --> 00:07:18,560 And we can simply hook the required interrupt. 107 00:07:19,260 --> 00:07:22,260 I'll talk more about which interrupt we might go for on my next slide. 108 00:07:23,320 --> 00:07:24,240 Some caveats. 109 00:07:24,360 --> 00:07:26,580 We may require physical access as I talked about. 110 00:07:27,880 --> 00:07:32,480 And some vendors Intel and Phoenix for example have secure flash these days. 111 00:07:32,620 --> 00:07:37,800 Which means that we can't necessarily update the firmware with an unsigned update. 112 00:07:38,380 --> 00:07:41,160 And of course if we have TPM in the system. 113 00:07:41,400 --> 00:07:44,060 And it's linked into a secure boot process. 114 00:07:44,100 --> 00:07:46,080 For example BitLocker on Vista. 115 00:07:46,320 --> 00:07:52,200 Then we may not be able to update the firmware and get the machine to still boot correctly. 116 00:07:52,880 --> 00:07:56,920 Simply having a TPM in your machine but not using any of the secure boot process. 117 00:07:57,720 --> 00:07:59,700 Then we can go ahead and flash the firmware. 118 00:07:59,960 --> 00:08:07,520 The TPM is simply a device to measure things like the hash of the BIOS for example. 119 00:08:07,840 --> 00:08:10,860 So simply having a TPM in your machine doesn't offer you any protection. 120 00:08:11,000 --> 00:08:13,320 You have to have the whole secure boot process. 121 00:08:16,320 --> 00:08:18,160 The second attack is option ROMs. 122 00:08:18,180 --> 00:08:20,140 As I mentioned briefly earlier. 123 00:08:20,360 --> 00:08:25,380 Option ROMs are simply ROMs on a PCI card that hold some initialization code. 124 00:08:26,260 --> 00:08:29,040 They can actually be for any architecture. 125 00:08:29,340 --> 00:08:31,740 But ultimately they're likely to contain x86 code. 126 00:08:33,320 --> 00:08:36,660 Option ROMs are copied to RAM during the system post. 127 00:08:36,900 --> 00:08:38,020 And then simply executed. 128 00:08:38,400 --> 00:08:42,200 So they're just blobs of x86 code that are taken straight off your card. 129 00:08:42,360 --> 00:08:43,660 Put into memory and executed. 130 00:08:44,700 --> 00:08:46,300 And they'll be stored in a storage. 131 00:08:46,300 --> 00:08:47,940 So it's either an EEPROM or an EEPROM. 132 00:08:48,340 --> 00:08:52,500 The difference being whether we have to actually remove the chip off the card to flash it. 133 00:08:53,140 --> 00:08:54,280 And here's an example. 134 00:08:54,520 --> 00:08:56,620 If you have a PCI express graphics card. 135 00:08:56,760 --> 00:08:58,520 It will likely have an EEPROM. 136 00:08:59,320 --> 00:09:05,120 And the initialization code will basically install a handler for int10 hex video. 137 00:09:05,820 --> 00:09:10,480 And that handler will implement the VGA and the VBE functionality. 138 00:09:13,240 --> 00:09:15,580 So to attack an option ROM. 139 00:09:16,680 --> 00:09:19,260 Ultimately we need to dump the option ROM off the card. 140 00:09:19,720 --> 00:09:22,160 Alternatively we can go to the vendor's website. 141 00:09:22,660 --> 00:09:25,000 So for example if we're talking about a graphics card. 142 00:09:25,220 --> 00:09:27,800 And you've updated the BIOS on your graphics card. 143 00:09:27,940 --> 00:09:30,600 You know how easy it is to download a tool to do it. 144 00:09:30,680 --> 00:09:31,840 And the BIOS from the website. 145 00:09:33,040 --> 00:09:34,460 We patch the option ROM. 146 00:09:35,600 --> 00:09:38,100 Again we're interested in subverting the bootloader. 147 00:09:38,120 --> 00:09:39,680 So we simply hook an interrupt. 148 00:09:42,060 --> 00:09:43,320 Which interrupt to hook? 149 00:09:43,640 --> 00:09:44,040 Well. 150 00:09:44,040 --> 00:09:49,400 EI released a proof of concept boot sector rootkit in 2005. 151 00:09:49,980 --> 00:09:52,760 And they demonstrated that if you hook int13 hex. 152 00:09:52,980 --> 00:09:54,220 As in the disk interrupt. 153 00:09:54,600 --> 00:10:00,000 When the bootloader starts loading some of the key device drivers in the kernel itself. 154 00:10:00,880 --> 00:10:03,460 Then essentially we can see that flow of data. 155 00:10:03,700 --> 00:10:06,780 And we can look for a byte stream and patch it on the fly. 156 00:10:08,660 --> 00:10:12,600 The approach I took when I was investigating putting rootkits on PCI cards. 157 00:10:12,600 --> 00:10:14,260 Was actually to hook int10. 158 00:10:14,280 --> 00:10:15,820 The video interrupt. 159 00:10:16,220 --> 00:10:18,260 Though this was a Windows specific technique. 160 00:10:18,640 --> 00:10:24,300 I noticed that the Windows kernel actually called int10 hex during the boot. 161 00:10:24,560 --> 00:10:26,580 And it's a relatively involved process. 162 00:10:26,680 --> 00:10:29,940 Because the Windows kernel is obviously 32 bit protected mode. 163 00:10:30,120 --> 00:10:33,200 And these are 16 bit real mode interrupts. 164 00:10:33,240 --> 00:10:37,920 So I found that the Windows kernel actually switched the processor into V8086 mode. 165 00:10:38,640 --> 00:10:42,420 And I was able to influence how it returned back to 32 bit protected mode. 166 00:10:43,680 --> 00:10:46,560 I guess my point here is that there are likely other candidates. 167 00:10:46,860 --> 00:10:50,640 The key takeaway is that the bootloader in a legacy BIOS. 168 00:10:51,000 --> 00:10:55,160 Relies on services exposed by the interrupt vector table. 169 00:10:55,480 --> 00:10:59,500 And if we're able to execute code during the power on self test. 170 00:10:59,560 --> 00:11:00,940 During the running of the BIOS. 171 00:11:01,100 --> 00:11:04,060 Then we can simply hook one of those interrupts that it depends upon. 172 00:11:06,760 --> 00:11:08,260 Pros and cons of option ROM attacks. 173 00:11:08,860 --> 00:11:10,980 Most PCI cards don't have any jumpers. 174 00:11:11,120 --> 00:11:12,580 So we can flash them pretty easily. 175 00:11:12,600 --> 00:11:17,480 The flashing process itself simply is doing IO to the card. 176 00:11:17,660 --> 00:11:19,120 So we just need root access. 177 00:11:19,460 --> 00:11:22,140 In both Linux, Windows, OSX for example. 178 00:11:22,260 --> 00:11:25,040 We don't actually need to get into kernel. 179 00:11:27,340 --> 00:11:29,380 Network cards also have option ROMs. 180 00:11:29,420 --> 00:11:32,000 And the option ROMs and network cards implement PICC. 181 00:11:32,340 --> 00:11:33,840 So the network booting. 182 00:11:34,120 --> 00:11:35,740 And this was a kind of nice idea. 183 00:11:35,900 --> 00:11:38,040 That we could make use of their network stack. 184 00:11:38,320 --> 00:11:41,840 So that we could actually do things like pre-boot updates. 185 00:11:41,840 --> 00:11:42,600 Of our rootkit. 186 00:11:43,420 --> 00:11:44,920 Before the bootloader kicks in. 187 00:11:45,000 --> 00:11:46,900 On phone, home, covert channels. 188 00:11:47,500 --> 00:11:49,280 Plenty of opportunity. 189 00:11:50,520 --> 00:11:53,980 One of the disadvantages is that we're limited by space on an option ROM. 190 00:11:54,240 --> 00:11:56,560 We can't simply dump the code that's there. 191 00:11:56,640 --> 00:11:58,860 Because your graphics card probably won't work. 192 00:11:59,380 --> 00:12:05,620 At least it won't work while the bootloader is working. 193 00:12:05,820 --> 00:12:08,560 By the time the operating system is loaded. 194 00:12:08,820 --> 00:12:11,300 We no longer rely on things like. 195 00:12:11,300 --> 00:12:13,380 The 10 handler. 196 00:12:13,560 --> 00:12:15,860 So the graphics card will work. 197 00:12:16,060 --> 00:12:20,200 But ultimately we want to shoehorn our code into some slack space. 198 00:12:21,240 --> 00:12:24,740 And I played with distributing my rootkit across multiple cards. 199 00:12:24,980 --> 00:12:27,700 But then obviously we're increasing the chances of detection. 200 00:12:27,820 --> 00:12:29,080 Or somebody removing a card. 201 00:12:29,180 --> 00:12:30,740 And us losing some code. 202 00:12:31,580 --> 00:12:33,200 And detection is fairly easy. 203 00:12:34,160 --> 00:12:35,780 It's very well documented. 204 00:12:35,800 --> 00:12:38,640 How to dump option ROMs off the PCI cards. 205 00:12:39,420 --> 00:12:40,700 In the PCI spec. 206 00:12:40,700 --> 00:12:45,820 And then we just apply some heuristics to analyze the ROM. 207 00:12:46,020 --> 00:12:48,640 And if for example we see that it has protected mode code. 208 00:12:48,940 --> 00:12:51,180 And as I said we're interested in. 209 00:12:51,640 --> 00:12:53,920 We're expecting the option ROM to have real mode code. 210 00:12:54,100 --> 00:12:54,620 That's a giveaway. 211 00:12:55,580 --> 00:12:58,640 Though I have come up with some ways of detecting the. 212 00:12:59,000 --> 00:13:00,940 Of subverting the detection process. 213 00:13:01,440 --> 00:13:02,720 As I'll talk about later. 214 00:13:02,800 --> 00:13:03,960 Using system management mode. 215 00:13:04,040 --> 00:13:05,640 It's possible to trap IO access. 216 00:13:05,960 --> 00:13:07,920 And basically give wrong results back. 217 00:13:10,700 --> 00:13:13,420 Okay moving on to the third attack against a legacy BIOS. 218 00:13:13,480 --> 00:13:16,480 And as I said many of these attacks are going to be applicable to EFI. 219 00:13:16,680 --> 00:13:17,940 Which is why I'm going into them now. 220 00:13:19,100 --> 00:13:22,880 This attack targets the advanced configuration and power interface. 221 00:13:23,800 --> 00:13:27,240 Which is basically a standard that replaces the advanced power management. 222 00:13:27,760 --> 00:13:30,160 And this handles all the power management. 223 00:13:30,160 --> 00:13:33,000 In everything from your notebook to a big server. 224 00:13:33,400 --> 00:13:34,860 And the way ACPE works. 225 00:13:35,200 --> 00:13:38,200 Is ultimately the BIOS contains some data tables. 226 00:13:39,060 --> 00:13:40,620 And these data tables hold. 227 00:13:41,600 --> 00:13:42,680 Virtual instructions. 228 00:13:42,880 --> 00:13:45,540 That are interpreted by the operating system. 229 00:13:45,660 --> 00:13:46,740 ACPE device driver. 230 00:13:48,160 --> 00:13:49,780 And ACPE is a standard. 231 00:13:50,020 --> 00:13:50,820 And consequently. 232 00:13:51,820 --> 00:13:55,400 There's ACPE implementations for pretty much every operating system. 233 00:13:56,280 --> 00:13:58,920 So the kind of nice thing here is that we're. 234 00:13:58,920 --> 00:14:00,100 Because we're using these virtual. 235 00:14:00,280 --> 00:14:01,280 Virtual instructions. 236 00:14:02,660 --> 00:14:04,200 We can actually make a root kit that's. 237 00:14:04,920 --> 00:14:06,100 Seemingly platform independent. 238 00:14:08,780 --> 00:14:10,680 So the way an attack would work again. 239 00:14:10,700 --> 00:14:11,040 Is to implement the ACPE. 240 00:14:11,620 --> 00:14:13,560 As I said the BIOS holds these tables. 241 00:14:13,640 --> 00:14:14,980 Containing ACPE machine language. 242 00:14:15,500 --> 00:14:18,080 The device driver interprets these instructions. 243 00:14:18,480 --> 00:14:19,420 So for example. 244 00:14:19,620 --> 00:14:23,860 If you press one of the hot keys on your laptop. 245 00:14:24,160 --> 00:14:26,140 Then ultimately that will result in. 246 00:14:26,540 --> 00:14:27,800 The ACPE device driver. 247 00:14:28,180 --> 00:14:30,040 Interpreting some of the AML instructions. 248 00:14:30,380 --> 00:14:32,260 That tell it what to do when you press that button. 249 00:14:33,360 --> 00:14:35,000 And the key thing is we can. 250 00:14:35,860 --> 00:14:38,540 Take the existing ACPE tables for a system. 251 00:14:38,540 --> 00:14:41,260 And we can append our own virtual instructions. 252 00:14:41,340 --> 00:14:42,320 Into these tables. 253 00:14:42,840 --> 00:14:44,780 And this allows us to pretty much. 254 00:14:44,820 --> 00:14:46,300 Exert full control over the system. 255 00:14:46,560 --> 00:14:48,720 So for example from the ACPE machine language. 256 00:14:49,060 --> 00:14:51,340 We can modify system memory. 257 00:14:51,620 --> 00:14:52,700 So we can patch the kernel. 258 00:14:53,680 --> 00:14:54,480 We can. 259 00:14:54,840 --> 00:14:57,000 We have full access to the IO space as well. 260 00:14:58,840 --> 00:15:01,460 So ultimately we would take a BIOS. 261 00:15:01,780 --> 00:15:03,740 Crack it open into its code modules. 262 00:15:03,840 --> 00:15:04,320 Its data modules. 263 00:15:04,980 --> 00:15:06,240 Locate the ACPE tables. 264 00:15:07,580 --> 00:15:08,380 Disassemble them. 265 00:15:08,540 --> 00:15:10,440 Into the ACPE source language. 266 00:15:10,580 --> 00:15:11,360 The high level language. 267 00:15:11,520 --> 00:15:13,960 That the platform designers use to make them. 268 00:15:14,320 --> 00:15:15,180 Modify them. 269 00:15:15,700 --> 00:15:17,040 To put our rootkit in there. 270 00:15:17,880 --> 00:15:18,560 Recompile them. 271 00:15:18,900 --> 00:15:20,240 Put the BIOS back together. 272 00:15:20,460 --> 00:15:21,220 And reflash it. 273 00:15:23,340 --> 00:15:24,340 Benefits as I said. 274 00:15:24,380 --> 00:15:26,380 The ACPE machine language is platform independent. 275 00:15:26,860 --> 00:15:27,980 It's these virtual instructions. 276 00:15:28,340 --> 00:15:29,760 That are implemented by the. 277 00:15:30,580 --> 00:15:31,840 Interpreted by the device driver. 278 00:15:32,720 --> 00:15:35,040 And as I said the ACPE source language. 279 00:15:35,160 --> 00:15:36,020 Is a high level language. 280 00:15:38,800 --> 00:15:40,480 And it's easy to disassemble. 281 00:15:40,540 --> 00:15:41,860 Between the ACPE machine language. 282 00:15:42,000 --> 00:15:43,040 That you find in the BIOS. 283 00:15:43,080 --> 00:15:43,820 And the ACPE source language. 284 00:15:46,240 --> 00:15:47,460 The ACPE device driver. 285 00:15:47,880 --> 00:15:48,940 By the time it's kicked in. 286 00:15:49,020 --> 00:15:50,320 Obviously the kernel is loaded. 287 00:15:50,760 --> 00:15:53,240 So this attack allows us to. 288 00:15:53,480 --> 00:15:55,080 Very easily patch the kernel. 289 00:15:56,380 --> 00:15:57,860 And also the fact that. 290 00:15:57,980 --> 00:15:59,040 We've got this virtual machine. 291 00:15:59,240 --> 00:16:00,000 Gives us an abstraction. 292 00:16:00,440 --> 00:16:01,880 So we can make some smart decisions. 293 00:16:02,200 --> 00:16:03,460 And we can future proof our rootkit. 294 00:16:03,460 --> 00:16:06,200 So at Black Hat DC. 295 00:16:06,320 --> 00:16:07,400 In 2006. 296 00:16:07,540 --> 00:16:09,960 I talked about a cross platform rootkit. 297 00:16:10,080 --> 00:16:11,000 That had some logic. 298 00:16:11,120 --> 00:16:12,480 That said are we running on Windows. 299 00:16:12,680 --> 00:16:13,400 Are we running on Linux. 300 00:16:14,040 --> 00:16:15,640 And did a series of tests. 301 00:16:15,980 --> 00:16:17,300 And made absolutely sure. 302 00:16:17,460 --> 00:16:18,660 It knew what the target was. 303 00:16:18,820 --> 00:16:21,100 Before then actually patching the kernel. 304 00:16:23,880 --> 00:16:24,320 Limitations. 305 00:16:24,480 --> 00:16:26,340 We need to modify the system BIOS. 306 00:16:26,540 --> 00:16:27,580 So again. 307 00:16:29,000 --> 00:16:31,980 If we have to have a signed update. 308 00:16:32,220 --> 00:16:33,280 Then this attack. 309 00:16:33,460 --> 00:16:34,240 Is mitigated. 310 00:16:34,680 --> 00:16:35,940 Also the operating system. 311 00:16:36,060 --> 00:16:37,360 Must have an ACPE device driver. 312 00:16:38,720 --> 00:16:39,160 Basically. 313 00:16:40,640 --> 00:16:43,000 If we can get hold of the raw ACPE tables. 314 00:16:43,080 --> 00:16:44,580 To then perform some analysis on them. 315 00:16:44,700 --> 00:16:45,960 Then we can spot our rootkit. 316 00:16:46,220 --> 00:16:48,140 So if we can stop the ACPE device driver. 317 00:16:48,280 --> 00:16:49,360 From interpreting our instructions. 318 00:16:49,660 --> 00:16:50,840 We can stop the rootkit deploying. 319 00:16:51,600 --> 00:16:53,100 And if you turn off ACPE. 320 00:16:54,060 --> 00:16:56,200 Your system performance is likely to suffer. 321 00:16:56,320 --> 00:16:58,500 But your operating system will work. 322 00:16:59,540 --> 00:17:00,300 And finally. 323 00:17:00,480 --> 00:17:01,640 This is one thing I noted. 324 00:17:03,460 --> 00:17:04,060 When I did this on Windows. 325 00:17:04,680 --> 00:17:06,640 Ultimately I was getting a load of event log messages. 326 00:17:06,780 --> 00:17:08,100 That were warning me. 327 00:17:08,200 --> 00:17:10,800 That the ACPE device driver was doing things. 328 00:17:10,940 --> 00:17:12,260 That could compromise stability. 329 00:17:12,740 --> 00:17:14,120 Because I was patching the kernel. 330 00:17:14,620 --> 00:17:15,740 And so ultimately. 331 00:17:16,660 --> 00:17:18,640 You could come up with some mitigations. 332 00:17:18,640 --> 00:17:19,600 In the ACPE device driver. 333 00:17:19,720 --> 00:17:22,000 That sandboxed what the interpreter was allowed to do. 334 00:17:22,280 --> 00:17:23,260 Because quite frankly. 335 00:17:24,160 --> 00:17:26,320 You shouldn't be patching certain areas of memory. 336 00:17:26,480 --> 00:17:27,900 You shouldn't be patching kernel code pages. 337 00:17:28,060 --> 00:17:28,380 For example. 338 00:17:30,900 --> 00:17:31,300 Okay. 339 00:17:33,460 --> 00:17:33,780 One of the privacy biases. 340 00:17:35,160 --> 00:17:36,620 Is warm reboot attacks. 341 00:17:36,980 --> 00:17:38,100 So the last three attacks. 342 00:17:38,280 --> 00:17:40,620 Require us to make modifications to firmware. 343 00:17:41,700 --> 00:17:43,240 Which kind of makes detection easier. 344 00:17:45,000 --> 00:17:46,520 And if we think about it. 345 00:17:46,600 --> 00:17:48,380 If you take the case of say a web server. 346 00:17:48,500 --> 00:17:49,220 Or a database server. 347 00:17:49,580 --> 00:17:50,860 They probably have SLAs. 348 00:17:50,920 --> 00:17:53,560 That mean that these things aren't turned off very often. 349 00:17:54,820 --> 00:17:56,240 They might be warm rebooted. 350 00:17:56,260 --> 00:17:57,960 Say once a month to install some patches. 351 00:17:58,480 --> 00:18:00,180 But the only time you might actually. 352 00:18:00,720 --> 00:18:02,020 Remove the power is to. 353 00:18:03,460 --> 00:18:04,560 Replace some hardware for example. 354 00:18:05,060 --> 00:18:07,280 So it may be sufficient for us to. 355 00:18:07,480 --> 00:18:09,160 Try and persist in memory alone. 356 00:18:09,300 --> 00:18:10,240 Without touching disk. 357 00:18:10,960 --> 00:18:11,920 Or firmware. 358 00:18:12,620 --> 00:18:14,500 So it's pretty easy to do this. 359 00:18:14,620 --> 00:18:16,260 Because what we actually find. 360 00:18:16,480 --> 00:18:18,780 Is that when the CPUs. 361 00:18:18,800 --> 00:18:20,580 When you first cold boot the system. 362 00:18:21,000 --> 00:18:22,800 Those first few memory accesses. 363 00:18:22,800 --> 00:18:23,960 That go to the firmware hub. 364 00:18:24,220 --> 00:18:25,340 Get cached in RAM. 365 00:18:25,800 --> 00:18:26,540 For speed. 366 00:18:27,200 --> 00:18:28,780 And when we warm reboot. 367 00:18:29,180 --> 00:18:32,040 Ultimately will actually just execute out of RAM. 368 00:18:33,540 --> 00:18:35,180 So basically all we need to do. 369 00:18:35,260 --> 00:18:36,420 Is modify this shadow RAM. 370 00:18:37,220 --> 00:18:38,320 It's called shadow RAM. 371 00:18:38,460 --> 00:18:39,640 Because it's obviously shadowing. 372 00:18:39,640 --> 00:18:41,180 The contents of the firmware device. 373 00:18:43,720 --> 00:18:45,140 So ultimately we can. 374 00:18:45,240 --> 00:18:46,860 Remove the right protection on the shadow RAM. 375 00:18:47,340 --> 00:18:48,100 Modify it. 376 00:18:48,960 --> 00:18:50,440 We can carry out a similar attack. 377 00:18:50,600 --> 00:18:51,900 To the other attacks by. 378 00:18:53,320 --> 00:18:55,800 We'll look to patch the interrupt vector table. 379 00:18:57,980 --> 00:18:59,540 And I guess. 380 00:18:59,600 --> 00:19:00,980 The only unfortunate thing is. 381 00:19:01,320 --> 00:19:02,520 It's kind of chipset dependent. 382 00:19:03,480 --> 00:19:05,420 So Intel have a concept of. 383 00:19:06,080 --> 00:19:06,480 PAMs. 384 00:19:07,000 --> 00:19:08,060 Programmable attribute maps. 385 00:19:09,240 --> 00:19:11,320 And AMD has MTRRs. 386 00:19:11,440 --> 00:19:12,680 Memory type range registers. 387 00:19:13,500 --> 00:19:15,260 But it's actually fairly easy to do this. 388 00:19:15,320 --> 00:19:16,300 Just download the specs. 389 00:19:16,620 --> 00:19:18,740 And if you have some code running in. 390 00:19:19,840 --> 00:19:20,940 Actually I was going to say ring zero. 391 00:19:21,080 --> 00:19:22,600 But again you don't need to be. 392 00:19:22,660 --> 00:19:24,280 You don't need to be ring zero. 393 00:19:24,380 --> 00:19:25,140 You just need to be root. 394 00:19:25,220 --> 00:19:27,180 To be able to remove the right protection. 395 00:19:27,280 --> 00:19:28,100 And modify these pages. 396 00:19:31,800 --> 00:19:32,200 Okay. 397 00:19:33,460 --> 00:19:35,460 So why do we need to replace the BIOS. 398 00:19:35,540 --> 00:19:36,300 With a new technology. 399 00:19:37,320 --> 00:19:39,600 Well the BIOS is written in 16 bit. 400 00:19:39,940 --> 00:19:40,920 Realmed assembler. 401 00:19:41,620 --> 00:19:43,340 Who writes that code these days. 402 00:19:43,780 --> 00:19:44,920 Not very many people. 403 00:19:45,860 --> 00:19:47,480 And the BIOS just doesn't. 404 00:19:47,480 --> 00:19:48,520 Expose clean interfaces. 405 00:19:49,340 --> 00:19:50,720 An example of this is. 406 00:19:51,480 --> 00:19:52,540 Interrupt 15 hex. 407 00:19:52,800 --> 00:19:54,260 The so called miscellaneous interrupt. 408 00:19:54,760 --> 00:19:56,920 And you'll find that the sub functions. 409 00:19:57,020 --> 00:19:58,220 For this interrupt. 410 00:19:58,800 --> 00:20:00,740 Just totally vary from vendor to vendor. 411 00:20:01,940 --> 00:20:03,180 And the few interfaces. 412 00:20:03,460 --> 00:20:04,080 That there are defined. 413 00:20:04,260 --> 00:20:05,260 Are pretty clunky. 414 00:20:05,440 --> 00:20:06,140 For example. 415 00:20:06,260 --> 00:20:09,360 I'll show you some documentation. 416 00:20:09,480 --> 00:20:11,160 From the post memory manager spec. 417 00:20:11,400 --> 00:20:13,640 Which is a spec for if your code. 418 00:20:14,020 --> 00:20:15,520 From another code module. 419 00:20:15,640 --> 00:20:16,560 For example an option ROM. 420 00:20:16,720 --> 00:20:18,080 Wants to allocate some memory. 421 00:20:20,780 --> 00:20:22,460 We have to jump through a load of hoops. 422 00:20:22,520 --> 00:20:23,240 To actually get there. 423 00:20:23,600 --> 00:20:26,240 We have to scan for a particular. 424 00:20:26,360 --> 00:20:27,060 Four byte string. 425 00:20:28,580 --> 00:20:30,100 Then we have to check some structure. 426 00:20:30,420 --> 00:20:31,440 To make sure we've found it. 427 00:20:33,460 --> 00:20:34,700 Some optional stability checks. 428 00:20:35,520 --> 00:20:36,720 And then finally we're allowed. 429 00:20:36,880 --> 00:20:38,320 To actually call through a function pointer. 430 00:20:38,620 --> 00:20:40,000 So it's basically a lot of work. 431 00:20:40,460 --> 00:20:41,180 So one of the key. 432 00:20:42,600 --> 00:20:43,640 Move on to it. 433 00:20:43,720 --> 00:20:45,420 Some of the key design principles of EFI. 434 00:20:45,620 --> 00:20:47,120 Were extensibility. 435 00:20:51,000 --> 00:20:52,020 One of the other things. 436 00:20:52,120 --> 00:20:53,840 The designers of EFI kept in mind. 437 00:20:53,860 --> 00:20:55,640 Is that they didn't want to implement. 438 00:20:55,760 --> 00:20:57,300 A whole new host of technology. 439 00:20:57,680 --> 00:21:00,120 So they want to use existing technologies. 440 00:21:00,980 --> 00:21:02,740 There's EFI system partition. 441 00:21:03,860 --> 00:21:05,440 Any people that have a MacBook. 442 00:21:05,560 --> 00:21:06,740 Will probably know about that. 443 00:21:06,800 --> 00:21:09,000 I believe it's about 200 megabytes. 444 00:21:09,260 --> 00:21:10,460 And it's just an empty partition. 445 00:21:10,940 --> 00:21:12,740 And it's a fat partition. 446 00:21:12,860 --> 00:21:14,820 That's the EFI system partition. 447 00:21:15,100 --> 00:21:16,420 That could potentially contain. 448 00:21:16,580 --> 00:21:17,600 Extra EFI modules. 449 00:21:19,860 --> 00:21:20,740 Executable images. 450 00:21:21,360 --> 00:21:22,560 In EFI. 451 00:21:23,020 --> 00:21:25,480 Are basically PE files. 452 00:21:26,460 --> 00:21:27,660 And EFI. 453 00:21:27,900 --> 00:21:29,080 Essentially doesn't mess. 454 00:21:29,220 --> 00:21:30,100 With any of the existing. 455 00:21:30,120 --> 00:21:30,800 Interfaces. 456 00:21:31,000 --> 00:21:32,680 That the operating system might use. 457 00:21:32,860 --> 00:21:33,980 So ACPE. 458 00:21:34,180 --> 00:21:36,880 And SMBIOS for retrieving information. 459 00:21:36,900 --> 00:21:37,740 About your system. 460 00:21:37,880 --> 00:21:38,940 Both of those are there. 461 00:21:39,160 --> 00:21:41,700 And by and large untouched. 462 00:21:43,760 --> 00:21:45,260 Another key design principle. 463 00:21:45,300 --> 00:21:46,700 Was modularity. 464 00:21:46,920 --> 00:21:48,700 So the core EFI implementation. 465 00:21:48,900 --> 00:21:49,960 Is stored in firmware. 466 00:21:50,260 --> 00:21:51,840 But the idea being. 467 00:21:52,120 --> 00:21:53,900 And this is really the key idea. 468 00:21:54,120 --> 00:21:56,280 That we can have third party device drivers. 469 00:21:56,900 --> 00:21:58,540 So we have just enough to. 470 00:22:00,120 --> 00:22:01,460 Implementation in the firmware itself. 471 00:22:01,620 --> 00:22:04,200 To be able to read the EFI system partition. 472 00:22:04,240 --> 00:22:04,760 For example. 473 00:22:05,000 --> 00:22:07,460 And then third parties can drop drivers in. 474 00:22:07,560 --> 00:22:09,820 To actually bootstrap other hardware. 475 00:22:12,440 --> 00:22:14,120 You can create EFI code. 476 00:22:14,200 --> 00:22:14,940 In C. 477 00:22:15,580 --> 00:22:16,960 And you can compile it. 478 00:22:17,020 --> 00:22:18,300 You can download a development kit. 479 00:22:18,520 --> 00:22:20,320 That will let you compile it. 480 00:22:20,380 --> 00:22:22,020 On any mainstream compiler. 481 00:22:24,840 --> 00:22:25,880 And EFI. 482 00:22:26,020 --> 00:22:27,060 Is a spec. 483 00:22:27,280 --> 00:22:28,320 It's not an implementation. 484 00:22:30,240 --> 00:22:31,860 It simply defines some interfaces. 485 00:22:34,000 --> 00:22:35,680 To solve the option ROM problem. 486 00:22:35,800 --> 00:22:37,520 Of option ROMs. 487 00:22:37,540 --> 00:22:39,060 Simply containing XX6 code. 488 00:22:40,300 --> 00:22:41,660 The Intel came up with. 489 00:22:41,760 --> 00:22:43,440 A concept of EFI bytecode. 490 00:22:43,740 --> 00:22:44,400 So essentially. 491 00:22:44,660 --> 00:22:46,420 Their own virtual instruction set. 492 00:22:46,660 --> 00:22:48,180 So that we can now create cards. 493 00:22:48,400 --> 00:22:49,740 That have option ROMs. 494 00:22:49,740 --> 00:22:50,520 Containing bytecode. 495 00:22:50,740 --> 00:22:53,460 That's then interpreted by the EFI driver. 496 00:22:56,860 --> 00:22:58,320 So here's a high level diagram. 497 00:22:58,500 --> 00:23:00,100 Of what EFI really looks like. 498 00:23:01,220 --> 00:23:01,700 Ultimately. 499 00:23:02,700 --> 00:23:03,900 We start with. 500 00:23:04,920 --> 00:23:06,600 Firmware platform initialization. 501 00:23:07,380 --> 00:23:08,260 Which as I said. 502 00:23:08,440 --> 00:23:09,940 Is just enough to get the thing going. 503 00:23:10,300 --> 00:23:12,360 And then we iteratively load drivers. 504 00:23:13,080 --> 00:23:14,620 And you can kind of think of EFI. 505 00:23:14,780 --> 00:23:16,600 As almost like an operating system. 506 00:23:16,800 --> 00:23:18,220 In that we have the concept of drivers. 507 00:23:18,500 --> 00:23:20,000 And we have the concept of applications. 508 00:23:21,840 --> 00:23:22,800 And eventually. 509 00:23:22,940 --> 00:23:24,420 We end up choosing a bootloader. 510 00:23:24,420 --> 00:23:25,840 Which is simply an EFI application. 511 00:23:27,000 --> 00:23:27,480 And. 512 00:23:28,700 --> 00:23:29,620 There's plenty of. 513 00:23:30,120 --> 00:23:31,100 Tools out there for. 514 00:23:32,220 --> 00:23:33,420 Investigating the EFI environment. 515 00:23:33,840 --> 00:23:34,720 So for example. 516 00:23:35,240 --> 00:23:36,360 I suspect many of you. 517 00:23:36,440 --> 00:23:37,780 That dual boot on a MacBook. 518 00:23:38,420 --> 00:23:40,700 Use something like Refit. 519 00:23:41,540 --> 00:23:43,600 Or R-E-F-I-T. 520 00:23:45,220 --> 00:23:45,740 Basically. 521 00:23:45,860 --> 00:23:48,220 A tool that will also let you drop to a shell. 522 00:23:49,600 --> 00:23:51,660 And type commands as if you're at a prompt. 523 00:23:55,480 --> 00:23:56,220 And actually. 524 00:23:57,120 --> 00:23:58,740 Refit is pretty flexible. 525 00:24:00,120 --> 00:24:01,160 Even uses network stacks. 526 00:24:01,320 --> 00:24:02,040 So that we can actually. 527 00:24:03,260 --> 00:24:04,420 Connect to sites on the internet. 528 00:24:04,460 --> 00:24:04,760 For example. 529 00:24:06,080 --> 00:24:07,220 So some EFI definitions. 530 00:24:09,060 --> 00:24:10,480 The concept of a protocol. 531 00:24:11,240 --> 00:24:12,700 Protocol is basically an interface. 532 00:24:12,960 --> 00:24:14,000 Exposes some functions. 533 00:24:15,260 --> 00:24:16,180 Contained in a driver. 534 00:24:18,040 --> 00:24:19,340 Each protocol has a GUID. 535 00:24:19,440 --> 00:24:20,720 Which ties in with the extensibility. 536 00:24:21,860 --> 00:24:24,020 Unlike the interrupt 15 hex. 537 00:24:24,140 --> 00:24:24,980 In a legacy BIOS. 538 00:24:25,040 --> 00:24:26,320 Where vendors have just kind of. 539 00:24:27,780 --> 00:24:28,980 Redefines sub functions. 540 00:24:30,300 --> 00:24:31,660 But hopefully with a GUID. 541 00:24:31,720 --> 00:24:32,720 There'll be no collisions. 542 00:24:32,940 --> 00:24:35,140 So everyone. 543 00:24:35,260 --> 00:24:37,820 Each vendor generates a GUID. 544 00:24:37,920 --> 00:24:38,940 And embeds it in the driver. 545 00:24:39,880 --> 00:24:41,960 And the driver can implement multiple protocols. 546 00:24:43,840 --> 00:24:45,660 When you launch an EFI application. 547 00:24:46,100 --> 00:24:46,920 Or driver. 548 00:24:47,260 --> 00:24:49,740 It's passed the pointer to an EFI system table. 549 00:24:50,460 --> 00:24:52,440 Or the EFI system table. 550 00:24:52,840 --> 00:24:53,920 And this is a pretty. 551 00:24:53,980 --> 00:24:54,640 Key data structure. 552 00:24:55,920 --> 00:24:57,180 That basically allows. 553 00:24:58,160 --> 00:24:59,240 An EFI application. 554 00:25:00,120 --> 00:25:00,940 To locate protocols. 555 00:25:01,220 --> 00:25:01,640 And therefore. 556 00:25:02,860 --> 00:25:03,840 Functions within them. 557 00:25:05,800 --> 00:25:07,000 The EFI environment. 558 00:25:07,120 --> 00:25:08,680 Is actually a protective mode. 559 00:25:09,160 --> 00:25:10,360 But it's a flat memory model. 560 00:25:10,800 --> 00:25:12,120 So we can simply pass around. 561 00:25:12,440 --> 00:25:13,760 Function pointers to things. 562 00:25:13,860 --> 00:25:15,560 In other drivers or applications. 563 00:25:17,900 --> 00:25:19,580 EFI defines boot services. 564 00:25:20,260 --> 00:25:21,260 And these are services. 565 00:25:21,320 --> 00:25:23,180 That are available for any application. 566 00:25:23,200 --> 00:25:24,180 Or driver to use. 567 00:25:24,700 --> 00:25:27,280 And they cover the kind of handy things. 568 00:25:27,400 --> 00:25:28,420 That you might need. For example. 569 00:25:30,120 --> 00:25:31,600 How to locate other protocols. 570 00:25:31,800 --> 00:25:32,520 That we can actually. 571 00:25:33,400 --> 00:25:34,340 Get stuff done. 572 00:25:34,700 --> 00:25:36,000 And how to actually query. 573 00:25:36,320 --> 00:25:37,620 EFI images themselves. 574 00:25:37,900 --> 00:25:38,580 So we can find out. 575 00:25:40,540 --> 00:25:41,920 File paths to things. 576 00:25:42,020 --> 00:25:42,500 That kind of thing. 577 00:25:45,100 --> 00:25:47,000 We also have the concept of runtime services. 578 00:25:47,760 --> 00:25:49,280 And this is quite interesting. 579 00:25:49,440 --> 00:25:50,940 These services are available. 580 00:25:51,100 --> 00:25:52,400 After EFI has. 581 00:25:52,580 --> 00:25:53,740 After the environment has finished. 582 00:25:54,160 --> 00:25:55,940 So once the bootloader is executing. 583 00:25:56,880 --> 00:25:57,640 Runtime services. 584 00:25:57,920 --> 00:25:58,580 Are still available. 585 00:25:59,500 --> 00:26:01,200 And the kind of idea of this. 586 00:26:01,380 --> 00:26:02,860 Is that ultimately. 587 00:26:03,640 --> 00:26:05,300 EFI can provide device drivers. 588 00:26:05,540 --> 00:26:07,500 That the operating system can also use. 589 00:26:08,860 --> 00:26:09,640 Right now. 590 00:26:10,220 --> 00:26:11,660 People aren't really using this. 591 00:26:11,880 --> 00:26:12,760 But it's an interesting idea. 592 00:26:13,080 --> 00:26:15,600 That you could expose some services. 593 00:26:15,840 --> 00:26:16,980 In the EFI environment. 594 00:26:17,120 --> 00:26:17,840 That are still available. 595 00:26:17,960 --> 00:26:19,400 When the operating system is booted up. 596 00:26:22,000 --> 00:26:23,060 The final definition. 597 00:26:23,400 --> 00:26:25,400 Is the framework. 598 00:26:25,940 --> 00:26:27,160 And this is Intel's reference implementation. 599 00:26:27,620 --> 00:26:29,480 And this is what's actually used by OS X. 600 00:26:30,240 --> 00:26:31,740 And the interesting thing. 601 00:26:31,820 --> 00:26:33,440 Is that it's actually partially open source. 602 00:26:33,860 --> 00:26:35,020 So if you're interested. 603 00:26:35,140 --> 00:26:37,340 Go to tianocore.org. 604 00:26:37,420 --> 00:26:38,580 And have a look at it. 605 00:26:39,100 --> 00:26:40,480 And perhaps unsurprisingly. 606 00:26:40,620 --> 00:26:41,780 Intel views the framework. 607 00:26:41,840 --> 00:26:43,540 As the implementation of choice. 608 00:26:43,720 --> 00:26:45,820 If you're looking for an EFI implementation. 609 00:26:48,980 --> 00:26:49,700 So what about. 610 00:26:49,760 --> 00:26:50,420 EFI and security. 611 00:26:50,800 --> 00:26:52,980 Well the 1.10 spec. 612 00:26:53,880 --> 00:26:55,320 Isn't really focused on security. 613 00:26:57,020 --> 00:26:58,280 The framework itself. 614 00:26:58,940 --> 00:27:00,400 The framework spec docs. 615 00:27:00,620 --> 00:27:02,070 Remember that's Intel's implementation. 616 00:27:03,240 --> 00:27:04,600 Actually starts to elaborate. 617 00:27:04,900 --> 00:27:06,520 And says you should have a security phase. 618 00:27:06,740 --> 00:27:07,720 The security phase. 619 00:27:07,720 --> 00:27:08,660 Is where you. 620 00:27:09,240 --> 00:27:10,760 Set your core roots of trust. 621 00:27:12,520 --> 00:27:13,480 And basically. 622 00:27:13,540 --> 00:27:14,580 You should make sure it's secure. 623 00:27:17,060 --> 00:27:18,700 So the security phase. 624 00:27:18,800 --> 00:27:20,000 In Intel's implementation. 625 00:27:20,440 --> 00:27:22,140 Is responsible for handling. 626 00:27:22,680 --> 00:27:23,220 Restarts. 627 00:27:23,380 --> 00:27:24,180 As I said. 628 00:27:25,940 --> 00:27:26,220 Of trust. 629 00:27:26,780 --> 00:27:28,780 And it's responsible for handing off. 630 00:27:28,860 --> 00:27:31,380 To the pre EFI phase. 631 00:27:32,060 --> 00:27:33,460 The pre EFI phase. 632 00:27:33,540 --> 00:27:34,340 Is basically. 633 00:27:35,640 --> 00:27:37,860 The phase in which the environments brought up. 634 00:27:38,080 --> 00:27:38,460 So. 635 00:27:38,780 --> 00:27:40,400 We have to get the hardware going. 636 00:27:41,420 --> 00:27:42,360 So for example. 637 00:27:42,460 --> 00:27:44,500 This is where the north bridge would be configured. 638 00:27:44,620 --> 00:27:45,700 And the south bridge would be configured. 639 00:27:46,720 --> 00:27:48,360 And the PEI phase. 640 00:27:48,900 --> 00:27:50,420 Invokes the driver execution environment. 641 00:27:50,780 --> 00:27:52,900 Which then means we can load drivers. 642 00:27:52,980 --> 00:27:53,640 And load our applications. 643 00:27:56,560 --> 00:27:58,100 So this is kind of what it looks like. 644 00:27:58,140 --> 00:27:59,000 With the various phases. 645 00:28:03,780 --> 00:28:04,260 So. 646 00:28:04,880 --> 00:28:06,160 How can we abuse EFI? 647 00:28:08,020 --> 00:28:09,680 The first objective is. 648 00:28:09,740 --> 00:28:11,640 We need to get our code running in the EFI environment. 649 00:28:12,640 --> 00:28:14,360 There's a few different ways of doing this. 650 00:28:14,860 --> 00:28:15,600 We could. 651 00:28:16,320 --> 00:28:17,600 Modify the bootloader itself. 652 00:28:18,260 --> 00:28:19,800 The bootloader for SX. 653 00:28:19,900 --> 00:28:22,360 Is just simply an EFI binary on disk. 654 00:28:22,500 --> 00:28:24,360 We can simply patch that binary. 655 00:28:25,440 --> 00:28:25,920 And then. 656 00:28:26,400 --> 00:28:27,900 The next stack I'm going to talk about. 657 00:28:28,300 --> 00:28:29,800 And I'll go through these in detail. 658 00:28:29,840 --> 00:28:30,580 On the next few slides. 659 00:28:30,640 --> 00:28:33,420 Is modifying NVRAM variables. 660 00:28:33,880 --> 00:28:35,520 So if you're familiar with open firmware. 661 00:28:35,760 --> 00:28:36,700 And the way that worked. 662 00:28:36,980 --> 00:28:39,300 Ultimately you have some global variables. 663 00:28:39,400 --> 00:28:40,920 Stored in some non-volatile RAM. 664 00:28:41,140 --> 00:28:42,640 That basically tell you. 665 00:28:42,980 --> 00:28:44,360 What bootloader you want to use. 666 00:28:45,940 --> 00:28:46,380 Thirdly. 667 00:28:46,400 --> 00:28:48,140 We could patch the framework itself. 668 00:28:48,640 --> 00:28:49,360 And reflash. 669 00:28:52,020 --> 00:28:52,460 Fourthly. 670 00:28:52,460 --> 00:28:54,080 We could go for an implementation floor. 671 00:28:54,220 --> 00:28:55,200 In one of the EFI drivers. 672 00:28:57,540 --> 00:28:58,720 Once we've actually got code. 673 00:28:59,040 --> 00:29:00,280 Running in the EFI environment. 674 00:29:00,680 --> 00:29:01,020 Then. 675 00:29:01,200 --> 00:29:03,080 How do we subvert the bootloader? 676 00:29:04,280 --> 00:29:05,160 We could. 677 00:29:05,460 --> 00:29:07,240 Hook one of the runtime services. 678 00:29:07,460 --> 00:29:08,220 Or a boot service. 679 00:29:08,460 --> 00:29:09,920 That we know the bootloader will rely on. 680 00:29:11,240 --> 00:29:13,040 We could modify the ACPE tables. 681 00:29:13,360 --> 00:29:14,100 As I said. 682 00:29:14,820 --> 00:29:15,700 EFI basically. 683 00:29:16,780 --> 00:29:18,060 Doesn't really mess with them. 684 00:29:18,320 --> 00:29:19,580 And it needs to keep them there. 685 00:29:22,460 --> 00:29:22,760 In the existing spec. 686 00:29:24,580 --> 00:29:26,540 We could load a system management mode driver. 687 00:29:26,800 --> 00:29:27,640 And that's probably. 688 00:29:27,760 --> 00:29:28,920 The most interesting attack. 689 00:29:29,140 --> 00:29:30,420 So I'll spend time on that. 690 00:29:32,060 --> 00:29:33,520 Or we could carry out an attack. 691 00:29:33,720 --> 00:29:34,940 That's kind of similar to attacks. 692 00:29:35,040 --> 00:29:36,120 Against the legacy BIOS. 693 00:29:36,640 --> 00:29:39,060 If we know that there's a compatibility. 694 00:29:39,140 --> 00:29:39,960 Support module. 695 00:29:40,480 --> 00:29:41,620 Boot camp for example. 696 00:29:44,540 --> 00:29:44,980 Okay. 697 00:29:45,020 --> 00:29:45,580 The first attack. 698 00:29:45,800 --> 00:29:46,620 And the simplest is. 699 00:29:46,740 --> 00:29:48,560 We modify the bootloader. 700 00:29:53,820 --> 00:29:54,960 OSX doesn't actually use. 701 00:29:55,020 --> 00:29:56,020 The EFI system partition. 702 00:29:57,200 --> 00:29:58,500 But carrying out this attack. 703 00:29:58,640 --> 00:30:00,000 Is kind of unstealthy. 704 00:30:00,740 --> 00:30:01,440 Simply because. 705 00:30:01,520 --> 00:30:02,720 We could detect it pretty easily. 706 00:30:02,840 --> 00:30:04,420 With anything like tripwire. 707 00:30:04,820 --> 00:30:06,300 Unless our rootkit is aware. 708 00:30:06,460 --> 00:30:08,520 That those tools are going to be looking for it. 709 00:30:09,080 --> 00:30:10,620 And if you're patching a file on disk. 710 00:30:10,740 --> 00:30:12,640 Why don't you just patch the kernel directly instead. 711 00:30:14,700 --> 00:30:15,720 This last point. 712 00:30:15,800 --> 00:30:17,700 Is not really applicable to OSX implementation. 713 00:30:18,280 --> 00:30:18,620 Sorry. 714 00:30:18,820 --> 00:30:20,060 Intel's implementation of EFI. 715 00:30:22,460 --> 00:30:24,220 Is not really applicable to the UEFI. 716 00:30:25,180 --> 00:30:25,720 Implementations. 717 00:30:26,210 --> 00:30:28,220 Where basically we can enforce driver signing. 718 00:30:29,560 --> 00:30:30,400 And so. 719 00:30:31,060 --> 00:30:32,980 Simply trying to get an unsigned. 720 00:30:33,580 --> 00:30:34,360 Bootloader working. 721 00:30:34,400 --> 00:30:34,800 Won't work. 722 00:30:39,100 --> 00:30:39,820 Modifying the. 723 00:30:39,920 --> 00:30:42,040 Non-volatile RAM variables. 724 00:30:43,500 --> 00:30:44,360 As I said. 725 00:30:44,360 --> 00:30:46,180 These specify which bootloader we want to use. 726 00:30:46,500 --> 00:30:48,080 There's an interface for us to do this. 727 00:30:48,160 --> 00:30:49,320 From EFI. 728 00:30:50,680 --> 00:30:52,340 If you run the MVRAM tool. 729 00:30:52,460 --> 00:30:53,140 From OSX. 730 00:30:53,240 --> 00:30:54,740 It lets you dump and modify. 731 00:30:56,060 --> 00:30:57,020 The variables. 732 00:30:58,280 --> 00:30:59,340 We can create a. 733 00:31:00,640 --> 00:31:01,600 Custom bootloader. 734 00:31:01,740 --> 00:31:03,740 We can set the EFI boot device. 735 00:31:04,000 --> 00:31:06,120 And tell the system to use that. 736 00:31:07,120 --> 00:31:08,500 And what we actually. 737 00:31:09,160 --> 00:31:10,520 Do in this bootloader. 738 00:31:11,180 --> 00:31:12,240 We'll typically do. 739 00:31:12,320 --> 00:31:13,060 One of the attacks. 740 00:31:13,180 --> 00:31:14,780 That I'm going to come on to shortly. 741 00:31:15,620 --> 00:31:17,820 Where we will shim one of the services. 742 00:31:17,960 --> 00:31:18,420 That's available. 743 00:31:18,420 --> 00:31:20,080 The boot services of the runtime service. 744 00:31:20,320 --> 00:31:22,400 And then simply call the original bootloader. 745 00:31:23,040 --> 00:31:24,200 Is this stealthier. 746 00:31:24,240 --> 00:31:25,160 Than the previous one. 747 00:31:25,380 --> 00:31:26,340 Well probably not. 748 00:31:26,420 --> 00:31:28,180 Because we are modifying MVRAM. 749 00:31:28,540 --> 00:31:31,180 And if I was doing forensics on OSX. 750 00:31:31,300 --> 00:31:33,240 I would definitely be interested in what's in MVRAM. 751 00:31:36,460 --> 00:31:37,640 Code injection attacks. 752 00:31:38,420 --> 00:31:39,880 These are going to be pretty important. 753 00:31:40,380 --> 00:31:40,900 When. 754 00:31:42,760 --> 00:31:44,100 When people actually implement. 755 00:31:44,220 --> 00:31:44,940 UEFI properly. 756 00:31:46,840 --> 00:31:47,360 Ultimately. 757 00:31:48,420 --> 00:31:49,580 For some kind of. 758 00:31:50,220 --> 00:31:50,680 Overflow. 759 00:31:52,240 --> 00:31:53,780 Or some kind of bug. 760 00:31:54,180 --> 00:31:55,660 In verifying digital signatures. 761 00:31:56,640 --> 00:31:57,800 And when we talk about. 762 00:31:57,860 --> 00:31:59,320 The possibility for this. 763 00:31:59,380 --> 00:32:00,400 And people might ask well. 764 00:32:01,580 --> 00:32:02,560 What kind of user. 765 00:32:02,760 --> 00:32:04,580 What kind of data do we control in this environment. 766 00:32:05,020 --> 00:32:06,580 There's actually some good targets. 767 00:32:07,240 --> 00:32:09,380 So we could target the file system drivers. 768 00:32:10,260 --> 00:32:10,880 We could. 769 00:32:11,380 --> 00:32:12,940 Malform the file system in some way. 770 00:32:13,900 --> 00:32:15,080 So that we cause an overflow. 771 00:32:16,440 --> 00:32:17,520 PE parsing code. 772 00:32:18,420 --> 00:32:19,180 Is always a good one. 773 00:32:19,400 --> 00:32:21,460 In my work as a security consultant. 774 00:32:21,760 --> 00:32:23,340 Looking at antivirus vendor software. 775 00:32:23,720 --> 00:32:24,480 For example. 776 00:32:25,100 --> 00:32:27,120 The number of bugs I've found in their code. 777 00:32:27,220 --> 00:32:28,460 Relating to PE parsing. 778 00:32:28,480 --> 00:32:30,260 That ultimately lead to code execution is huge. 779 00:32:30,640 --> 00:32:32,660 So I'd be really surprised. 780 00:32:32,760 --> 00:32:34,500 If there aren't any bugs like that. 781 00:32:35,440 --> 00:32:36,080 Crypto code. 782 00:32:36,200 --> 00:32:39,260 Again we'll obviously be verifying. 783 00:32:39,260 --> 00:32:40,600 Digital signatures on binaries. 784 00:32:40,840 --> 00:32:42,580 So we've got some good targets here. 785 00:32:42,800 --> 00:32:44,520 We can modify the data in the certs. 786 00:32:44,520 --> 00:32:46,380 The data itself in the certs. 787 00:32:46,380 --> 00:32:48,360 Or we could go for ASM1 decoding. 788 00:32:49,660 --> 00:32:51,660 And any data coming off the network. 789 00:32:55,140 --> 00:32:56,540 So how might we actually. 790 00:32:57,740 --> 00:32:59,000 Subvert the bootloader. 791 00:32:59,000 --> 00:33:00,340 Once we've got code running in EFI. 792 00:33:01,240 --> 00:33:01,760 Well. 793 00:33:01,940 --> 00:33:04,080 The spec says that when the bootloader exits. 794 00:33:05,000 --> 00:33:05,520 Sorry. 795 00:33:05,600 --> 00:33:08,100 When the bootloader is ready to transfer control to the kernel. 796 00:33:08,400 --> 00:33:10,160 It must notify the EFI environment. 797 00:33:10,620 --> 00:33:12,060 By calling exit boot services. 798 00:33:13,800 --> 00:33:14,320 So. 799 00:33:14,520 --> 00:33:15,500 This is a great place to hook. 800 00:33:15,720 --> 00:33:16,160 Because. 801 00:33:16,640 --> 00:33:18,780 We know at this point the kernel is going to be loaded. 802 00:33:19,240 --> 00:33:21,120 So if we hook exit boot services. 803 00:33:22,420 --> 00:33:23,800 When the bootloader actually. 804 00:33:24,480 --> 00:33:25,420 Calls exit boot services. 805 00:33:25,640 --> 00:33:26,220 We get control. 806 00:33:26,800 --> 00:33:28,120 And we can patch the kernel. 807 00:33:30,180 --> 00:33:32,540 It's fairly easy to actually carry out this attack. 808 00:33:32,940 --> 00:33:34,440 We can create a runtime driver. 809 00:33:34,640 --> 00:33:37,440 That simply locates the EFI system table. 810 00:33:37,980 --> 00:33:40,740 And replaces the function pointer for exit boot services. 811 00:33:42,220 --> 00:33:44,260 I also looked at shimming runtime services. 812 00:33:44,520 --> 00:33:45,000 But. 813 00:33:45,360 --> 00:33:46,940 Not many of them are actually called. 814 00:33:47,820 --> 00:33:49,480 By far the exit boot services. 815 00:33:49,680 --> 00:33:51,100 Seem the best place to hook. 816 00:33:54,500 --> 00:33:55,300 This is what. 817 00:33:55,920 --> 00:33:58,060 Elilo booting Linux looks like. 818 00:33:59,440 --> 00:34:00,260 So we see that. 819 00:34:00,320 --> 00:34:00,900 It loads the kernel. 820 00:34:02,180 --> 00:34:03,040 Free some resources. 821 00:34:03,660 --> 00:34:06,100 And then calls boot services. 822 00:34:06,560 --> 00:34:07,560 And then calls the. 823 00:34:07,660 --> 00:34:08,580 Sorry exit boot services. 824 00:34:08,800 --> 00:34:11,080 And then it calls the start kernel function. 825 00:34:12,040 --> 00:34:13,020 So you can see that. 826 00:34:14,520 --> 00:34:14,920 When we get in control. 827 00:34:15,020 --> 00:34:15,960 When it calls exit boot services. 828 00:34:16,460 --> 00:34:18,740 It's pretty easy for us to locate the kernel. 829 00:34:18,880 --> 00:34:19,280 In memory. 830 00:34:23,040 --> 00:34:23,900 Okay this is. 831 00:34:23,920 --> 00:34:25,720 This is probably the most interesting attack. 832 00:34:25,780 --> 00:34:26,460 Against EFI. 833 00:34:27,520 --> 00:34:28,740 System management mode. 834 00:34:29,460 --> 00:34:31,060 Has been on most processors. 835 00:34:31,500 --> 00:34:32,660 Since the 386. 836 00:34:33,540 --> 00:34:34,020 And. 837 00:34:35,420 --> 00:34:37,300 I know virtualization rootkits. 838 00:34:37,380 --> 00:34:38,880 Are getting a lot of press these days. 839 00:34:39,740 --> 00:34:41,120 But actually I think. 840 00:34:41,300 --> 00:34:42,340 System management mode. 841 00:34:44,520 --> 00:34:44,740 Has been on virtualization. 842 00:34:44,760 --> 00:34:47,080 And it's been on most people's processors. 843 00:34:48,500 --> 00:34:49,500 System management mode. 844 00:34:49,580 --> 00:34:51,340 Is a kind of get out of jail free card. 845 00:34:51,460 --> 00:34:52,360 For platform designers. 846 00:34:52,940 --> 00:34:55,900 So pretty much any time they need to do something. 847 00:34:56,140 --> 00:34:57,700 That the hardware doesn't let them. 848 00:34:57,840 --> 00:34:59,680 They can probably do it in system management mode. 849 00:35:00,400 --> 00:35:00,880 So. 850 00:35:01,880 --> 00:35:04,160 Basically things like the century rollover bug. 851 00:35:04,340 --> 00:35:05,280 Was fixed with. 852 00:35:06,040 --> 00:35:08,500 By vendors putting some code in system management mode. 853 00:35:10,320 --> 00:35:12,080 And ultimately system management mode. 854 00:35:12,240 --> 00:35:14,360 Is very similar to virtualization. 855 00:35:14,520 --> 00:35:16,160 In that the operating system. 856 00:35:16,620 --> 00:35:17,400 Doesn't know. 857 00:35:17,540 --> 00:35:19,800 That we've gone into system management mode. 858 00:35:20,420 --> 00:35:22,280 So in the same way that. 859 00:35:22,400 --> 00:35:23,500 In virtualization. 860 00:35:23,780 --> 00:35:25,720 The operating system shouldn't really know. 861 00:35:25,800 --> 00:35:27,040 That hypervisor even exists. 862 00:35:28,960 --> 00:35:29,900 In this scenario. 863 00:35:30,000 --> 00:35:31,480 The operating system won't know. 864 00:35:31,540 --> 00:35:33,480 That we've executed code in system management mode. 865 00:35:34,580 --> 00:35:36,460 And we can get into system management mode. 866 00:35:36,520 --> 00:35:37,240 A number of ways. 867 00:35:38,020 --> 00:35:40,560 Ultimately we need to get a system management interrupt fired. 868 00:35:41,000 --> 00:35:42,960 And these can be triggered by external events. 869 00:35:43,320 --> 00:35:43,920 So for example. 870 00:35:44,520 --> 00:35:46,260 Plugging a USB device into your laptop. 871 00:35:46,260 --> 00:35:47,580 Probably generates an SMI. 872 00:35:48,760 --> 00:35:50,200 We can also set these up. 873 00:35:50,260 --> 00:35:51,300 To be triggered periodically. 874 00:35:51,560 --> 00:35:52,560 Every few seconds. 875 00:35:53,740 --> 00:35:56,660 And we can also trigger SMIs. 876 00:35:56,740 --> 00:35:57,800 On IO access. 877 00:35:58,340 --> 00:35:59,540 So this is quite interesting. 878 00:35:59,720 --> 00:36:02,860 If we do IO access to a particular port. 879 00:36:03,080 --> 00:36:04,140 Then we can track that. 880 00:36:04,400 --> 00:36:06,520 And jump straight into system management mode. 881 00:36:09,480 --> 00:36:11,400 How might we abuse system management mode. 882 00:36:11,400 --> 00:36:11,980 Well. 883 00:36:12,540 --> 00:36:14,060 The only presentation I've seen. 884 00:36:14,140 --> 00:36:15,480 That actually discussed this. 885 00:36:15,620 --> 00:36:17,640 Was Luc Deflois at CanSec. 886 00:36:18,080 --> 00:36:20,940 And he used it for subverting BSD secure levels. 887 00:36:21,460 --> 00:36:22,420 And in his paper. 888 00:36:22,500 --> 00:36:24,460 He hinted that system management mode. 889 00:36:24,520 --> 00:36:25,620 Would be pretty bad for malware. 890 00:36:27,420 --> 00:36:28,380 Why is that exactly? 891 00:36:28,600 --> 00:36:28,800 Well. 892 00:36:29,780 --> 00:36:31,160 Things like hardware breakpoints. 893 00:36:31,260 --> 00:36:32,780 Just don't work in system management mode. 894 00:36:33,560 --> 00:36:35,560 So if we had some detection software. 895 00:36:35,980 --> 00:36:37,480 And we were using hardware breakpoints. 896 00:36:37,560 --> 00:36:38,760 To try and detect a rootkit. 897 00:36:42,560 --> 00:36:43,760 It would be pretty bad. 898 00:36:43,760 --> 00:36:45,200 The operating system cannot get access. 899 00:36:45,280 --> 00:36:47,680 To the RAM allocated. 900 00:36:47,860 --> 00:36:48,860 For system management mode. 901 00:36:49,100 --> 00:36:51,720 If the system management. 902 00:36:52,140 --> 00:36:54,040 The SMRAM config register. 903 00:36:54,140 --> 00:36:54,900 Has been set. 904 00:36:55,060 --> 00:36:56,020 To not allow it access. 905 00:36:56,680 --> 00:36:57,940 So there's a lock bit. 906 00:36:58,440 --> 00:37:00,480 That some vendors set. 907 00:37:00,600 --> 00:37:01,340 Some don't. 908 00:37:01,380 --> 00:37:04,780 In fact Luc Deflois talk. 909 00:37:05,220 --> 00:37:05,740 Basically. 910 00:37:06,700 --> 00:37:08,040 Only concerns systems. 911 00:37:08,120 --> 00:37:09,320 Where the lock bit wasn't set. 912 00:37:11,540 --> 00:37:13,500 So once we've actually set that lock bit. 913 00:37:13,580 --> 00:37:14,760 The operating system cannot see. 914 00:37:14,820 --> 00:37:15,680 System management RAM. 915 00:37:17,760 --> 00:37:19,040 SMIs can't be interrupted. 916 00:37:19,120 --> 00:37:19,520 By anything. 917 00:37:20,320 --> 00:37:21,980 Even non-maskable interrupts. 918 00:37:23,100 --> 00:37:24,040 And as I said. 919 00:37:24,160 --> 00:37:26,240 SMM can also trap IO reads and writes. 920 00:37:26,360 --> 00:37:27,020 Which is kind of scary. 921 00:37:28,120 --> 00:37:30,220 So this is the kind of perfect fodder. 922 00:37:30,260 --> 00:37:31,440 For a rootkit. 923 00:37:31,660 --> 00:37:33,620 That is seemingly undetectable. 924 00:37:34,920 --> 00:37:35,880 I say seemingly. 925 00:37:36,000 --> 00:37:36,680 Because ultimately. 926 00:37:36,680 --> 00:37:38,180 If you're looking for it. 927 00:37:38,240 --> 00:37:39,080 You could probably find it. 928 00:37:39,380 --> 00:37:40,560 Timing attacks for example. 929 00:37:42,300 --> 00:37:44,120 But why haven't we actually seen. 930 00:37:44,160 --> 00:37:45,480 A SMM rootkit. 931 00:37:45,640 --> 00:37:47,040 Considering that it's been on processors. 932 00:37:47,180 --> 00:37:48,380 Since 386 SL. 933 00:37:49,300 --> 00:37:51,520 Well the barrier is pretty high for entry. 934 00:37:53,160 --> 00:37:53,620 Ultimately. 935 00:37:53,680 --> 00:37:55,080 To debug system management mode. 936 00:37:55,160 --> 00:37:56,340 You need a logic analyzer. 937 00:37:57,820 --> 00:38:00,140 So it's not going to be too easy to develop. 938 00:38:00,720 --> 00:38:02,980 And there's actually not much code out there. 939 00:38:03,040 --> 00:38:03,580 That shows you. 940 00:38:03,640 --> 00:38:06,000 How to get into system management mode. 941 00:38:06,940 --> 00:38:09,060 How to write a system management mode handler. 942 00:38:11,100 --> 00:38:12,140 There's limited opportunity. 943 00:38:12,180 --> 00:38:13,880 If the vendor has set the lock bit. 944 00:38:13,960 --> 00:38:15,620 For malware to use it. 945 00:38:16,680 --> 00:38:18,280 Ultimately if we compromise somebody. 946 00:38:18,860 --> 00:38:19,600 And the. 947 00:38:21,040 --> 00:38:22,200 Buyer has set the lock bit. 948 00:38:22,500 --> 00:38:24,600 Then we'll have to wait for the next reboot. 949 00:38:24,760 --> 00:38:25,120 To actually. 950 00:38:25,740 --> 00:38:27,660 We'll have to carry out the. 951 00:38:28,660 --> 00:38:30,540 One of the warm reboot attacks for example. 952 00:38:30,540 --> 00:38:32,560 To then try and get our code into system management mode. 953 00:38:33,820 --> 00:38:34,400 And also. 954 00:38:34,480 --> 00:38:36,280 System dependencies make it less attractive. 955 00:38:36,680 --> 00:38:37,700 That's to say that. 956 00:38:39,100 --> 00:38:40,320 You don't really know. 957 00:38:40,400 --> 00:38:41,380 What your vendor is using. 958 00:38:41,420 --> 00:38:42,940 System management mode for. 959 00:38:43,600 --> 00:38:45,400 So you probably don't want to go blindly. 960 00:38:45,560 --> 00:38:46,900 Trashing system management RAM. 961 00:38:46,980 --> 00:38:47,620 With your own code. 962 00:38:47,780 --> 00:38:49,660 Because you're probably likely to make something stop working. 963 00:38:52,740 --> 00:38:54,760 So why do I mention system management mode. 964 00:38:54,840 --> 00:38:55,820 In the context of EFI. 965 00:38:57,080 --> 00:38:58,460 Well EFI actually. 966 00:38:58,680 --> 00:39:00,200 Provides some very clean. 967 00:39:00,280 --> 00:39:01,880 Very easy to use interfaces. 968 00:39:01,980 --> 00:39:03,180 For system management mode. 969 00:39:03,940 --> 00:39:04,860 They actually take. 970 00:39:04,960 --> 00:39:06,440 All of the hard work out of. 971 00:39:08,260 --> 00:39:09,160 Creating a system. 972 00:39:09,240 --> 00:39:10,260 Management mode driver. 973 00:39:11,180 --> 00:39:12,700 They provide us with a protocol. 974 00:39:13,060 --> 00:39:15,160 For registering our driver. 975 00:39:15,960 --> 00:39:17,000 An access protocol. 976 00:39:17,160 --> 00:39:18,520 So we can toggle the lock bit. 977 00:39:19,300 --> 00:39:20,820 They provide protocol for triggering. 978 00:39:20,920 --> 00:39:22,200 System management interrupts. 979 00:39:22,700 --> 00:39:24,760 And the child dispatch protocol for. 980 00:39:25,120 --> 00:39:26,980 Setting up things like periodic callbacks. 981 00:39:28,360 --> 00:39:29,440 They even go further. 982 00:39:29,520 --> 00:39:31,140 They give us some functionality. 983 00:39:31,160 --> 00:39:33,000 To use when we're in system management mode. 984 00:39:33,180 --> 00:39:34,860 So the SMST. 985 00:39:35,400 --> 00:39:36,640 Allows us to allocate memory. 986 00:39:38,060 --> 00:39:39,120 It also gives us. 987 00:39:39,160 --> 00:39:40,540 Access to the CPU context. 988 00:39:40,600 --> 00:39:41,520 Through a nice interface. 989 00:39:42,560 --> 00:39:43,480 So for example. 990 00:39:44,260 --> 00:39:45,520 The way it might work is. 991 00:39:45,620 --> 00:39:47,480 We'll load our driver into system management mode. 992 00:39:47,740 --> 00:39:49,320 We'll set up a periodic interrupt. 993 00:39:51,080 --> 00:39:52,660 And every time our callback. 994 00:39:52,720 --> 00:39:54,660 In system management mode gets executed. 995 00:39:55,040 --> 00:39:56,860 We might want to use one of these protocols. 996 00:39:57,060 --> 00:39:59,140 To examine the state of the CPU. 997 00:39:59,460 --> 00:40:00,840 So we have a context structure. 998 00:40:01,020 --> 00:40:02,340 When we can see exactly what code. 999 00:40:03,400 --> 00:40:04,920 We can modify things appropriately. 1000 00:40:10,420 --> 00:40:12,480 The only kind of warning about. 1001 00:40:12,760 --> 00:40:14,340 The power of system management mode. 1002 00:40:14,780 --> 00:40:16,440 In the specs that I read. 1003 00:40:16,820 --> 00:40:19,320 Basically said that you have to preserve the chain of trust. 1004 00:40:19,560 --> 00:40:20,700 That you've already set up. 1005 00:40:21,000 --> 00:40:22,760 Which is kind of a pretty vague statement. 1006 00:40:23,380 --> 00:40:25,240 If you don't have a chain of trust. 1007 00:40:25,600 --> 00:40:26,960 Set up then ultimately. 1008 00:40:27,060 --> 00:40:28,760 We can trivially write a driver. 1009 00:40:28,940 --> 00:40:30,540 And get it into system management mode. 1010 00:40:30,540 --> 00:40:33,140 Which is what I've been able to do. 1011 00:40:33,220 --> 00:40:33,840 On OSX actually. 1012 00:40:34,440 --> 00:40:35,980 And if anyone's interested. 1013 00:40:36,300 --> 00:40:37,420 I'll show them. 1014 00:40:37,700 --> 00:40:39,780 Just the amount of code required to do this. 1015 00:40:39,840 --> 00:40:40,800 It's actually pretty small. 1016 00:40:45,000 --> 00:40:46,160 Next thing I want to talk about. 1017 00:40:46,240 --> 00:40:47,900 Is compatibility support modules. 1018 00:40:48,680 --> 00:40:50,360 And these provide legacy compatibility. 1019 00:40:51,380 --> 00:40:52,320 So for example. 1020 00:40:52,500 --> 00:40:54,220 You want to install an operating system. 1021 00:40:54,360 --> 00:40:55,140 On an EFI system. 1022 00:40:55,340 --> 00:40:56,560 That requires a BIOS. 1023 00:40:58,340 --> 00:40:59,580 Basically all you need to do. 1024 00:41:00,540 --> 00:41:01,400 Is the compatibility support module. 1025 00:41:01,560 --> 00:41:03,140 Which is simply an EFI application. 1026 00:41:03,460 --> 00:41:04,720 Or it could be a driver. 1027 00:41:05,680 --> 00:41:07,340 The majority of the work is. 1028 00:41:07,440 --> 00:41:09,800 You need to implement the interrupt vector table. 1029 00:41:10,100 --> 00:41:11,680 So that when the bootloader. 1030 00:41:12,620 --> 00:41:13,420 Fires an interrupt. 1031 00:41:15,060 --> 00:41:16,020 Ultimately you. 1032 00:41:16,780 --> 00:41:17,580 You can actually. 1033 00:41:18,420 --> 00:41:19,620 Carry out the same functionality. 1034 00:41:20,180 --> 00:41:22,300 So most compatibility support modules. 1035 00:41:22,700 --> 00:41:24,260 The two I've looked at. 1036 00:41:24,440 --> 00:41:25,920 XP on Mac and Boot Camp. 1037 00:41:26,340 --> 00:41:28,480 Will thunk to. 1038 00:41:28,640 --> 00:41:29,780 32 bit protective mode. 1039 00:41:30,540 --> 00:41:32,000 So they'll execute the. 1040 00:41:32,980 --> 00:41:34,260 Bootloader in 16 bit real mode. 1041 00:41:34,480 --> 00:41:34,740 And then. 1042 00:41:34,960 --> 00:41:35,980 When it calls the interrupt. 1043 00:41:36,200 --> 00:41:38,140 There'll be a thunk into 32 bit protective mode. 1044 00:41:38,440 --> 00:41:40,620 It will then carry out the equivalent EFI function. 1045 00:41:41,060 --> 00:41:42,020 And then thunk back. 1046 00:41:43,980 --> 00:41:44,520 So really. 1047 00:41:45,960 --> 00:41:47,640 If we have code execution at this point. 1048 00:41:47,760 --> 00:41:49,700 All we need to do is hit the interrupt vector table. 1049 00:41:50,000 --> 00:41:51,340 Or we can patch the handlers. 1050 00:41:55,640 --> 00:41:56,040 UFI. 1051 00:41:57,780 --> 00:41:58,260 UFI. 1052 00:41:58,500 --> 00:41:58,980 UFI. 1053 00:41:59,200 --> 00:42:00,760 Is basically the next version of EFI. 1054 00:42:01,000 --> 00:42:03,260 So Intel developed EFI. 1055 00:42:04,200 --> 00:42:04,680 And. 1056 00:42:05,320 --> 00:42:07,020 Version 1.10 is theirs. 1057 00:42:07,240 --> 00:42:10,000 They then gave that to the UEFI consortium. 1058 00:42:10,060 --> 00:42:11,760 Which has all the major players. 1059 00:42:11,780 --> 00:42:12,560 You'd expect in it. 1060 00:42:12,800 --> 00:42:14,900 And they're up to version 2.1 of the spec. 1061 00:42:15,580 --> 00:42:17,060 And they've started to. 1062 00:42:17,720 --> 00:42:19,220 Flesh out security now. 1063 00:42:19,780 --> 00:42:20,740 So for example. 1064 00:42:21,260 --> 00:42:22,960 The trusted computing group. 1065 00:42:22,960 --> 00:42:24,440 Have also released specs to say. 1066 00:42:24,520 --> 00:42:26,380 How EFI is supposed to link in with. 1067 00:42:26,480 --> 00:42:27,280 The TPM. 1068 00:42:27,520 --> 00:42:28,860 And how we can actually start. 1069 00:42:29,860 --> 00:42:32,500 Doing a secure boot process for EFI. 1070 00:42:34,920 --> 00:42:35,500 Kind of. 1071 00:42:36,140 --> 00:42:37,620 I put this in just to. 1072 00:42:38,220 --> 00:42:39,620 Demonstrate the point about complexity. 1073 00:42:39,940 --> 00:42:41,800 This is what the UEFI spec says. 1074 00:42:42,100 --> 00:42:44,240 This is how you have a PE file that you have to sign. 1075 00:42:44,960 --> 00:42:45,840 And ultimately. 1076 00:42:46,620 --> 00:42:48,740 I'm sure there's going to be code execution bugs. 1077 00:42:49,080 --> 00:42:49,180 In. 1078 00:42:49,960 --> 00:42:51,720 As I talked about implementation flaws. 1079 00:42:54,280 --> 00:42:54,720 So. 1080 00:42:54,780 --> 00:42:56,640 Some summary and conclusions here. 1081 00:42:57,340 --> 00:42:58,240 EFI is interesting. 1082 00:42:58,480 --> 00:43:00,560 It offers a pretty large attack surface. 1083 00:43:00,760 --> 00:43:02,280 Versus a legacy BIOS. 1084 00:43:02,960 --> 00:43:04,820 The fact that these high level. 1085 00:43:05,080 --> 00:43:06,200 Development tools are available. 1086 00:43:06,360 --> 00:43:08,100 The fact that you just need to be able to write C code. 1087 00:43:08,340 --> 00:43:10,300 Is basically now making it a target for. 1088 00:43:11,280 --> 00:43:12,240 Much more of a target. 1089 00:43:12,320 --> 00:43:13,360 Than the original BIOS was. 1090 00:43:14,420 --> 00:43:16,660 I will expect that in the next few years. 1091 00:43:16,720 --> 00:43:18,680 We will see some attempt at malware. 1092 00:43:18,860 --> 00:43:20,180 That runs in the EFI environment. 1093 00:43:22,260 --> 00:43:22,700 And. 1094 00:43:22,960 --> 00:43:24,100 The third party driver model. 1095 00:43:24,380 --> 00:43:26,040 Presents an easy target. 1096 00:43:26,140 --> 00:43:27,380 You can download the development kit. 1097 00:43:27,520 --> 00:43:29,420 And write your own EFI application or driver. 1098 00:43:29,480 --> 00:43:29,920 Pretty easily. 1099 00:43:30,940 --> 00:43:33,100 The EFI spec is pretty vague on security. 1100 00:43:33,500 --> 00:43:34,400 It's an interface. 1101 00:43:37,780 --> 00:43:38,520 It's the interface. 1102 00:43:38,660 --> 00:43:39,340 It's not the implementation. 1103 00:43:39,920 --> 00:43:42,780 But I guess I would have preferred to see some more. 1104 00:43:43,100 --> 00:43:44,920 Concrete information on what they're expecting. 1105 00:43:46,000 --> 00:43:46,780 For example. 1106 00:43:47,040 --> 00:43:48,400 The actual framework. 1107 00:43:48,540 --> 00:43:49,260 So Intel's implementation. 1108 00:43:49,880 --> 00:43:51,340 Doesn't go into a great deal of detail. 1109 00:43:51,440 --> 00:43:53,120 About how the sec phase should be implemented. 1110 00:43:55,180 --> 00:43:57,260 UEFI is starting to make things a lot clearer. 1111 00:43:58,040 --> 00:43:59,140 But I really believe. 1112 00:43:59,180 --> 00:44:00,420 There will be code injection attacks. 1113 00:44:02,300 --> 00:44:03,200 So that's pretty much. 1114 00:44:03,260 --> 00:44:05,200 As far as I've got on EFI right now. 1115 00:44:06,440 --> 00:44:07,360 If I was to say. 1116 00:44:07,460 --> 00:44:09,560 The key kind of take away from this talk. 1117 00:44:09,800 --> 00:44:10,900 I think it would be that. 1118 00:44:10,940 --> 00:44:13,000 We should all be concerned about system management mode. 1119 00:44:14,120 --> 00:44:15,320 I don't necessarily think. 1120 00:44:15,380 --> 00:44:16,420 It's a threat that. 1121 00:44:16,960 --> 00:44:18,160 We're going to see any malware. 1122 00:44:18,260 --> 00:44:19,200 Like run of the mill malware. 1123 00:44:19,360 --> 00:44:20,980 That tries to get into system management mode. 1124 00:44:21,260 --> 00:44:22,840 But it's something to keep in mind. 1125 00:44:23,020 --> 00:44:26,380 When people are talking about virtualized rootkits. 1126 00:44:26,520 --> 00:44:27,760 I'd actually be more concerned. 1127 00:44:27,820 --> 00:44:28,840 About system management mode. 1128 00:44:29,000 --> 00:44:30,460 Because that's probably on your processor. 1129 00:44:30,740 --> 00:44:32,040 Whereas virtualization. 1130 00:44:32,460 --> 00:44:35,640 It's obviously not on all processors right now. 1131 00:44:36,260 --> 00:44:37,440 So thanks very much.