Lynis is a security tool for audit and hardening Linux/Unix systems. This tool scan our systems, do some tests and gather information about it. At the end, Lynis will provide us a report with suggestions and security-related warning to increase the security of the system.

Lynis is compatible for many Operating Systems, such as :

AIX

Arch Linux

BackTrack Linux

CentOS

Debian, DragonFlyBSD

Fedora Core, FreeBSD

Gentoo

HPUX

Kali, Knoppix

Linux Mint

MacOS X, Mageia, Mandriva

NetBSD

OpenBSD, OpenSolaris, openSUSE, Oracle Linux

PcBSD, PCLinuxOS

Red Hat Enterprise Linux (RHEL) and derivatives

Sabayon, Scientific Linux, Slackware, Solaris 10, SuSE

TrueOS

Ubuntu and derivatives

Lynis can also auditing software such as :

Database servers: MySQL, Oracle, PostgreSQL

Time daemons: dntpd, ntpd, timed

Web servers: Apache, Nginx

Installation

There are two type of Lynis installation.

Method 1: Install from package

Both methods are equally easy. Lynis is available in .deb and .rpm package. So we can install it from your Linux repository.

On Debian / Ubuntu and its derivates

$ sudo apt-get install lynis

On RedHat / CentOS and Fedora

$ yum install lynis

Once Lynis installed, you can run it by typing lynis from your console.

Please notice that Lynis will need root privilege (or equal) to run.

Method 2: Install from source

With this method, we will need to download the source manually. You can go to Lynis download page to download the source. At the time the article was written, the latest version of Lynis is 1.3.8.

Actuall,y Lynis don’t need to be install. You just download the source files, extract it and run it. Here are the steps :

Download the source. You can use wget to download it.

$ wget http://cisofy.com/files/lynis-1.3.8.tar.gz

Extract it

$ tar zxfv lynis-1.3.8.tar.gz

Go to the Lynis folder and run it

$ cd lynis-1.3.8 # ./lynis

Please notice that Lynis will need a root privilege (or equal) to run.

How to run Lynis

To run it at the first time, it is recommended to use -c paramater. -c parameter means doing all tests to check the systems. If you want to put the Auditor name, just add --auditor parameter there. Here’s some samples output :

# lynis -c --auditor “Pungki Arianto”



Figure 1. Initialize



Figure 2. System Tools



Figure 3. Boot & Services and Kernel



Figure 4. Users and Group



Figure 5. Shell and storage



Figure 6. Software, Ports and Packages



Figure 7. Networking and Printer



Figure 8. Email, Firewalls and Web Server



Figure 9. SSH, SNMP and Databases



Figure 10. PHP, Squid Proxy and Logging



Figure 11. Inetd, Banner and Cron



Figure 12. Accounting, NTP and Cryptography



Figure 13. Virtualization, Security Frameworks and File Integrity



Figure 14. Malware Scanners, System Tool and Home directory



Figure 15. Kernel Hardening



Figure 16. Hardening, Custom Tests and Result



Figure 17. Hardening Index

Run Lynis with Custom Tests

Your system may not need to run all the tests. If your server not running a web server, you don’t need to test it. For this purpose, we can use --tests parameter. The syntax is :

# lynis --tests “Test-IDs”

For version 1.3.8 , there are more than 100 tests that we can do. Here are some list of Lynis Tests-ID.

FILE-7502 (Check all system binaries) BOOT-5121 (Check for GRUB boot loader presence) BOOT-5124 (Check for FreeBSD boot loader presence) BOOT-5139 (Check for LILO boot loader presence) BOOT-5142 (Check SPARC Improved boot loader (SILO)) BOOT-5155 (Check for YABOOT boot loader configuration file) BOOT-5159 (Check for OpenBSD i386 boot loader presence) BOOT-5165 (Check for FreeBSD boot services) BOOT-5177 (Check for Linux boot and running services) BOOT-5180 (Check for Linux boot services (Debian style)) BOOT-5184 (Check permissions for boot files/scripts) BOOT-5202 (Check uptime of system) KRNL-5622 (Determine Linux default run level) KRNL-5677 (Check CPU options and support) KRNL-5695 (Determine Linux kernel version and release number) KRNL-5723 (Determining if Linux kernel is monolithic) KRNL-5726 (Checking Linux loaded kernel modules) KRNL-5728 (Checking Linux kernel config) KRNL-5745 (Checking FreeBSD loaded kernel modules) [04:57:04] Reason to skip: Test not in list of tests to perform KRNL-5770 (Checking active kernel modules) KRNL-5788 (Checking availability new kernel) KRNL-5820 (Checking core dumps configuration)

Below is a sample command to run Check uptime of system and Checking core dumps configuration tests. If you want to add more tests, just add more Test-ID separated by space.

# ./lynis --tests “BOOT-5202 KRNL-5820”

To get more Tests-IDs, you can find it inside /var/log/lynis.log. Here’s a trick how to do it.

1. First, we need to run lynis with -c (check-all) parameter.

# ./lynis -c -Q

2. Then look at inside /var/log/lynis.log file. Use cat command and combine it with grep. Let say you want to search Test-ID which related to Kernel. Use keyword KRNL to find it.

# cat /var/log/lynis.log | grep KRNL

Below is a complete keywords of Test-IDs that available in Lynis.

BOOT KRNL (kernel) PROC (processor) AUTH (authentication) SHLL (shell) FILE STRG (storage) NAME (dns) PKGS (packaging) NETW (network) PRNT (printer) MAIL FIRE (firewall) HTTP (webserver) SSH SNMP DBS (database) PHP LDAP SQD (squid proxy) LOGG (logging) INSE (insecure services - inetd) SCHD (scheduling - cron job) ACCT (accounting) TIME (time protocol - NTP) CRYP (cryptography) VIRT (virtualization) MACF (AppArmor - SELINUX) MALW (malware) HOME HRDN (hardening)

Run lynis with categories

If you feel that put a lot of Test-IDs is painful, you can use --test-category parameter. With this option, Lynis will run Test-IDs which included inside specific category. For example, you want to run Firewall and Kernel tests. Then you can do this :

# ./lynis --tests-category “firewalls kernel”

To see a full list of the available categories, run :

# ./lynis --view-categories

Run Lynis as Cronjob

Since security need to be consistent, you can automate Lynis to run periodically. Let say, you want to run it every month to see is there any improvement since the last Lynis run.

To do this, we can run Lynis as cronjob. Here’s a sample cronjob to run it every month.

#!/bin/sh AUDITOR="automated" DATE=$(date +%Y%m%d) HOST=$(hostname) LOG_DIR="/var/log/lynis" REPORT="$LOG_DIR/report-${HOST}.${DATE}" DATA="$LOG_DIR/report-data-${HOST}.${DATE}.txt" cd /usr/local/lynis ./lynis -c --auditor "${AUDITOR}" --cronjob > ${REPORT} mv /var/log/lynis-report.dat ${DATA} # End

Save the script into /etc/cron.monthly/lynis. Don’t forget to add related paths (/usr/local/lynis and /var/log/lynis), otherwise the script will not work properly.

Check the latest version of Lynis

We can use --check-update parameter to do this.

# lynis --check-update

If it outdated, Lynis only tell us about it. We have to download the update manually.

Once we install the latest update, we will see the information.

Conclusion

Security need to be consistent. Lynis can remind us to stay consistent. Lynis will scan your system and warn you for any security holes. Don’t forget to maintain Lynis always in the latest version to get more updates and more tests routine. As usual, we can always type man lynis or lynis --view-manpage to display Lynis manual page and explore it more detail. Or if you are connected to Internet, you can also go to Lynis documentation page.