Following on from my Securing Ubuntu in the cloud blog post I have installed Lynis open source security audit tool to check out to the security of my server in the cloud.
Lynis is an open source security auditing tool. Used by system administrators, security professionals, and auditors, to evaluate the security defences of their Linux and Unix-based systems. It runs on the host itself, so it performs more extensive security scans than vulnerability scanners. https://cisofy.com/lynis and https://github.com/CISOfy/lynis.
It is easy to setup a server in the cloud (create a server on Vultr or Digital Ocean here). Guides on setting up servers exist ( setup up a Vultr VM and configure it and digital ocean server) but how about securing it? You can install a LetsEncrypt SSL certificate in minutes or setup Content Security Policy and Public Key Pinning but don’t forget to get an external in-depth review of the security of your server(s).
Lynis Security Auditing Tool
Preparing install location (for Lynis)
Install Lynis
Running a Lynus system scan
./lynis audit system -Q
Lynis Results 1/3 Output (removed sensitive output)
[ Lynis 2.5.5 ] ################################################################################ Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License. See the LICENSE file for details about using this software. 2007-2017, CISOfy - https://cisofy.com/lynis/ Enterprise support available (compliance, plugins, interface and tools) ################################################################################ [+] Initializing program ------------------------------------ - Detecting OS... [ DONE ] - Checking profiles... [ DONE ] --------------------------------------------------- Program version: 2.5.5 Operating system: Linux Operating system name: Ubuntu Linux Operating system version: 16.04 Kernel version: 4.4.0 Hardware platform: x86_64 Hostname: yourservername --------------------------------------------------- Profiles: /linis/lynis/default.prf Log file: /var/log/lynis.log Report file: /var/log/lynis-report.dat Report version: 1.0 Plugin directory: ./plugins --------------------------------------------------- Auditor: [Not Specified] Test category: all Test group: all --------------------------------------------------- - Program update status... [ NO UPDATE ] [+] System Tools ------------------------------------ - Scanning available tools... - Checking system binaries... [+] Plugins (phase 1) ------------------------------------ : plugins have more extensive tests and may take several minutes to complete - Plugin pam [..] - Plugin systemd [................] [+] Boot and services ------------------------------------ - Service Manager [ systemd ] - Checking UEFI boot [ DISABLED ] - Checking presence GRUB [ OK ] - Checking presence GRUB2 [ FOUND ] - Checking for password protection [ OK ] - Check running services (systemctl) [ DONE ] : found 24 running services - Check enabled services at boot (systemctl) [ DONE ] : found 30 enabled services - Check startup files (permissions) [ OK ] [+] Kernel ------------------------------------ - Checking default run level [ RUNLEVEL 5 ] - Checking CPU support (NX/PAE) support: PAE and/or NoeXecute supported [ FOUND ] - Checking kernel version and release [ DONE ] - Checking kernel type [ DONE ] - Checking loaded kernel modules [ DONE ] active modules - Checking Linux kernel configuration file [ FOUND ] - Checking default I/O kernel scheduler [ FOUND ] - Checking for available kernel update [ OK ] - Checking core dumps configuration [ DISABLED ] - Checking setuid core dumps configuration [ PROTECTED ] - Check if reboot is needed [ NO ] [+] Memory and Processes ------------------------------------ - Checking /proc/meminfo [ FOUND ] - Searching for dead/zombie processes [ OK ] - Searching for IO waiting processes [ OK ] [+] Users, Groups and Authentication ------------------------------------ - Administrator accounts [ OK ] - Unique UIDs [ OK ] - Consistency of group files (grpck) [ OK ] - Unique group IDs [ OK ] - Unique group names [ OK ] - Password file consistency [ OK ] - Query system users (non daemons) [ DONE ] - NIS+ authentication support [ NOT ENABLED ] - NIS authentication support [ NOT ENABLED ] - sudoers file [ FOUND ] - Check sudoers file permissions [ OK ] - PAM password strength tools [ OK ] - PAM configuration files (pam.conf) [ FOUND ] - PAM configuration files (pam.d) [ FOUND ] - PAM modules [ FOUND ] - LDAP module in PAM [ NOT FOUND ] - Accounts without expire date [ OK ] - Accounts without password [ OK ] - Checking user password aging (minimum) [ DISABLED ] - User password aging (maximum) [ DISABLED ] - Checking expired passwords [ OK ] - Checking Linux single user mode authentication [ OK ] - Determining default umask - umask (/etc/profile) [ NOT FOUND ] - umask (/etc/login.defs) [ SUGGESTION ] - umask (/etc/init.d/rc) [ SUGGESTION ] - LDAP authentication support [ NOT ENABLED ] - Logging failed login attempts [ ENABLED ] [+] Shells ------------------------------------ - Checking shells from /etc/shells : found 6 shells (valid shells: 6). - Session timeout settings/tools [ NONE ] - Checking default umask values - Checking default umask in /etc/bash.bashrc [ NONE ] - Checking default umask in /etc/profile [ NONE ] [+] File systems ------------------------------------ - Checking mount points - Checking /home mount point [ SUGGESTION ] - Checking /tmp mount point [ SUGGESTION ] - Checking /var mount point [ SUGGESTION ] - Query swap partitions (fstab) [ NONE ] - Testing swap partitions [ OK ] - Testing /proc mount (hidepid) [ SUGGESTION ] - Checking for old files in /tmp [ OK ] - Checking /tmp sticky bit [ OK ] - ACL support root file system [ ENABLED ] - Mount options of / [ NON DEFAULT ] - Checking Locate database [ FOUND ] - Disable kernel support of some filesystems - Discovered kernel modules: cramfs freevxfs hfs hfsplus jffs2 udf [+] Storage ------------------------------------ - Checking usb-storage driver (modprobe config) [ NOT DISABLED ] - Checking USB devices authorization [ ENABLED ] - Checking firewire ohci driver (modprobe config) [ DISABLED ] [+] NFS ------------------------------------ - Check running NFS daemon [ NOT FOUND ] [+] Name services ------------------------------------ - Searching DNS domain name [ UNKNOWN ] - Checking /etc/hosts - Checking /etc/hosts (duplicates) [ OK ] - Checking /etc/hosts (hostname) [ OK ] - Checking /etc/hosts (localhost) [ SUGGESTION ] - Checking /etc/hosts (localhost to IP) [ OK ] [+] Ports and packages ------------------------------------ - Searching package managers - Searching dpkg package manager [ FOUND ] - Querying package manager - Query unpurged packages [ NONE ] - Checking security repository in sources.list file [ OK ] - Checking APT package database [ OK ] - Checking vulnerable packages [ OK ] - Checking upgradeable packages [ SKIPPED ] - Checking package audit tool [ INSTALLED ] [+] Networking ------------------------------------ - Checking IPv6 configuration [ ENABLED ] method [ AUTO ] only [ NO ] - Checking configured nameservers - Testing nameservers : 108.xx.xx.xx [ OK ] : 2001:xxx:xxx:xxx::6 [ OK ] - Minimal of 2 responsive nameservers [ OK ] - Checking default gateway [ DONE ] - Getting listening ports (TCP/UDP) [ DONE ] * Found 18 ports - Checking promiscuous interfaces [ OK ] - Checking waiting connections [ OK ] - Checking status DHCP client [ NOT ACTIVE ] - Checking for ARP monitoring software [ NOT FOUND ] [+] Printers and Spools ------------------------------------ - Checking cups daemon [ NOT FOUND ] - Checking lp daemon [ NOT RUNNING ] [+] Software: e-mail and messaging ------------------------------------ - Sendmail status [ RUNNING ] [+] Software: firewalls ------------------------------------ - Checking iptables kernel module [ FOUND ] - Checking iptables policies of chains [ FOUND ] - Checking for empty ruleset [ OK ] - Checking for unused rules [ FOUND ] - Checking host based firewall [ ACTIVE ] [+] Software: webserver ------------------------------------ - Checking Apache (binary /usr/sbin/apache2) [ FOUND ] : No virtual hosts found * Loadable modules [ FOUND (106) ] - Found 106 loadable modules - anti-DoS/brute force [ OK ] - web application firewall [ OK ] - Checking nginx [ FOUND ] - Searching nginx configuration file [ FOUND ] - Found nginx includes [ 2 FOUND ] - Parsing configuration options - /etc/nginx/nginx.conf - /etc/nginx/sites-enabled/default - SSL configured [ YES ] - Ciphers configured [ YES ] - Prefer server ciphers [ YES ] - Protocols configured [ YES ] - Insecure protocols found [ NO ] - Checking log file configuration - Missing log files (access_log) [ NO ] - Disabled access logging [ NO ] - Missing log files (error_log) [ NO ] - Debugging mode on error_log [ NO ] [+] SSH Support ------------------------------------ - Checking running SSH daemon [ FOUND ] - Searching SSH configuration [ FOUND ] - SSH option: AllowTcpForwarding [ SUGGESTION ] - SSH option: ClientAliveCountMax [ SUGGESTION ] - SSH option: ClientAliveInterval [ OK ] - SSH option: Compression [ SUGGESTION ] - SSH option: FingerprintHash [ OK ] - SSH option: GatewayPorts [ OK ] - SSH option: IgnoreRhosts [ OK ] - SSH option: LoginGraceTime [ OK ] - SSH option: LogLevel [ SUGGESTION ] - SSH option: MaxAuthTries [ SUGGESTION ] - SSH option: MaxSessions [ SUGGESTION ] - SSH option: PermitRootLogin [ SUGGESTION ] - SSH option: PermitUserEnvironment [ OK ] - SSH option: PermitTunnel [ OK ] - SSH option: Port [ SUGGESTION ] - SSH option: PrintLastLog [ OK ] - SSH option: Protocol [ OK ] - SSH option: StrictModes [ OK ] - SSH option: TCPKeepAlive [ SUGGESTION ] - SSH option: UseDNS [ OK ] - SSH option: VerifyReverseMapping [ NOT FOUND ] - SSH option: X11Forwarding [ SUGGESTION ] - SSH option: AllowAgentForwarding [ SUGGESTION ] - SSH option: AllowUsers [ NOT FOUND ] - SSH option: AllowGroups [ NOT FOUND ] [+] SNMP Support ------------------------------------ - Checking running SNMP daemon [ NOT FOUND ] [+] Databases ------------------------------------ - MySQL process status [FOUND ] [+] LDAP Services ------------------------------------ - Checking OpenLDAP instance [ NOT FOUND ] [+] PHP ------------------------------------ - Checking PHP [ FOUND ] - Checking PHP disabled functions [ FOUND ] - Checking expose_php option [ OFF ] - Checking enable_dl option [ OFF ] - Checking allow_url_fopen option [ ON ] - Checking allow_url_include option [ OFF ] - Checking PHP suhosin extension status [ OK ] - Suhosin simulation mode status [ OK ] [+] Squid Support ------------------------------------ - Checking running Squid daemon [ NOT FOUND ] [+] Logging and files ------------------------------------ - Checking for a running log daemon [ OK ] - Checking Syslog-NG status [ NOT FOUND ] - Checking systemd journal status [ FOUND ] - Checking Metalog status [ NOT FOUND ] - Checking RSyslog status [ FOUND ] - Checking RFC 3195 daemon status [ NOT FOUND ] - Checking minilogd instances [ NOT FOUND ] - Checking logrotate presence [ OK ] - Checking log directories (static list) [ DONE ] - Checking open log files [ DONE ] - Checking deleted files in use [ FILES FOUND ] [+] Insecure services ------------------------------------ - Checking inetd status [ NOT ACTIVE ] [+] Banners and identification ------------------------------------ - /etc/issue [ FOUND ] - /etc/issue contents [ OK ] - /etc/issue.net [ FOUND ] - /etc/issue.net contents [ OK ] [+] Scheduled tasks ------------------------------------ - Checking crontab/cronjob [ DONE ] - Checking atd status [ RUNNING ] - Checking at users [ DONE ] - Checking at jobs [ NONE ] [+] Accounting ------------------------------------ - Checking accounting information [ NOT FOUND ] - Checking sysstat accounting data [ NOT FOUND ] - Checking auditd [ NOT FOUND ] [+] Time and Synchronization ------------------------------------ - NTP daemon found: ntpd [ FOUND ] - NTP daemon found: systemd (timesyncd) [ FOUND ] - Checking for a running NTP daemon or client [ OK ] - Checking valid association ID's [ FOUND ] - Checking high stratum ntp peers [ OK ] - Checking unreliable ntp peers [ FOUND ] - Checking selected time source [ OK ] - Checking time source candidates [ OK ] - Checking falsetickers [ OK ] - Checking NTP version [ FOUND ] [+] Cryptography ------------------------------------ - Checking for expired SSL certificates [0/1] [ NONE ] [+] Virtualization ------------------------------------ [+] Containers ------------------------------------ [+] Security frameworks ------------------------------------ - Checking presence AppArmor [ FOUND ] - Checking AppArmor status [ ENABLED ] - Checking presence SELinux [ NOT FOUND ] - Checking presence grsecurity [ NOT FOUND ] - Checking for implemented MAC framework [ OK ] [+] Software: file integrity ------------------------------------ - Checking file integrity tools - Checking presence integrity tool [ NOT FOUND ] [+] Software: System tooling ------------------------------------ - Checking automation tooling - Automation tooling [ NOT FOUND ] - Checking presence of Fail2ban [ FOUND ] - Checking Fail2ban jails [ ENABLED ] - Checking for IDS/IPS tooling [ FOUND ] [+] Software: Malware ------------------------------------ [+] File Permissions ------------------------------------ - Starting file permissions check /root/.ssh [ OK ] [+] Home directories ------------------------------------ - Checking shell history files [ OK ] [+] Kernel Hardening ------------------------------------ - Comparing sysctl key pairs with scan profile - fs.protected_hardlinks (exp: 1) [ OK ] - fs.protected_symlinks (exp: 1) [ OK ] - fs.suid_dumpable (exp: 0) [ DIFFERENT ] - kernel.core_uses_pid (exp: 1) [ DIFFERENT ] - kernel.ctrl-alt-del (exp: 0) [ OK ] - kernel.dmesg_restrict (exp: 1) [ DIFFERENT ] - kernel.kptr_restrict (exp: 2) [ DIFFERENT ] - kernel.randomize_va_space (exp: 2) [ OK ] - kernel.sysrq (exp: 0) [ DIFFERENT ] - net.ipv4.conf.all.accept_redirects (exp: 0) [ OK ] - net.ipv4.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv4.conf.all.bootp_relay (exp: 0) [ OK ] - net.ipv4.conf.all.forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.conf.all.mc_forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.proxy_arp (exp: 0) [ OK ] - net.ipv4.conf.all.rp_filter (exp: 1) [ OK ] - net.ipv4.conf.all.send_redirects (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.accept_redirects (exp: 0) [ OK ] - net.ipv4.conf.default.accept_source_route (exp: 0) [ OK ] - net.ipv4.conf.default.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.icmp_echo_ignore_broadcasts (exp: 1) [ OK ] - net.ipv4.icmp_ignore_bogus_error_responses (exp: 1) [ OK ] - net.ipv4.tcp_syncookies (exp: 1) [ DIFFERENT ] - net.ipv4.tcp_timestamps (exp: 0) [ DIFFERENT ] - net.ipv6.conf.all.accept_redirects (exp: 0) [ OK ] - net.ipv6.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv6.conf.default.accept_redirects (exp: 0) [ OK ] - net.ipv6.conf.default.accept_source_route (exp: 0) [ OK ] [+] Hardening ------------------------------------ - Installed compiler(s) [ FOUND ] - Installed malware scanner [ NOT FOUND ] [+] Custom Tests ------------------------------------ - Running custom tests... [ NONE ] [+] Plugins (phase 2) ------------------------------------ - Plugins (phase 2) [ DONE ] ================================================================================ ...
Lynis Results 2/3 – Warnings
I resolved the only warning by typing
After updating the Lynis system scan I re-ran the text and got
Lynis Results 3/3 – Suggestions
Installing a Malware Scanner
Install ClamAV
Download virus and malware definitions (this takes about 30 min)
Output:
sudo freshclam > ClamAV Update process started at Wed Nov 15th 20:44:55 2017 > Downloading main.cvd [10%]
I had an issue on some boxes with clamav reporting I could not run freshclam
sudo freshclam ERROR: /var/log/clamav/freshclam.log is locked by another process ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).
This was fixed by typing
Troubleshooting clamav
Clam AV does not like low ram boxes and may produce this error
It looks like the solution is to increase your total ram.
fyi: Scan with ClamAV
Re-running Lynis gave me the following malware status
Lynis Security rating
Installed
After re-running the test I got this Lynis security rating score (an improvement of 1)
Installed and configured debsums and auditd
Now I get the following Lynis security rating score.
Conclusion
Lynis is great at performing an audit and recommending areas of work to allow you to harden your system (brute force protection, firewall, etc)
Security Don’ts
- Never think you are done securing a system.
Security Do’s
- Update Software (and remove software you do not use.)
- Check Lynis Suggestions and try and resolve.
- Security is an ongoing process, Do install a firewall, do ban bad IP’s, Do whitelist good IP’s, Do review Logs,
- Do limit port access, make backups and keep on securing.
I will keep on securing and try and get remove all issues.
Read my past post on Securing Ubuntu in the cloud.
Scheduling an auto system updates is not enough in Ubuntu (as it is not recommended as the administrator should make decisions, not a scheduled job).
apt-get update apt-get upgrade
fyi: CISOFY/Lynis do have paid subscriptions to have external scans of your servers: https://cisofy.com/pricing. (why upgrade?)
I will look into this feature soon.
Updating Lynis
I checked the official documentation and ran an update check
./lynis --check-update This option is deprecated Use: lynis update info ./lynis update info == Lynis == Version : 2.5.5 Status : Outdated Installed version : 255 Latest version : 257 Release date : 2017-09-07 Update location : https://cisofy.com/lynis/ 2007-2017, CISOfy - https://cisofy.com/lynis/
Not sure how to update?
./lynis update Error: Need a target for update Examples: lynis update check lynis update info ./lynis update check status=outdated
I opened an issue about updating v2.5.5 here. I asked Twiter for help.
Official Response: https://packages.cisofy.com/community/#debian-ubuntu
Waiting..
I ended up deleting Lynis 2.5.5
Updated
And reinstalled to v2.5.8
Output:
More actions post upgrade to 2.5.8
- Added a legal notice to “/etc/issues”, “/etc/issues.net” file’s.
Installing Lynis via apt-get instead of git clone
The official steps can be located here: https://packages.cisofy.com/community/#debian-ubuntu
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C80E383C3DE9F082E01391A0366C67DE91CA5D5F apt install apt-transport-https echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/99disable-translations echo "deb https://packages.cisofy.com/community/lynis/deb/xenial main" > /etc/apt/sources.list.d/cisofy-lynis.list apt update apt install lynis lynis show version
Unfortunately, I had an error with “apt update”
Error:
Complete install output
I reopened Github issue 491. A quick reply revealed that I did not put a space before “xenial” (oops)
fyi: I removed the dead keystore from apt by typing…
I can now install and update other packages with apt and not have the following error
I will remove the git clone and re-run the apt version later and put in more steps to get to a High 90’s Lynis score.
More
Read the official documentation https://cisofy.com/documentation/lynis/
Next: This guide will investigate the enterprise version of https://cisofy.com/pricing/ soon.
Hope this helps. If I have missed something please let me know on Twitter at @FearbySoftware
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]
v1.46 Git hub response.