System hardening
Hardening reduces what a system offers an attacker: fewer services, fewer privileges, fewer legacy protocols, and secure settings instead of factory defaults. It’s the direct counterpart of privilege escalation (Windows, Linux): every path those pages exploit is something hardening closes before the attacker gets there. And it isn’t a project you finish: it’s a baseline that is measured, applied as code and watched so it doesn’t degrade.
What it solves
Section titled “What it solves”- Limiting the damage of the first compromise: a well-hardened machine turns a user session into a dead end instead of domain admin.
- Removing the easy wins: default credentials, legacy protocols, services nobody uses and “just in case” permissions.
- Being able to prove it: measuring against a public standard instead of trusting that “it’s configured”.
From standard to machine
Section titled “From standard to machine”flowchart LR
B["Baseline<br/>CIS, STIG, vendor guide"] --> A["Adapt<br/>exceptions with owner<br/>and expiry"]
A --> C["Code<br/>GPO, Intune, Ansible"]
C --> H["Machines"]
H --> M["Measure<br/>Lynis, OpenSCAP,<br/>ssh-audit"]
M -->|"drift"| C
M --> V["Validate as attacker<br/>enumeration<br/>tools"]
V -->|"gap"| A
| Source | What it is | When to use it |
|---|---|---|
| CIS Benchmarks | Guides per system and product, with level 1 (basic) and level 2 (strict) profiles | General reference for almost any organization |
| DISA STIG | US Department of Defense guides | Environments that require them or aim for maximum rigor |
| Vendor baselines | Microsoft Security Baselines, each distribution’s guides | A starting point the vendor tests |
| SCAP / OpenSCAP | Format and tool to evaluate a baseline automatically | Repeatable audits with a report |
No baseline is applied as is: it has to be adapted to the environment, with each exception documented with its owner, justification and review date. An exception with no expiry is a permanent hole.
In practice (Linux): measure, fix, measure again
Section titled “In practice (Linux): measure, fix, measure again”Lynis runs hundreds of checks and returns warnings, suggestions and an indicative index. On a freshly installed Ubuntu 24.04 (Lynis 3.0.9, the distribution package):
lynis audit system --quick Hardening index : 57 [########### ] Tests performed : 241 Warnings (3): ! Found one or more vulnerable packages. [PKGS-7392] ! iptables module(s) loaded, but no rules active [FIRE-4512] ! klogd is not running, which could lead to missing kernel messages in log files [LOGG-2138] Suggestions (45): * Default umask in /etc/login.defs could be more strict like 027 [AUTH-9328] * Determine if protocol 'dccp' is really needed on this system [NETW-3200] * Disable drivers like USB storage when not used ... [USB-1000] ...Fixes applied (about ten lines of configuration):
sed -i 's/^UMASK\s.*/UMASK\t\t027/' /etc/login.defs # new files without "other" permissionsprintf 'SHA_CRYPT_MIN_ROUNDS 5000\nSHA_CRYPT_MAX_ROUNDS 50000\n' >> /etc/login.defsecho 'Access restricted to authorized personnel.' | tee /etc/issue /etc/issue.netecho '* hard core 0' >> /etc/security/limits.conf # no core dumpsmkdir -p /etc/modprobe.dprintf 'install %s /bin/true\n' dccp sctp rds tipc usb-storage firewire-core > /etc/modprobe.d/hardening.confapt install libpam-tmpdir libpam-pwquality debsums apt-show-versions auditd aide-common Hardening index : 68 [############# ] Tests performed : 244 Warnings (4): ... ! No AIDE database was found, needed for AIDE functionality [FINT-4316] Suggestions (31):What the second run teaches:
- The index goes from 57 to 68 and 14 suggestions disappear, but a new warning shows up: installing AIDE without initializing its database (
aideinit) leaves an integrity tool that protects nothing. - The Lynis index is not a security score: it measures how many checks from its list pass. A server with an index of 90 and a vulnerable web application still falls.
- Not every suggestion applies: Lynis proposes password expiry, while NIST SP 800-63B-4 (2025) advises against periodic changes unless there’s evidence of compromise (IAM). The organization’s baseline decides.
SSH: harden it and prove it
Section titled “SSH: harden it and prove it”ssh-audit (3.9.0) analyzes which algorithms an SSH server offers. Against Ubuntu 24.04’s default OpenSSH 9.6p1:
(kex) ecdh-sha2-nistp256 -- [fail] using elliptic curves that are suspected as being backdoored by the U.S. National Security Agency(kex) curve25519-sha256 -- [warn] does not provide protection against post-quantum attacks(key) ecdsa-sha2-nistp256 -- [fail] using elliptic curves that are suspected as being backdoored ...(mac) hmac-sha1 -- [fail] using broken SHA-1 hash algorithm(mac) umac-64-etm@openssh.com -- [warn] using small 64-bit tag size...6 [fail], 18 [warn]Configuration in a separate file (the package’s sshd_config stays untouched):
PermitRootLogin noPasswordAuthentication noKbdInteractiveAuthentication noMaxAuthTries 3LoginGraceTime 30AllowGroups ssh-usersX11Forwarding noAllowAgentForwarding noAllowTcpForwarding noKexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.orgHostKeyAlgorithms ssh-ed25519,rsa-sha2-512,rsa-sha2-256Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.comMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.comsshd -t && sshd -T | grep -E '^(permitrootlogin|passwordauthentication|kexalgorithms) 'Result: 0 [fail] and 2 [warn]. Both warnings are curve25519, kept on purpose for clients that don’t support post-quantum key exchange yet; the first one in the list, sntrup761x25519, is post-quantum.
- Always validate with
sshd -tbefore reloading, and keep a session open while testing: a mistake inAllowGroupsleaves the server without remote access. - ssh-audit’s warning about NIST curves is the tool’s own criterion, not an industry consensus; removing SHA-1 and 64-bit MACs, on the other hand, is objective.
- OpenSSH 10.0 (April 2025) uses the hybrid post-quantum key exchange
mlkem768x25519-sha256by default and disables finite-field Diffie-Hellman on the server; 10.1 warns the user when the connection doesn’t use a post-quantum algorithm.
Windows: what’s now default and what isn’t
Section titled “Windows: what’s now default and what isn’t”Defaults have improved a lot; the work is knowing what each version ships and closing the gap on older ones.
| Control | Default state | What to do |
|---|---|---|
| Required SMB signing | Windows 11 24H2 (Enterprise, Pro, Education): inbound and outbound; Windows Server 2025: outbound only | Require it on servers and older versions; it stops NTLM relay |
| LDAP signing | Required on Windows Server 2025 domain controllers | Enforce it and enable channel binding on older domains |
| RC4 in Kerberos | Since April 2026, updated DCs only assume AES for accounts without explicit encryption types (CVE-2026-20833) | Review KDCSVC events 201-209 first, and remove RC4 from service accounts (Kerberos) |
| SMBv1 | Not installed on modern installs | Check it doesn’t come back with old software |
| LLMNR and NBT-NS | On | Disable via GPO (LLMNR/NBT-NS) |
| Local administrator password | Identical on every machine if the image was cloned | Windows LAPS: a unique, rotated password per machine |
| Credential Guard and LSA Protection | On by default on compatible enterprise devices with Windows 11 22H2 or later, subject to hardware and licensing conditions | Verify actual state; enable them on older machines and servers |
| Vulnerable driver blocklist | On by default since Windows 11 22H2 | Complement with App Control (EDR) |
| Application control | None | App Control for Business (WDAC) or AppLocker, starting in audit mode |
And what doesn’t depend on the version: removing unnecessary roles and features, unprivileged accounts for daily work, services running under managed accounts (gMSA), and the auditing from the detection page.
Linux: the rest of the list
Section titled “Linux: the rest of the list”- Services:
systemctl list-unit-files --state=enabledand disable anything without an owner. - Permissions: review SUID/SGID binaries; mount
/tmpand data partitions withnodev,nosuid,noexecwhere possible. - Kernel:
sysctl(ICMP redirects,kernel.kptr_restrict,kernel.dmesg_restrict,fs.protected_*) and unused modules blocked. - MAC: SELinux or AppArmor in enforcing mode, not permissive “until it works”.
- Integrity and logging:
auditd, AIDE initialized, and logs shipped off the machine. - OpenSCAP: with the distribution’s SCAP Security Guide content,
oscap xccdf eval --profile <profile> --report report.html <content-ds.xml>evaluates a CIS or STIG profile. It needs content for the same system version; on Ubuntu 24.04 thessg-debderivedpackage doesn’t ship it yet.
Configuration drift
Section titled “Configuration drift”A hardened machine degrades over time: a temporary exception that stays, a service someone re-enables, a new image that doesn’t inherit the configuration. That’s why:
- Configuration lives as code (exported GPOs, Intune, Ansible, DSC) and is reapplied periodically.
- Measurement is scheduled, not one-off: Lynis or OpenSCAP on every machine, with results sent to the SIEM.
- Drift alerts (a protocol that reappears, a new listening service) are handled like any other SOC alert.
Validate as an attacker
Section titled “Validate as an attacker”The enumeration tools a pentester uses in post-exploitation (see Windows escalation and Linux escalation) are the final test: if, from an unprivileged account, they find no services with weak permissions, credentials in files or abusable binaries, the hardening works. Only on your own machines or within an authorized engagement.
Common mistakes
Section titled “Common mistakes”- Applying a whole baseline untested and breaking services: then everything gets reverted.
- Chasing the Lynis index instead of real risks.
- Installing security tools without configuring them (AIDE without a database,
auditdwithout rules). - Hardening the image and forgetting the machines already deployed.
- Exceptions with no expiry date.
Real cases
Section titled “Real cases”- Shared local administrator password: in many ransomware intrusions, the same local administrator password across the fleet allows lateral movement from a single credential dump. That’s the problem LAPS solves and the reason Microsoft built it into Windows.
- Terrapin (CVE-2023-48795, 2023): a truncation attack on SSH affecting
chacha20-poly1305and ETM modes. The mitigation was a protocol change (kex-strict, visible in ssh-audit’s output askex-strict-s-v00@openssh.com): updating OpenSSH was part of hardening.
Checklist
Section titled “Checklist”- Baseline chosen per system type (CIS, STIG or vendor)
- Exceptions documented with owner, justification and expiry
- Configuration as code, reapplied periodically
- SSH: no root, no passwords, algorithms reviewed with ssh-audit
- Windows: SMB and LDAP signing, LLMNR/NBT-NS off, LAPS, Credential Guard, App Control
- Kerberos without RC4 on service accounts
- Linux: minimal services, MAC enforcing,
auditdand AIDE initialized - Scheduled measurement (Lynis, OpenSCAP) with results in the SIEM