[personal profile] mjg59
The Evil Maid attack has been discussed for some time - in short, it's the idea that most security mechanisms on your laptop can be subverted if an attacker is able to gain physical access to your system (for instance, by pretending to be the maid in a hotel). Most disk encryption systems will fall prey to the attacker replacing the initial boot code of your system with something that records and then exfiltrates your decryption passphrase the next time you type it, at which point the attacker can simply steal your laptop the next day and get hold of all your data.

There are a couple of ways to protect against this, and they both involve the TPM. Trusted Platform Modules are small cryptographic devices on the system motherboard[1]. They have a bunch of Platform Configuration Registers (PCRs) that are cleared on power cycle but otherwise have slightly strange write semantics - attempting to write a new value to a PCR will append the new value to the existing value, take the SHA-1 of that and then store this SHA-1 in the register. During a normal boot, each stage of the boot process will take a SHA-1 of the next stage of the boot process and push that into the TPM, a process called "measurement". Each component is measured into a separate PCR - PCR0 contains the SHA-1 of the firmware itself, PCR1 contains the SHA-1 of the firmware configuration, PCR2 contains the SHA-1 of any option ROMs, PCR5 contains the SHA-1 of the bootloader and so on.

If any component is modified, the previous component will come up with a different measurement and the PCR value will be different, Because you can't directly modify PCR values[2], this modified code will only be able to set the PCR back to the "correct" value if it's able to generate a sequence of writes that will hash back to that value. SHA-1 isn't yet sufficiently broken for that to be practical, so we can probably ignore that. The neat bit here is that you can then use the TPM to encrypt small quantities of data[3] and ask it to only decrypt that data if the PCR values match. If you change the PCR values (by modifying the firmware, bootloader, kernel and so on), the TPM will refuse to decrypt the material.

Bitlocker uses this to encrypt the disk encryption key with the TPM. If the boot process has been tampered with, the TPM will refuse to hand over the key and your disk remains encrypted. This is an effective technical mechanism for protecting against people taking images of your hard drive, but it does have one fairly significant issue - in the default mode, your disk is decrypted automatically. You can add a password, but the obvious attack is then to modify the boot process such that a fake password prompt is presented and the malware exfiltrates the data. The TPM won't hand over the secret, so the malware flashes up a message saying that the system must be rebooted in order to finish installing updates, removes itself and leaves anyone except the most paranoid of users with the impression that nothing bad just happened. It's an improvement over the state of the art, but it's not a perfect one.

Joanna Rutkowska came up with the idea of Anti Evil Maid. This can take two slightly different forms. In both, a secret phrase is generated and encrypted with the TPM. In the first form, this is then stored on a USB stick. If the user suspects that their system has been tampered with, they boot from the USB stick. If the PCR values are good, the secret will be successfully decrypted and printed on the screen. The user verifies that the secret phrase is correct and reboots, satisfied that their system hasn't been tampered with. The downside to this approach is that most boots will not perform this verification, and so you rely on the user being able to make a reasonable judgement about whether it's necessary on a specific boot.

The second approach is to do this on every boot. The obvious problem here is that in this case an attacker simply boots your system, copies down the secret, modifies your system and simply prints the correct secret. To avoid this, the TPM can have a password set. If the user fails to enter the correct password, the TPM will refuse to decrypt the data. This can be attacked in a similar way to Bitlocker, but can be avoided with sufficient training: if the system reboots without the user seeing the secret, the user must assume that their system has been compromised and that an attacker now has a copy of their TPM password.

This isn't entirely great from a usability perspective. I think I've come up with something slightly nicer, and certainly more Web 2.0[4]. Anti Evil Maid relies on having a static secret because expecting a user to remember a dynamic one is pretty unreasonable. But most security conscious people rely on dynamic secret generation daily - it's the basis of most two factor authentication systems. TOTP is an algorithm that takes a seed, the time of day and some reasonably clever calculations and comes up with (usually) a six digit number. The secret is known by the device that you're authenticating against, and also by some other device that you possess (typically a phone). You type in the value that your phone gives you, the remote site confirms that it's the value it expected and you've just proven that you possess the secret. Because the secret depends on the time of day, someone copying that value won't be able to use it later.

But instead of using your phone to identify yourself to a remote computer, we can use the same technique to ensure that your computer possesses the same secret as your phone. If the PCR states are valid, the computer will be able to decrypt the TOTP secret and calculate the current value. This can then be printed on the screen and the user can compare it against their phone. If the values match, the PCR values are valid. If not, the system has been compromised. Because the value changes over time, merely booting your computer gives your attacker nothing - printing an old value won't fool the user[5]. This allows verification to be a normal part of every boot, without forcing the user to type in an additional password.

I've written a prototype implementation of this and uploaded it here. Do pay attention to the list of limitations - without a bootloader that measures your kernel and initrd, you're still open to compromise. Adding TPM support to grub is on my list of things to do. There are also various potential issues like an attacker being able to use external DMA-capable devices to obtain the secret, especially since most Linux distributions still ship kernels that don't enable the IOMMU by default. And, of course, if your firmware is inherently untrustworthy there's multiple ways it can subvert this all. So treat this very much like a research project rather than something you can depend on right now. There's a fair amount of work to do to turn this into a meaningful improvement in security.

[1] I wrote about them in more detail here, including a discussion of whether they can be used for general purpose DRM (answer: not really)

[2] In theory, anyway. In practice, TPMs are embedded devices running their own firmware, so who knows what bugs they're hiding.

[3] On the order of 128 bytes or so. If you want to encrypt larger things with a TPM, the usual way to do it is to generate an AES key, encrypt your material with that and then encrypt the AES key with the TPM.

[4] Is that even a thing these days? What do we say instead?

[5] Assuming that the user is sufficiently diligent in checking the value, anyway

Date: 2015-07-06 06:03 pm (UTC)
From: (Anonymous)
Is the TOTP calculation done in the TPM, or on the host? If it's done on the host, wouldn't you be able to read out the persistent secret value just by compromising the host, without compromising the firmware? That means you could turn a transient attack (such as on a partially stateless system) into a persistent attack.

Date: 2015-07-06 09:37 pm (UTC)
From: (Anonymous)
Good call. Does your code do that? Should it?

Date: 2015-07-06 09:49 pm (UTC)
From: (Anonymous)
Or, is that a thing some surrounding code otherwise managing PCRs should do? Is this a known pattern in PCR usage, to obtain a secret and then immediately make it unavailable?

Related: why do you use the specific numbered PCRs you do?

Date: 2015-07-06 09:20 pm (UTC)
From: (Anonymous)
There is another way, no need for TPM. Install grub on external device - a USB stick can always fit into your pocket.

Date: 2015-07-06 09:35 pm (UTC)
From: (Anonymous)
It doesn't, but the same checks described can be made from initramfs. Both TPM way and this needs implementation. I wouldn't put my trust in TPM.

Date: 2015-07-16 08:57 pm (UTC)
From: (Anonymous)
"Only if you're using the TPM, because otherwise you have no means of validating that the firmware isn't now lying to you."

Can't changing firmware be prevented even without the TPM, by a simple password check? Most laptops seem to have the ability to lock bios down.

Date: 2015-07-06 09:41 pm (UTC)
From: (Anonymous)
.. and installing grub on a usb stick is something you can do right now.

usb sticks - a better solution?

Date: 2015-07-16 08:53 pm (UTC)
From: (Anonymous)
> How does that verify your firmware?

The original article says:
"A user can prevent such an attack by using two-factor authentication (RSA challenge-response implemented in a USB token) or e.g. one-time passwords, so that there is no benefit for the attacker to capture the keystrokes."

One notes that this would also solve the problem with hardware based key-loggers.
It also says
"Another suggested approach has been to keep your boot partition on a separate USB stick. This solution obviously doesn't take into account the fact that the attacker might install Evil Maid into your BIOS."
But on most laptops, BIOS modifications can be password-protected - how does the maid get installed into the BIOS then?

This sounds a lot more complex...

Date: 2015-07-08 10:56 am (UTC)
From: [identity profile] afuera.me.uk
than putting your laptop in the safe. Although I find it hard to trust the digital safes in hotels these days, no way of knowing whether the hotel itself has a back door to access it.

Re: This sounds a lot more complex...

Date: 2015-07-08 05:35 pm (UTC)
From: (Anonymous)
For the typical models, the hotel staff doesn't directly have a backdoor, but the management can call the safe company and have them unlock it.

Without a TPM

Date: 2015-07-16 03:07 pm (UTC)
From: (Anonymous)
A more simple version is also possible with some coreboot/libreboot/chromebooks laptops:

1) You create some seals: To do that you can use nail polish with glider to create random patterns. You can, for instance, put the seals on the screws that you have to remove to open the laptop. Then you take pictures of the patterns. That seals are used to make sure your computer was not reflashed externally. You'd have to manually inspect the seals to be sure.

That can work well with gpg keys: if you only check from time to time, and that at some point the seals is broken => you revoke your key.

2) Then you use you "boot fimrware"(Coreboot+grub for instance) to safely boot your system. You could either:
-> Boot on a fully encrypted disk. You type your passphrase from grub (And then the initramfs can have the rootfs key, since it's in an encrypted filesystem)
-> Make it verify the detached signatures of your kernel and initramfs from a clear text filesystem(You'd have to hook the initramfs creation process to sign it though).

3) To prevent someone from booting arbitrary code and reflashing the laptop, you can put a password in grub, preventing any use of the laptop without the password. There are also many ways of making the flash chip read-only (trough software and hardware).

Notes:
a) Even if the computer verifies what you boot, I'm not sure it also protects against malicious hdd/ssd firmwares: Would the LUKS default (aes-xts-plain64) still hold in that case?

b) The point I'm not sure of is if the commonly used ciffers (For instance aes-xts-plain64 which is LUKS's default) used in disk encryption can prevent any arbitrary code execution by modifying the ciffertext.

c) There are also ways to have a verified filesystem, but the only ways I know are read-only, like DM-verity (https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity).

d) As for choosing the laptop, you'd have to do your homework. Some pointers:
* Some have and use a management engine (like the intel chromebooks, and some recent lenovos laptops).
* Some ARM chromebooks have signed, non-free code run first (The exynos ones).

e) As with the possible boot firmwares:
-> Coreboot + grub supports LUKS and the verification of detached gpg signatures.
-> uboot supports verified boot (vboot)
-> Some other bootloaders might also support some sort of boot verification.

Denis.

AEM vulnerabilities

Date: 2015-07-28 04:06 pm (UTC)
From: (Anonymous)
Adding the OTP stuff is an interesting idea. Others have been poking at the ITL AEM implementation recently and getting some interesting results:

https://github.com/QubesOS/qubes-secpack/blob/master/QSBs/qsb-019-2015.txt
https://github.com/QubesOS/qubes-secpack/blob/master/QSBs/qsb-021-2015.txt

FYI

Profile

Matthew Garrett

About Matthew

Power management, mobile and firmware developer on Linux. Security developer at Google. Ex-biologist. @mjg59 on Twitter. Content here should not be interpreted as the opinion of my employer.

Page Summary

Expand Cut Tags

No cut tags