2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
# Copyright 2013-2016, CISOfy
#
# Website : https://cisofy.com
# Blog : http://linux-audit.com
# GitHub : https://github.com/CISOfy/lynis
2014-08-26 17:33:55 +02:00
#
# 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 LICENSE file for usage of this software.
#
#################################################################################
#
# Kernel
#
#################################################################################
#
InsertSection "Kernel"
#
#################################################################################
#
CORE_DUMPS_DISABLED=0
CPU_PAE=0
CPU_NX=0
2014-09-19 02:23:07 +02:00
LINUXCONFIGFILE=""
LINUXCONFIGFILE_ZIPPED=0
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : KRNL-5622
# Description : Check default run level on Linux machines
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5622 --os Linux --weight L --network NO --category security --description "Determine Linux default run level"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
# Checking if we can find the systemd default target
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for systemd default.target"
2014-08-26 17:33:55 +02:00
if [ -L /etc/systemd/system/default.target ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: symlink found"
2014-08-26 17:33:55 +02:00
if [ ! "${READLINKBINARY}" = "" ]; then
FIND=`${READLINKBINARY} /etc/systemd/system/default.target`
if [ "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Exception: can't find the target of the symlink of /etc/systemd/system/default.target"
2014-08-26 17:33:55 +02:00
ReportException "${TEST_NO}:01"
else
2016-08-25 15:31:33 +02:00
FIND2=`echo ${FIND} | ${EGREPBINARY} "runlevel5|graphical"`
2014-08-26 17:33:55 +02:00
if [ ! "${FIND2}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found match on runlevel5/graphical"
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking default runlevel" --result "runlevel 5" --color GREEN
2015-12-21 21:17:15 +01:00
Report "linux_default_runlevel=5"
2015-09-07 17:35:07 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: No match found on runlevel, defaulting to runlevel 3"
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking default runlevel" --result "runlevel 3" --color GREEN
2015-12-21 21:17:15 +01:00
Report "linux_default_runlevel=3"
2014-08-26 17:33:55 +02:00
fi
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: No readlink binary, can't determine where symlink is pointing to"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking default run level" --result "${STATUS_UNKNOWN}" --color YELLOW
2014-08-26 17:33:55 +02:00
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: no systemd found, so trying inittab"
LogText "Test: Checking /etc/inittab"
2014-08-26 17:33:55 +02:00
if [ -f /etc/inittab ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: file /etc/inittab found"
LogText "Test: Checking default Linux run level"
2016-08-25 15:31:33 +02:00
FIND=`${AWKBINARY} -F: '/^id/ { print $2; }' /etc/inittab | head -n 1`
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking default runlevel" --result "${STATUS_UNKNOWN}" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: Can't determine default run level from /etc/inittab"
2014-08-26 17:33:55 +02:00
else
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking default run level" --result "${FIND}" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Found default run level '${FIND}'"
Report "linux_default_runlevel=${FIND}"
2014-08-26 17:33:55 +02:00
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: file /etc/inittab not found"
2014-08-26 17:33:55 +02:00
if [ "${LINUX_VERSION}" = "Debian" -o "${LINUX_VERSION}" = "Ubuntu" ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking run level with who -r, for Debian based systems"
2016-08-25 15:31:33 +02:00
FIND=`who -r | ${AWKBINARY} '{ if ($1=="run-level") { print $2 } }'`
2014-08-26 17:33:55 +02:00
if [ ! "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found default run level '${FIND}'"
Report "linux_default_runlevel=${FIND}"
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking default run level" --result "RUNLEVEL ${FIND}" --color GREEN
else
2015-12-21 21:17:15 +01:00
LogText "Result: Can't determine default run level from who -r"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking default run level" --result "${STATUS_UNKNOWN}" --color YELLOW
2014-09-15 12:01:09 +02:00
fi
fi
fi
2014-08-26 17:33:55 +02:00
fi
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : KRNL-5677
# Description : Check CPU options and support (PAE, No eXecute, eXecute Disable)
# More info : pae and nx bit are both visible on AMD and Intel CPU's if supported
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5677 --os Linux --weight L --network NO --category security --description "Check CPU options and support"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
Display --indent 2 --text "- Checking CPU support (NX/PAE)"
2015-12-21 21:17:15 +01:00
LogText "Test: Checking /proc/cpuinfo"
2014-08-26 17:33:55 +02:00
if [ -f /proc/cpuinfo ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found /proc/cpuinfo"
LogText "Test: Checking CPU options (XD/NX/PAE)"
2016-08-25 15:31:33 +02:00
FIND_PAE_NX=`${GREPBINARY} " pae " /proc/cpuinfo | ${GREPBINARY} " nx "`
FIND_PAE=`${GREPBINARY} " pae " /proc/cpuinfo`
FIND_NX=`${GREPBINARY} " nx " /proc/cpuinfo`
2014-08-26 17:33:55 +02:00
FOUND=0
if [ ! "${FIND_PAE_NX}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "PAE: Yes"
LogText "NX: Yes"
2014-08-26 17:33:55 +02:00
CPU_PAE=1
CPU_NX=1
2015-12-21 21:17:15 +01:00
LogText "Result: PAE or No eXecute option(s) both found"
Report "cpu_pae=1"
Report "cpu_nx=1"
2014-08-26 17:33:55 +02:00
FOUND=1
else
if [ ! "${FIND_PAE}" = "" -a "${FIND_NX}" = "" ]; then
2015-12-21 21:17:15 +01:00
Report "cpu_pae=1"
LogText "Result: found PAE"
2014-08-26 17:33:55 +02:00
CPU_PAE=1
FOUND=1
else
if [ ! "${FIND_NX}" = "" -a "${FIND_PAE}" = "" ]; then
2015-12-21 21:17:15 +01:00
Report "cpu_nx=1"
LogText "Result: found No eXecute"
2014-08-26 17:33:55 +02:00
CPU_NX=1
FOUND=1
else
2015-12-21 21:17:15 +01:00
LogText "Result: found no CPU options enabled (PAE or NX bit)"
2014-08-26 17:33:55 +02:00
fi
fi
fi
if [ ${FOUND} -eq 1 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "CPU support: PAE and/or NoeXecute supported" --result "${STATUS_FOUND}" --color GREEN
2014-08-26 17:33:55 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "CPU support: No PAE or NoeXecute supported" --result "${STATUS_NONE}" --color YELLOW
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Use a PAE enabled kernel when possible to gain native No eXecute/eXecute Disable support"
fi
else
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "CPU support: no /proc/cpuinfo" --result "${STATUS_SKIPPED}" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: /proc/cpuinfo not found"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5680
# Description : Check if installed kernel has PAE support
# Dependency : KRNL-5677
# More info : RedHat/CentOS/Fedora uses the package name 'kernel-PAE'
#
#################################################################################
#
# Test : KRNL-5695
# Description : Determining Linux kernel version and release number
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5695 --os Linux --weight L --network NO --category security --description "Determine Linux kernel version and release number"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
# Kernel number (and suffix)
LINUX_KERNEL_RELEASE=`uname -r`
2015-12-21 21:17:15 +01:00
Report "linux_kernel_release=${LINUX_KERNEL_RELEASE}"
LogText "Result: found kernel release ${LINUX_KERNEL_RELEASE}"
2014-08-26 17:33:55 +02:00
# Type and build date
LINUX_KERNEL_VERSION=`uname -v`
2015-12-21 21:17:15 +01:00
Report "linux_kernel_version=${LINUX_KERNEL_VERSION}"
LogText "Result: found kernel version ${LINUX_KERNEL_VERSION}"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking kernel version and release" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : KRNL-5723
# Description : Check if Linux is build as a monolithic kernel or not
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5723 --os Linux --weight L --network NO --category security --description "Determining if Linux kernel is monolithic"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-19 01:46:40 +02:00
if [ ! "${LSMODBINARY}" = "" -a -f /proc/modules ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: checking if kernel is monolithic or modular"
2014-08-26 17:33:55 +02:00
# Checking if any modules are loaded
2016-09-08 21:04:17 +02:00
FIND=`${LSMODBINARY} | ${GREPBINARY} -v "^Module" | wc -l | ${TRBINARY} -s ' ' | ${TRBINARY} -d ' '`
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking kernel type" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "0" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found monolithic kernel"
Report "linux_kernel_type=monolithic"
2014-08-26 17:33:55 +02:00
MONOLITHIC_KERNEL=1
else
2015-12-21 21:17:15 +01:00
LogText "Result: Found modular kernel"
Report "linux_kernel_type=modular"
2014-08-26 17:33:55 +02:00
MONOLITHIC_KERNEL=0
fi
else
2015-12-21 21:17:15 +01:00
LogText "Test skipped, lsmod binary not found or /proc/modules can not be opened"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5726
# Description : Checking Linux loaded kernel modules
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5726 --os Linux --weight L --network NO --category security --description "Checking Linux loaded kernel modules"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-19 01:46:40 +02:00
if [ ! "${LSMODBINARY}" = "" -a -f /proc/modules ]; then
2016-08-25 15:31:33 +02:00
FIND=`${LSMODBINARY} | ${AWKBINARY} '{ if ($1!="Module") print $1 }' | sort`
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking loaded kernel modules" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
if [ ! "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Loaded modules according lsmod:"
2014-08-26 17:33:55 +02:00
N=0
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Loaded module: ${I}"
Report "loaded_kernel_module[]=${I}"
2016-05-03 14:57:53 +02:00
N=$((N + 1))
2014-08-26 17:33:55 +02:00
done
Display --indent 6 --text "Found ${N} active modules"
else
2015-12-21 21:17:15 +01:00
LogText "Result: no loaded modules found"
LogText "Notice: No loaded kernel modules could indicate a broken/malformed lsmod, or a (custom) monolithic kernel"
2014-08-26 17:33:55 +02:00
fi
else
2015-12-21 21:17:15 +01:00
LogText "Test skipped, lsmod binary not found or /proc/modules can not be opened"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5728
# Description : Checking for available Linux kernel configuration file in /boot
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5728 --os Linux --weight L --network NO --category security --description "Checking Linux kernel config"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-19 02:23:07 +02:00
CHECKFILE="/boot/config-`uname -r`"
if [ -f ${CHECKFILE} ]; then
LINUXCONFIGFILE="${CHECKFILE}"
2015-12-21 21:17:15 +01:00
LogText "Result: found config (${LINUXCONFIGFILE})"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Linux kernel configuration file" --result "${STATUS_FOUND}" --color GREEN
2014-09-22 03:46:13 +02:00
elif [ -f /proc/config.gz ]; then
2014-09-19 02:23:07 +02:00
LINUXCONFIGFILE="${CHECKFILE}"
LINUXCONFIGFILE_ZIPPED=1
2015-12-21 21:17:15 +01:00
LogText "Result: found config: /proc/config.gz (compressed)"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Linux kernel configuration file" --result "${STATUS_FOUND}" --color GREEN
2014-08-26 17:33:55 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no Linux kernel configuration file found in /boot"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Linux kernel configuration file" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-08-26 17:33:55 +02:00
fi
2014-09-19 02:23:07 +02:00
if [ ! "${LINUXCONFIGFILE}" = "" ]; then
2015-12-21 21:17:15 +01:00
Report "linux_config_file=${LINUXCONFIGFILE}"
2014-09-19 02:23:07 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : KRNL-5730
# Description : Checking default I/O kernel scheduler
2015-09-07 17:43:00 +02:00
# Notes : This test could be extended with testing some of the specific devices like disks
# cat /sys/block/sda/queue/scheduler
2014-08-26 17:33:55 +02:00
PREQS_MET="NO"
if [ ! "${LINUXCONFIGFILE}" = "" ]; then
if [ -f ${LINUXCONFIGFILE} ]; then PREQS_MET="YES"; fi
fi
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5730 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking disk I/O kernel scheduler"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-19 02:23:07 +02:00
if [ ${LINUXCONFIGFILE_ZIPPED} -eq 1 ]; then GREPTOOL="${ZGREPBINARY}"; else GREPTOOL="${GREPBINARY}"; fi
if [ ! "${GREPTOOL}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking the default I/O kernel scheduler"
2016-09-08 21:04:17 +02:00
LINUX_KERNEL_IOSCHED=`${GREPTOOL} "CONFIG_DEFAULT_IOSCHED" ${LINUXCONFIGFILE} | ${AWKBINARY} -F= '{ print $2 }' | ${SEDBINARY} s/\"//g`
2014-09-19 02:23:07 +02:00
if [ ! "${LINUX_KERNEL_IOSCHED}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found IO scheduler '${LINUX_KERNEL_IOSCHED}'"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking default I/O kernel scheduler" --result "${STATUS_FOUND}" --color GREEN
2015-12-21 21:17:15 +01:00
Report "linux_kernel_io_scheduler[]=${LINUX_KERNEL_IOSCHED}"
2014-09-19 02:23:07 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no default i/o kernel scheduler found"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking default I/O kernel scheduler" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-09-19 02:23:07 +02:00
fi
2014-08-26 17:33:55 +02:00
else
2016-08-25 15:31:33 +02:00
ReportException "${TEST_NO}" "No valid ${GREPBINARY} tool found to search kernel settings"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5745
# Description : Checking FreeBSD loaded kernel modules
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5745 --os FreeBSD --weight L --network NO --category security --description "Checking FreeBSD loaded kernel modules"
2016-11-19 13:39:57 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
Display --indent 2 --text "- Checking active kernel modules"
LogText "Test: Active kernel modules (KLDs)"
LogText "Description: View all active kernel modules (including kernel)"
LogText "Test: Checking modules"
if [ -f /sbin/kldstat ]; then
FIND=`kldstat | ${GREPBINARY} -v 'Name' | ${TRBINARY} -s ' ' | ${CUTBINARY} -d ' ' -f6`
if [ $? -eq 0 ]; then
LogText "Loaded modules according kldstat:"
N=0
for I in ${FIND}; do
LogText "Loaded module: ${I}"
Report "loaded_kernel_module[]=${I}"
N=$((N + 1))
done
Display --indent 4 --text "Found ${N} kernel modules" --result "${STATUS_DONE}" --color GREEN
else
Display --indent 4 --text "Test failed" --result "${STATUS_WARNING}" --color RED
LogText "Result: Problem with executing kldstat"
fi
else
echo "[ ${WHITE}SKIPPED${NORMAL} ]"
LogText "Result: no results, can't find /sbin/kldstat"
fi
fi
#
#################################################################################
#
# Test : KRNL-5831
# Description : Checking DragonFly loaded kernel modules
Register --test-no KRNL-5831 --os DragonFly --weight L --network NO --category security --description "Checking DragonFly loaded kernel modules"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking active kernel modules"
2015-12-21 21:17:15 +01:00
LogText "Test: Active kernel modules (KLDs)"
LogText "Description: View all active kernel modules (including kernel)"
LogText "Test: Checking modules"
2014-08-26 17:33:55 +02:00
if [ -f /sbin/kldstat ]; then
2016-09-08 21:04:17 +02:00
FIND=`kldstat | ${GREPBINARY} -v 'Name' | ${TRBINARY} -s ' ' | ${CUTBINARY} -d ' ' -f6`
2014-08-26 17:33:55 +02:00
if [ $? -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Loaded modules according kldstat:"
2014-08-26 17:33:55 +02:00
N=0
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Loaded module: ${I}"
Report "loaded_kernel_module[]=${I}"
2016-05-03 14:57:53 +02:00
N=$((N + 1))
2014-08-26 17:33:55 +02:00
done
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "Found ${N} kernel modules" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "Test failed" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: Problem with executing kldstat"
2014-08-26 17:33:55 +02:00
fi
else
echo "[ ${WHITE}SKIPPED${NORMAL} ]"
2015-12-21 21:17:15 +01:00
LogText "Result: no results, can't find /sbin/kldstat"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5770
# Description : Checking Solaris load modules
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5770 --os Solaris --weight L --network NO --category security --description "Checking active kernel modules"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: searching loaded kernel modules"
2016-08-25 15:31:33 +02:00
FIND=`modinfo -c -w | ${GREPBINARY} -v "UNLOADED" | ${GREPBINARY} LOADED | ${AWKBINARY} '{ print $3 }' | sort`
2014-08-26 17:33:55 +02:00
if [ ! "${FIND}" = "" ]; then
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Found module: ${I}"
Report "loaded_kernel_module[]=${I}"
2014-08-26 17:33:55 +02:00
done
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Solaris active kernel modules" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no output"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Solaris active kernel modules" --result "${STATUS_UNKNOWN}" --color YELLOW
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5788
# Description : Checking availability new kernel
if [ "${LINUX_VERSION}" = "Debian" -o "${LINUX_VERSION}" = "Ubuntu" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5788 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking availability new Linux kernel"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching apt-cache, to determine if a newer kernel is available"
2014-08-26 17:33:55 +02:00
if [ -x /usr/bin/apt-cache ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found /usr/bin/apt-cache"
LogText "Test: checking readlink location of /vmlinuz"
2016-04-25 09:34:14 +02:00
if [ -f /vmlinuz ]; then
2016-11-20 16:16:02 +01:00
FINDKERNFILE=$(readlink -f /vmlinuz)
2016-04-25 09:34:14 +02:00
LogText "Output: readlink reported file ${FINDKERNFILE}"
LogText "Test: checking package from dpkg -S"
2016-11-20 16:16:02 +01:00
FINDKERNEL=$(dpkg -S ${FINDKERNFILE} 2> /dev/null | ${AWKBINARY} -F : '{print $1}')
2016-04-25 09:34:14 +02:00
LogText "Output: dpkg -S reported package ${FINDKERNEL}"
2016-04-25 10:56:11 +02:00
elif [ -e /dev/grsec ]; then
2016-11-20 16:16:02 +01:00
FINDKERNEL=linux-image-$(uname -r)
2016-04-25 10:56:11 +02:00
LogText "/vmlinuz missing due to grsecurity; assuming ${FINDKERNEL}"
2016-04-25 09:34:14 +02:00
else
2016-04-25 10:56:11 +02:00
LogText "This system is missing /vmlinuz. Unable to check whether kernel is up-to-date."
2016-11-20 16:16:02 +01:00
ReportSuggestion ${TEST_NO} "Determine why /vmlinuz is missing on this Debian/Ubuntu system." "/vmlinuz"
2016-04-25 09:34:14 +02:00
fi
2015-12-21 21:17:15 +01:00
LogText "Test: Using apt-cache policy to determine if there is an update available"
2016-11-20 16:16:02 +01:00
FINDINST=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Installed' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
FINDCAND=$(apt-cache policy ${FINDKERNEL} | ${EGREPBINARY} 'Candidate' | ${CUTBINARY} -d ':' -f2 | ${TRBINARY} -d ' ')
2015-12-21 21:17:15 +01:00
LogText "Kernel installed: ${FINDINST}"
LogText "Kernel candidate: ${FINDCAND}"
2016-11-20 16:16:02 +01:00
if [ -z "${FINDINST}" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_UNKNOWN}" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: Exception occured, no output from apt-cache policy"
2014-08-26 17:33:55 +02:00
ReportException "${TEST_NO}:01"
2015-12-21 21:17:15 +01:00
LogText "Exception: apt-cache policy did not return an installed kernel version"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Check the output of apt-cache policy manually to determine why output is empty"
2016-04-25 09:34:14 +02:00
else
2014-08-26 17:33:55 +02:00
if [ "${FINDINST}" = "${FINDCAND}" ]; then
2016-04-25 09:34:14 +02:00
if [ -e /dev/grsec ]; then
Display --indent 2 --text "- Checking for available kernel update" --result GRSEC --color GREEN
LogText "Result: Grsecurity is installed; unable to determine if there's a newer kernel available"
2016-04-25 10:56:11 +02:00
ReportManual "Manually check to confirm you're using a recent kernel and grsecurity patch"
2016-04-25 09:34:14 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking for available kernel update" --result "${STATUS_OK}" --color GREEN
2016-04-25 09:34:14 +02:00
LogText "Result: no kernel update available"
fi
else
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking for available kernel update" --result "UPDATE AVAILABLE" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: kernel update available according 'apt-cache policy'."
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Determine priority for available kernel update"
fi
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: could NOT find /usr/bin/apt-cache, skipped other tests."
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : KRNL-5820
# Description : Checking core dumps configuration (Linux)
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5820 --os Linux --weight L --network NO --category security --description "Checking core dumps configuration"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking presence /etc/security/limits.conf"
2014-08-26 17:33:55 +02:00
if [ -f /etc/security/limits.conf ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: file /etc/security/limits.conf exists"
LogText "Test: Checking if core dumps are disabled in /etc/security/limits.conf"
2016-09-06 20:57:47 +02:00
FIND1=$(${GREPBINARY} -v "^#" /etc/security/limits.conf | ${GREPBINARY} -v "^$" | ${AWKBINARY} '{ if ($1=="*" && $2=="soft" && $3=="core" && $4=="1") { print "soft core enabled" } }')
FIND2=$(${GREPBINARY} -v "^#" /etc/security/limits.conf | ${GREPBINARY} -v "^$" | ${AWKBINARY} '{ if ($1=="*" && $2=="hard" && $3=="core" && $4=="1") { print "hard core enabled" } }')
2014-08-26 17:33:55 +02:00
if [ "${FIND1}" = "soft core enabled" -o "${FIND2}" = "hard core enabled" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: core dumps (soft or hard) are enabled"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking core dumps configuration" --result "${STATUS_ENABLED}" --color YELLOW
2016-09-06 20:57:47 +02:00
ReportSuggestion "${TEST_NO}" "Check if core dumps need to be enabled on this system"
2014-08-26 17:33:55 +02:00
AddHP 1 2
2016-09-06 20:57:47 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: core dumps (soft and hard) are both disabled"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking core dumps configuration" --result "${STATUS_DISABLED}" --color GREEN
2014-08-26 17:33:55 +02:00
CORE_DUMPS_DISABLED=1
AddHP 3 3
fi
# Sysctl option
2015-12-21 21:17:15 +01:00
LogText "Test: Checking sysctl value of fs.suid_dumpable"
2016-09-06 20:57:47 +02:00
FIND=$(${SYSCTLBINARY} fs.suid_dumpable 2> /dev/null | ${AWKBINARY} '{ if ($1=="fs.suid_dumpable") { print $3 } }')
if [ -z "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: sysctl key fs.suid_dumpable not found"
2016-09-06 20:57:47 +02:00
else
2016-05-02 17:35:55 +02:00
LogText "Result: value ${FIND} found"
2014-08-26 17:33:55 +02:00
fi
if [ "${FIND}" = "2" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: programs can dump core dump, but only readable by root (value 2, for debugging with file protection)"
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking setuid core dumps configuration" --result PROTECTED --color GREEN
2014-08-26 17:33:55 +02:00
AddHP 1 1
elif [ "${FIND}" = "1" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: all programs can perform core dumps (value 1, for debugging)"
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking setuid core dumps configuration" --result DEBUG --color YELLOW
2016-09-06 20:57:47 +02:00
ReportSuggestion "${TEST_NO}" "Determine if all binaries need to be able to core dump"
2014-08-26 17:33:55 +02:00
AddHP 0 1
2016-09-06 20:57:47 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: found default option, some programs can dump (not processes which need to change credentials)"
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking setuid core dumps configuration" --result DEFAULT --color YELLOW
2014-08-26 17:33:55 +02:00
AddHP 1 1
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: file /etc/security/limits.conf does not exist, skipping test"
2014-08-26 17:33:55 +02:00
fi
2016-09-06 20:57:47 +02:00
# TODO: Check ulimit settings in /etc/profile and /etc/profile.d
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : KRNL-5826
# Description : Checking core dumps configuration (Solaris)
2016-07-24 17:22:00 +02:00
#Register --test-no KRNL-5826 --os Linux --weight L --network NO --category security --description "Checking core dumps configuration"
2014-08-26 17:33:55 +02:00
#if [ ${SKIPTEST} -eq 0 ]; then
#
#################################################################################
#
# Test : KRNL-5830
2014-09-18 22:20:15 +02:00
# Description : Check if system needs a reboot (Linux only)
2016-07-24 17:22:00 +02:00
Register --test-no KRNL-5830 --os Linux --weight L --network NO --category security --description "Checking if system is running on the latest installed kernel"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-18 22:20:15 +02:00
REBOOT_NEEDED=2
2016-09-10 16:12:44 +02:00
FILE="${ROOTDIR}var/run/reboot-required.pkgs"
2015-12-21 21:17:15 +01:00
LogText "Test: Checking presence ${FILE}"
2014-08-26 17:33:55 +02:00
if [ -f ${FILE} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: file ${FILE} exists"
2016-09-10 16:12:44 +02:00
FIND=$(${WCBINARY} -l < ${FILE})
2016-07-31 16:28:17 +02:00
if [ "${FIND}" = "0" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: No reboot needed (file empty)"
2014-09-18 22:20:15 +02:00
REBOOT_NEEDED=0
2016-07-31 16:28:17 +02:00
else
2016-09-10 16:12:44 +02:00
PKGSCOUNT=$(${WCBINARY} -l < ${FILE})
2015-12-21 21:17:15 +01:00
LogText "Result: reboot is needed, related to ${PKGSCOUNT} packages"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Package: ${I}"
2014-08-26 17:33:55 +02:00
done
2014-09-18 22:20:15 +02:00
REBOOT_NEEDED=1
2014-08-26 17:33:55 +02:00
fi
2016-07-31 16:28:17 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: file ${FILE} not found"
2014-09-18 22:20:15 +02:00
fi
# Check if /boot exists
2016-09-10 16:12:44 +02:00
if [ -d ${ROOTDIR}boot ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: /boot exists, performing more tests from here"
2016-09-10 16:12:44 +02:00
FIND=$(${LSBINARY} ${ROOTDIR}boot/* 2> /dev/null)
if [ ! -z "${FIND}" ]; then
if [ -f ${ROOTDIR}boot/vmlinuz -a ! -L ${ROOTDIR}boot/vmlinuz ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found /boot/vmlinuz (not symlinked)"
2014-12-05 19:42:12 +01:00
NEXTLINE=0
FINDVERSION=""
2016-09-10 16:12:44 +02:00
for I in $(file ${ROOTDIR}boot/vmlinuz-linux); do
2014-12-05 19:42:12 +01:00
if [ ${NEXTLINE} -eq 1 ]; then
FINDVERSION="${I}"
2016-07-31 16:28:17 +02:00
else
2014-12-05 19:42:12 +01:00
# Searching for the Linux kernel after the keyword 'version'
if [ "${I}" = "version" ]; then NEXTLINE=1; fi
fi
done
2016-09-10 16:12:44 +02:00
if [ ! -z "${FINDVERSION}" ]; then
2014-12-05 19:42:12 +01:00
CURRENT_KERNEL=`uname -r`
if [ ! "${CURRENT_KERNEL}" = "${FINDVERSION}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: reboot needed, as current kernel is different than the one loaded"
2014-12-05 19:42:12 +01:00
REBOOT_NEEDED=1
fi
2016-07-31 16:28:17 +02:00
else
2014-12-05 19:42:12 +01:00
ReportException "${TEST_NO}:1" "Can't determine kernel version on disk, need debug data"
fi
2016-09-10 16:12:44 +02:00
elif [ -f ${ROOTDIR}boot/vmlinuz-linux ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: /found /boot/vmlinuz-linux (usually Arch Linux or similar)"
LogText "Test: checking kernel version on disk"
2016-09-10 16:12:44 +02:00
VERSION_ON_DISK=$(${FILEBINARY} -b ${ROOTDIR}boot/vmlinuz-linux | ${AWKBINARY} '{ if ($1=="Linux" && $7=="version") { print $8 }}')
if [ ! -z "${VERSION_ON_DISK}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found version ${VERSION_ON_DISK}"
2014-09-25 16:55:02 +02:00
ACTIVE_KERNEL=`uname -r`
2015-12-21 21:17:15 +01:00
LogText "Result: active kernel version ${ACTIVE_KERNEL}"
2014-09-25 16:55:02 +02:00
if [ "${VERSION_ON_DISK}" = "${ACTIVE_KERNEL}" ]; then
REBOOT_NEEDED=0
2015-12-21 21:17:15 +01:00
LogText "Result: no reboot needed, active kernel is the same version as the one on disk"
2016-07-31 16:28:17 +02:00
else
2014-09-25 16:55:02 +02:00
REBOOT_NEEDED=1
2015-12-21 21:17:15 +01:00
LogText "Result: reboot needed, as there is a difference between active kernel and the one on disk"
2014-09-25 16:55:02 +02:00
fi
2016-07-31 16:28:17 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: could not find the version on disk"
2014-09-25 16:55:02 +02:00
ReportException "${TEST_NO}:4" "Could not find the kernel version from /boot/vmlinux-linux"
2014-09-19 17:55:00 +02:00
fi
2016-07-31 16:28:17 +02:00
else
2016-09-10 16:12:44 +02:00
if [ -L ${ROOTDIR}boot/vmlinuz ]; then
LogText "Result: found symlink of ${ROOTDIR}boot/vmlinuz, skipping file"
2016-07-31 16:28:17 +02:00
else
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}boot/vmlinuz not on disk, trying to find ${ROOTDIR}boot/vmlinuz*"
2014-12-03 22:50:25 +01:00
fi
2016-08-25 15:31:33 +02:00
# Extra current kernel version and replace dashes to allow numeric ${SORTBINARY} later on
2016-09-10 16:12:44 +02:00
MYKERNEL=$(${UNAMEBINARY} -r | ${SEDBINARY} 's/\.[a-z].*.//g' | ${SEDBINARY} 's/-[a-z].*.//g' | ${SEDBINARY} 's/-/./g')
2015-12-21 21:17:15 +01:00
LogText "Result: using ${MYKERNEL} as my kernel version (stripped)"
2016-09-10 16:12:44 +02:00
FIND=$(ls ${ROOTDIR}boot/vmlinuz* 2> /dev/null)
if [ ! -z "${FIND}" ]; then
2016-08-17 11:49:02 +02:00
for ITEM in ${FIND}; do
LogText "Result: found ${ITEM}"
done
2016-08-25 15:31:33 +02:00
# Display kernels, extract version numbers and ${SORTBINARY} them numeric per column (up to 6 numbers)
2016-07-31 21:09:05 +02:00
# Ignore rescue images. Remove generic. and huge. for Slackware machines
2016-08-17 11:49:02 +02:00
LogText "Action: checking relevant kernels"
2016-09-10 16:12:44 +02:00
KERNELS=$(${LSBINARY} /boot/vmlinuz* | ${GREPBINARY} -v rescue | ${SEDBINARY} 's/vmlinuz-//' | ${SEDBINARY} 's/generic.//' | ${SEDBINARY} 's/huge.//' | ${SEDBINARY} 's/\.[a-z].*.//g' | ${SEDBINARY} 's/-[a-z].*.//g' | ${SEDBINARY} 's./boot/..' | ${SEDBINARY} 's/-/./g' | ${SORTBINARY} -n -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 -k6,6 -t \.)
2016-09-08 21:04:17 +02:00
KERNELS_ONE_LINE=$(echo ${KERNELS} | ${TRBINARY} '\n' ' ')
2016-08-17 11:49:02 +02:00
LogText "Output: ${KERNELS_ONE_LINE}"
2016-09-10 16:12:44 +02:00
elif [ ! "$(ls ${ROOTDIR}boot/kernel* 2> /dev/null)" = "" ]; then
LogText "Output: Found a kernel file in ${ROOTDIR}boot"
2016-08-25 15:31:33 +02:00
# Display kernels, extract version numbers and ${SORTBINARY} them numeric per column (up to 6 numbers)
2014-09-25 16:55:02 +02:00
# Examples:
# /boot/kernel-genkernel-x86_64-3.14.14-gentoo
2016-09-10 16:12:44 +02:00
KERNELS=$(${LSBINARY} ${ROOTDIR}boot/kernel* | ${AWKBINARY} -F- '{ if ($2=="genkernel") { print $4 }}' | ${GREPBINARY} "^[0-9]" | ${SORTBINARY} -n -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 -k6,6 -t \.)
2016-03-17 19:39:36 +01:00
LogText "Output: ${KERNELS}"
2016-07-31 16:28:17 +02:00
else
2014-10-14 10:03:29 +02:00
ReportException "${TEST_NO}:2" "Can not find any vmlinuz or kernel files in /boot, which is unexpected"
fi
2016-09-10 16:12:44 +02:00
if [ ! -z "${KERNELS}" ]; then
2014-09-25 16:55:02 +02:00
FOUND_KERNEL=0
for I in ${KERNELS}; do
2014-10-14 10:03:29 +02:00
# Check if we already found a kernel and it is not equal to what we run (e.g. double versions may exist)
if [ ${FOUND_KERNEL} -eq 1 -a ! "${MYKERNEL}" = "${I}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found a kernel (${I}) later than running one (${MYKERNEL})"
2014-09-25 16:55:02 +02:00
REBOOT_NEEDED=1
fi
if [ "${MYKERNEL}" = "${I}" ]; then
FOUND_KERNEL=1
2015-12-21 21:17:15 +01:00
LogText "Result: Found ${I} (= our kernel)"
2016-07-31 16:28:17 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: Found ${I}"
2014-09-25 16:55:02 +02:00
fi
done
# Check if we at least found the kernel on disk
if [ ${FOUND_KERNEL} -eq 0 ]; then
ReportException "${TEST_NO}:3" "Could not find our running kernel on disk, which is unexpected"
2016-07-31 16:28:17 +02:00
else
2014-09-25 16:55:02 +02:00
# If we are not sure yet reboot it needed, but we found running kernel as last one on disk, we run latest kernel
if [ ${REBOOT_NEEDED} -eq 2 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: we found our kernel on disk as last entry, so seems to be up-to-date"
2014-09-25 16:55:02 +02:00
REBOOT_NEEDED=0
fi
2014-09-18 22:20:15 +02:00
fi
2014-10-14 10:03:29 +02:00
fi
2014-09-18 22:20:15 +02:00
fi
2016-07-31 16:28:17 +02:00
# No files in /boot
else
2015-12-21 21:17:15 +01:00
LogText "Result: Skipping this test, as there are no files in /boot"
2014-09-18 22:20:15 +02:00
fi
2016-07-31 16:28:17 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: /boot does not exist"
2014-09-18 22:20:15 +02:00
fi
# Display discovered status
if [ ${REBOOT_NEEDED} -eq 0 ]; then
2016-07-31 16:28:17 +02:00
Display --indent 2 --text "- Check if reboot is needed" --result "${STATUS_NO}" --color GREEN
AddHP 5 5
elif [ ${REBOOT_NEEDED} -eq 1 ]; then
Display --indent 2 --text "- Check if reboot is needed" --result "${STATUS_YES}" --color RED
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "Reboot of system is most likely needed"
2016-07-31 16:28:17 +02:00
AddHP 0 5
else
Display --indent 2 --text "- Check if reboot is needed" --result "${STATUS_UNKNOWN}" --color YELLOW
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
2016-04-28 12:31:57 +02:00
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#================================================================================
2015-12-21 21:17:15 +01:00
# Lynis - Copyright 2007-2016, CISOfy - https://cisofy.com