Module 5 · Unit 12 · Lesson 7 of 7
Operating-System Hardening
The previous six lessons presented the security's principles (12.1), the authentication (12.2), the authorization (12.3), the access control models (12.4), the Linux security (12.5), and the sandboxing (12.6). This final lesson of the unit presents the hardening: the ongoing's discipline of configuring, monitoring, and maintaining a system so that its attack surface is the minimum, its defenses are the layers, and its compromises are the detected. Hardening is not a product but a process — the security baselines, the configuration's reviews, the patch's management, the monitoring, and the incident's response — and it is the security's operations's central's activity. The lesson presents the hardening's methodology, the security baselines, the attack surface's reduction, the kernel's and the file systems' hardening, the monitoring and the detection, the patch management, the compliance and the auditing, and the security operations.
01 Introduction
The previous six lessons presented the security's mechanisms: the principles (Lesson 12.1), the authentication (Lesson 12.2), the authorization (Lesson 12.3), the access control models (Lesson 12.4), the Linux security (Lesson 12.5), and the sandboxing (Lesson 12.6). This lesson presents the hardening: the discipline that turns the mechanisms into a secure's system, and that keeps the system's security as the threats evolve. The hardening's central's observation: the security is a process, not a product. A system is not secure because it has the firewall, the SELinux, or the strong's passwords; it is secure because the configuration is the reviewed, the patches are the applied, the logs are the monitored, and the incidents are the responded to. The hardening is that process's name.
The hardening is the system's security's configuration's and the operation's discipline: the reduction of the attack's surface, the strengthening of the defenses, the monitoring of the security's state, and the response to the security's incidents. The hardening's goal is threefold:
- The attack's surface's reduction. The system should expose the minimum number of the services, the ports, the accounts, the privileges, and the features, so the attacker has the fewer's entry's points and the fewer's exploitable's components.
- The defense's strengthening. The system's mechanisms (the authentication, the authorization, the sandboxing, the monitoring) should be the configured for the maximum's effectiveness: the strong's passwords, the multi-factor's authentication, the least privilege, the mandatory access control, the sandboxing's confinement, the logging's coverage.
- The compromise's detection. The system should record the security-relevant's events (the authentication, the authorization, the file's accesses, the network's connections, the privilege's escalations), and the records should be the monitored for the anomalies, so the compromises and the attacks are the detected and the responded to.
The hardening's practice is iterative and ongoing: the baselines are the applied, the systems are the assessed, the gaps are the remediated, the new's baselines are the selected, and the cycle repeats. The observation is the reason the security's operations (the SecOps) is the security's central's activity: the modern's threat's environment changes (the new's vulnerabilities, the new's attacks, the new's workloads), and the static's configuration cannot keep pace. The hardening is the security's discipline that keeps the system secure as the environment changes.
This lesson presents the hardening. It defines the hardening and its goals. It presents the hardening's methodology (the standards, the benchmarks, the baselines). It presents the attack's surface's reduction (the services, the ports, the packages, the kernel's modules). It presents the identity's and the authentication's hardening. It presents the kernel's hardening (the sysctl's parameters, the ASLR, the kernel's modules' signing), the file systems' hardening (the permissions, the mount's options, the disk's encryption), and the network's hardening (the firewalls, the segmentation). It presents the logging, the monitoring, and the detection (the auditd, the file's integrity's monitoring, the HIDS, the SIEM), the patch management and the vulnerability scanning, and the compliance and the auditing (the CIS, the NIST, the STIG, the PCI-DSS). It presents the security operations (the SecOps, the incident's response, the hardening's lifecycle). It closes with the hardening's design's principles and the unit's synthesis.
Prerequisites
This lesson builds on the whole unit and the
whole course. The security's goals (the CIA
triad), the AAA model, the reference monitor,
the Saltzer and Schroeder principles, and the
defence in depth are assumed (Lesson 12.1).
The authentication's mechanisms (the
passwords, the KDFs, the MFA, the PAM, the
SSH keys) are assumed (Lesson 12.2). The
authorization's concepts, the access control
matrix, and the four models (the DAC, the
MAC, the RBAC, the ABAC) are assumed (Lesson
12.3). The formal models (the Bell-LaPadula,
the Biba, the Clark-Wilson) are assumed
(Lesson 12.4). The Linux security's
mechanisms (the identity's model, the
permissions, the capabilities, the LSM's
framework, the SELinux, the AppArmor, the
auditd, the sysctl's parameters) are assumed
(Lesson 12.5). The sandboxing's mechanisms
(the namespaces, the cgroups, the seccomp,
the systemd's hardening's directives, the
containers) are assumed (Lesson 12.6). The
file systems' permissions (Lesson 10.2), the
network's stack (Unit 11), and the process's
credentials (Lesson 3.1) are the context for
the hardening's discussions. Familiarity
with the Linux command line from Lesson 2.2
is essential, since the interactive activity
uses the ss, the
systemctl, the
ufw, the firewalld,
the sysctl, the
auditctl, the
ausearch, the lynis,
the oscap, and the
systemd-analyze security
commands.
02 Learning objectives
By the end of this lesson you will be able to
- Define the operating-system hardening and explain its goals, and describe the hardening's methodology and the security baselines (the CIS Benchmarks, the NIST's guides, the DISA STIGs).
- Describe the attack's surface's reduction: the services, the ports, the packages, the kernel's modules, and the accounts.
- Describe the identity's and the authentication's hardening, the kernel's hardening, the file systems' hardening, and the network's hardening.
- Describe the logging and the monitoring's mechanisms (the auditd, the file's integrity's monitoring, the HIDS, the SIEM), and explain the detection's role in the hardening's process.
- Describe the patch management and the vulnerability scanning, the compliance and the auditing (the CIS, the NIST, the STIG, the PCI-DSS), and the security operations (the SecOps, the incident's response).
- Explain the hardening's lifecycle and the hardening's design's principles, and evaluate a system's hardening's state against the lesson's criteria.
This lesson contributes to U12.7 and the unit's synthesis, and to course learning outcomes CLO1, CLO7, and CLO8.
03 Required reading
- Operating System Concepts — Chapter 16, Security, Sections 16.6–16.8 (the security's implementation, the auditing, and the assurance), and Chapter 17, Protection. The standard treatment of the security's implementation and the assurance's concerns.
- OSTEP — the Security chapters and the dialogue Summary. OSTEP's treatment of the security's operations and its discussion of the assurance's concerns is the clearest available account, and it is the basis for the worked example in this lesson.
- Tanenbaum & Bos — Modern Operating Systems, Chapter 9, Security, and Chapter 10, Case Study 1: UNIX, Linux, and Android. A complementary treatment that develops the hardening's practices from first principles.
- Bauer, M. — Paranoid Penguin: A Step-by-Step Guide to Building a Secure Linux Server. No Starch Press, 2005. The comprehensive's hardening's reference for the Linux systems.
- Barrett, D., Silverman, R. E., & Byrnes, R. G. — Linux Security Cookbook. O'Reilly, 2003. The practical's hardening's recipes for the Linux systems.
- NIST SP 800-123 — Guide to General Server Security. The National Institute of Standards and Technology's guide to the server's hardening.
- NIST SP 800-40 Rev. 4 — Guide to Enterprise Patch Management Planning. The NIST's guide to the patch's management.
- NIST SP 800-92 — Guide to Computer Security Log Management. The NIST's guide to the logs' management.
- NIST SP 800-137 — Information Security Continuous Monitoring (ISCM) for Federal Information Systems and Organizations. The NIST's guide to the continuous's monitoring.
- The CIS Benchmarks — The Center for Internet Security's benchmarks for the operating systems (the Linux, the Windows, the macOS), the applications, and the cloud's platforms. The benchmarks are the hardening's standard's references.
- The DISA STIGs — The Defense Information Systems Agency's Security Technical Implementation Guides. The government's hardening's baselines, with the detailed's configuration's requirements.
- Bejtlich, R. — The Tao of Network Security Monitoring, 2nd ed. Addison-Wesley, 2013. The comprehensive's reference for the network's monitoring and the incident's detection.
- Sanders, C., & Smith, J. — Applied Network Security Monitoring. Syngress, 2014. The practical's guide to the NSM's operations.
-
Linux man pages:
man 8 sysctl,man 5 sysctl.conf,man 8 systemctl,man 5 systemd.unit,man 5 systemd.exec,man 1 ss,man 8 ufw,man 1 firewall-cmd,man 8 iptables,man 8 nft,man 8 auditctl,man 8 ausearch,man 8 aureport,man 5 auditd.conf,man 1 aide(if available),man 8 aideinit,man 1 tripwire(if available),man 1 rkhunter,man 1 lynis,man 8 oscap,man 1 apt(orman 8 dnf),man 8 unattended-upgrades,man 1 systemd-analyze,man 1 nmap,man 1 openvas(orman 1 nessus),man 1 trivy(if available),man 5 fail2ban,man 1 fail2ban-client,man 1 sudo,man 5 sudoers,man 8 sshd,man 5 sshd_config,man 8 usermod,man 1 chage,man 1 passwd,man 5 login.defs,man 1 cryptsetup,man 5 fstab,man 1 mount,man 8 mount,man 8 tune2fs,man 1 dmesg,man 1 journalctl,man 5 rsyslog.conf,man 8 logrotate,man 8 cron,man 5 crontab,man 8 systemd.timer,man 8 aa-status,man 8 getenforce,man 8 semanage.
Reading strategy
Read the Silberschatz chapter first. It presents the security's implementation and the assurance's concerns, and it is the formal context for the hardening's discussions. Then read the NIST SP 800-123 (the server's hardening's guide), the NIST SP 800-40 (the patch's management), the NIST SP 800-92 (the logs' management), and the NIST SP 800-137 (the continuous's monitoring). The four NIST guides are the authoritative references for the hardening's components, and they are worth reading for the frameworks and the recommendations. The CIS Benchmarks are the practical's baselines, and they are worth consulting for the specific's configuration's requirements (the Linux's, the distributions', the applications'). The DISA STIGs are the government's baselines, and they are worth consulting for the detailed's controls and the compliance's testing. The Bauer book (the Paranoid Penguin) is the classical's Linux's hardening's reference, and it is worth reading for the practical's recipes and the design's rationales. The Bejtlich and the Sanders & Smith books are the NSM's comprehensive's references, and they are worth reading for the monitoring's and the detection's designs. Finally, the Linux man pages are the practical's tools, and the interactive activity uses them throughout. Pay particular attention to the hardening's iterative and ongoing character: the hardening is not a one-time's configuration but a continuous's process. The observation is the reason the lesson emphasizes the security operations (the SecOps): the baselines are the applied, the systems are the assessed, the gaps are the remediated, the new's baselines are the selected, and the cycle repeats. The hardening is the security's discipline that keeps the system secure as the threats, the workloads, and the environments change.
04 Core content
4.1 What hardening is
The operating-system hardening is the discipline of configuring, monitoring, and maintaining a system so that its attack surface is the minimum, its defenses are the layered, and its compromises are the detected. The hardening's goals (the introduction's threefold):
- The attack's surface's reduction. The fewer the services, the ports, the accounts, the privileges, and the features, the fewer the attacker's entry's points and the fewer the exploitable's components.
- The defense's strengthening. The stronger the authentication, the authorization, the sandboxing, and the monitoring, the higher the attacker's cost and the smaller the compromise's damage.
- The compromise's detection. The more complete the logging, the better the monitoring, the faster the detection, and the smaller the compromise's duration.
The hardening's central's observation: the security is a process, not a product. The observation has three consequences:
- The hardening is not the configuration's checklist. The checklist (the CIS Benchmark, the STIG, the internal's baseline) is the starting's point, and the checklist's application is the beginning, not the end. The hardening requires the understanding of the system's role, the threats, and the compromises' impacts, and the configuration's choices must reflect the context.
- The hardening is not the one-time's activity. The threats evolve (the new's vulnerabilities, the new's attacks, the new's exploits), the workloads evolve (the new's applications, the new's users, the new's data), and the environments evolve (the new's networks, the new's regulations, the new's compliance's requirements). The hardening's configuration must be the reviewed and the adjusted as the environment changes, and the observation is the reason the hardening is the ongoing process.
- The hardening is not the perfect's security. The hardening reduces the risk (the attack's likelihood, the compromise's impact), but it does not eliminate the risk. The observation is the reason the hardening includes the detection and the response: the assumption is that the compromise will happen, and the design is the detection and the containment. The assume breach's posture (the zero-trust's principle) is the modern's security's standard.
4.2 The hardening's methodology and the security baselines
The hardening's methodology is the structured's approach to the system's security's configuration:
- The system's inventory and the role's definition. The system's role (the web server, the database, the workstation, the container host), the system's assets (the data, the services, the credentials), and the system's users (the internal, the external, the privileged) are the inventory's and the role's definition's subjects. The inventory is the hardening's foundation: the system's role determines the services, the ports, and the privileges the system needs, and the role's clarity is the configuration's clarity's precondition.
- The threat's model and the risk's assessment. The threats (the external's attackers, the internal's attackers, the malware, the supply chain, the insiders) and the risks (the impact's estimates: the data's loss, the service's disruption, the reputation's damage) are the threat's model's and the risk's assessment's subjects. The model and the assessment determine the hardening's priorities: the high-risk's components are the most hardened, and the low-risk's components are the acceptable's exposure.
- The baseline's selection. The security's baseline is the configuration's template that the system's hardening is measured against. The baselines' sources: the CIS Benchmarks (the Center for Internet Security's consensus-based's configurations: the Level 1's for the general use, the Level 2's for the high-security's use), the NIST's guides (the NIST SP 800-53's controls, the NIST SP 800-123's server's guide, the NIST SP 800-171's CUI's guide), the DISA STIGs (the Defense Information Systems Agency's detailed's configurations for the government's systems), the vendor's guides (the Red Hat's, the Ubuntu's, the Microsoft's hardening's guides), and the organizational's baselines (the organization's tailored's configurations that reflect its specific's requirements).
- The configuration's application. The baseline's configuration is the applied (the services, the ports, the accounts, the privileges, the kernel's parameters, the file systems, the monitoring), and the application is the automated where possible (the Ansible, the Puppet, the Chef, the SaltStack, the cloud-init) so the configuration is the consistent and the reproducible.
-
The configuration's assessment.
The configuration is the assessed against
the baseline (the
oscap's OpenSCAP's scanning, thelynis's audit, theusg's Ubuntu Security Guide, the organization's scripts), and the gaps (the unmet's controls, the drifted's configurations) are the identified. - The gaps' remediation. The gaps are the remediated (the configuration's changes, the services' disabling, the patches' application, the accounts' review), and the remediation is the tracked (the tickets, the change's records, the exceptions' documentation).
- The monitoring and the review. The configuration is the monitored (the file's integrity's monitoring, the auditd's events, the logs' analysis), and the configuration is the reviewed periodically (the baseline's updates, the new's vulnerabilities, the workload's changes, the compliance's requirements). The cycle repeats.
The baselines' comparison:
| Baseline | The source | The focus | The typical use |
|---|---|---|---|
| The CIS Benchmarks | The Center for Internet Security (the consensus's process) | The detailed's configuration's requirements with the two levels (the Level 1's for the general, the Level 2's for the high-security) | The commercial's and the enterprise's systems; the widely adopted baseline |
| The NIST's guides (the SP 800-53, the SP 800-123, the SP 800-171) | The National Institute of Standards and Technology | The controls' frameworks and the guides for the specific's areas (the server's hardening, the CUI's protection) | The U.S. federal's systems and the commercial's systems that follow the NIST's frameworks |
| The DISA STIGs | The Defense Information Systems Agency | The detailed's configurations for the government's systems, with the strict's controls | The U.S. Department of Defense's systems; the government's contractors |
| The vendor's guides | The vendors (the Red Hat, the Ubuntu, the Microsoft) | The vendor's specific's recommendations, integrated with the products | The systems that use the vendors' products; the vendor's support's scope |
| The organizational's baselines | The organization's security's team | The tailored's configurations that reflect the organization's specific's requirements and the compliance's obligations | The organization's systems, consistent with the organization's policies and the regulations |
The baselines' design's observations:
- The baselines are the starting's points, not the ending's points. The baseline's application is the beginning; the system's specific's requirements (the workload, the threats, the compliance) may require the deviations (the exceptions, the additional's controls), and the deviations must be the documented and the reviewed.
- The baselines' levels. The baselines often have the multiple's levels (the CIS's Level 1 and Level 2, the NIST's low, moderate, and high), and the level's selection depends on the system's risk's profile: the higher's level is the more restrictive and the more disruptive, and the observation is the reason the level's selection is the risk's assessment's outcome.
-
The baselines' automation.
The baselines' application and the assessment
are the automated (the
oscap's OpenSCAP's profiles, thelynis's audits, theusg's Ubuntu Security Guide, the Ansible's roles), so the configuration is the consistent and the assessment is the repeatable. The automation's design is the hardening's scalability's mechanism.
4.3 The attack surface's reduction
The attack surface's reduction is the hardening's first's principle (the Lesson 12.1's attack surface's discussion). The system's attack surface is the set of the components that an attacker can interact with (the network's services, the local's interfaces, the users' interactions, the supply chain), and the reduction minimizes the components:
- The services
-
The system's running services are the
attacker's entry's points, and the
hardening's first's step is the services'
inventory and the unnecessary's services'
disabling. The commands: the
systemctl list-units --type=service --state=running(the running's services), thesystemctl list-unit-files --state=enabled(the enabled's services), thesystemctl disable <service>(the disabling), and thesystemctl mask <service>(the preventing's of the service's start, even by the dependencies). The services' review's criteria: the system's role (the web server does not need the print's service), the necessity (the service's function), and the alternatives (the service's replacement with the more secure's mechanism). - The ports
-
The listening's ports are the network's
attacker's entry's points, and the
hardening's step is the ports' inventory and
the unnecessary's ports' closing. The
commands: the
ss -tlnp(the TCP's listening's ports with the processes), thess -tlnup(the TCP and the UDP's ports), thenmap's scan (the ports' scan from the external's perspective), and the firewall's rules (theufw, thefirewalld, thenftables). The ports' review's criteria: the necessity (the service's external's exposure), the binding (the service should bind to the specific's interfaces: the localhost for the management's services, the specific's network's interfaces for the services' functions), and the firewall's rules (the deny's default with the specific's allows). - The packages
-
The installed's packages are the components
that the attacker can exploit (the
vulnerabilities, the misconfigurations, the
unnecessary's features), and the hardening's
step is the packages' inventory and the
unnecessary's packages' removal. The
commands: the
dpkg -l(the Debian's packages), therpm -qa(the RPM's packages), thednf history(the DNF's history), theapt autoremove(the unnecessary's dependencies' removal), and theapt purge <package>(the package's removal with the configuration). The packages' review's criteria: the necessity (the package's function), the alternatives (the package's replacement with the more secure's mechanism), and the vulnerabilities (the package's known's vulnerabilities and the patch's availability). - The kernel's modules
-
The kernel's modules are the kernel's
extensions (the drivers, the file systems,
the network's protocols), and the
unnecessary's modules are the attack's
surface's components (the modules' bugs are
the kernel's bugs). The hardening's step is
the modules' inventory and the unnecessary's
modules' blacklisting. The mechanisms: the
lsmod(the loaded's modules), themodprobe.d's configuration (the blacklist's directives), thekernel.modules_disabled=1's sysctl (the modules' loading's disabling: the one-way's switch, the systems that do not need the modules should set it after the boot), and the kernel's build's configuration (the unused's modules' exclusion). The observation: the modern's systems' kernels have the hundreds of the modules, and the unnecessary's modules' blacklisting reduces the attack's surface. - The accounts
-
The system's accounts are the attacker's
entry's points (the unnecessary's accounts,
the default's accounts, the weak's accounts),
and the hardening's step is the accounts'
inventory and the unnecessary's accounts'
removal or locking. The commands: the
cat /etc/passwd(the accounts), theawk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd(the regular's users), theusermod -L <user>(the account's locking), theuserdel -r <user>(the account's removal with the home), and thechage -l <user>(the account's aging's information). The accounts' review's criteria: the necessity (the account's function), the privileges (the account's group's memberships and the sudo's rules), the aging (the password's aging's policy), and the inactivity (the unused's accounts' disabling).
The attack surface's reduction's observations:
- The reduction's tension with the functionality. The services' disabling, the packages' removal, and the accounts' locking reduce the functionality (the users' convenience, the features' availability), and the reduction's design must balance the two: the reduction should not break the system's legitimate's functions, and the observation is the reason the reduction is the iterative process (the inventory, the assessment, the disabling, the testing, the adjustment).
- The reduction's automation. The reduction is the automated where possible (the Ansible's playbooks, the Puppet's manifests, the cloud-init's configurations, the golden's images), so the configuration is the consistent across the fleet and the drift is the detected.
- The reduction's documentation. The reduction's decisions (the services' disabled, the packages' removed, the accounts' locked) must be the documented, so the system's function is the understood and the changes are the reviewed. The documentation is the hardening's auditability's foundation.
4.4 The identity's and the authentication's hardening
The identity's and the authentication's hardening strengthens the system's identity's model and its authentication's mechanisms:
-
The account's hardening. The
accounts' review (the unnecessary's
accounts' removal, the default's accounts'
locking, the service's accounts' creation
with the
nologin's shells), the accounts' aging (thechage's policies: the password's minimum and maximum ages, the warning's period, the inactivity's period), the accounts' privilege's review (the group's memberships, the sudo's rules, the capabilities), and the accounts' auditing (thelastand thelastlog's reports, the/etc/shadow's review). -
The password's hardening. The
strong's passwords (the length over the
complexity, the passphrase, the password's
managers: the Lesson 12.2's guidance), the
password's policies (the
pam_pwquality's rules: the minimum's length, the character's classes, the dictionary's check), the password's aging (thechage's policies), the password's storage (the strong's KDFs: the yescrypt's default in the modern's Linux, the bcrypt's, the Argon2id's), and the password's breach's checking (thepam_pwquality'sdictcheckand theusercheckdirectives). -
The SSH's hardening. The
key-based's authentication (the
PasswordAuthentication no, thePubkeyAuthentication yes, theAuthorizedKeysFile's configuration, the keys' algorithms: the ed25519's, the RSA's 4096 bits, the keys' passphrases), the root's login's disabling (thePermitRootLogin no), the non-standard's port (thePort 2222's change: the security's through the obscurity's limited's benefit), the users' restriction (theAllowUsers's and theAllowGroups's directives), the protocols' restriction (theProtocol 2's only), the ciphers' and the MACs' restriction (theCiphers's and theMACs's directives with the strong's algorithms only), the sessions' timeout (theClientAliveInterval's and theClientAliveCountMax's directives), the X11's forwarding's disabling (theX11Forwarding no), and the verbose's logging (theLogLevel VERBOSE). -
The multi-factor's authentication.
The MFA's deployment (the TOTP: the
pam_google_authenticator's module, the FIDO2: the U2F's keys, the smart cards: the PIV's), and the MFA's enforcement for the privileged's accesses (the SSH's logins, the sudo's commands, the administrative's interfaces). -
The sudo's hardening. The
sudoers's rules' design (the specific's commands, the per-user's and the per-host's specifications), theNOPASSWD's avoidance (the password's requirement for the sensitive's operations), theDefaults's directives (therequiretty's setting, theenv_reset, thesecure_path, thelogfile's and thelog_input's settings), thesudo's logging (the/var/log/auth.log's and thejournalctl's events), and thesudo's version's updates. -
The PAM's hardening. The
PAM's stack's review (the
/etc/pam.d/'s files), thepam_faillock's lockout (the failed's attempts' policy: thedeny=5, theunlock_time=900), thepam_limits's resource's limits, thepam_unix's options (thesha512's or theyescrypt's hashing, thenullok's absence), and thepam_exec's and thepam_script's additional's controls.
The identity's and the authentication's hardening's observations:
- The hardening's balance. The identity's and the authentication's hardening has the usability's tension (the strong's passwords, the frequent's re-authentications, the MFA's additional's steps), and the observation is the psychological acceptability's principle (Lesson 12.1's principle 8): the mechanism must be the usable, or the users will find the ways around it.
-
The hardening's verification.
The identity's and the authentication's
hardening's state is the verified (the
pam_faillock'sfaillock's command, thechage -l's reports, thepasswd -S's status, the SSH's configuration's review), and the verification is the hardening's assessment's component.
4.5 The kernel's hardening
The kernel's hardening strengthens the kernel's security's mechanisms and reduces the kernel's attack surface:
-
The sysctl's parameters. The
kernel's runtime's security's parameters (the
Lesson 12.5's section 4.13's discussion):
the network's parameters (the
net.ipv4.tcp_syncookies=1, thenet.ipv4.conf.all.rp_filter=1, thenet.ipv4.conf.all.accept_redirects=0, thenet.ipv4.conf.all.accept_source_route=0, thenet.ipv4.conf.all.log_martians=1, thenet.ipv4.icmp_echo_ignore_broadcasts=1), the kernel's parameters (thekernel.randomize_va_space=2, thekernel.dmesg_restrict=1, thekernel.kptr_restrict=2, thekernel.yama.ptrace_scope=1, thekernel.sysrq=0, thekernel.kexec_load_disabled=1), the file system's parameters (thefs.protected_hardlinks=1, thefs.protected_symlinks=1, thefs.suid_dumpable=0, thefs.protected_fifos=2, thefs.protected_regular=2), and the virtual memory's parameters (thevm.mmap_min_addr=65536). -
The ASLR's enforcement. The
kernel.randomize_va_space=2(the full's randomization: the stack, the heap, the libraries, the mmap's regions), and the observation is the ASLR's effectiveness's requirement: the randomization's entropy's reduction (the container's or the VM's constraints) can weaken the ASLR, and the observation is the reason the modern's systems verify the ASLR's state. -
The kernel's modules' signing.
The
CONFIG_MODULE_SIG_FORCE=yes's kernel's configuration (the modules' signing's enforcement), thekernel.modules_disabled=1's sysctl (the modules' loading's disabling after the boot), and the observation: the kernel's modules are the kernel's code, and the malicious's module is the full's kernel's compromise. The signing's enforcement and the loading's disabling are the kernel's integrity's mechanisms. -
The kernel's lockdown. The
lockdown=confidentiality's or thelockdown=integrity's kernel's command-line's parameter (the kernel's lockdown: the restrictions on the privileged's operations: the/dev/mem's access, thekexec's loading, theiomem's reading, the unsigned's modules' loading), and the observation: the lockdown is the UEFI's Secure Boot's complement (the boot's chain's integrity), and it is the modern's systems' mechanism for the kernel's integrity's enforcement. -
The boot's chain's integrity.
The UEFI's Secure Boot (the boot's chain's
signature's verification: the firmware, the
boot loader, the kernel), the measured's
boot (the TPM's measurements: the PCR's
values), the
IMA(the Integrity Measurement Architecture: the files' measurements, the appraisal, the audit), and the observation: the boot's chain's integrity is the kernel's integrity's foundation, and the modern's systems' designs include the mechanisms.
4.6 The file systems' hardening
The file systems' hardening strengthens the file systems' security's mechanisms and reduces the file systems' attack surface:
-
The permissions' review. The
world-writable's files' search (the
find / -type f -perm -o+w), the setuid's and the setgid's programs' review (thefind / -perm -4000 -type f, thefind / -perm -2000 -type f), the unowned's files' search (thefind / -nouser -o -nogroup), the/tmp's and the/var/tmp's permissions (the sticky's bit's presence), the home's directories' permissions (the700's or the750's modes), the/etc/shadow's permissions (the640's or the000's modes with the root's ownership), and the sensitive's files' review (the SSH's keys: the600's mode; the/etc/sudoers: the440's mode; the/etc/crontab: the644's mode with the root's ownership). -
The mount's options. The
/etc/fstab's mount's options for the security's partitions: thenodev(the device's files' ignoring), thenosuid(the setuid's bits' ignoring), thenoexec(the binaries' execution's prevention) for the/tmp, the/var/tmp, the/home, and the/dev/shm; thero(the read-only's mount) for the/usrand the/boot; thenodev,nosuidfor the/boot; and the observation: the mount's options are the per-file-system's restrictions, and they are the layered's defenses (the mode's bits' restrictions are the complements). -
The disk's encryption. The
full's disk's encryption (the LUKS: the
cryptsetup luksFormat's initialization, thecryptsetup luksOpen's opening, the/etc/crypttab's configuration), the encryption's algorithms (the AES's with the XTS's mode, theaes-xts-plain64), the key's derivation (the Argon2id's or the PBKDF2's), the encrypted's swap (the swap's encryption or the disabling), and the observation: the full's disk's encryption protects the data at rest (the device's theft, the improper's disposal, the physical's access), and it is the modern's systems' standard for the laptops and the portable's devices. -
The file's attributes. The
chattr +i's immutable's attribute for the critical's files (the/etc/passwd's, the/etc/shadow's, the/etc/sudoers's, the/etc/ssh/sshd_config's protection), thechattr +a's append-only's attribute for the logs (the/var/log/audit/audit.log's protection), and the observation: the attributes are the additional's protections beyond the mode's bits, and they are the critical's files' defense's depth. -
The files' ACLs. The ACLs'
design for the shared's directories (the
projects' directories with the default's
ACLs), the ACLs' review (the
getfacl -R's recursive's listing, thefind / -type f -acl's search for the files with the ACLs), and the observation: the ACLs are the finer's granularity's mechanism, and their design must be the documented and the reviewed (the ACLs' sprawl is the management's concern).
4.7 The network's hardening
The network's hardening reduces the system's network's attack surface and strengthens the network's defenses:
-
The firewall's rules. The
firewall's design (the
ufw's simplification, thefirewalld's zones, thenftables's rules, theiptables's legacy), the default's policy (thedeny's incoming, theallow's outgoing), the specific's allows (the SSH's port, the HTTP's and the HTTPS's ports, the database's port from the application's server only), and the observation: the firewall's default's deny is the Lesson 12.1's fail-safe defaults' principle's application, and the specific's allows are the least privilege's principle's application. - The network's segmentation. The system's network's placement (the DMZ's public's services, the internal's network's private's services, the management's network's administrative's interfaces), the VLANs' or the subnets' separation, the host's firewall's rules' per-interface's configuration, and the observation: the segmentation is the attacker's lateral's movement's limitation's mechanism, and it is the network's defence's depth's principle's application.
-
The services' binding. The
services' binding's configuration (the
services should bind to the specific's
interfaces: the localhost for the
management's services, the specific's
network's interfaces for the services'
functions), the services'
bind's directives (the database'sbind-address = 127.0.0.1's setting, the web's server'sListen 443's configuration), and the observation: the binding's restriction is the services' exposure's reduction, and the observation is the reason the services' binding is the attack surface's reduction's component. -
The TLS's configuration. The
TLS's versions (the TLS 1.2's and the TLS
1.3's only, the SSLv3's and the TLS 1.0's
and the TLS 1.1's disabling), the ciphers'
suites (the strong's suites only, the
forward's secrecy's suites: the ECDHE's),
the certificates' management (the valid's
certificates, the renewal's automation:
the Let's Encrypt's certbot, the
acme.sh), the HSTS's deployment (theStrict-Transport-Security's header), and the observation: the TLS's configuration is the network's traffic's confidentiality's and the integrity's mechanism, and its strength depends on the versions and the ciphers. -
The fail2ban's intrusion's
prevention. The fail2ban's
configuration (the
jail.local's jails: the SSH's, the web's, the database's), the bans' rules (the failed's attempts' threshold, the ban's duration), the actions (the firewall's rules' addition, the notification's email), and the observation: the fail2ban is the brute force's prevention's mechanism, and it is the authentication's hardening's complement.
4.8 The logging, monitoring, and detection
The logging, the monitoring, and the detection are the hardening's detection's component (the introduction's third goal). The mechanisms:
- The auditd (the kernel's audit's framework)
-
The Linux's audit's subsystem (the Lesson
12.5's section 4.11's discussion): the
kernel's audit's framework generates the
security-relevant's events, the
auditd's daemon writes them to the/var/log/audit/audit.log, and the tools (ausearch, theaureport) query and report the events. The audit's rules (the/etc/audit/rules.d/'s files): the file's watches (the-w /etc/passwd -p wa -k passwd_changes), the system calls (the-a always,exit -F arch=b64 -S execve -k exec), the authentication's events (the-w /var/log/faillock -p wa -k logins), and the privilege's escalations (the-w /etc/sudoers -p wa -k sudoers_changes). - The file's integrity's monitoring (the FIM)
- The file's integrity's monitoring's tools (the AIDE, the Tripwire, the Samhain, the OSSEC's FIM) compute the baseline's database of the files' hashes, the metadata, and the permissions, and the periodic's scans detect the changes. The tools' purpose: the compromise's detection's (the modified's system's binaries, the added's backdoors, the changed's configurations) and the unauthorized's changes' detection (the accidental's mistakes, the malicious's modifications). The observation: the FIM is the compromise's detection's central's mechanism, and its design's subtleties (the baseline's creation, the exclusions's configuration, the scans' schedule, the changes' review) determine its effectiveness.
- The HIDS (the host's intrusion's detection's systems)
- The HIDS's tools (the OSSEC, the Wazuh, the Samhain, the Tripwire's HIDS, the Suricata's HIDS's mode) monitor the host's events (the logs, the file's changes, the processes, the network's connections, the registry's changes) and detect the suspicious's activities (the brute force's attempts, the privilege's escalations, the malware's indicators, the anomalous's behaviors). The HIDS's design's components: the agents (the host's monitoring's daemons), the managers (the central's analysis's servers), the rules (the detection's logic), and the alerts (the notifications). The observation: the HIDS is the host's monitoring's central's mechanism, and its rules' maintenance (the updates, the tuning) determines its effectiveness.
- The SIEM (the security's information's and the event's management)
- The SIEM's platforms (the Splunk, the ELK's stack, the Graylog, the Wazuh, the Sumo Logic, the ArcSight) aggregate the logs from the multiple's sources (the systems, the applications, the network's devices, the security's tools), the correlate the events (the multiple's sources' events' association), the analyze the data (the pattern's detection, the anomaly's detection, the threat's intelligence's matching), and the present the results (the dashboards, the alerts, the reports). The observation: the SIEM is the enterprise's monitoring's central's platform, and its design's components (the log's ingestion, the normalization, the correlation's rules, the alerting's workflows) determine its effectiveness.
- The logs' management
- The logs' management's mechanisms: the logging's levels (the debug, the info, the warning, the error, the critical), the logs' rotation (the logrotate's configuration, the systemd-journald's settings), the logs' retention (the retention's policies: the legal's requirements, the forensics's needs, the storage's capacity), the logs' protection (the permissions, the attributes, the encryption), the logs' remote's delivery (the rsyslog's configuration, the journald's upload, the syslog-ng's destinations), and the logs' integrity (the cryptographic's signing, the append-only's attribute). The observation: the logs are the security's evidence, and their management determines the detection's and the forensics's effectiveness.
The logging's, the monitoring's, and the detection's observations:
- The detection's role in the hardening's process. The detection is the hardening's assume breach's component: the assumption is that the compromise will happen, and the detection's design is the fast's identification and the containment. The observation is the reason the detection's mechanisms are the hardening's equal's components (the prevention's mechanisms): the prevention reduces the likelihood, and the detection reduces the impact.
- The monitoring's coverage. The monitoring's coverage determines the detection's effectiveness: the events' coverage (the authentication, the authorization, the file's accesses, the network's connections, the privilege's escalations), the sources' coverage (the systems, the applications, the network, the security's tools), and the times' coverage (the real-time's monitoring, the periodic's scans, the historical's analysis). The coverage's design is the risk's assessment's outcome.
- The alerts' quality. The alerts' quality determines the response's effectiveness: the alerts' precision (the false positives' rate), the alerts' recall (the false negatives' rate), the alerts' context (the relevant's information: the source, the target, the event's details), and the alerts' routing (the appropriate's team, the appropriate's priority). The alerts' quality is the monitoring's design's central's concern, and the observation is the reason the SIEM's and the HIDS's tuning is the ongoing's activity.
4.9 The patch management and the vulnerability scanning
The patch management and the vulnerability scanning are the hardening's maintenance's component:
-
The patch management. The
patches' lifecycle: the patch's availability's
monitoring (the vendors' advisories, the
CVE's databases, the NVD's feeds, the
distributions' security's announcements), the
patch's evaluation (the severity's
assessment, the applicability, the impact),
the patch's testing (the non-production's
environments, the staging's systems), the
patch's deployment (the production's systems,
the maintenance's windows, the rollback's
plans), and the patch's verification (the
versions' checks, the functionality's tests).
The tools: the
apt's and theunattended-upgrades's (the Debian's and the Ubuntu's), thednf's and thednf-automatic's (the Fedora's and the RHEL's), thezypper's (the openSUSE's), theyum-cron's (the older's), and the configuration's management's tools (the Ansible's, the Puppet's, the Chef's). -
The vulnerability scanning. The
scanners: the network's scanners (the
Nessus, the OpenVAS, the Qualys, the
Rapid7's Nexpose), the host's scanners (the
Lynis, the OpenSCAP's
oscap, thelynis audit system), the container's scanners (the Trivy, the Clair, the Anchore, the Snyk), the application's scanners (the SAST's, the DAST's, the SCA's), and the cloud's scanners (the AWS's Inspector, the Azure's Defender, the GCP's Security Command Center). The scanners' outputs: the vulnerability's list (the CVE's identifiers, the CVSS's scores, the affected's components), the prioritization (the critical's and the high-severity's findings' first), and the remediation's tracking (the tickets, the exceptions, the verification). - The patch's cadence. The patch's cadence's design: the critical's patches' immediate's application (the actively's exploited's vulnerabilities, the zero-days), the high-severity's patches' rapid's application (the days to the weeks), the moderate's and the low-severity's patches' regular's application (the monthly's cycles), and the exceptions' management (the systems that cannot be patched: the legacy's applications, the embedded's devices, the vendor's constraints). The cadence's design is the risk's assessment's outcome, and the observation is the reason the patch's and the vulnerability's management is the ongoing's activity.
4.10 The compliance and the auditing
The compliance and the auditing are the hardening's verification's component: the frameworks, the standards, and the audits that verify the system's security's state:
- The frameworks and the standards. The NIST Cybersecurity Framework (the five functions: the identify, the protect, the detect, the respond, the recover), the ISO/IEC 27001 (the information's security's management's systems), the CIS Controls (the eighteen's controls: the inventory, the configuration, the access, the vulnerabilities, the monitoring), the PCI-DSS (the payment's card's industry's standard: the twelve's requirements), the HIPAA (the health's information's protection), the GDPR (the European's data's protection), the SOC 2 (the service's organizations' controls), and the FISMA (the federal's information's security's management). The frameworks and the standards provide the controls' catalogues and the auditing's requirements.
- The audits. The audits' types: the internal's audits (the organization's security's team), the external's audits (the third-party's auditors), the compliance's audits (the regulators' inspections), the certification's audits (the ISO 27001's, the SOC 2's), and the penetration's tests (the ethical's hackers' simulated's attacks). The audits' outputs: the findings (the controls' gaps, the vulnerabilities, the misconfigurations), the ratings (the severity's levels, the risk's scores), the remediation's plans (the actions, the owners, the deadlines), and the attestations (the compliance's reports, the certifications).
- The compliance's automation. The compliance's automation's tools: the OpenSCAP (the SCAP's profiles, the automated's assessments), the Lynis (the audit's tool with the recommendations), the InSpec (the Chef's compliance's framework), the Cloud's compliance's tools (the AWS's Config, the Azure's Policy, the GCP's Security Command Center), and the continuous's compliance's platforms (the Vanta, the Drata, the Secureframe). The automation's design is the compliance's scalability's and the consistency's mechanism.
4.11 The security operations (SecOps)
The security operations (the SecOps) is the security's operations's discipline: the ongoing's monitoring, the incident's response, the threat's hunting, and the security's engineering. The SecOps's components:
- The monitoring. The continuous's monitoring (the SIEM's alerts, the HIDS's events, the network's monitoring's data), the triage (the alerts' prioritization, the false positives' filtering), the investigation (the events' correlation, the incident's assessment), and the escalation (the incidents' routing to the response's team).
- The incident's response. The incident's response's lifecycle (the NIST SP 800-61's framework): the preparation (the plans, the playbooks, the tools, the training), the detection and the analysis (the monitoring's and the triage's outputs), the containment (the affected's systems' isolation, the compromise's spread's prevention), the eradication (the threat's removal, the vulnerabilities' remediation), the recovery (the systems' restoration, the services' resumption, the monitoring's enhancement), and the lessons's learned (the post-incident's review, the improvements).
- The threat's hunting. The proactive's search for the threats within the environment (the hypothesis-driven's investigations, the anomalies' analysis, the threat's intelligence's application), the observation: the threat's hunting is the assume breach's posture's proactive's component, and it is the detection's mechanisms' complement.
- The security's engineering. The security's mechanisms' design and the deployment (the authentication's mechanisms, the authorization's models, the sandboxing's configurations, the monitoring's tools), the security's architecture (the zero-trust's designs, the defence in depth, the least privilege), the security's automation (the infrastructure's as the code, the policy's as the code, the detection's as the code), and the security's research (the new's threats, the new's mechanisms, the new's practices).
The SecOps's design's observations:
- The SecOps's integration with the DevOps. The modern's practice (the DevSecOps) integrates the security into the DevOps's lifecycle: the security's requirements in the planning, the security's tests in the development (the SAST, the DAST, the SCA), the security's configurations in the deployment (the infrastructure's as the code, the policy's as the code), and the security's monitoring in the operations (the SIEM's integration, the feedback's loops). The observation is the reason the DevSecOps is the modern's software's development's standard.
- The SecOps's metrics. The SecOps's metrics: the mean time to detect (the MTTD), the mean time to respond (the MTTR), the mean time to remediate (the MTTR's alternative), the vulnerabilities' backlog's size and the aging, the incidents' count and the severity, the patch's compliance's rate, and the alerts' quality (the false positives' rate). The metrics' design is the SecOps's performance's management's foundation.
- The SecOps's maturity. The SecOps's maturity's models: the CMMC's (the Cybersecurity Maturity Model Certification), the C2M2's (the Cybersecurity Capability Maturity Model), the SOC-CMM's, and the NIST's CSF's implementation's tiers. The maturity's assessment is the SecOps's improvement's roadmap's foundation, and the observation is the reason the maturity's models are the modern's security's organizations' frameworks.
4.12 The hardening's design principles
The hardening's design applies the Lesson 12.1's principles, and the specific's applications:
- The least privilege (the principle 6). The users, the services, and the processes have the minimum's privileges: the service's accounts, the capability's minimization, the sudo's rules, the container's dropped's capabilities, the systemd's directives.
- The fail-safe defaults (the principle 2). The defaults are the secure's: the firewall's deny's default, the services' disabled's default, the permissions' restrictive's default, the SELinux's enforcing's default, the systemd's hardening's directives' defaults.
- The complete mediation (the principle 3). The every access is the mediated: the kernel's reference monitor, the LSM's hooks, the auditd's rules, the FIM's monitoring, the network's firewall.
- The economy of mechanism (the principle 1). The mechanisms are the simple and the small: the minimal's services, the minimal's packages, the minimal's kernel's modules, the minimal's PAM's stack, the minimal's sudoers's rules.
- The separation of privilege (the principle 5). The critical's operations require the multiple's conditions: the MFA for the privileged's accesses, the separation of duties for the sensitive's changes, the multiple's approvals for the critical's operations.
- The least common mechanism (the principle 7). The shared's resources are the minimized: the per-user's home's directories, the per-service's accounts, the per-container's namespaces, the per-VM's isolation.
- The psychological acceptability (the principle 8). The mechanisms are the usable: the sensible's defaults, the understandable's configurations, the reasonable's trade-offs, the escape's hatches for the legitimate's needs.
- The open design (the principle 4). The mechanisms are the public and the auditable: the open-source's implementations, the standard's interfaces, the reviewable's configurations, the documented's decisions.
4.13 Common misconceptions
"The hardening is a one-time's configuration."
The hardening is the ongoing's process: the threats evolve, the workloads change, the software updates, and the configuration drifts. The hardening's lifecycle (the inventory, the threat's model, the baseline's selection, the configuration's application, the configuration's assessment, the gaps' remediation, the monitoring, the review) repeats, and the observation is the reason the hardening is the security's operations's central's activity. A system that was hardened last year is not necessarily hardened this year.
"The baseline's application is the hardening's end."
The baseline's application is the hardening's beginning, not the end. The system's specific's requirements (the workload, the threats, the compliance) may require the deviations (the exceptions, the additional's controls), and the deviations must be the documented and the reviewed. The observation is the reason the hardening's practice includes the risk's assessment and the tailored's configurations, not the blind's baseline's application.
"The hardening is the security's team's responsibility."
The hardening is everyone's responsibility: the designers (the secure's architectures), the developers (the secure's code), the operations's teams (the secure's configurations), the users (the secure's behaviors), and the security's team (the oversight, the monitoring, the response). The observation is the reason the modern's practice (the DevSecOps) integrates the security into the whole's lifecycle, not the security's team's isolated's activity.
"The hardening's baseline is the same for every system."
The baseline's application depends on the system's role, the threats, and the compliance's requirements. A web server's baseline differs from a workstation's, a database's differs from a build's agent, and a production's system differs from a development's. The observation is the reason the baselines have the multiple's levels (the CIS's Level 1 and Level 2, the NIST's low, moderate, and high) and the reason the organizational's baselines are the tailored's configurations.
"The patches are the security's panacea."
The patches are necessary but not sufficient: the patches address the known's vulnerabilities, and the zero-days, the misconfigurations, the design's flaws, and the users' behaviors are the patches' blind's spots. The observation is the reason the hardening's design includes the multiple's layers (the defence in depth, the least privilege, the monitoring, the detection), not the patch's only's strategy.
"The monitoring is the optional's feature."
The monitoring is the hardening's detection's component, and it is the assume breach's posture's central's mechanism. A system without the monitoring has the blind's spots: the compromises are the undetected, the attacks are the unnoticed, and the forensics's evidence is the missing. The observation is the reason the monitoring (the auditd, the HIDS, the SIEM) is the hardening's equal's component (the prevention's mechanisms).
"The compliance is the security."
The compliance is the security's verification's component, not the security's goal. A system can be compliant (the checkboxes' checked) and insecure (the actual's threats' unaddressed), and the observation is the reason the modern's security's practice emphasizes the outcomes (the risk's reduction, the incidents' prevention) over the compliance's artifacts (the reports, the attestations).
"The hardening is the security's perfection."
The hardening reduces the risk, not eliminates it. The system's compromise is the matter of the when, not the if, and the hardening's design includes the detection and the response (the assume breach's posture). The observation is the reason the modern's security's practices include the incident's response, the business's continuity, the disaster's recovery, and the cyber's insurance, not the prevention's only's strategy.
05 Worked example
The following example performs a hardening's assessment of a Linux server, applies the hardening's controls, and evaluates the improvement with the automated's tools.
The initial's assessment
The following commands perform the initial's assessment of a Linux server:
# The system's information
uname -a
cat /etc/os-release | head -5
hostnamectl
# The running's services
systemctl list-units --type=service --state=running
# The listening's ports
ss -tlnp
sudo ss -tlnup
# The users' accounts
cat /etc/passwd | grep -vE 'nologin|false'
sudo awk -F: '$3 >= 1000 && $3 < 65534 {print $1, $3}' /etc/passwd
sudo chage -l $(whoami)
# The setuid and the setgid's programs
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null
# The world-writable's files
find / -type f -perm -o+w 2>/dev/null
# The firewall's rules
sudo ufw status 2>/dev/null
sudo firewall-cmd --list-all 2>/dev/null
sudo nft list ruleset 2>/dev/null | head -20
# The SSH's configuration
sudo grep -E 'PermitRootLogin|PasswordAuthentication|PubkeyAuthentication|Port|AllowUsers' /etc/ssh/sshd_config
# The kernel's parameters
sysctl -a 2>/dev/null | grep -E 'net.ipv4.tcp_syncookies|net.ipv4.conf.all.rp_filter|kernel.randomize_va_space|kernel.dmesg_restrict|kernel.kptr_restrict|fs.protected_hardlinks|fs.protected_symlinks'
# The SELinux's or the AppArmor's status
getenforce 2>/dev/null
sudo aa-status 2>/dev/null | head -10
# The audit's subsystem
sudo auditctl -s 2>/dev/null
# The cgroups' state
systemd-cgls 2>/dev/null | head -20
The initial's assessment's findings (the typical's example):
| The area | The finding | The severity |
|---|---|---|
| The services | The cups's (the printing's), the avahi-daemon's (the mDNS's), and the rpcbind's services are the running and the unnecessary for the server's role |
High |
| The ports | The port 22 (the SSH) is the open (the necessary), the port 631 (the CUPS) is the open (the unnecessary), and the port 111 (the rpcbind) is the open (the unnecessary) | High |
| The users | The games's account (the default's) is the present; the root's account is the SSH's permitted |
Medium |
| The SSH | The PasswordAuthentication is the yes (the passwords are the accepted); the PermitRootLogin is the yes; the port is the 22 |
High |
| The kernel | The kernel.dmesg_restrict is the 0; the kernel.kptr_restrict is the 0; the fs.protected_hardlinks is the 0 |
Medium |
| The firewall | The ufw is the inactive; the iptables's rules are the default's (the permissive) |
High |
| The auditing | The auditd is the enabled but the rules are the minimal's (the default's) |
Medium |
| The SELinux's or the AppArmor's | The getenforce's output is the Permissive (the SELinux is the enabled but the not enforcing) |
Medium |
The hardening's application
The following commands apply the hardening's controls:
# The services' disabling
sudo systemctl stop cups avahi-daemon rpcbind 2>/dev/null
sudo systemctl disable cups avahi-daemon rpcbind 2>/dev/null
sudo systemctl mask cups avahi-daemon rpcbind 2>/dev/null
# The firewall's configuration
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose
# The SSH's hardening
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/^#*X11Forwarding.*/X11Forwarding no/' /etc/ssh/sshd_config
sudo sshd -t # the configuration's syntax's check
sudo systemctl restart sshd
# The kernel's parameters
sudo tee /etc/sysctl.d/99-hardening.conf << 'EOF'
# The network's hardening
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
# The kernel's hardening
kernel.randomize_va_space = 2
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
kernel.yama.ptrace_scope = 1
# The file system's hardening
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
fs.suid_dumpable = 0
fs.protected_fifos = 2
fs.protected_regular = 2
# The virtual memory's hardening
vm.mmap_min_addr = 65536
EOF
sudo sysctl --system
# The accounts' hardening
sudo usermod -L games 2>/dev/null
sudo chage -M 90 -m 1 -W 7 -I 30 $(whoami)
sudo passwd -S $(whoami)
# The auditd's rules
sudo tee /etc/audit/rules.d/99-hardening.rules << 'EOF'
# The identity's files
-w /etc/passwd -p wa -k passwd_changes
-w /etc/shadow -p wa -k shadow_changes
-w /etc/group -p wa -k group_changes
-w /etc/sudoers -p wa -k sudoers_changes
# The SSH's configuration
-w /etc/ssh/sshd_config -p wa -k sshd_config_changes
# The privileged's operations
-a always,exit -F arch=b64 -S execve -F euid=0 -k root_commands
# The kernel's modules
-w /sbin/insmod -p x -k module_load
-w /sbin/rmmod -p x -k module_unload
-w /sbin/modprobe -p x -k module_load
EOF
sudo augenrules --load 2>/dev/null
sudo auditctl -l | head -20
# The SELinux's enforcing's mode
sudo setenforce 1 2>/dev/null
sudo sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config 2>/dev/null
getenforce
# The fail2ban's installation
sudo apt install -y fail2ban 2>/dev/null
sudo systemctl enable --now fail2ban 2>/dev/null
sudo fail2ban-client status 2>/dev/null
# The automatic's updates
sudo apt install -y unattended-upgrades 2>/dev/null
sudo dpkg-reconfigure --priority=low unattended-upgrades 2>/dev/null
The post-hardening's assessment
The post-hardening's assessment:
# The services' verification
systemctl list-units --type=service --state=running
# The ports' verification
ss -tlnp
# The firewall's verification
sudo ufw status verbose
# The SSH's verification
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|pubkeyauthentication|x11forwarding'
# The kernel's parameters' verification
sysctl -a 2>/dev/null | grep -E 'net.ipv4.tcp_syncookies|kernel.dmesg_restrict|kernel.kptr_restrict|fs.protected_hardlinks'
# The auditd's verification
sudo auditctl -l | wc -l
sudo auditctl -s
# The SELinux's verification
getenforce
# The fail2ban's verification
sudo fail2ban-client status sshd 2>/dev/null
# The automated's hardening's assessment
sudo apt install -y lynis 2>/dev/null
sudo lynis audit system 2>/dev/null | tail -40
The post-hardening's assessment's findings:
| The area | The before | The after |
|---|---|---|
| The services | The 12 running's services (the unnecessary's included) | The 8 running's services (the unnecessary's disabled and masked) |
| The ports | The 3 listening's ports (the 22, the 111, the 631) | The 1 listening's port (the 22, and the firewall's rules allow the 80 and the 443 when needed) |
| The SSH | The passwords accepted, the root's login permitted | The keys only, the root's login denied, the X11's forwarding disabled |
| The kernel | The 0's for the dmesg_restrict, the kptr_restrict, the protected_hardlinks | The hardened's values (the 1's and the 2's) |
| The firewall | Inactive, the permissive's default | Active, the deny's incoming's default with the specific's allows |
| The auditing | The default's minimal's rules | The 10's hardening's rules (the identity's files, the SSH's configuration, the privileged's operations, the kernel's modules) |
| The SELinux's or the AppArmor's | The permissive's mode | The enforcing's mode |
| The Lynis's score | The 60's hardening's index | The 85's hardening's index |
The comparison shows the hardening's effect: the attack surface's reduction (the services, the ports), the defense's strengthening (the SSH, the kernel, the firewall, the SELinux), and the detection's enhancement (the auditd's rules). The Lynis's hardening's index's improvement (the 60 to the 85) is the quantitative's measure, and the observation is the reason the hardening's process includes the assessment's and the remediation's cycles: the initial's assessment identifies the gaps, the remediation addresses them, and the post-assessment verifies the improvement.
The hardening's verification's checklist
The hardening's verification's checklist for the ongoing's review:
- The quarterly's reviews: the services' and the ports' inventory, the accounts' review, the setuid's programs' review, the firewall's rules' review, the auditd's rules' review.
- The monthly's activities: the patch's application (the security's updates), the vulnerability's scanning (the Lynis, the OpenVAS), the logs' review (the auditd's, the authentication's, the system's), the backups' verification.
- The weekly's activities: the alerts' triage (the SIEM's, the HIDS's, the fail2ban's), the file's integrity's scans (the AIDE's), the patch's status' verification.
- The annual's activities: the baselines' review (the new's CIS's benchmarks, the new's threats), the penetration's testing, the incident's response's exercises, the disaster's recovery's tests, the compliance's audits.
The hardening's automation's example
The hardening's automation's example with the Ansible's playbook (the conceptual's illustration):
# The Ansible's playbook (the hardening.yml):
---
- name: The Linux server's hardening
hosts: all
become: yes
tasks:
- name: The unnecessary's services' disabling
systemd:
name: "{{ item }}"
state: stopped
enabled: no
masked: yes
loop:
- cups
- avahi-daemon
- rpcbind
- name: The firewall's configuration (the ufw)
ufw:
state: enabled
policy: deny
direction: incoming
# The specific's allows are the separate's tasks.
- name: The SSH's hardening
lineinfile:
path: /etc/ssh/sshd_config
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^#*PermitRootLogin', line: 'PermitRootLogin no' }
- { regexp: '^#*PasswordAuthentication', line: 'PasswordAuthentication no' }
- { regexp: '^#*PubkeyAuthentication', line: 'PubkeyAuthentication yes' }
notify: restart sshd
- name: The kernel's parameters
sysctl:
name: "{{ item.name }}"
value: "{{ item.value }}"
state: present
reload: yes
loop:
- { name: 'kernel.randomize_va_space', value: '2' }
- { name: 'kernel.dmesg_restrict', value: '1' }
- { name: 'kernel.kptr_restrict', value: '2' }
- { name: 'net.ipv4.tcp_syncookies', value: '1' }
- name: The auditd's rules
copy:
src: files/99-hardening.rules
dest: /etc/audit/rules.d/99-hardening.rules
notify: reload auditd
handlers:
- name: restart sshd
systemd:
name: sshd
state: restarted
- name: reload auditd
command: augenrules --load
The playbook's design: the tasks are the declarative's specifications of the hardening's state, and the Ansible's idempotent's execution ensures the configuration's consistency across the fleet. The observation is the reason the automation is the hardening's scalability's mechanism: the manual's configuration of the hundreds of the servers is the error-prone and the inconsistent, and the automation's configuration is the reproducible and the auditable.
06 Interactive activity
Activity · harden a Linux system
The goal of this activity is to use the Linux command line to perform a hardening's assessment of your VM, apply the hardening's controls, and verify the improvement with the automated's tools. Work through the steps in your course VM. Note: the activity's commands modify the system's configuration; the VM is the appropriate's environment for the experiments.
-
The initial's assessment.
Perform the initial's assessment of the
system's security's state.
What are the running's services? Which are the necessary, and which are the unnecessary? What are the listening's ports? What is the firewall's state? What is the SSH's configuration? Write down your findings.# The system's information uname -a cat /etc/os-release | head -5 # The running's services systemctl list-units --type=service --state=running # The listening's ports ss -tlnp sudo ss -tlnup # The users' accounts sudo awk -F: '$3 >= 1000 && $3 < 65534 {print $1, $3}' /etc/passwd sudo cat /etc/shadow | head -5 # The setuid's programs find / -perm -4000 -type f 2>/dev/null # The world-writable's files find / -type f -perm -o+w 2>/dev/null | head -10 # The firewall's state sudo ufw status 2>/dev/null # The SSH's configuration sudo grep -E 'PermitRootLogin|PasswordAuthentication|PubkeyAuthentication|Port' /etc/ssh/sshd_config # The kernel's parameters sysctl -a 2>/dev/null | grep -E 'net.ipv4.tcp_syncookies|kernel.randomize_va_space|kernel.dmesg_restrict|fs.protected_hardlinks' # The SELinux's or the AppArmor's state getenforce 2>/dev/null sudo aa-status 2>/dev/null | head -5 # The auditd's state sudo auditctl -s 2>/dev/null -
The attack's surface's
reduction.
Disable the unnecessary's services and
close the unnecessary's ports.
Did the services disable? Did the firewall activate? What are the listening's ports after the firewall's configuration? How does the attack surface's reduction change the system's exposure?# Disable the unnecessary's services # (adjust the list to your VM's services) sudo systemctl stop cups avahi-daemon rpcbind 2>/dev/null sudo systemctl disable cups avahi-daemon rpcbind 2>/dev/null # Configure the firewall sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow 22/tcp sudo ufw enable sudo ufw status verbose # Verify the ports' reduction ss -tlnp -
The kernel's hardening.
Apply the kernel's hardening's parameters.
What are the parameters' values after the application? What are the parameters' effects? How does the kernel's hardening strengthen the system's security?# Create the hardening's parameters' file sudo tee /etc/sysctl.d/99-hardening.conf << 'EOF' # The network's hardening net.ipv4.tcp_syncookies = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.icmp_echo_ignore_broadcasts = 1 # The kernel's hardening kernel.randomize_va_space = 2 kernel.dmesg_restrict = 1 kernel.kptr_restrict = 2 kernel.yama.ptrace_scope = 1 # The file system's hardening fs.protected_hardlinks = 1 fs.protected_symlinks = 1 fs.suid_dumpable = 0 EOF # Apply the parameters sudo sysctl --system # Verify the parameters sysctl -a 2>/dev/null | grep -E 'net.ipv4.tcp_syncookies|kernel.randomize_va_space|kernel.dmesg_restrict|fs.protected_hardlinks' -
The SSH's hardening.
Harden the SSH's configuration.
Did the SSH's configuration's syntax check pass? What are the configuration's values after the hardening? What is the SSH's hardening's effect on the system's security? Note: the# Back up the SSH's configuration sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak # Apply the hardening's directives sudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config sudo sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config sudo sed -i 's/^#*X11Forwarding.*/X11Forwarding no/' /etc/ssh/sshd_config # Verify the configuration's syntax sudo sshd -t # Restart the SSH sudo systemctl restart sshd # Verify the configuration sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|x11forwarding'PasswordAuthentication no's setting requires the SSH keys' setup before the disconnection. -
The auditd's rules.
Configure the auditd's rules for the
security-relevant's events.
What are the auditd's rules after the application? Did the test's event trigger the audit's record? What does the# Create the auditd's rules sudo mkdir -p /etc/audit/rules.d sudo tee /etc/audit/rules.d/99-hardening.rules << 'EOF' # The identity's files -w /etc/passwd -p wa -k passwd_changes -w /etc/shadow -p wa -k shadow_changes -w /etc/group -p wa -k group_changes -w /etc/sudoers -p wa -k sudoers_changes # The SSH's configuration -w /etc/ssh/sshd_config -p wa -k sshd_config_changes # The privileged's operations -a always,exit -F arch=b64 -S execve -F euid=0 -k root_commands # The kernel's modules -w /sbin/insmod -p x -k module_load -w /sbin/rmmod -p x -k module_unload EOF # Load the rules sudo augenrules --load 2>/dev/null || sudo systemctl restart auditd # Verify the rules sudo auditctl -l | head -20 # Test the rules (the trigger's event) sudo useradd testaudit 2>/dev/null sudo userdel testaudit 2>/dev/null # Search the audit's log sudo ausearch -k passwd_changes 2>/dev/null | head -20ausearch's output show? How does the auditd's configuration enhance the system's detection? -
The automated's hardening's
assessment.
Use the
lynis's tool to perform the automated's assessment.
What is the hardening's index (the percentage)? What are the warnings and the suggestions? Which of the suggestions would you implement? How does the automated's assessment help the hardening's process?# Install lynis (if necessary) sudo apt install -y lynis 2>/dev/null || \ sudo dnf install -y lynis 2>/dev/null # Run the audit sudo lynis audit system 2>/dev/null | tee /tmp/lynis-output.txt | tail -50 # Show the hardening's index grep -E 'Hardening index' /tmp/lynis-output.txt # Show the warnings grep -E '^\s*\*' /tmp/lynis-output.txt | head -20 # Show the suggestions grep -A2 'Suggestions' /tmp/lynis-output.txt | head -30 -
The systemd's hardening's
assessment.
Use the
systemd-analyze security's command to assess the services' sandboxes.
What are the services' exposure's scores? What is the hardened's service's score, and how does it compare with the others? Which of the services' directives would you add to the hardened's service?# Evaluate the services for svc in sshd systemd-journald cron dbus; do echo "=== $svc ===" systemd-analyze security $svc 2>/dev/null | tail -3 done # Show the detailed's assessment systemd-analyze security sshd 2>/dev/null | head -30 # Create a hardened's transient's service sudo systemd-run --unit=hardened-demo \ --property=ProtectSystem=strict \ --property=ProtectHome=yes \ --property=PrivateTmp=yes \ --property=NoNewPrivileges=yes \ --property=CapabilityBoundingSet= \ --property=SystemCallFilter=@system-service \ /bin/bash -c 'echo "The hardened service"' # Evaluate the hardened's service systemd-analyze security hardened-demo 2>/dev/null | tail -3 # Clean up sudo systemctl stop hardened-demo 2>/dev/null sudo systemctl reset-failed hardened-demo 2>/dev/null -
Read the man pages.
Read the man pages that document the
hardening's mechanisms.
For each, write a sentence describing its main contribution to your understanding of the hardening. Theman 8 sysctl man 5 sysctl.conf man 8 systemctl man 1 ss man 8 ufw man 8 auditctl man 8 ausearch man 8 aureport man 5 auditd.conf man 5 systemd.exec man 1 systemd-analyze man 8 sshd man 5 sshd_config man 5 sudoers man 8 apt man 8 dnf man 8 unattended-upgrades man 1 lynis man 8 oscap man 1 nmap man 5 fail2ban man 1 fail2ban-clientman 8 sysctlpage documents the kernel's parameters; theman 5 systemd.execpage documents the sandboxing's directives; theman 8 auditctlpage documents the auditd's rules.
Reflect: the hardening is the security's operations's discipline, and its design's goal is the balance among the security, the functionality, and the usability. The attack surface's reduction, the defense's strengthening, and the detection's enhancement are the hardening's three goals, and their implementation requires the ongoing's attention: the baselines are the applied, the systems are the assessed, the gaps are the remediated, the new's baselines are the selected, and the cycle repeats. Which of the hardening's domains is the most important for the systems you administer? What would you change about the hardening's practices if you could? How would you explain the hardening's lifecycle to someone who thinks the security is a product? What is the right balance between the hardening's strictness and the system's usability?
07 Knowledge check
Check your understanding
Question 1
Define the operating-system hardening and explain its goals. What are the hardening's central's observations (the security as the process, the hardening's iterative's character, and the assume breach's posture)?
Show answer
Question 2
Describe the hardening's methodology and the security baselines (the CIS Benchmarks, the NIST's guides, the DISA STIGs, the vendor's guides, the organizational's baselines). What is each baseline's focus, and how do the baselines relate to the hardening's lifecycle?
Show answer
oscap, the
lynis, the
usg), the gaps'
remediation (the changes, the
tickets, the exceptions), and the
monitoring and the review (the
auditd's events, the logs' analysis, the
baseline's updates). The security
baselines are the configuration's
templates:
the CIS Benchmarks (the
Center for Internet Security's
consensus-based's configurations, with
the two levels: the Level 1's for the
general use and the Level 2's for the
high-security's use; the commercial's
and the enterprise's systems' standard);
the NIST's guides (the
National Institute of Standards and
Technology's frameworks and guides: the
SP 800-53's controls, the SP 800-123's
server's guide, the SP 800-171's CUI's
guide; the U.S. federal's systems and
the commercial's systems that follow
the NIST's frameworks);
the DISA STIGs (the
Defense Information Systems Agency's
detailed's configurations for the
government's systems; the U.S.
Department of Defense's systems and the
government's contractors);
the vendor's guides
(the Red Hat's, the Ubuntu's, the
Microsoft's hardening's guides,
integrated with the products; the
systems that use the vendors'
products); and the
organizational's baselines
(the organization's security's team's
tailored's configurations; the
organization's systems, consistent with
the policies and the regulations). The
baselines relate to the hardening's
lifecycle as the selection
step's inputs and the assessment
step's references: the baseline's
selection determines the configuration's
targets, and the configuration's
assessment measures the system's state
against the baseline. The baselines are
the starting's points, not the ending's
points: the system's specific's
requirements may require the deviations
(the exceptions, the additional's
controls), and the deviations must be
the documented and the reviewed.
Question 3
Describe the attack surface's reduction: the services, the ports, the packages, the kernel's modules, and the accounts. What is each component's review's criteria, and what are the reduction's tools and mechanisms?
Show answer
systemctl list-units --type=service
--state=running and the
systemctl list-unit-files
--state=enabled; the criteria:
the system's role, the necessity, the
alternatives; the tools: the
systemctl disable and the
systemctl mask); the
ports (the listening's
ports, reviewed with the
ss -tlnp, the
ss -tlnup, the
nmap's scans, and the
firewall's rules; the criteria: the
necessity, the binding (the services
should bind to the specific's
interfaces: the localhost for the
management's services), the firewall's
rules (the deny's default with the
specific's allows); the tools: the
ufw, the
firewalld, the
nftables); the
packages (the installed
packages, reviewed with the
dpkg -l, the
rpm -qa, the
dnf history; the criteria:
the necessity, the alternatives, the
vulnerabilities; the tools: the
apt autoremove, the
apt purge); the
kernel's modules (the
loaded's modules, reviewed with the
lsmod; the criteria: the
necessity, the alternatives; the
tools: the modprobe.d's
blacklist's directives, the
kernel.modules_disabled=1's
sysctl, the kernel's build's
configuration); and the
accounts (the
system's accounts, reviewed with the
cat /etc/passwd, the
awk -F: '$3 >= 1000 ...'
/etc/passwd, the
chage -l; the criteria:
the necessity, the privileges, the
aging, the inactivity; the tools: the
usermod -L, the
userdel -r, the
chage). The reduction's
observations: the reduction's tension
with the functionality (the reduction
should not break the system's
legitimate's functions), the
reduction's automation (the Ansible's
playbooks, the Puppet's manifests, the
cloud-init's configurations, the
golden's images), and the reduction's
documentation (the decisions must be
the documented).
Question 4
Describe the kernel's hardening, the file systems' hardening, and the network's hardening. What are each domain's mechanisms, and how do the domains complement one another?
Show answer
net.ipv4.tcp_syncookies=1,
the
net.ipv4.conf.all.rp_filter=1,
the
net.ipv4.conf.all.accept_redirects=0,
the others; the kernel's: the
kernel.randomize_va_space=2,
the kernel.dmesg_restrict=1,
the kernel.kptr_restrict=2,
the
kernel.yama.ptrace_scope=1;
the file system's: the
fs.protected_hardlinks=1,
the
fs.protected_symlinks=1,
the fs.suid_dumpable=0;
the virtual memory's: the
vm.mmap_min_addr=65536),
the ASLR's enforcement, the kernel's
modules' signing (the
CONFIG_MODULE_SIG_FORCE=yes,
the kernel.modules_disabled=1),
the kernel's lockdown (the
lockdown=confidentiality's
or the lockdown=integrity's
parameter), and the boot's chain's
integrity (the UEFI's Secure Boot, the
measured's boot, the IMA). The
file systems' hardening
strengthens the file systems' security's
mechanisms: the permissions' review
(the world-writable's files, the
setuid's and the setgid's programs,
the unowned's files, the
/etc/shadow's permissions,
the SSH's keys' modes), the mount's
options (the nodev, the
nosuid, the
noexec for the
/tmp, the
/home, the
/dev/shm; the
ro for the
/usr, the
/boot), the disk's
encryption (the LUKS: the
cryptsetup, the
/etc/crypttab, the
AES-XTS's algorithms, the Argon2id's
key's derivation), the file's attributes
(the chattr +i for the
critical's files, the
chattr +a for the logs),
and the files' ACLs. The
network's hardening
reduces the network's attack surface
and strengthens the network's defenses:
the firewall's rules (the
ufw, the
firewalld, the
nftables; the deny's
incoming's default with the specific's
allows), the network's segmentation
(the DMZ, the internal's network, the
management's network; the VLANs, the
subnets), the services' binding (the
localhost for the management's
services, the specific's interfaces
for the services' functions), the
TLS's configuration (the TLS 1.2's
and 1.3's versions, the strong's
ciphers, the certificates' management,
the HSTS), and the fail2ban's
intrusion's prevention. The domains
complement one another: the kernel's
hardening strengthens the kernel's
security (the foundation), the file
systems' hardening protects the data
(the assets), and the network's
hardening reduces the remote's attack
surface (the entry's points). The
combination is the defence in depth's
principle: the attacker must bypass
the multiple's domains, and the
multiple's failures are the
uncorrelated.
Question 5
Describe the logging, monitoring, and detection's mechanisms (the auditd, the file's integrity's monitoring, the HIDS, the SIEM), the patch management and the vulnerability scanning, the compliance and the auditing, and the security operations (the SecOps). How do the mechanisms support the hardening's lifecycle?
Show answer
/var/log/audit/audit.log;
the ausearch and the
aureport tools), the
file's integrity's monitoring
(the AIDE, the Tripwire, the Samhain,
the OSSEC's FIM: the baseline's
database, the periodic's scans, the
changes' detection), the HIDS
(the OSSEC, the Wazuh, the Samhain,
the Suricata: the host's events'
monitoring, the suspicious's
activities' detection, the rules, the
alerts), the SIEM (the
Splunk, the ELK, the Graylog, the
Wazuh: the multiple's sources'
aggregation, the correlation, the
analysis, the dashboards), and the
logs' management (the levels, the
rotation, the retention, the
protection, the remote's delivery, the
integrity). The patch
management and the vulnerability
scanning are the hardening's
maintenance's component: the patch's
lifecycle (the availability's
monitoring: the vendors' advisories,
the CVE's databases, the NVD; the
evaluation, the testing, the
deployment, the verification), the
patch's cadence (the critical's
immediate's, the high-severity's
rapid's, the moderate's regular's),
the vulnerability's scanning (the
network's: the Nessus, the OpenVAS;
the host's: the Lynis, the OpenSCAP;
the container's: the Trivy, the Clair;
the application's: the SAST, the
DAST, the SCA), and the remediation's
tracking (the tickets, the exceptions,
the verification). The
compliance and the
auditing are the hardening's
verification's component: the
frameworks and the standards (the
NIST's CSF, the ISO 27001, the CIS
Controls, the PCI-DSS, the HIPAA, the
GDPR, the SOC 2, the FISMA), the
audits (the internal's, the
external's, the compliance's, the
certification's, the penetration's
tests), and the compliance's
automation (the OpenSCAP, the Lynis,
the InSpec, the cloud's tools, the
continuous's compliance's platforms).
The security operations
(SecOps) is the security's
operations's discipline: the
monitoring (the SIEM's alerts, the
HIDS's events, the triage, the
investigation), the incident's
response (the NIST SP 800-61's
lifecycle: the preparation, the
detection and the analysis, the
containment, the eradication, the
recovery, the lessons's learned), the
threat's hunting (the proactive's
search, the hypothesis-driven's
investigations, the threat's
intelligence), and the security's
engineering (the mechanisms' design,
the architecture, the automation, the
research). The mechanisms support the
hardening's lifecycle: the
assessment step uses the
vulnerability's scanning and the
compliance's tools; the
remediation step uses the
patch management; the
monitoring and the review
step uses the auditd, the FIM, the
HIDS, the SIEM, and the SecOps's
practices; and the
lifecycle's iteration is the
SecOps's ongoing's activity. The
observation is the reason the
monitoring and the detection are the
hardening's equal's components (the
prevention's mechanisms): the
prevention reduces the likelihood, and
the detection reduces the impact, and
the two together are the hardening's
complete's discipline.
08 Unit discussion
Discussion prompt
The hardening is the security's operations's discipline, and its history is a history of the security's practices' evolution. The classical's Unix hardening (the 1980s and the 1990s) was the manual's configuration: the administrators read the vendors' guides, the mailing lists, and the security's books (the Paranoid Penguin, the Practical Unix and Internet Security), and they applied the recommendations by the hand. The 2000s brought the standards and the benchmarks (the CIS Benchmarks, the NIST's guides, the DISA STIGs), and the hardening became the compliance's activity: the baselines were the selected, the systems were the assessed, and the gaps were the remediated. The 2010s and the 2020s brought the automation (the Ansible, the Puppet, the Chef, the cloud-init), the DevSecOps's integration (the security's requirements in the lifecycle), and the continuous's compliance (the Vanta, the Drata, the Secureframe). Each era was the response to the previous era's limitations, and each was shaped by the technology and the threats of its time.
The trend is toward the automation and the continuous's verification. The classical's hardening was the manual's configuration and the periodic's audits; the modern's hardening is the policy's as the code (the Ansible's playbooks, the Kubernetes's policies, the infrastructure's as the code), the continuous's assessment (the CI/CD's security's tests, the runtime's monitoring), and the automated's compliance (the continuous's compliance's platforms). The trend's driver is the scale and the speed: the modern's systems are the many (the thousands of the servers, the millions of the containers), the changes are the frequent (the daily's deployments, the hourly's updates), and the manual's hardening cannot keep pace. The observation is the reason the automation is the modern's hardening's standard.
The trend also raises a question about the human's role. The automation handles the configuration's consistency, the assessment's repetition, and the compliance's verification, but the understanding — the system's role, the threats, the risks, the exceptions, the incidents — requires the humans. The observation is the reason the modern's security's roles (the security's engineers, the analysts, the incident's responders) emphasize the judgment, the investigation, and the communication, and the observation is the reason the security's training and the awareness's programs are the hardening's essential's components. The automation is the tool, not the replacement.
Which of the hardening's domains is the most important for the modern's systems, and why? Should the hardening's design prioritize the automation (the policy's as the code, the continuous's compliance) or the human's judgment (the risk's assessment, the incident's response)? What is the right balance between the baseline's strictness and the system's functionality? How should the hardening's practices evolve for the cloud's native's architectures, the edge's computing, and the AI's systems? Post your response to the Unit 12 discussion forum and reply to at least two classmates. Supports CLO1, CLO7, and CLO8.
09 Practice exercise
This ungraded exercise consolidates the lesson and completes Unit 12. Aim to spend 90–120 minutes on it.
-
The hardening's assessment's
checklist.
Create a comprehensive hardening's
assessment's checklist for a Linux server.
Your checklist should cover:
- The attack surface's reduction (the services, the ports, the packages, the kernel's modules, the accounts).
- The identity's and the authentication's hardening.
- The kernel's hardening.
- The file systems' hardening.
- The network's hardening.
- The logging and the monitoring.
- The patch management.
- The compliance and the auditing.
-
Perform a full hardening of your
VM.
Apply the hardening's controls to your
VM, following the lesson's steps:
Record the before and the after's states for the each's area, and compute the Lynis's hardening's index's improvement. Write a report (500–750 words) that describes the changes and their effects.# The attack surface's reduction systemctl list-units --type=service --state=running ss -tlnp find / -perm -4000 -type f 2>/dev/null # The hardening's application (the services, the firewall, # the SSH, the kernel, the auditd, the SELinux) # The assessment sudo lynis audit system 2>/dev/null | tail -40 systemd-analyze security sshd 2>/dev/null | tail -5 -
Design a hardening's baseline.
Create the hardening's baseline for a
specific's system's role (a web server, a
database's server, a container host, or a
workstation):
- The system's role and the assets.
- The threat's model.
- The baseline's source (the CIS's Level 1 or the Level 2, the NIST's, the STIG's).
- The specific's controls for the each's area.
- The exceptions and the deviations.
- The assessment's tools and the cadence.
- The monitoring's and the detection's design.
- The patch's cadence and the vulnerability's scanning.
-
Analyze a security's incident.
Choose a known security incident (the
Equifax, the Target, the WannaCry, the
NotPetya, the SolarWinds, the Colonial
Pipeline, the Log4Shell) and analyze it
through the hardening's framework:
- The incident's timeline.
- The vulnerabilities that the attackers exploited.
- The hardening's controls that were missing (the attack surface's reduction, the kernel's hardening, the monitoring).
- The hardening's controls that would have prevented or detected the incident.
- The lessons for the hardening's practices.
-
Design the SecOps's workflow.
Design the security operations's workflow
for a small organization:
- The monitoring's tools (the auditd, the HIDS, the SIEM, the network's monitoring).
- The alerts' triage's process.
- The incident's response's playbooks (the common's incidents: the compromised's accounts, the malware, the data's exfiltration).
- The escalation's paths.
- The metrics (the MTTD, the MTTR, the vulnerabilities' backlog).
- The communication's plans (the internal, the external, the regulatory).
-
Compare the hardening's
automation's tools.
Write a short essay (400–500 words)
comparing the hardening's automation's
tools (the Ansible, the Puppet, the
Chef, the SaltStack, the cloud-init).
Your essay should address:
- Each tool's architecture (the agentless's vs. the agent-based).
- Each tool's strengths and weaknesses.
- Each tool's use's cases.
- The tools' integration with the CI/CD's pipelines.
- The tools' role in the DevSecOps's practices.
-
Design the monitoring's
stack.
Design the logging and the monitoring's
stack for a Linux server:
What are the auditd's rules? What does the FIM's baseline contain? What are the HIDS's rules? How do the logs route to the SIEM? Write a report (500–750 words) that describes the stack and its design's rationales.# The auditd's rules sudo auditctl -l # The file's integrity's monitoring # (install and configure the AIDE) # The HIDS # (install and configure the OSSEC or the Wazuh) # The logs' management # (the logrotate, the rsyslog, the journald) # The alerts' routing - Reflect on Unit 12. In your own words, summarize the arc of Unit 12: how the security's principles (Lesson 12.1), the authentication (12.2), the authorization (12.3), the access control models (12.4), the Linux security (12.5), the sandboxing (12.6), and the hardening (12.7) fit together. Then identify one concept from the unit that changed your understanding of the operating system's security, and explain why. Finally, identify one question about the security that the unit did not answer, and explain what you would need to learn to answer it.
- Reflect on the course. In your own words, summarize the course's arc: how the process management (Unit 3), the CPU scheduling (Unit 5), the memory management (Units 8 and 9), the file systems (Unit 10), the I/O and the storage (Unit 11), and the security and the protection (Unit 12) fit together. Then identify the course's most valuable concept for your own professional's practice, and explain why. Finally, describe one aspect of the operating systems that the course did not cover (or covered the briefly), and explain how you would pursue the deeper's understanding.
10 Summary
- The operating-system hardening is the discipline of configuring, monitoring, and maintaining a system so that its attack surface is the minimum, its defenses are the layered, and its compromises are the detected. Its goals: the attack's surface's reduction, the defense's strengthening, and the compromise's detection. Its central's observations: the security is a process, not a product; the hardening is the ongoing's activity; and the hardening is the risk's reduction, not the security's perfection (the assume breach's posture).
- The hardening's methodology: the inventory and the role's definition, the threat's model and the risk's assessment, the baseline's selection, the configuration's application, the configuration's assessment, the gaps' remediation, and the monitoring and the review. The security baselines: the CIS Benchmarks, the NIST's guides, the DISA STIGs, the vendor's guides, and the organizational's baselines.
- The attack surface's reduction covers the services, the ports, the packages, the kernel's modules, and the accounts. The reduction's criteria: the necessity, the alternatives, the vulnerabilities, the privileges, and the binding. The reduction's tension with the functionality, the automation, and the documentation.
- The identity's and the authentication's hardening covers the accounts, the passwords, the SSH, the MFA, the sudo, and the PAM. The kernel's hardening covers the sysctl's parameters, the ASLR, the kernel's modules' signing, the kernel's lockdown, and the boot's chain's integrity. The file systems' hardening covers the permissions, the mount's options, the disk's encryption, the file's attributes, and the ACLs. The network's hardening covers the firewall's rules, the segmentation, the services' binding, the TLS's configuration, and the fail2ban.
- The logging, the monitoring, and the detection cover the auditd, the file's integrity's monitoring, the HIDS, the SIEM, and the logs' management. The patch management and the vulnerability scanning cover the patch's lifecycle, the patch's cadence, the vulnerability's scanning, and the remediation's tracking. The compliance and the auditing cover the frameworks and the standards (the NIST's CSF, the ISO 27001, the CIS Controls, the PCI-DSS, the HIPAA, the GDPR, the SOC 2, the FISMA), the audits, and the compliance's automation.
- The security operations (SecOps) is the security's operations's discipline: the monitoring, the incident's response (the NIST SP 800-61's lifecycle), the threat's hunting, and the security's engineering. The SecOps's integration with the DevOps (the DevSecOps) is the modern's software's development's standard, and the metrics (the MTTD, the MTTR, the vulnerabilities' backlog) are the performance's management's foundation.
- The hardening's design principles apply the Lesson 12.1's principles: the least privilege, the fail-safe defaults, the complete mediation, the economy of mechanism, the separation of privilege, the least common mechanism, the psychological acceptability, and the open design.
Unit 12 complete — the course's synthesis
This lesson completes Unit 12 and the course's security's unit. The unit has presented the security's principles (the CIA triad, the AAA model, the Saltzer and Schroeder principles), the authentication (the factors, the passwords, the MFA, the SSO, the Linux stack), the authorization (the access control matrix, the DAC, the MAC, the RBAC, the ABAC), the formal access control models (the Bell-LaPadula, the Biba, the Clark-Wilson, the RBAC's formalization, the ABAC's framework), the Linux security (the identity's model, the permissions, the capabilities, the LSM's framework, the SELinux, the AppArmor, the PAM, the auditd), the sandboxing (the namespaces, the cgroups, the seccomp, the containers, the browsers' sandboxes), and the hardening (the baselines, the attack surface's reduction, the hardening's domains, the monitoring, the patch management, the compliance, the SecOps). The unit's synthesis is the modern's security's architecture: the layered's defenses (the defence in depth), the least privilege's enforcement (the fine-grained's privileges, the minimal's services, the confined's sandboxes), the complete mediation (the reference monitor's every access's check), and the assume breach's posture (the monitoring's and the detection's mechanisms). The course's synthesis is the operating system's role: the manager of the processor, the memory, the storage, and the devices, and the protector of the system's users, data, and resources. The two roles are intertwined, and the observation is the reason the operating system's design is the balancing act: the performance vs. the security, the functionality vs. the simplicity, the users' convenience vs. the threats' severity. Unit 13 continues the story: it presents the virtualization and the cloud, where the operating system's abstractions are extended across the hypervisor, the containers, and the distributed's systems.
11 References
- Silberschatz, A., Galvin, P. B., & Gagne, G. Operating System Concepts, 10th ed., Chapters 16 and 17.
-
Arpaci-Dusseau, R. H., & Arpaci-Dusseau, A. C.
Operating Systems: Three Easy Pieces,
the Security chapters and the
Summary dialogue. Available online
at
ostep.org. - Tanenbaum, A. S., & Bos, H. Modern Operating Systems, 4th ed., Chapters 9 and 10.
- Bauer, M. Paranoid Penguin: A Step-by-Step Guide to Building a Secure Linux Server. No Starch Press, 2005.
- Barrett, D., Silverman, R. E., & Byrnes, R. G. Linux Security Cookbook. O'Reilly, 2003.
- NIST SP 800-123. Guide to General Server Security. National Institute of Standards and Technology.
- NIST SP 800-40 Rev. 4. Guide to Enterprise Patch Management Planning. National Institute of Standards and Technology.
- NIST SP 800-92. Guide to Computer Security Log Management. National Institute of Standards and Technology.
- NIST SP 800-137. Information Security Continuous Monitoring (ISCM) for Federal Information Systems and Organizations. National Institute of Standards and Technology.
- NIST SP 800-61 Rev. 2. Computer Security Incident Handling Guide. National Institute of Standards and Technology.
- The CIS Benchmarks. Center for Internet Security.
- The DISA STIGs. Defense Information Systems Agency.
- Bejtlich, R. The Tao of Network Security Monitoring, 2nd ed. Addison-Wesley, 2013.
- Sanders, C., & Smith, J. Applied Network Security Monitoring. Syngress, 2014.
-
Linux man-pages:
man 8 sysctl,man 5 sysctl.conf,man 8 systemctl,man 5 systemd.exec,man 1 ss,man 8 ufw,man 8 auditctl,man 8 ausearch,man 8 aureport,man 5 auditd.conf,man 1 systemd-analyze,man 8 sshd,man 5 sshd_config,man 5 sudoers,man 1 lynis,man 8 oscap,man 1 nmap,man 5 fail2ban,man 1 fail2ban-client.