linux

Lynis: Linux Security Auditing and Hardening Tool

Lynis: Linux Security Auditing and Hardening Tool

Lynis is an auditing tool for Unix/Linux systems that analyzes configurations, permissions, patches, and hardening. Ideal for penetration testers and blue teams.

  • Posted on 2026-02-17
  • Reading time: 3 min

Introduction #

Lynis is a security auditing tool for Unix/Linux systems that analyzes operating system configuration, identifies misconfigurations, recommends hardening, and verifies compliance. In penetration testing, it is used in two contexts: post-exploitation to map the weaknesses of a compromised host and identify privilege escalation paths, or in white-box assessments where you have legitimate access to the system.

Lynis checks hundreds of tests: file permissions, SSH configuration , firewall, kernel parameters, running services, account policies, encryption, and much more. The output is a hardening index (0-100) and a list of findings categorized by severity.

Kill chain: Discovery / Privilege Escalation (MITRE ATT&CK T1082).


1️⃣ Setup and Installation #

bash
sudo apt install lynis

Or from the official repository:

bash
git clone https://github.com/CISOfy/lynis.git
cd lynis
./lynis audit system

Verify: lynis --versionVersion: 3.1.1.


2️⃣ Basic Use #

bash
sudo lynis audit system

Output (extract):

text
[+] Boot and services
  - Checking presence GRUB2                       [ FOUND ]
  - Checking UEFI boot                            [ ENABLED ]

[+] Kernel
  - Checking default runlevel                     [ RUNLEVEL 5 ]
  - Checking kernel version and release           [ DONE ]

[+] Users, Groups and Authentication
  - Checking user password aging                  [ CONFIGURED ]
  - Query accounts without password               [ NONE ]
  - Checking sudo configuration file              [ FOUND ]

[+] SSH Support
  - Checking SSH configuration                    [ FOUND ]
  - SSH option: PermitRootLogin                   [ NO ]
  - SSH option: StrictModes                       [ YES ]

Hardening index : 72 [##############      ]
Tests performed : 283

Quick audit:

bash
sudo lynis audit system --quick

Skip interactive prompts.


3️⃣ Operational Techniques #

Specific profile audit #

bash
sudo lynis audit system --profile custom.prf

Detailed report #

bash
sudo lynis audit system --report-file /tmp/lynis_report.dat
cat /tmp/lynis_report.dat | grep "warning\|suggestion"

Specific checks only #

bash
sudo lynis audit system --tests-from-group "firewalls kernel ssh"

Remote audit (via SSH) #

bash
ssh root@target "cd /opt/lynis && ./lynis audit system --quick --no-colors" > remote_audit.txt

4️⃣ Advanced Techniques #

Post-exploitation — Finding privilege escalation vectors #

After getting shell:

bash
./lynis audit system --quick 2>/dev/null | grep -E "WARNING|SUGGESTION|SUID"

Focus on: Unusual SUID binaries, sudo misconfiguration, services with excessive permissions, vulnerable kernel.

Custom test plugins #

Lynis supports custom plugins /usr/share/lynis/plugins/. Write tests specific to the target environment.


5️⃣ Practical Pentest Scenarios #

Scenario 1: White-box audit of a server #

bash
sudo lynis audit system --quick

Expected output: hardening index, warning and suggestion. Timeline: 1-2 minutes.

Scenario 2: Post-exploitation private recon #

bash
curl -sO https://raw.githubusercontent.com/CISOfy/lynis/master/lynis
chmod +x lynis
./lynis audit system --quick --no-colors 2>/dev/null | grep -i "warning"

Scenario 3: Compliance check #

bash
sudo lynis audit system --profile /etc/lynis/default.prf

6️⃣ Toolchain Integration #

Post-exploitation flow: Shell → Lynis (system audit) → linPEAS (privesc enum) → Exploit privesc

toolSystem auditPrivesc hintsComplianceagentless
LynisYes (complete)YesYesYes
linPEASLimitedYes (focus)NoYes
chkrootkitRootkit onlyNoNoYes
OpenSCAPYesLimitedYes (SCAP)No

7️⃣ Complete Attack Chain #

Step 1: Shell as www-data → upload Lynis (30 sec). Phase 2: Lynis finds SUID on custom binary (2 min). Phase 3: Exploit SUID → root (5 min). Timeline: ~8 min.


8️⃣ Detection & Evasion #

Blue Team: process monitoring sees lynis Running. File access audit. Evasion: rename binary, run from /tmp, remove after.


9️⃣ Performance & Scaling #

Single host: 1-2 minutes. Consumption: <50MB RAM.


🔟 Technical Tables #

FlagDescription
audit systemFull audit
--quickNo prompt
--profile fileCustom profile
--report-fileReport output
--tests-from-groupSpecific groups
--no-colorsOutput plain

11️⃣ Troubleshooting #

ProblemFix
Permission deniedRun as root/sudo
Test skippedMissing tool dependencies

12️⃣ FAQ #

Lynis finds privesc? Indirectly — it reports misconfigurations that can be exploited.

Does it work on macOS? Yes, partially.


13️⃣ Cheat Sheet #

ActionCommand
Quick auditsudo lynis audit system --quick
With reportsudo lynis audit system --report-file report.dat
SSH/kernel onlysudo lynis audit system --tests-from-group "ssh kernel"
Remotessh target "lynis audit system --quick --no-colors"

Disclaimer: Lynis for authorized security assessment. Repository: github.com/CISOfy/lynis.


Want to support HackIta? Visit hackita.it/supporto to donate. For professional penetration testing and one-on-one training, check out hackita.it/servizi.

#system-hardening

leave a message

I'm not a robot