Sub topic 8
Bootloader, Process Hardening, and Warning Banners
This chapter covers three small CIS Benchmark sections that sit between filesystem hardening and service minimization. They protect the boot path, limit what a running process can reveal or do, and present a legal notice to anyone who logs in.
It assumes you can edit files as root, know the basics of systemd and GRUB, and have a test server or VM with a snapshot. Paths and package names below follow RHEL 9 and Debian-family systems. Check your benchmark version for the exact recommendation numbers.
Why these controls matter
An attacker with console access can edit boot parameters (for example, add init=/bin/bash) and get a root shell without a password. A local user can read memory addresses or trigger core dumps that leak secrets. A login prompt with no notice weakens your position when you need to act against an intruder or an insider.
None of these controls stops a remote attacker on its own. They reduce what is left after another control fails. CIS marks most of them Level 1, and the GRUB password is usually Level 1 on servers too.
Bootloader hardening
CIS asks for two things from GRUB 2: a password for editing boot entries, and restricted permissions on the configuration file.
Set a GRUB password
On RHEL 9, grub2-setpassword does the work. On Debian and Ubuntu, you generate a hash and add it to a custom file.
# RHEL 9 and derivatives: prompts for a password, writes /boot/grub2/user.cfg
sudo grub2-setpassword
# Debian and Ubuntu: generate a PBKDF2 hash to paste into the config below
grub-mkpasswd-pbkdf2On Debian-family systems, put the result in /etc/grub.d/40_custom:
set superusers="grubadmin"
password_pbkdf2 grubadmin grub.pbkdf2.sha512.10000.REPLACE_WITH_YOUR_HASHThen regenerate the configuration and check it.
sudo update-grub
sudo grep -n 'superusers' /boot/grub/grub.cfgOn RHEL 9, grub2-setpassword already stores the hash in /boot/grub2/user.cfg, so a separate regeneration is not needed.
By default, once superusers is set, GRUB requires the password for every menu entry, including a normal boot. That would stop unattended reboots. Debian's generated entries include --unrestricted for this reason. On RHEL, the default entries are also unrestricted, so only editing and the GRUB command line need the password. Always reboot a test machine to confirm the server still comes up without a prompt.
Restrict the configuration file
The GRUB configuration should be readable and writable only by root.
# Debian and Ubuntu
sudo chown root:root /boot/grub/grub.cfg
sudo chmod u-wx,go-rwx /boot/grub/grub.cfg
# RHEL 9 (UEFI systems keep it under /boot/efi/EFI/redhat/)
sudo chown root:root /boot/grub2/grub.cfg
sudo chmod u-x,go-rwx /boot/grub2/grub.cfg
stat -c '%a %U:%G %n' /boot/grub2/grub.cfgOn UEFI systems, the FAT filesystem under /boot/efi does not support Unix permissions. CIS scanners may report this as not applicable or may check the mount options instead.
Physical access still wins
A GRUB password does not stop someone who can boot from removable media or remove the disk. For that threat you need firmware passwords, Secure Boot, and disk encryption. Treat the GRUB password as a barrier against casual console tampering, not a complete defense.
Process hardening
The benchmark's process hardening items reduce the information and power available to a compromised or hostile process. Three settings matter most.
| Setting | Recommended value | What it does |
|---|---|---|
| `kernel.randomize_va_space` | `2` | Randomizes the memory layout (ASLR), which makes exploits less reliable |
| `kernel.yama.ptrace_scope` | `1` or higher | Stops a process from attaching a debugger to unrelated processes |
| `fs.suid_dumpable` | `0` | Prevents setuid programs from writing core dumps |
Apply the kernel settings
Use a drop-in file, as in the network chapter, so the settings survive reboots.
# /etc/sysctl.d/60-cis-process.conf
kernel.randomize_va_space = 2
kernel.yama.ptrace_scope = 1
fs.suid_dumpable = 0sudo sysctl --system
sysctl kernel.randomize_va_space kernel.yama.ptrace_scope fs.suid_dumpableThe ptrace_scope setting can break debuggers such as gdb -p and strace -p when run by a non-root user against an existing process. Developers on a server may notice this. Root can still trace, and strace command on a new process still works.
Disable core dumps for users
Core dumps contain process memory, which can include passwords and keys. Limit them in two places. First, set a hard limit.
# /etc/security/limits.d/60-cis-coredump.conf
* hard core 0Second, tell systemd not to store dumps.
# /etc/systemd/coredump.conf.d/60-cis.conf
[Coredump]
Storage=none
ProcessSizeMax=0sudo systemctl daemon-reload
ulimit -cRun ulimit -c in a new login session. It should print 0. The limits.d file is applied by PAM, so existing sessions keep their old limit.
Remove or review related packages
CIS also asks you to check for packages that add risk without a server role. Examples are prelink (which rewrites binaries and conflicts with integrity checking) and apport on Ubuntu (which collects crash data). Remove them if you do not need them.
# Debian and Ubuntu
dpkg -l prelink apport 2>/dev/null | grep '^ii'
# RHEL 9
rpm -q prelink abrt 2>/dev/nullWarning banners
CIS requires a message shown before login on the console, over SSH, and after login. The text should state that access is restricted and monitored. It should not reveal the operating system, kernel version, or hostname. Your legal team should approve the wording.
The three files
| File | Shown when |
|---|---|
| `/etc/issue` | Before login on a local console |
| `/etc/issue.net` | Before login over a network service such as SSH |
| `/etc/motd` | After a successful login |
sudo tee /etc/issue /etc/issue.net >/dev/null <<'EOF'
Authorized use only. Activity on this system is monitored and
logged. Unauthorized access is prohibited and may be prosecuted.
EOF
# Remove the default message of the day, or replace it with the same notice
sudo sh -c ': > /etc/motd'Why avoid \r, \s, \m and \v? These escape sequences in /etc/issue print the kernel release, OS name and architecture. A scanner flags them, and they help an attacker pick an exploit.
Make SSH show the banner
SSH does not read /etc/issue.net unless you tell it to. Add the directive in a drop-in file.
# /etc/ssh/sshd_config.d/61-banner.conf
Banner /etc/issue.netsudo sshd -t
sudo systemctl reload sshd
ssh -o PreferredAuthentications=none localhostOn Debian-family systems the service name is ssh. The last command should show the banner before it prompts or fails. Remember that sshd keeps the first value it reads for most directives, so check with sudo sshd -T | grep -i banner if the banner does not appear.
Set permissions
Make the files root-owned and world-readable, since login programs must read them.
sudo chown root:root /etc/issue /etc/issue.net /etc/motd
sudo chmod 644 /etc/issue /etc/issue.net /etc/motdVerifying with OpenSCAP
After the changes, rerun the scan from the assessment chapter and filter the results for these rules.
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--results results.xml \
--report report.html \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml
grep -Ei 'grub|coredump|banner|ptrace' report.html | headCompare against your baseline. Rules that were failing should now pass. Rules that still fail need a reason, which you record as an exception in a later chapter.
Common errors
- Locked out of unattended reboots. A GRUB entry without
--unrestrictedasks for a password at boot. Test a reboot before you leave a remote host. - Forgotten GRUB password. Store it in your password manager. Recovery needs rescue media.
- Edited
grub.cfgdirectly. Updates overwrite it. Change/etc/grub.d/or/etc/default/gruband regenerate. - Banner not shown over SSH. The
Bannerdirective is missing, or an earlier drop-in file sets it first. - Core dumps still appear. Another file in
limits.dorsysctl.doverrides yours. Checkulimit -candsysctl fs.suid_dumpablein a fresh session.
Exercise
After applying /etc/security/limits.d/60-cis-coredump.conf with * hard core 0, ulimit -c in your existing SSH session still prints unlimited. Why, and how do you confirm the setting works?
Show answer
The limits file is read by PAM when a session is created, so existing sessions keep their old limit. Log out and open a new session, then run ulimit -c. It should print 0. Also check that no other file in /etc/security/limits.d/ sets a conflicting value.
Exercise
You set a GRUB superuser and password on a Debian server, and the next unattended reboot hangs at the boot menu. What caused it, and how do you prevent it?
Show answer
The menu entries were not marked --unrestricted, so GRUB required superuser credentials to boot them. Make sure the generated entries include --unrestricted (Debian's default scripts do this unless changed), regenerate with update-grub, and test a reboot at the console before relying on remote reboots.