CIS 4360 Secure Computer Systems System Boot
Total Page:16
File Type:pdf, Size:1020Kb
CIS 4360 Secure Computer Systems System Boot Professor Qiang Zeng Spring 2017 Previous Class • What a TPM is: – Hardware protected keys • Endorsement key: for signing (PCR values) • Storage root key: for encrypting storage keys – Crypto-processor • RSA • HMAC • SHA-1 (SHA-2 in TPM 2.0) – PCR • What the TPM can do – Attestation – Sealed storage CIS 4360 – Secure Computer Systems 2 TPM-Based Attestation Example [Gasser et al. ‘89], [Arbaugh et al. ‘97], [Sailer et al. ‘04], [Marchesini et al. ‘04] Module Module Module App Module App App BIOS Bootloader OS PCRs TPM KPriv 3 Establishing Trust via a TPM [Gasser et al. ‘89], [Arbaugh et al. ‘97], [Sailer et al. ‘04], [Marchesini et al. ‘04] Guarantees randomModule # Accurate! Module freshness Module A Module Module A Module p App Module p A Module App p p p App K OS Pu p BIOS Bootloader Guarantees BIOS Bootloader b OS Module A real TPM Module A Module p Module p A p p p OS p BIOS Bootloader Sign ( random # ) Kpriv PCRs Guarantees actual TPM logs TPM KPriv 4 BitLocker • At system boot (before OS boot) – Optional: BIOS requests PIN or USB key from user – TPM unseals VMK, if PCR and PIN are correct • PIN is to derive the keyAuth (recall TPM_SEAL) • TPM defends against dictionary attack on PIN • Many options for VMK recovery in certain cases – Disk, USB, paper (all encrypted with password) – Recovery needed after legitimate system change: • Moving disk to a new computer • Replacing system board containing TPM • Clearing TPM CIS 4360 – Secure Computer Systems 5 Previous Class What is Measured Boot? At each stage of system booIng, the code and configuraon for the next stage is scanned and the hash value is recorded in TPM (by extending a specified PCR) CIS 4360 – Secure Computer Systems 6 Previous Class What aacks can you do if you have extracted the private key from a TPM A soSware module can claim itself as a TPM. It can (1) Sign arbitrary PCR values it wants; and (2) Steal the storage keys originally sealed by the hacked TPM CIS 4360 – Secure Computer Systems 7 Previous Class What knowledge should an IT service have for aestaon over a laptop of the company? Remote aestaon is great as it stops potenIally malicious computers from connecIng to the company network. But it also requires extra work from the IT department, as they have to first know what PCR values are good; in other words, they have to know the set of legiImate firmware, bootloader, OS and applicaons. CIS 4360 – Secure Computer Systems 8 Outline • How does a system boot? – BIOS-MBR (generation 1) – UEFI-GPT (generation 2) CIS 4360 – Secure Computer Systems 9 Have you encountered such errors? • “Operating System not found” • “DISK BOOT FAILURE – INSERT SYSTEM DISK AND PRESS ENTER” • Your installed operating system is missing CIS 4360 – Secure Computer Systems 10 Terms • BIOS and UEFI are both firmware (for h/w initialization and loading boot loaders) – UEFI is to replace BIOS • MBR and GPT are both disk partitioning scheme – GPT is to supersede MBR • GRUB and Bootmgr are both boot loaders – GRUB is for linux/unix – Bootmgr is for Windows (since Windows 7) • Don’t worry; we will introduce each in detail CIS 4360 – Secure Computer Systems 11 What is System Boot? • Boot is short for bootstrap • System boot is to initialize a computer system typically until an OS is loaded and initialized • Two big steps: – The computer firmware initializes the h/w and locates, loads, and executes the boot loader – The boot loader loads and executes the OS CIS 4360 – Secure Computer Systems 12 Why is System Boot complicated? • Little intelligence upon power on – There is no concept of file system; only raw disk read in the beginning • Many h/w and s/w standards are involved – From BIOS to UEFI – From MBR to GPT – “Blind” boot, trusted boot, secure boot • Multiple OSes may be installed on one disk – Dual boot, triple boot, … – Chain loading: a boot loader calls another boot loader; e.g., GRUB loads bootmgr (a windows-specific boot loader) to start Windows 10 CIS 4360 – Secure Computer Systems 13 BIOS • BIOS: Basic Input-Output System • What does it do? – Power-on self-test (POST): test and initialize h/w, such as RAM, interrupts, keyboard, etc. – Execute extension ROM: some disk controllers and video cards include their own BIOS extension – Locate, load and execute the boot loader from a bootable device CIS 4360 – Secure Computer Systems 14 Questions to be explored • How does BIOS recognize a bootable device? • How does BIOS locate the boot loader? • Hint: BIOS is dumb and it solves the problems above by following some hard-wired flags and addresses • Let’s continue… CIS 4360 – Secure Computer Systems 15 MBR (Master Boot Record) • Sector 0 (512 bytes) on a disk: – 440 bytes: primary boot loader code – 4 bytes: disk signature; 2 bytes NULLs – 16 x 4 for partition table: so at most 4 primary partitions – 2 bytes magic: 0xAA55 indicates a valid MBR CIS 4360 – Secure Computer Systems 16 AcIve ParIIon: its entry in the parIIon table starts with 0x80. This parIIon contains some other boot loader code, used by windows boot loader Flag of mbr (liQle endian)CIS 4360 – Secure Computer Systems 17 BIOS-MBR • How does BIOS recognize a bootable device? • How does BIOS locate the boot loader? • After POST, BIOS loads the first sector (512 bytes) of the current device (say HDD1->HDD2->USB; the order can be configured in BIOS) into memory • Check if the 511th and 512th bytes are 0x55 and 0xAA, respectively. – If not, go back to step 1 and try the next device, or give up if there aren't any more. – If yes, execute the boot loader code from the MBR sector, thus passing control to (hopefully) a boot loader • Who knows? It may be just some virus CIS 4360 – Secure Computer Systems 18 Case study: Grub2 with BIOS-MBR • Grub2 (GRand Unified Bootloader) is a popular boot loader in Linux/Unix. Its boot setting is stored in / boot/grub/grub.cfg (GRUB2) • MBR stores Stage 1 of the boot loader: boot.img • The empty space between MBR and the first partition store Stage 1.5: core.img, which contains file system drivers • The final part (stage 2) loads the config file (accessed through file names rather than raw disk read) and displays the menu of installed OSes to users CIS 4360 – Secure Computer Systems 19 CIS 4360 – Secure Computer Systems 20 Case study: Bootmgr with BIOS-MBR This sector is also called a Volume Boot Record (VBR) or ParIIon Boot Sector CIS 4360 – Secure Computer Systems 21 Question Dual-boot with BIOS-MBR is awkward. E.g., aer installing Windows on a Linux-preinstalled machine, your Linux will “disappear”. Why? MBR code previously for GRUB is overwriQen with Window’s boot loader code, and Windows is so arrogant that it does not bother to perform chain loading (Tips: the tool EasyBCD can fix the situaon). More essenIal reason: MBR can store only one boot loader CIS 4360 – Secure Computer Systems 22 If you want to install both Linux and Windows on a machine with BIOS firmware, install Windows first and then Linux When Linux is installed on a Windows-preinstalled machine, the entry for Windows is displayed on the Grub menu, as Grub does extra work to detect windows and create an entry in Grub’s config file CIS 4360 – Secure Computer Systems 23 How Chain Loading works • Chain loading: one boot loader hands over the control to another boot loader. • E.g., Grub can chain load Windows’s boot loader by invoking the Windows’ boot loader code in the specified location // in grub.config menuentry "Windows 7 BIOS MBR" { insmod part_msdos insmod ntldr insmod ns ntldr (hd0,msdos1)/bootmgr } CIS 4360 – Secure Computer Systems 24 Limitations of BIOS-MBR • MBR is very limited – Support ~2TB disk only – 4 primary partitions at most (so four OSes at most) – A MBR can store only one boot loader • BIOS is very restrictive – 16-bit processor mode; 1MB memory space (little spare space to accommodate a file system driver) – Blindly executes whatever code on MBR CIS 4360 – Secure Computer Systems 25 Say Goodbye to BIOS! CIS 4360 – Secure Computer Systems 26 Say Hello to UEFI! CIS 4360 – Secure Computer Systems 27 UEFI (to replace BIOS) • UEFI: Unified Extensible Firmware Interface • Successor to BIOS • The effort to resolve the limitations of BIOS CIS 4360 – Secure Computer Systems 28 UEFI vs. BIOS • Disk partitioning schemes – GPT (GUID Partition Table): part of UEFI spec.; to replace MBR – MBR supports disk size 232 x 512B = 2TB, while UEFI supports much larger disks (264 x 512B = 8,000,000,000 TB) – MBR supports 4 partitions, while GPT supports 128 • Memory space – BIOS: 20-bit addressing; UEFI: 32-bit or 64-bit • Pre-OS environment – BIOS only provides raw disk access, while UEFI supports the FAT file system (so you can use file names to read files) • Booting – BIOS supports boot through boot sectors (MBR and VBR) – UEFI provides a boot partition of hundreds megabytes (and boot manager and secure boot) CIS 4360 – Secure Computer Systems 29 EFI System Partition • UEFI specification considers a dedicated boot partition, called EFI System Partition (ESP), which is OS independent – Hundreds of megabytes (recall that MBR has 512 bytes) – FAT file system (UEFI contains driver for the file system) • It contains – boot manager (after h/w initialization, UEFI passes control to it) – all the installed boot loaders (Recall that in BIOS-MBR only one boot loader can be stored in MBR) – necessary utilities and drivers to load OSes • The ESP partition has a unique GUID in the GPT partition table, so it can be easily located CIS 4360 – Secure Computer Systems 30 Boot partition: EFI System Partition CIS 4360 – Secure Computer Systems 31 EFI System Partition CIS 4360 – Secure Computer Systems 32 What OS vendors (should) do? • Each vendor should create a separate directory in the ESP partition, such that vendors would not step over each other – \EFI\$vendor\$bootloader.efi – E.g., \EFI\redhat\grub.efi and \EFI\Microsoft\Boot\Bootmgfw.efi • E.g., Debian installs grub-efi for its EFI bootloader, as: Architecture Path amd64 \EFI\debian\grubx64.efi I386 \EFI\debian\grubia32.efi arm64 \EFI\debian\grubaa64.efi – Each *.efi file contains code and configuration for loading the OSes by that vendor CIS 4360 – Secure Computer Systems 33 Question When you install Windows on a Linux-preinstalled machine with UEFI, will your Linux disappear? No.