Перейти к основному содержимому
Linux Security Auditing & Remediation Baselines
Урок 6 из 12

Linux Security Auditing & Remediation Baselines

Learn how to run automated Linux host audits with Lynis, interpret warnings, suggestions, and the hardening index, verify basic integrity with chkrootkit, and apply clean baseline remediation.

Средний 22 мин Linux и Windows
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Run a local security audit with Lynis and inspect the generated report and log files
  • Distinguish actionable warnings and high-value suggestions from context-dependent noise
  • Verify system hardening changes using drop-in configuration files and re-auditing
  • Explain the scope and limitations of signature-based integrity tools such as chkrootkit

Рекомендуется заранее: Sudo Rules, SUID/SGID Binaries & Linux CapabilitiesCron Jobs, PATH Hijacking & Service Misconfigs

#Why this matters

Checking SSH settings, kernel parameters, sudoers, scheduled tasks, and file permissions by hand works on one host, but breaks down across a server fleet. Under deadline pressure, manual steps get skipped and configuration drift creeps in after package updates or emergency hotfixes.

Automated host auditing tools run repeatable, read-only checks against a security baseline and produce structured reports. The core defender skill is reading those findings critically, fixing high-risk gaps cleanly, and verifying improvements without breaking production workloads.

#How host auditing with Lynis works

Lynis is a lightweight, read-only auditing tool for Linux and Unix hosts. Running lynis audit system inspects boot settings, kernel sysctl parameters, PAM and SSH configuration, sudoers, file permissions, logging (auditd), firewalls, and installed security packages.

Each scan creates console output and two files on disk:

  • /var/log/lynis.log: detailed trace of every test executed and its result.
  • /var/log/lynis-report.dat: structured key=value output holding warnings, suggestions, test IDs, and the Hardening Index (a relative score from 0 to 100).
  1. Run lynis audit systemInspect /var/log/lynis-report.dat | Triage warnings & suggestions | Apply drop-in patches | Re-run audit to verify
Running a quick Lynis audit on a lab host
$ sudo lynis audit system --quick
[+] Kernel
  - Checking default run level                                [ RUNLEVEL 5 ]
  - Checking CPU support (NX/PAE)                             [ SUPPORTED ]
[+] Hardening
  - Hardening index : 64 [############        ]
  - Tests performed : 248
  - Warnings (1):
    ! Reboot of system is most likely needed [KRNL-5830]
  - Suggestions (14):
    * Consider hardening SSH configuration [SSH-7408]
    * Check PAM configuration, add password quality module [AUTH-9262]

#Interpreting findings and prioritising remediation

Lynis divides findings into Warnings (broken or missing core controls) and Suggestions (recommended hardening). Avoid chasing a Hardening Index of 100 blindly; the score is a relative progress gauge, not an absolute measure of security.

Triage findings against the host's actual role:

Finding type Meaning Recommended response
Warning Broken or missing control Investigate promptly and patch or document exception
Suggestion (relevant) Missing hardening for server role Apply via drop-in config and test service
Suggestion (irrelevant) Control unsuitable for host role Document exception in custom Lynis profile

Inspect a finding before editing config by running lynis show details <TEST-ID> or filtering /var/log/lynis-report.dat:

Filtering warnings and suggestions from the Lynis report
$ sudo grep -E "^(warning|suggestion)\[\]=" /var/log/lynis-report.dat | head -n 4
warning[]=KRNL-5830|Reboot of system is most likely needed|-|
suggestion[]=SSH-7408|Consider hardening SSH configuration|OpenSSH|
suggestion[]=AUTH-9262|Check PAM configuration, add password quality module|-|

High-value items often match controls from earlier lessons: disabling root/password SSH logins, tightening sysctl (kernel.kptr_restrict = 2, fs.suid_dumpable = 0), enabling auditd, and locking down cron or compiler permissions.

#Integrity and rootkit checks with chkrootkit

Alongside baseline auditing, defenders sometimes run chkrootkit to scan local binaries (ls, ps, netstat, sshd) for known rootkit signatures, hidden processes, and promiscuous interfaces:

Running chkrootkit in quiet mode on a lab host
$ sudo chkrootkit -q
Searching for suspicious files and dirs, it may take a while...

Quiet mode (-q) hides clean checks so only suspicious items appear. Keep its limits in mind:

  • Signature blind spots: Unknown or custom implants do not match built-in signatures.
  • Live-host deception: A kernel rootkit can intercept syscalls and hide from user-space scanners.
  • False positives: Legitimate tools such as tcpdump trigger promiscuous-mode alerts. Cross-check flagged binaries with package checksums (dpkg -V or rpm -Va) or inspect offline images if compromise is suspected.

#Defending and common mistakes

  • Use drop-in files, not vendor defaults: Put overrides in /etc/sysctl.d/ and /etc/ssh/sshd_config.d/ so package upgrades keep your hardening intact.
  • Do not chase 100% blindly: Installing unneeded tools or disabling required services just to boost the score adds operational risk.
  • Never treat a clean chkrootkit run as proof of innocence: Investigate suspected compromises offline rather than trusting local user-space checks.
  • Audit repeatedly: Compare lynis-report.dat over time to catch configuration drift early.

#Summary

  • Lynis automates read-only Linux security auditing and writes structured findings to /var/log/lynis-report.dat alongside /var/log/lynis.log.
  • Use the Hardening Index as a relative baseline gauge, prioritising warnings and role-appropriate suggestions over a perfect score.
  • Apply fixes in drop-in directories (/etc/sysctl.d/, /etc/ssh/sshd_config.d/) and verify by re-running the audit.
  • chkrootkit provides a fast sanity check for known rootkits, but cannot reliably detect novel or kernel-level implants on a live host.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания