Wow. Hello everybody. Thank you for coming. Just a little survey before we start. Does everybody have any experience with writing viruses kind of thing for master boot records? Please raise your hand. Okay, so officer, those two guys. Okay, more seriously, if you have absolutely no idea what is a BIOS or what is a boot loader, maybe you should take an app or something for the next 50 minutes. Okay, basically we're going to talk about pre-boot authentication passwords. Okay, everybody see? Okay. Pre-boot authentication. So let's start with the initial introduction kind of thing. So I'm a French guy. I live in India. I work for a company named IVS Security. I mean, IVS Technology Solutions Private Limited. I would like to pass a private message kind of thing also to the girl who leaked my tattoo yesterday night at the immunity party. So we have not been introduced formally, but my room number is 524 at the Sahara Hotel, so you're most welcome anytime. Okay, so basically we're going to talk about one new class of vulnerabilities. It's not something affecting only one piece of software, but multiple pre-boot authentication implementations. We'll define later what is exactly a pre-boot authentication password. We focus on password-based authentication only. The thing that's a bit remarkable, like if you've been to Blackout or something this year, there was a talk called boot attacks. Here, we don't need at all physical access to the computer. Okay, so we'll start with a few definitions, like defining exactly what is the scope of the talk, and what is a pre-boot authentication password. Then we'll switch to Windows, and then to unique exploitation, and then we will see a few further enhancements to the technology we've been developing. Okay, so just as a reminder, I'm pretty sure all of you know the boot seconds kind of stuff, but I've read so many mistakes that just to fix the IDs, I spent some time on that. Then we will define the different types of passwords we're going to be attacking, and have a closer look at the bias functions to read user keyboard, user input basically. Okay, here we go. So when you start a computer, the CPU starts in read mode. There is pretty nothing which is known, like there is no disk, there is no RAM, there is no nothing at the very beginning. So while memory, I mean, control is transferred to the bias by performing a long jump kind of thing, which is basically translated via hardware, since there is no RAM, to the bias entry point. So the bias itself is in charge of several things, like setting up the power, initializing the clock. Okay, it then discovers your RAM, so we can start doing things. Your hard drive with the master boot record. Okay, one thing really important, it starts at address zero, the interrupt vector table. So from now on, we can basically issue interruptions, which was not the case before. So using interruption 19, the master boot record is mapped in RAM. Okay, it's basically the boot loader. It was in charge of loading later on the kernel. So if we think about it, like let's do our kind of collecting, kind of brainstorming. Let's say we want to code a boot loader. Basically, which is the API which is available to you? There is no kernel in memory, no nothing. So what can you use? No one? Okay, so all the API which is available is indeed the bias. The bias provides you input-output interface, okay? And you could use also physical ERQs, like writing directly to disk and stuff like that. So this is very important for the rest of the speech, right? We'll focus on bias stuff for a reason. Because basically, when you want to write a boot loader, it's the only API which is available. Okay, let's see a bit the different kind of passwords you can have when you boot a computer. By pre-boot, we mean anything that can ask for a password before there is actually a kernel in memory, right? So they could be of several kinds. Like bias passwords, you know those blue screens that pop up when you first start your computer. So those are one kind. Boot loader passwords, basically those are the most common. Like if you want to have a full disk encryption, or even partial disk encryption, usually it's implemented at that level. So it could be like Vista Boot Loader, Grub, Lilo. We'll see some other examples later on. And it could be also early stage passwords. Typically, when the kernel first starts in real mode, before switching in private mode, it could ask you for a password. So we'll see that later on also. Okay, let's have a closer look at the BIOS functions. They are used to read user input. Okay, there is basically one interruption for the BIOS, which is interruption 16, which has two function relevance to us. The first one, getsKeyStroke, is mostly used to check and retrieve one keystroke at a time. And the second one, when you invoke it with a parameter, I mean, AH, parameter 01, it does pretty much the same, only it does not update the carry flag. Zero flag, sorry. So this is typically used to first check if a keystroke has been entered, and then retrieve it. For instance, in Lilo, this is done like that. So you can see there are, I mean, there's two functions implemented, right? The first one is using function, I mean, sub-function 01, and the second one is actually retrieving the key. Okay, give me two second. Okay, so if you've been doing any kind of assembly, like especially under Windows, I mean, under MS-DOS, in the good old times, when we could actually trigger BIOS interrupts and stuff like that, because nowadays, I mean, most OSCs will prevent you to do that, they are running in private mode, okay? So they have segmentation and stuff, and obviously you cannot trigger BIOS interrupts. So when you code either in real mode or under MS-DOS, which is a virtual mode kind of thing, when you try to access BIOS interrupt routines, so you enter as a parameter into AX either 0 or 01, and you later on call interruption 16, and in return, okay, you opt to retrieve an ASCII scan code, okay, for a key that was pressed. Okay, you must probably know that, or in fear, that somewhere on the field, there is a keyboard. Fine. The real question is, how is it all tied together? Like, what's in the middle? Okay, so let's detail a bit how this is all working from the keyboard to the process. Because this is really the whole core of my presentation. So basically, inside the keyboard, you have the first PIC. So if you know PIC programming, you can actually program your keyboard. I mean, the data sheets are available on Intel website. So this one is the first one. Okay, that chip is responsible for triggering an event every time you press or you release a key. There is a second one, which is embedded inside your motherboard. So the first PIC sends to the other one an event every time you press or release. This is actually not good enough. Like, if you press for quite a time, you would like the key to be repeated. And if you just press and release, you would like it to be counted as only one key. So this is the role of the second PIC, which actually unifies the scan codes and sends them to interruption 09, which is also called DRQ01, which is responsible for handling the keyboard in the level. Okay, the interesting thing is really the next thing. Inside the RAM, there is a data structure called the BIOS data area. It contains many fields of your BIOS configuration. Okay, there are two pointers and one buffer who are interesting to us. So what happens when you press a key, the keyboard interrupt service routine copies that key into the yellow buffer and updates the pointers accordingly. And same thing when you try to retrieve a key. So here we have the full process, I mean, from a keyboard to a process kind of thing. Okay, that's clear? Everybody? Awesome. Okay, so in details, if you look at the keyboard buffer, that yellow thing inside memory, every time you enter a key, the pointer to the last character is incremented. Okay, so this is the yellow arrow there. And when you retrieve a key, the red one, the pointer to the next character is updated. Okay, so it's always pointing to the next one. The big problem here, I guess you guys can already see it. Okay, is that this buffer is actually never flushed. So every time you enter a password at boot time, and the BIOS takes care of reading it, it remains in memory forever. Okay? Yeah. Thank you. So this has been there for like 25 years, and more than that actually. And we're going to see that pretty much everybody is vulnerable to that. So in an ideal world, what you would do when you called a bootloader kind of thing, you would sanitize the BIOS keyboard buffer, that yellow thing, after reading a password. Okay, let's see how it actually works in real life, and how it is implemented. So a good example to check how BIOS aware are people, is to look at the way the BIOS guys implemented the BIOS password inside the BIOS itself. Okay? So to do that, I mean, every code you edit on the CD-ROM, there is a toggle on the CD-ROM, so I really encourage you to have a look at it, and give us feedback if you have questions out of it. So anyway, we wrote a small USB bootable OS, in 60-byte read mode, to dump the content of the BIOS keyboard buffer. So basically you boot, the BIOS asks you for a password, and then, for a small OS kind of thing, dumps the content of the memory. Okay, what we've been seeing is that most BIOS passwords are vulnerable to that. So let's imagine third-party developers, like a guy writing software encryption things, or any kind of bootloader asking for a password, they are most probably not aware of it. I mean, even if the BIOS developers make mistakes, don't expect a third-party to be much more aware of it. Okay, one interesting thing, let's imagine we have two passwords checking in a row. Could be like, for instance, you have a BIOS password, plus a GRUB or LILO password, or you could have a GRUB password, like asking an MD5 password, plus a disk encryption software in a row, okay? So in that case, what would the BIOS keyboard buffer look like? Okay, so actually, pass one would be the password for the first BIOS password, then you would have the enter key, then you would have the second password, and then you would have enter. So basically, if you have several passwords in a row, they are all concatenated inside the BIOS keyboard buffer. So from an exploitation point of view, this is really like the best possible thing ever. Okay, from now on, we're going to see... Okay, so just to summarize the scope, we've seen that in many cases, when we have preboot authentication passwords, the passwords remain in physical memory at a given location we know. Okay, we know that location in physical memory. The problem is, once the operating system is loaded, the kernel first switches in protected mode. So there, there is segmentation, paging and stuff, so you're not supposed to read physical memory anymore. So the whole deal of the next two chapters, Windows exploitation and Unix exploitation, is actually to manage to retrieve the password from that physical location we know in physical memory. Once the computer has booted. Okay, so we assume that the OS has been fully booted and we're given a shell. We're going to define the conditions later on. So the big change with a common approach to cold boot attacks, we don't need physical access. Okay, let's first discuss the Windows case. We will discuss a bit, so just summarize the challenges, like I just did actually. Then discuss possible attack scenario, and well, discuss the actual implementation we've done. So that's the physical address, 40.0x1.e, from protected mode. And we want to try to retrieve it. So possible things we could do, like how do you read physical memory? So one thing could be to get back to real mode. That way you would disable segmentation, disable paging, so you could very well read the stuff from the physical memory. That's one solution. You could think of switching to SMM, which is another CPU mode. So same thing, there is no segmentation, no paging. So that could be an option. Or you could try to get it from Kernel land. The big problem is that all those solutions require typically huge amount of privileges. So under Windows you need system privileges or kernel privileges. So let's not do that. We're going to use a Microsoft feature. Yeah, you can start laughing, but just wait to look at it. I mean, it's pretty awesome. Okay, we're going to use the MS-DOS emulation mode. Basically it has been there since Windows 95 to allow retro compatibility with MS-DOS. So it's built over the last CPU mode we've not seen so far, which is a virtual mode. It basically emulates an 8886 CPU, so a very old Intel CPU, with some restrictions and with some mistakes. Like, okay, this is fully documented, but the addressing from 16-bit to 32-bit triggers some problem in the stack and stuff. Anyway, the good thing about that is that it maps physical memory in the ranges which are interesting to us into user layout. So let's go for a demo. Okay, I launched a demo in the background and let's keep going. Now let's discuss the thing about UNIX. By UNIX we mean BSD, Saurus, whatever, which is running Intel-compatible CPUs. Otherwise, you don't have a BIOS in the first place, and it's not really interesting to us. So, unfortunately, we don't have such a good thing as the kernel mapping all the interesting BIOS data area thing inside user layout for you. So we will have to assume we have some privileges to retrieve the password. So, first of all, we could try to get it from user layout. When it comes to physical memory under UNIX, you have a special device which is called DevMem, which is actually a mapping of your physical memory. So if you use a simple tool, you can actually read the password in plain text into DevMem. This is really awesome also. It has been there for years. Everybody has been using password, and apparently it's the first time someone is disclosing it. Instead of using DevMem, you could use DevCardMem, which is a mapping of the kernel. For the technical guys here, I'm assuming 3GB, 1GB kernel split. Otherwise, the addresses won't be the same. But the principle is always the same. You can get it from KernelN also. DevCardCore, which basically contains the very same information in the form of a core file. So using the very same tool, you can also retrieve your password. Okay, so we have implemented a simple tool to automate pretty much the test for you. It's been testing under a wide range of Unix distributions, running on x86 CPUs. Okay, so same thing. You can see the stuff in red. It's your actual whatever password. Like it could be a BIOS password, book loader password, and stuff. Okay, let's get back to the demo. Okay, so this is Windows. I have a guest account. And I'm using a very simple COM file. The VOX is encrypted with, I mean it has full disk encryption with TrueCrypt. And you can see my password is total. You can applaud here. Thank you. Okay, so we can also think about getting the password under Unix from a kernel end. So actually what happens is that the BIOS data area is copied inside a special page inside the kernel, which is called the zero page. This is done in setup.c if you want to look at the kernel source. So it's really early stage of the kernel before switching to protected mode. So we're assuming the same kernel split I explained before. So does everybody know what is a kernel split in the first place? Okay, basically it means that you have a user land and kernel land. And the amount of memory allocated to both can differ. And you can actually on any kind of distribution specify at boot time which kind of split you want. So in case of the standard three gigabyte, one gigabyte split, the address where it is copied. So this is defined by setup.c where it is copied inside the zero page. This is the address written there. So let's verify the password is actually located there in memory. So to do that, we can use, for instance, kernel debugging. Okay, remote kernel debugging. Here I'm using a VMware machine and I'm debugging the kernel inside the VMware machine. And what we see if we print what is at the given address, everybody gets to see it. So the letters in red are actually my BIOS password. Okay, since you probably don't want to have to do kernel debugging every time you want to read a password, we have written a small kernel module which adds an entry in the slash file system. And just by doing a cat on it, you can retrieve any kind of password. Thank you. Okay, so like we mentioned before, this bug has been there since humans have been using BIOS. So since we have PCs. And the awesome stuff is everything is in plain text. So just open your eyes, there might be other kinds of bugs like that. Okay, I'll give you a Unix demo. Okay, this is a raw Ubuntu. It has a GRUB MD5 password. So I need to assume several privileges. So typically I have a root console. Okay, here are the kind of attacks you can do against it. So you could try to retrieve it from DevMem, OldMem, whatever. I mean, under Ubuntu, you have many links. Like, slash dev static dev core is actually a link to dev core and stuff like that. But still, you have many options to try to retrieve that stuff. Even if you are into a stripped-down demo, you will... stripped-down distribution. And any kind of Unix, not only Linux, you will at least find DevMem or something like that, right? So let's execute it. Okay, so guess what's my password? Okay, it's not actually DefCon1. That was a trick. Every time you have one character, which is the ASCII code, the next one inside the BIOS keyboard buffer is a scan code. So you have to ignore that one. It pretty much contains the same information, okay? But it's the convention used by the microcontrollers we've seen earlier. So here my password was indeed DefCon. Okay, so now that we think about it, we know that for many pre-boot authentication passwords, developers do not sanitize the memory after reading the password. Okay, good. One case which you might find when you try to break into a computer is that it would be nice to reboot the computer. So in some cases, it's not that difficult, but let's imagine you have a full disk encryption. You rooted the box already. You want to reboot it for some reason, like you want to flash the BIOS or something. For instance, to, I don't know, downgrade the BIOS EPROM, possibly to do SMM rootkit stuff, or you want to manipulate... I mean, if you have access to the machine before there is a kernel in memory, it's like ring minus one. You can't do anything, right? You broke the integrity very early. So let's assume we have a disk encryption kind of thing, and we want to reboot it anyway. If you just do a reboot, what's going to happen is that the computer will switch down, and then it will boot again until the moment that someone... I mean, the encryption software asks you for a password, right? And since you don't have access to the console, because we assume that you don't have physical access to the computer, well, pretty much you're fucked. So in the next section, we will try to find ways to reboot the computer anyway. So we assume you can write to the master boot record, and you can indeed reboot the computer. So typically, this will mean you have root kind of access. There are several cases that can be interesting, where you don't actually need root itself. For instance, if you're running Ubuntu, the default user would be good enough. If you have access to KMM, basically KMM group, you can read to DevMem, so that's good enough. But let's say, okay, for the sake of simplicity, let's say you have root access to the computer. So there are really two cases here. First one, the bootloader asks for a password, which is just there to bug you, but is not used to decrypt anything. This is typically the case of Lilo, Grub. There is no disk encryption stuff, so if you just nopped the password checking routine, you can bypass the authentication routine, right? The other case is when the password is actually used to decipher the disk. Then, if you just try to nop the password checking routine, well, nothing will happen. Like, you won't decrypt your drive, and that's it. Okay, so while the first case is really trivial, like we mentioned, if you have a Lilo or Grub password, or whatever, which does not use the password to decrypt anything on the drive, you can pretty much just patch the bootloader. This has been studied deeply in not the latest, but the previous FRAC issue. It's an article called Hacking Deeper in the System. It's pretty much a patch in Grub for fun and profit. Okay, so this is the example, I mean, a typical example of what could happen if you can write to the master boot record. Here, I had Lilo asking for a password, and I patched it, so it doesn't ask for a password anymore, and just reboots. If you look at Lilo, it's actually amazing. You can change the delays and stuff like that. Pretty fun. Okay, let's now go to the actual interesting case where you have a password check which will use a password to decrypt your hard drive. Okay, you might be thinking here, why is he talking about that anyway? So I'll show you that this is pretty linked to what we've been doing before. I will show you an actual attack scenario and a demo for it. Okay, here's a problem. We've seen that we can retrieve the password from memory because the guys who write bootloaders do not sanitize, typically, the BIOS keyboard buffer after reading the password. What if they don't initialize it before reading the password? So actually, what you could do... Okay, this is a world map we've been seeing before. Like you have the bootloader which uses BIOS interruptions to retrieve the content of the BIOS keyboard buffer. Okay, we don't need all of that. Okay, let's imagine I write... I replace the master boot record with mine. Okay, a rogue bootloader kind of thing. What it would do is actually talk directly using PIC programming to the two PICs inside the motherboard and the one inside the keyboard in order to... Okay, so this is done via EOPorts so you need root privileges to do that too. I mean, it's nonsense. Like, when you're a rogue bootloader you're running in real mode so you have access to anything anyway. But you can use EOPorts to reprogram those two PICs. So it's pretty much like emulating the fact of typing keys inside a keyboard. Okay, so you can fill in the BIOS keyboard buffer with the password you've discovered previously. Okay, and then remove the rogue bootloader replace it by the original bootloader which will do its task normally which is, it will ask for... it will ask using interruption 16 for user input and the BIOS interruption service routine will read the password you've entered previously. Okay? Normal stuff here. Okay, so in order to do that we need to write a rogue bootloader which is, first of all, backup the old master boot record. Okay, there are some conditions not very interesting. I'll check all the details later. Okay, so it basically backups the old master boot record. Okay, that's the installation process. This rogue bootloader will, using PIC programming enter a password inside the BIOS data area using PIC programming. And then it will copy back the old master boot record in place using, for instance, interruption 19. It's very valid. And transfer, control transfer to the original bootloader. Okay, I'll give you a demo here only it's a bit tricky to put in place so I'll cheat a bit, I'll show you a video. Hopefully... Okay, so in that case the computer is protected with two passwords. The first one is a grub password using md5 encryption and the computer is also... so we're under Linux we want to reboot that Windows machine which is also encrypted using TrueCrypt. So you can check the md5 password and stuff. There is one trick here. The name of the entry in grub is very long so I can actually not copy I cannot enter in grub the whole name of the grub entry because the size of the BIOS keyboard buffer is limited to 16. So what we do using character backslash x19 is to use the arrow key. First of all, the first character we use the escape character to escape the graphical interface entering the grub menu then we choose the actual entry we want to reboot using arrow keys we write the password for the first bootloader grub, which is owned then we press enter it's really the exact same stuff you would do if you were in front of the computer only we do that using a bootloader so we don't have to have access to the computer itself. Ok, so we wrote a small installer for that so you need to know the device and here is what happened it's going to be very fast Ok, this is it So, I don't know if you've seen Thank you So what happens is you can really reboot a computer even if it has multiple encryption and multiple password checking Ok, let's go to the I mean, I've been telling most of the people I've enabled and stuff so now I'm going to disclose the full list of people actually enabled First of all, I would like to thank the vendors for their attitude they've been very responsible and cooperative but TrueCrypt, like these guys told us the vulnerability only exists because you are misusing the software Thank you, that's very deep Ok, so the first kind of passwords we've been talking about are biased passwords so here is a list of vulnerable APROMs so you can see pretty much everybody is vulnerable ranging from, well, you read it Full disk encryption software with pre-boot authentication capabilities so BitLocker, which is the encryption software for Microsoft Vista on the version SP0 is vulnerable it has been fixed in SP1 TrueCrypt so even if those guys deny the truth I showed you before that you can also reboot it DiskCryptor and DriveCrypt and bootloader passwords so Grub and Lilo are also vulnerable for the sake of completeness I will also show you the list of non-vulnerable software we've seen so there are several biased passwords full disk encryption software. This list is obviously far from being exhaustive so I entitle you to, I mean, do your own experiments. Actually the exploit is the same everywhere. So there is one exploit for Unix which is going to work for any pre-boot authentication password if available. And one version for Windows. So you just check this, install a few software and check if they are vulnerable. If you do so, I would appreciate if you sent me a mail or something. Okay, so how do we mitigate those vulnerabilities? Okay, the most obvious, I mean, the most obvious advice I could give is like to sanitize the BIOS keyboard buffer before and after use, right? You can check on the website. We are trying to keep a list of patches to do that. Unfortunately when it comes, for instance, to BIOS EEPROMs, it's very difficult to patch it yourself. You have to wait for the vendor to issue fix. So you must probably looking for an intermediary solution which will not fix all the problems but, I mean, will fix most of them. So if you're using Linux, I can, I really entitle you to download the geosecurity patch from openworld.net. Brad has been very keen to release a new version today, including the patch we've written for it. So what it does basically is, yeah, absolutely not. No, no. What do you mean you have to actually? You're the true creep guy or something? Okay. See, what happens is, if the password can be entered by the keyboard, okay, just let me reply to you. If the password can be entered at the keyboard, okay, from the keyboard, there is no difference from the bootloader point of view if it's actually typed at boot time on the console or if it has been stored in the BIOS keyboard buffer by a previous rogue bootloader, okay? It's exactly the same thing. I mean, it's following the same process. It's... Okay. So see, I'm afraid I don't really understand your question, but we can... Okay. So what happens with, for instance, TPM ships, you can't actually mitigate, yeah, you're right. So you can retrieve the password, but you can't actually reboot the computer using the, I mean, rogue bootloader method. That was your point? So it's very true. No, I have no method to bypass TPM so far. I have not studied it deeply. There are really three vulnerabilities here. Like the first one is the ability to retrieve the password in plain text. The second one is the effect of rebooting, okay? And the third one is actually the kernel leakage inside user LAN from Microsoft, right? Which allows you to kind of retrieve the password with less privileges, okay? So I've discussed with the, I mean, guys responsible at Microsoft, they are working on a fix. This is very complicated to fix, okay? But you're right. My bypassing of TrueCrypt, of BitLocker, sorry, is not full. I could not reboot it. Okay, so just a few greetings. So first of all, I would like to thank my reviewers, the technical team which I work with, and the guys from EverybodyDies.com. It's actually a game, computer game, and they allowed me to use their screenshots of the game which is now called DEFCON inside my slides. This is why my slides look so good. Community guys, so plug the plug, plug security. Thank you for coming and waking up after the parties and stuff. All you for coming to the presentation, and indeed the DEFCON staff for the awesome event and parties. I think we can clap for that, yeah.