sections in this module City College of San Francisco - CS260A
Unix/Linux System Administration

Module: StartupShutdown II
module list

Protecting the Boot Process

Any machine can be compromised if physical access is permitted. All they need is the ability to restart the system using their own startup medium. The first step in protecting any system then is to secure its location.

Even if it is physically secure, it is still wise to protect a machine from compromise during the boot process. Although allowing anyone to physically boot the machine opens it to compromise, the level of preparation and knowledge required by an attacker can be significantly increased by taking a few steps.

Traditionally, the boot process is assumed to occur in a secure location. Thus it is easy to alter the level of boot so that it stops at single-user mode rather than multi-user mode. In single-user mode, init starts a single-user shell for root access at the console. Traditionally, it was assume that an authorized root user was performing the boot process, so the single-user (root) shell did not require a password.

Protecting the single-user shell

By definition, init starts a single-user shell when it enters single-user mode. Whether this shell forces you to enter the root password before continuing or not is configurable.

For traditional init, if an inittab is found and it has an entry with runlevel S, init runs that entry instead. The program /sbin/sulogin is often used in this entry. It forces the user to enter the root password prior to starting a single-user shell. The inittab entry looks like

xx:S:wait:/sbin/sulogin

For systems that use upstart, the single-user shell is specified in /etc/sysconfig/init using the SINGLE variable. There are two possibilites for SINGLE

/sbin/sulogin - this is the password-protected single-user shell

/sbin/sushell - this shell is not password-protected.

To control whether the single-user shell is password-protected, set SINGLE to the appopriate shell.

Protecting grub

Unless there is a separate configuration entry to invoke single-user mode, getting to it requires modifying grub's default configuration entry like this:

To disable editing boot configurations, add a password to grub. You must add the line

password --encrypted   XXXXXXXXXXXXXXXXX

to your grub.conf file, where XXXXXXXXXXXXXXXXX is the encrypted form of a password you select. 

# grep password /boot/grub/grub.conf
password --encrypted $1$AWn0c$9yM.P5qtG1LTIHOZ7Zv2a1

You can generate the encrypted password using the command grub-crypt. You can give it your choice of algorithms. I suggest the strongest encryption possible always (sha-512). sha-256 is shown here so it will fit.

# grub-crypt --sha-256
Password:
Retype password:
$5$L4/6iSJfBnqa6Vc3$zOFsi.pV.6uyOt.e3Y68XcLsbhmt5uepmNppQIBLcJ0

Then simply create (or edit) a password --encrypted line with the new encrypted password.

Note: I suggest you use stronger encryption than md5, such as sha-512, but that is very ugly to include here. Check out the man page of grub-crypt. Since the encryption algorithm used is indicated by the first two characters of the encrypted password, you can just cut and paste the new version of the encrypted password in the grub.conf file.

When grub is password-protected, the only command available (except b to boot) when you have stopped the boot at the title-display step is 'p' for enter password. After you have entered the grub password you can then proceed with editing the kernel line as above.

If you want to experiment with generating the various types of encrypted passwords, check out grub-crypt(1). It can be used to generate encrypted passwords using md5, sha-256 or sha-512. You can even use the appropriate length of sha to generate your own user passwords in a pinch (currently sha-512)).

Access to grub 

Security (and functionality) require a few restrictions on grub's data:

$ ls -ld /boot/grub
drwxr-xr-x 2 root root 1024 Nov 20 22:22 /boot/grub
$ ls -l /boot/grub/grub.conf
-rw------- 1 root root 874 Nov 20 22:22 /boot/grub/grub.conf
# cd /boot/grub
# ls -l stage2
-rw-r--r-- 1 root root 104988 Jan 27 09:01 stage2
# filefrag stage2
stage2: 1 extent found
#
# ls -l /var/log/wtmp-rw-rw-r-- 1 root utmp 128256 Mar  2 16:45 /var/log/wtmp
# filefrag /var/log/wtmp
/var/log/wtmp: 7 extents found, perfection would be 1 extent

Preview question: Suppose you start your personal linux system and it won't boot. What would you do?

Prev This page was made entirely with free software on linux:  
the Mozilla Project
and Openoffice.org      
Next

Copyright 2012 Greg Boyd - All Rights Reserved.