Lynis security audit tool for linux

Lynis is an open source and one of the most trusted automated auditing tool for software patch management, malware scanning and vulnerability detecting in Unix based systems. This tool is useful for auditors, network and system administrators, security specialists and penetration testers. This Lynis security audit tool for linux.

Lynis performs hundreds of individual tests, to determine the security state of the system. The security scan itself consists of performing a set of steps, from initializing the program, up to the displaying the report.

security audit tool

security audit tool

What Lynis is doing?

  • Determine operating system
  • Search for available tools and utilities
  • Check for Lynis update
  • Run tests from enabled plugins
  • Run security tests per category
  • Report status of security scan
  • During the scan, technical details about the scan are stored in a log file. At the same time findings (warnings, suggestions, data collection), are stored in a report file.

Download and Install

Download latest version from https://cisofy.com/download/lynis/

Login your server using root permission

[[email protected]]# wget https://cisofy.com/files/lynis-2.2.0.tar.gz
[[email protected]]# tar -zxvf lynis-2.2.0.tar.gz
[[email protected]]# cd lynis

[[email protected] lynis]# ./lynis audit system

[ Lynis 2.1.8 ]

################################################################################
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.

Copyright 2007-2016 – CISOfy, https://cisofy.com
Enterprise support and plugins available via CISOfy
################################################################################

[+] Initializing program
————————————
– Detecting OS… [ DONE ]

—————————————————
Program version: 2.1.8
Operating system: Linux
Operating system name: CentOS
Operating system version: CentOS Linux release 7.1.1503 (Core)
Kernel version: 3.10.0
Hardware platform: x86_64
Hostname: testvm1
Auditor: [Unknown]
Profile: ./default.prf
Log file: /var/log/lynis.log
Report file: /var/log/lynis-report.dat
Report version: 1.0
Plugin directory: ./plugins
—————————————————
– Checking profile file (./default.prf)…
– Program update status… [ SKIPPED ]

[+] System Tools
————————————
– Scanning available tools…
– Checking system binaries…

[+] Plugins (phase 1)
————————————
Note: plugins have more extensive tests, which may take a few minutes to complete

– Plugin: pam
[.]

[+] Boot and services
————————————
– Service Manager [ systemd ]
– Checking UEFI boot [ DISABLED ]
– Checking presence GRUB [ OK ]
– Checking presence GRUB2 [ FOUND ]
– Checking for password protection [ WARNING ]
– Check running services (systemctl) [ DONE ]
Result: found 14 running services
– Check enabled services at boot (systemctl) [ DONE ]
Result: found 18 enabled services
– Check startup files (permissions) [ OK ]

[ Press [ENTER] to continue, or [CTRL]+C to stop ]
use help option for more information

[[email protected] lynis]# ./lynis –help

[ Lynis 2.2.0 ]

################################################################################
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.

Copyright 2007-2016 – CISOfy, https://cisofy.com/lynis/
Enterprise support and plugins available via CISOfy
################################################################################

[+] Initializing program
————————————

Usage: lynis [options] mode
Mode:

audit
audit system : Perform security scan
audit dockerfile <file> : Analyze Dockerfile

update
update info : Show update details
update release : Update Lynis release
Scan options:
–auditor “<name>” : Auditor name
–dump-options : See all available options
–no-log : Don’t create a log file
–pentest : Non-privileged scan (useful for pentest)
–profile <profile> : Scan the system with the given profile file
–quick (-Q) : Quick mode, don’t wait for user input
–tests “<tests>” : Run only tests defined by <tests>
–tests-category “<category>” : Run only tests defined by <category>

Layout options:
–no-colors : Don’t use colors in output
–quiet (-q) : No output, except warnings
–reverse-colors : Optimize color display for light backgrounds

Misc options:
–debug : Debug logging to screen
–view-manpage (–man) : View man page
–version (-V) : Display version number and quit

Enterprise options:
–plugin-dir “<path>” : Define path of available plugins
–upload : Upload data to central node
More scan options are available. See man page and online documentation for details.

 

Docker – Container technology in Cloud

Docker is a container virtualization technology that offers the promise of a more efficient, lightweight approach to application deployment than most organizations are currently implementing. Docker uses the resource isolation features of the Linux kernel such as cgroups and kernel namespaces, and a union-capable filesystem such as aufs and others to allow independent “containers” to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines.

Docker is a tool that is designed to benefit both developers and system administrators, making it a part of many DevOps (developers + operations) toolchains. For developers, it means that they can focus on writing code without worrying about the system that it will ultimately be running on. It also allows them to get a head start by using one of thousands of programs already designed to run in a Docker container as a part of their application. For operations staff, Docker gives flexibility and potentially reduces the number of systems needed because of its small footprint and lower overhead.

Docker Security

There are three major areas to consider when reviewing Docker security:

  • the intrinsic security of the kernel and its support for namespaces and cgroups;
  • the attack surface of the Docker daemon itself;
  • loopholes in the container configuration profile, either by default, or when customized by users.
    the “hardening” security features of the kernel and how they interact with containers.

One of the many security feature is provided by modern Linux kernels. It is also possible to leverage existing, well-known systems like TOMOYO, AppArmor, SELinux, GRSEC, etc. with Docker.

docker

docker container

Docker installation

You can review all other platform installation here

Docker installation on Centos

It should be need kernel version 3.10 at minimum.

You can install Docker engine using the yum package manager. Log into your machine as a user with sudo or root privileges.

Make sure your existing yum packages are up-to-date.

# yum update

Add the yum repo.

vi /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

Install the Docker package.

# yum install docker

Start the Docker daemon.

#service docker start

Thats it. Check your docker container status.

#docker ps
 

secure ssh server attacks – DenyHosts

DenyHosts is a Python script that analyzes the sshd server log messages to determine what hosts are attempting to hack into your system. It also determines what user accounts are being targeted. It keeps track of the frequency of attempts from each host. Additionally, upon discovering a repeated attack host, the /etc/hosts.deny file is updated to prevent future break-in attempts from that host. An email report can be sent to a system admin and you may be alarmed to see how many hackers attempted to gain access to your server.

Secure SSH server attacks using DenyHosts tool for Linux servers.

Features

– Parses /var/log/secure to find all login attempts and filters failed and successful attempts.

– Synchronization mode (new in 2.0) allows DenyHosts daemons the ability to share data via a centralized server to proactively thwart attacks.

– Can be run from the command line, cron or as a daemon (new in 0.9)

– Records all failed login attempts for the user and offending host

– For each host that exceeds a threshold count, records the evil host

– Keeps track of each non-existent user (eg. sdadasd) when a login attempt failed.

– Keeps track of each existing user (eg. root) when a login attempt failed.

– Keeps track of each offending host (with 0.8+ these hosts can be purged if the associated entry in /etc/hosts.deny is
expired)

– Keeps track of suspicious logins (that is, logins that were successful for a host that had many login failures)

– Keeps track of the file offset, so that you can reparse the same file (/var/log/secure) continuously (until it is rotated).

– When the log file is rotated, the script will detect it and parse from the beginning.

– Appends /etc/hosts.deny and adds the newly banned hosts

– Optionally sends an email of newly banned hosts and suspicious logins.

– Keeps a history of all user, host, user/host combo and suspicious logins encountered which includes the data and number of corresponding failed login attempts.

– Maintains failed valid and invalid user login attempts in separate files, such that it is easy to see which valid user is
under attack (which would give you the opportunity to remove the account, change the password or change it’s default shell to something like /sbin/nologin

– Upon each run, the script will load the previously saved data and re-use it to append new failures.

– Resolves IP addresses to hostnames, if available (new in v0.6.0).

– /etc/hosts.deny entries can be expired (purge) at a user specified time (new in 0.8)

 

secure ssh server attacks denyhosts

Secure SSH server attacks in centos

Install DenyHosts on RHEL 6.3/6.2/6.1/6/5.8, CentOS 6.3/6.2/6.1/6/5.8 and Fedora 17,16,15,14,13,12 systems using epel repository.

 

By default DenyHosts tool is not included in the Linux systems, we need to install it using third party EPEL repository.

 

## RHEL/CentOS 7 64-Bit ##

# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# rpm -ivh epel-release-7-5.noarch.rpm

## RHEL/CentOS 6 32-Bit ##

# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

## RHEL/CentOS 6 64-Bit ##

# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
# yum install denyhosts

Once the Denyhosts installed, make sure to whitelist your own IP address, so you will never get locked out. To do this, open a file /etc/hosts.allow.

# vi /etc/hosts.allow

sshd: <yourIp>
sshd: <yourIP>

Configuring Email Alerts

# vi /etc/denyhosts.conf

change ADMIN_EMAIL and SMTP_FROM details.

ADMIN_EMAIL = [email protected]

SMTP_FROM = DenyHosts <[email protected]>

SMTP_SUBJECT = DenyHosts Report from $[HOSTNAME]

# chkconfig denyhosts on
# service denyhosts start

To watch denyhosts ssh logs for how many attackers and hackers are attempted to gain access to your server.

# tail -f /var/log/secure

Add your IP Addresses Permanently in whitelist

# vi /var/lib/denyhosts/allowed-hosts

### We mustn't block localhost
127.0.0.1
110.18.15.11

You can view denied ipaddress in /etc/hosts.deny

[[email protected] ~]# cat /etc/hosts.deny

#
# hosts.deny This file contains access rules which are used to deny connections to network services that either use
# the tcp_wrappers library or that have been # started through a tcp_wrappers-enabled xinetd.
## The rules in this file can also be set up in /etc/hosts.allow with a 'deny' option instead.
#
# DenyHosts: Thu Mar 5 03:26:50 2015 | sshd: 192.168.1.110
sshd: 192.168.1.110
# DenyHosts: Thu Mar 5 03:26:50 015 | sshd: 192.168.1.11
sshd: 192.168.1.11

In order to remove or delete banned IP address completely. You need to edit the following files and remove the IP address.

# vi /etc/hosts.deny
#  vi /var/lib/denyhosts/hosts
# vi /var/lib/denyhosts/hosts-restricted
# vi /var/lib/denyhosts/hosts-root
#  vi /var/lib/denyhosts/hosts-valid
# vi /var/lib/denyhosts/users-hosts

Once completed, restart denyhost service.

service denyhosts start

Thats all!!

 

DenyHosts v2.6 release contains a minor DoS security fix and some minor bug fixes. The DoS security issue affects all versions of DenyHosts prior to v2.6. All users are urged to upgrade to DenyHosts v2.6. Consult the Changelog for the gory details.