Lynis – der Sicherheitsscanner für Linux
# Lynis installieren
apt install -y lynis
# System-Audit (als root)
lynis audit system
# Ausgabe-Beispiel:
# [+] Boot and services
# - Boot loader [ GRUB2 ]
# [!] Consider hardening SSH configuration
# [!] No swap partition found
#
# Hardening index : 62 [############ ]
# Suggestions: 42
Lynis-Report analysieren
# Nur Warnungen und Vorschläge anzeigen
lynis audit system 2>/dev/null | grep -E "Warning|Suggestion"
# Detaillierter Report
cat /var/log/lynis.log | grep -A2 "WARNING"
# Spezifische Tests
lynis audit system --tests-from-group ssh
lynis audit system --tests-from-group authentication
# Automatischer CI-Scan
lynis audit system --quiet --logfile /var/log/lynis.log
echo "Hardening Index: $(grep hardening_index /var/log/lynis-report.dat)"
OpenSCAP – CIS Benchmark prüfen
# OpenSCAP und SCAP-Security-Guide installieren
apt install -y libopenscap8 ssg-debian
# Verfügbare Profile anzeigen
oscap info /usr/share/xml/scap/ssg/content/ssg-ubuntu2404-ds.xml | grep Profile
# CIS Level 1 Check
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server --results /tmp/scan-results.xml --report /tmp/scan-report.html /usr/share/xml/scap/ssg/content/ssg-ubuntu2404-ds.xml
# HTML-Report anzeigen
# firefox /tmp/scan-report.html
Häufige Findings und Lösungen
# 1. AIDE (File Integrity Monitoring)
apt install -y aide
aideinit
cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
aide --check # Täglicher Check
# 2. Auditd konfigurieren
apt install -y auditd
# CIS-konforme Regeln
apt install -y auditd audispd-plugins
# /etc/audit/rules.d/cis.rules
cat > /etc/audit/rules.d/cis.rules << 'EOF'
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
-w /etc/group -p wa -k identity
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/sudoers -p wa -k privilege-change
-w /var/log/faillog -p wa -k logins
-w /var/log/lastlog -p wa -k logins
-a always,exit -F arch=b64 -S mount -k mounts
-a always,exit -F arch=b64 -S unlink -S unlinkat -k delete
EOF
augenrules --load
Automatisierter Sicherheits-Report (monatlich)
# /opt/scripts/security-report.sh
#!/bin/bash
DATE=$(date +%Y-%m-%d)
REPORT="/var/reports/security-$DATE.txt"
mkdir -p /var/reports
echo "=== Sicherheits-Report $DATE ===" > $REPORT
lynis audit system --quiet 2>/dev/null >> $REPORT
grep -i "hardening_index" /var/log/lynis-report.dat >> $REPORT
# Per E-Mail
mail -s "Server Sicherheits-Report $DATE" [email protected] < $REPORT
FAQ
Was ist der Unterschied zwischen Lynis und OpenSCAP?
Lynis: generischer Sicherheitsscanner mit Empfehlungen. OpenSCAP: formale Compliance-Prüfung gegen definierte Standards (CIS, PCI DSS).
Fazit
Monatliche Sicherheitsaudits mit Lynis und OpenSCAP sind Best Practice für jeden produktiven Linux-Server.
Linux-Sicherheitsaudits für KMU in Heidelberg, Mannheim und der Rhein-Neckar-Region. Anfragen.