{"id":1129,"date":"2018-10-28T21:27:57","date_gmt":"2018-10-28T18:27:57","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1129"},"modified":"2024-03-11T19:53:55","modified_gmt":"2024-03-11T16:53:55","slug":"how-to-perform-system-security-auditing-with-lynis-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-perform-system-security-auditing-with-lynis-on-ubuntu-18-04\/","title":{"rendered":"How to Perform System Security Auditing with Lynis on Ubuntu 18.04"},"content":{"rendered":"\n<p>Lynis is an open-source security tool that can perform an in-depth system security scan in order to evaluate the system&#8217;s security profile. Due to its simplicity and flexibility, Lynis can be used to achieve the following;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automated Security auditing<\/li>\n\n\n\n<li>Compliance testing (e.g. PCI, HIPAA, SOx)<\/li>\n\n\n\n<li>Penetration testing<\/li>\n\n\n\n<li>Vulnerability detection<\/li>\n\n\n\n<li>System hardening<\/li>\n\n\n\n<li>Configuration and asset management<\/li>\n\n\n\n<li>Software patch management<\/li>\n\n\n\n<li>Intrusion detection<\/li>\n<\/ul>\n\n\n\n<p>Lynis was designed for systems running Linux, macOS, or Unix-based operating system. It, however, doesn&#8217;t provide system hardening automatically but instead provide tips on how to harden your system.<\/p>\n\n\n\n<p>In this tutorial, we are going to learn how to install and setup Lynis on Ubuntu 18.04 for system auditing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Lynis on Ubuntu 18.04<\/h2>\n\n\n\n<p>There are several ways in which Lynis can be installed;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installing via package manager<\/li>\n\n\n\n<li>Installation via Git by cloning the project to some parent directory on the local system<\/li>\n\n\n\n<li>Downloading the binary to specific directory on your system<\/li>\n<\/ul>\n\n\n\n<p>In this tutorial, we are going to install Lynis via the package manager.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add Lynis Software Repository<\/h3>\n\n\n\n<p>Lynis is usually available by default on Ubuntu repositories. However, to get the latest version of it, you need to add the software repositories.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Import the repository signing key<\/h4>\n\n\n\n<p>Run either of the commands below to download the Lynis repository signing key from the central key server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C80E383C3DE9F082E01391A0366C67DE91CA5D5F<\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># wget -O - https:\/\/packages.cisofy.com\/keys\/cisofy-software-public.key | sudo apt-key add -<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Add software repository<\/h4>\n\n\n\n<p>The Lynis software repository uses HTTPS for secure transport.Therefore you need to enable https transport method for APT as shown below if it is not already enabled.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># apt install apt-transport-https<\/pre>\n\n\n\n<p>Configure APT to skip downloading software translations if you are using your software in English.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># echo 'Acquire::Languages \"none\";' &gt; \/etc\/apt\/apt.conf.d\/99disable-translations<\/pre>\n\n\n\n<p>Once that is done, run the command below to add the software repository.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># echo \"deb https:\/\/packages.cisofy.com\/community\/lynis\/deb\/ stable main\" &gt; \/etc\/apt\/sources.list.d\/cisofy-lynis.list<\/pre>\n\n\n\n<p>Once you have the software repository set, update you system to re-synchronize the package index files from their sources.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># apt update<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install Lynis<\/h4>\n\n\n\n<p>Now that we have the software repositories and the local package database has been refreshed, run the command below to install Lynis.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># apt install lynis -y<\/pre>\n\n\n\n<p>Once the installation is done, you can verify the version using the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># lynis show version\n2.7.0<\/pre>\n\n\n\n<p>You can also run the command below verify whether a new version is available.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># lynis update info\n\n == Lynis ==\n\n  Version            : 2.7.0\n  Status             : <strong>Up-to-date<\/strong>\n  Release date       : 2018-10-26\n  Update location    : https:\/\/cisofy.com\/lynis\/\n\n\n2007-2018, CISOfy - https:\/\/cisofy.com\/lynis\/<\/pre>\n\n\n\n<p>So you got the latest version of Lynis program.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lynis Commands<\/h3>\n\n\n\n<p>The Lynis command syntax is <strong class=\"userinput\"><code>lynis [scan mode] [other options]<\/code><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To show Lynis command, run <strong class=\"userinput\"><code>lynis show commands<\/code><\/strong><\/li>\n\n\n\n<li>To show Lynis Settings run; <strong class=\"userinput\"><code>lynis show settings<\/code><\/strong><\/li>\n\n\n\n<li>To show discovered audit profiles; <strong class=\"userinput\"><code>lynis show profiles<\/code><\/strong><\/li>\n<\/ul>\n\n\n\n<p>For a comprehensive list of options, check <strong class=\"userinput\"><code>man lynis<\/code><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run System Audit<\/h2>\n\n\n\n<p>To run system audit, execute; <strong class=\"userinput\"><code>lynis audit system<\/code><\/strong><\/p>\n\n\n\n<p>When Lynis run, it audits various parts of the system including;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Boot loader files<\/li>\n\n\n\n<li>Configuration files<\/li>\n\n\n\n<li>Software packages<\/li>\n\n\n\n<li>Directories and files related to logging and auditing<\/li>\n<\/ul>\n\n\n\n<p>The test and debug information is found in: <strong class=\"userinput\"><code>\/var\/log\/lynis.log<\/code> <\/strong>while the audit report data is found on: <strong class=\"userinput\"><code>\/var\/log\/lynis-report.dat<\/code><\/strong>.<\/p>\n\n\n\n<p><strong class=\"userinput\"><code>\/var\/log\/lynis.log<\/code><\/strong> is the file an auditor has to check and intepret the results as it explains the reason for the issues identified as well suggestions on how to fix those issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lynis Warnings<\/h3>\n\n\n\n<p>The output of the Lynis may show OK or WARNING with OK meaning good while WARNING shows an identified issue in the system that requires attention. Sometimes what may be flagged as OK may not actually be good to the best practice and what is flagged as WARNING may actually be nothing and can be ignored.<\/p>\n\n\n\n<p>Sample output of the warnings;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">================================================================================\n<strong>...output-cut...<\/strong>\n  -[ Lynis 2.7.0 Results ]-\n\n  Warnings (2):\n  ----------------------------\n  ! Found BIND version in banner [NAME-4210] \n      https:\/\/cisofy.com\/lynis\/controls\/NAME-4210\/\n\n  ! Found some information disclosure in SMTP banner (OS or software name) [MAIL-8818] \n      https:\/\/cisofy.com\/lynis\/controls\/MAIL-8818\/\n<strong>...output-cut...<\/strong><\/pre>\n\n\n\n<p>To get more information about a warning, you can use the command; <strong class=\"userinput\"><code>lynis show details TEST-ID<\/code> <\/strong>for example to show more details about BIND warning, run the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># lynis show details NAME-4210\n2018-10-28 20:07:58 Performing test ID NAME-4210 (Check DNS banner)\n2018-10-28 20:07:58 Test: Trying to determine version from banner\n2018-10-28 20:07:58 Result: possible BIND version available in version banner\n2018-10-28 20:07:58 Warning: Found BIND version in banner [test:NAME-4210] [details:-] [solution:-]\n2018-10-28 20:07:58 Suggestion: The version in BIND can be masked by defining 'version none' in the configuration file [test:NAME-4210] [details:-] [solution:-]\n2018-10-28 20:07:58 Hardening: assigned partial number of hardening points (0 of 2). Currently having 92 points (out of 128)\n2018-10-28 20:07:58 ===---------------------------------------------------------------===<\/pre>\n\n\n\n<p>This at least shades light on the identified warnings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Disable the test (whitelisting)<\/h3>\n\n\n\n<p>If for some reasons you have a test which gives a warning and you are not interested in the result of that particular test, you can set it to be ignored. To achieve this, you need create a custom profile where you can define your test options.<\/p>\n\n\n\n<p>Lynis uses profiles to have a set of predefined options for your operating system and preferences. If you don&#8217;t provide a profile (&#8211;profile &lt;name&gt;), the default profile (default.prf) will be used. You can copy the default profile and edit it to define your custom test options.<\/p>\n\n\n\n<p>For instance, to skip the warnings shown above, create a custom profile and put the following contents.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># vim \/etc\/lynis\/custom.prf<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">#################################################################################\n#\n#\n# Lynis - Custom Scan Profile to ignore some warnings\n#\n# Ignore BIND version in the banner\n<strong>skip-test=NAME-4210<\/strong>\n\n# Ignore SMTP banner information disclosure\n<strong>skip-test=MAIL-8818<\/strong><\/pre>\n\n\n\n<p>When you run system audit next time, these warnings will be ignored. See the output below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>...<\/strong>\n================================================================================\n\n  -[ Lynis 2.7.0 Results ]-\n\n  <strong>Great, no warnings<\/strong>\n\n  Suggestions (40):\n  ----------------------------\n  * Install a PAM module for password strength testing like pam_cracklib or pam_passwdqc [AUTH-9262] \n      https:\/\/cisofy.com\/lynis\/controls\/AUTH-9262\/\n\n  * Configure minimum password age in \/etc\/login.defs [AUTH-9286] \n      https:\/\/cisofy.com\/lynis\/controls\/AUTH-9286\/\n\n  * Configure maximum password age in \/etc\/login.defs [AUTH-9286] \n      https:\/\/cisofy.com\/lynis\/controls\/AUTH-9286\/\n<strong>...<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Lynis Suggestions<\/h3>\n\n\n\n<p>Apart from WARNINGS, there are also suggestions in the Lynis audit output. Basically, suggestions tells you how to go about fixing an identified issue. Take for example, the SSH hardening suggestions shown. It is made of the suggestion and the specific changes to make.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong> Suggestions (42):<\/strong>\n  ----------------------------\n  * Install Apache modsecurity to guard webserver against web application attacks [HTTP-6643] \n      https:\/\/cisofy.com\/lynis\/controls\/HTTP-6643\/\n\n  <strong>* Consider hardening SSH configuration [SSH-7408] <\/strong>\n<strong>    - Details  : AllowTcpForwarding (YES --&gt; NO)<\/strong>\n<strong>      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/<\/strong>\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : ClientAliveCountMax (3 --&gt; 2)<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : Compression (YES --&gt; NO)<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : LogLevel (INFO --&gt; VERBOSE)<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : MaxAuthTries (6 --&gt; 2)<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : MaxSessions (10 --&gt; 2)<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - <strong>Details  : PermitRootLogin (YES --&gt; (NO|PROHIBIT-PASSWORD|WITHOUT-PASSWORD))<\/strong>\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - Details  : Port (22 --&gt; )\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - Details  : TCPKeepAlive (YES --&gt; NO)\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - Details  : X11Forwarding (YES --&gt; NO)\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n\n  * Consider hardening SSH configuration [SSH-7408] \n    - Details  : AllowAgentForwarding (YES --&gt; NO)\n      https:\/\/cisofy.com\/lynis\/controls\/SSH-7408\/\n<strong>...<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Lynis Hardening Index<\/h3>\n\n\n\n<p>Lynis system audit output also show the system hardening index. See part of the output below with a hardening index of 65%.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>...<\/strong>\n================================================================================\n\n  Lynis security scan details:\n\n  Hardening index : <strong>65<\/strong> [#############       ]\n  Tests performed : 238\n  Plugins enabled : 0\n<strong>...<\/strong><\/pre>\n\n\n\n<p>This basically shows the hardening index in percentage, the number of tests performed and the number of plugins enabled.<\/p>\n\n\n\n<p>The hardening index shows how secure your system is based on the Lynis tests. The more you carry out the fixes of the identified issues, the hardening index percentage will increase.<\/p>\n\n\n\n<p>Well, so far so good, we have seen and learnt how to install and perform system auditing with Lynis on Ubuntu 18.04. We hope you enjoyed.<\/p>\n\n\n\n<p>Reference;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cisofy.com\/documentation\/lynis\/get-started\/\" target=\"_blank\" rel=\"noopener\">Get Started with Lynis<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/CISOfy\/lynis\" target=\"_blank\" rel=\"noopener\"><span class=\"text-gray-dark mr-2\">Lynis &#8211; Security auditing tool for Linux, macOS, and UNIX-based systems<\/span><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lynis is an open-source security tool that can perform an in-depth system security scan in order to evaluate the system&#8217;s security profile. Due to its<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,34,218],"tags":[219,220],"class_list":["post-1129","post","type-post","status-publish","format-standard","hentry","category-howtos","category-security","category-system-auditing","tag-audit","tag-lynis","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1129"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1129"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1129\/revisions"}],"predecessor-version":[{"id":21018,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1129\/revisions\/21018"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}