2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
2021-01-07 15:22:19 +01:00
# Copyright 2007-2021, CISOfy
2016-03-13 16:00:39 +01:00
#
# 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.
#
#################################################################################
#
# File systems
#
#################################################################################
#
# Number of days to mark a file as old
TMP_OLD_DAYS=90
LVM_VG_USED=0
#
#################################################################################
#
2020-10-22 00:13:42 +02:00
InsertSection "${SECTION_FILE_SYSTEMS}"
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : FILE-6310
2015-04-07 17:19:25 +02:00
# Description : Checking if some mount points are separated from /
# Goal : Users should not be able to fill their home directory or temporary directory and creating a Denial of Service
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6310 --weight L --network NO --category security --description "Checking /tmp, /home and /var directory"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
Display --indent 2 --text "- Checking mount points"
2015-04-07 17:19:25 +02:00
SEPARATED_FILESYTEMS="/home /tmp /var"
2014-08-26 17:33:55 +02:00
for I in ${SEPARATED_FILESYTEMS}; do
2015-12-21 21:17:15 +01:00
LogText "Test: Checking if ${I} is mounted separately or mounted on / file system"
2014-08-26 17:33:55 +02:00
if [ -L ${I} ]; then
2016-03-08 11:35:15 +01:00
ShowSymlinkPath ${I}
LogText "Result: ${I} is a symlink. Manual check required to determine exact file system options"
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Symlinked mount point needs to be checked manually" "${I}" ""
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking ${I} mount point" --result SYMLINK --color WHITE
2016-09-10 16:12:44 +02:00
elif [ -d ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: directory ${I} exists"
2019-06-06 14:20:12 +02:00
case "${OS}" in
"AIX") FIND=$(${MOUNTBINARY} | ${AWKBINARY} -v MP=${I} '{ if ($2==MP) { print $2 }}') ;;
2020-01-22 16:31:49 +01:00
"HP-UX") FIND=$(${MOUNTBINARY} | ${AWKBINARY} -v MP=${I} '{ if ($1==MP) { print $1 }}') ;;
2019-06-06 14:20:12 +02:00
*) FIND=$(${MOUNTBINARY} | ${AWKBINARY} -v MP=${I} '{ if ($3==MP) { print $3 }}') ;;
esac
2017-07-28 10:42:17 +02:00
if IsEmpty "${FIND}"; then
2015-12-21 21:17:15 +01:00
LogText "Result: ${I} not found in mount list. Directory most likely stored on / file system"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking ${I} mount point" --result "${STATUS_SUGGESTION}" --color YELLOW
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "To decrease the impact of a full ${I} file system, place ${I} on a separate partition"
2015-04-07 17:19:25 +02:00
AddHP 9 10
2017-07-28 10:42:17 +02:00
else
LogText "Result: found ${I} as a separated mount point"
Display --indent 4 --text "- Checking ${I} mount point" --result "${STATUS_OK}" --color GREEN
AddHP 10 10
2014-08-26 17:33:55 +02:00
fi
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: directory ${I} does not exist"
2014-08-26 17:33:55 +02:00
fi
done
fi
#
#################################################################################
#
# Test : FILE-6311
# Description : Checking LVM Volume Groups
# Notes : No volume groups found is sent to STDERR for unclear reasons. Filtering both STDERR redirecting and grep.
2014-10-26 23:33:08 +01:00
if [ ! "${VGDISPLAYBINARY}" = "" -o ! "${LSVGBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6311 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking LVM volume groups"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for LVM volume groups"
2014-10-26 23:33:08 +01:00
case ${OS} in
AIX)
2016-09-10 16:12:44 +02:00
FIND=$(${LSVGBINARY} -o)
2014-10-26 23:33:08 +01:00
;;
Linux)
2016-09-10 16:12:44 +02:00
FIND=$(${VGDISPLAYBINARY} 2> /dev/null | ${GREPBINARY} -v "No volume groups found" | ${GREPBINARY} "VG Name" | ${AWKBINARY} '{ print $3 }' | ${SORTBINARY})
2014-10-26 23:33:08 +01:00
;;
*)
ReportException "${TEST_NO}:1" "Don't know this specific operating system yet, while volume group manager was found"
;;
esac
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more volume groups"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Found LVM volume group: ${I}"
Report "lvm_volume_group[]=${I}"
2014-08-26 17:33:55 +02:00
done
LVM_VG_USED=1
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking LVM volume groups" --result "${STATUS_FOUND}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no LVM volume groups found"
2016-06-18 11:14:01 +02:00
if IsVerbose; then Display --indent 2 --text "- Checking LVM volume groups" --result "${STATUS_NONE}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FILE-6312
# Description : Checking LVM volumes
2014-10-26 23:33:08 +01:00
if [ ${LVM_VG_USED} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6312 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking LVM volumes"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for LVM volumes"
2014-10-26 23:33:08 +01:00
case ${OS} in
AIX)
2016-09-10 16:12:44 +02:00
ACTIVE_VG_LIST=$(${LSVGBINARY} -o)
FIND=$(for I in ${ACTIVE_VG_LIST}; do ${LSVGBINARY} -l ${I} | ${AWKBINARY} 'NR>2 { print $1 }'; done)
2014-10-26 23:33:08 +01:00
;;
Linux)
2016-09-10 16:12:44 +02:00
FIND=$(${LVDISPLAYBINARY} | ${GREPBINARY} -v "No volume groups found" | ${GREPBINARY} "LV Name" | ${AWKBINARY} '{ print $3 }' | ${SORTBINARY})
2014-10-26 23:33:08 +01:00
;;
*)
ReportException "${TEST_NO}:1" "Need specific test for gathering volume manager data"
;;
esac
2014-08-26 17:33:55 +02:00
if [ ! "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more volumes"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Found LVM volume: ${I}"
Report "lvm_volume[]=${I}"
2014-08-26 17:33:55 +02:00
done
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking LVM volumes" --result "${STATUS_FOUND}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no LVM volume groups found"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking LVM volumes" --result "${STATUS_NONE}" --color WHITE
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FILE-6316
# Description : Checking /etc/fstab file permissions
2016-07-24 17:22:00 +02:00
#Register --test-no FILE-6316 --os Linux --weight L --network NO --category security --description "Checking /etc/fstab"
2014-08-26 17:33:55 +02:00
#if [ ${SKIPTEST} -eq 0 ]; then
# 644
#
#################################################################################
#
# Test : FILE-6323
# Description : Checking Linux EXT2, EXT3, EXT4 file systems
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6323 --os Linux --weight L --network NO --category security --description "Checking EXT file systems"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for Linux EXT file systems"
2016-09-10 16:12:44 +02:00
FIND=$(${MOUNTBINARY} -t ext2,ext3,ext4 | ${AWKBINARY} '{ print $3","$5 }')
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more EXT file systems"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2016-09-10 16:12:44 +02:00
FILESYSTEM=$(echo ${I} | ${CUTBINARY} -d ',' -f1)
FILETYPE=$(echo ${I} | ${CUTBINARY} -d ',' -f2)
2015-12-21 21:17:15 +01:00
LogText "File system: ${FILESYSTEM} (type: ${FILETYPE})"
Report "file_systems_ext[]=${FILESYSTEM}|${FILETYPE}|"
2014-08-26 17:33:55 +02:00
done
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no EXT file systems found"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
2019-04-02 07:46:04 +02:00
#
# Test : FILE-6324
# Description : Checking Linux XFS file systems
Register --test-no FILE-6324 --os Linux --weight L --network NO --category security --description "Checking XFS file systems"
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking for Linux XFS file systems"
FIND=$(${MOUNTBINARY} -t xfs | ${AWKBINARY} '{ print $3","$5 }')
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2019-04-02 07:46:04 +02:00
LogText "Result: found one or more XFS file systems"
for I in ${FIND}; do
FILESYSTEM=$(echo ${I} | ${CUTBINARY} -d ',' -f1)
FILETYPE=$(echo ${I} | ${CUTBINARY} -d ',' -f2)
LogText "File system: ${FILESYSTEM} (type: ${FILETYPE})"
Report "file_systems_xfs[]=${FILESYSTEM}|${FILETYPE}|"
done
else
LogText "Result: no XFS file systems found"
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FILE-6329
# Description : Query all FFS/UFS mounts from /etc/fstab
if [ -f /etc/fstab ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6329 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking FFS/UFS file systems"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Query /etc/fstab for available FFS/UFS mount points"
2016-09-10 16:12:44 +02:00
FIND=$(${AWKBINARY} '{ if ($3 == "ufs" || $3 == "ffs" ) { print $1":"$2":"$3":"$4":" }}' /etc/fstab)
if [ -z "${FIND}" ]; then
2016-06-18 11:14:01 +02:00
if IsVerbose; then Display --indent 2 --text "- Querying FFS/UFS mount points (fstab)" --result "${STATUS_NONE}" --color WHITE; fi
2015-12-21 21:17:15 +01:00
LogText "Result: unable to find any single mount point (FFS/UFS)"
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Querying FFS/UFS mount points (fstab)" --result "${STATUS_FOUND}" --color GREEN
2015-12-21 21:17:15 +01:00
Report "filesystem[]=ufs"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "FFS/UFS mount found: ${I}"
Report "mountpoint_ufs[]=${I}"
2014-08-26 17:33:55 +02:00
done
fi
fi
#
#################################################################################
#
# Test : FILE-6330
2020-06-02 16:34:35 +02:00
# Description : Query ZFS mounts
# Note : mount -p does not work under Linux
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6330 --os FreeBSD --weight L --network NO --category security --description "Checking ZFS file systems"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2020-06-02 16:34:35 +02:00
LogText "Test: Discover for available ZFS mount points"
2016-09-10 16:12:44 +02:00
FIND=$(${MOUNTBINARY} -p | ${AWKBINARY} '{ if ($3 == "zfs") { print $1":"$2":"$3":"$4":" }}')
if [ -z "${FIND}" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Querying ZFS mount points (mount -p)" --result "${STATUS_NONE}" --color WHITE
2015-12-21 21:17:15 +01:00
LogText "Result: unable to find any single mount point (ZFS)"
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Querying ZFS mount points (mount -p)" --result "${STATUS_FOUND}" --color GREEN
2015-12-21 21:17:15 +01:00
Report "filesystem[]=zfs"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "ZFS mount found: ${I}"
Report "mountpoint_zfs[]=${I}"
2014-08-26 17:33:55 +02:00
done
fi
fi
#
#################################################################################
2016-11-19 13:39:57 +01:00
#
# Test : FILE-6439
# Description : Query all HAMMER PFS mounts from /etc/fstab
Register --test-no FILE-6439 --os DragonFly --weight L --network NO --category security --description "Checking HAMMER PFS mounts"
if [ ${SKIPTEST} -eq 0 ]; then
2020-06-02 16:30:43 +02:00
LogText "Test: Query /etc/fstab for available HAMMER PFS mount points"
2016-11-19 13:39:57 +01:00
FIND=$(${MOUNTBINARY} -p | ${AWKBINARY} '{ if ($3 == "null") { print $1":"$2":"$3":"$4":" }}')
if [ -z "${FIND}" ]; then
Display --indent 2 --text "- Querying HAMMER PFS mount points (mount -p)" --result "${STATUS_NONE}" --color WHITE
LogText "Result: unable to find any single PFS mount point"
else
Display --indent 2 --text "- Querying HAMMER PFS mount points (mount -p)" --result "${STATUS_FOUND}" --color GREEN
Report "filesystem[]=hammer"
for I in ${FIND}; do
LogText "HAMMER mount found: ${I}"
Report "mountpoint_hammer[]=${I}"
done
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FILE-6332
# Description : Check swap partitions
if [ -f /etc/fstab ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6332 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking swap partitions"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
FOUND=0
2015-12-21 21:17:15 +01:00
LogText "Test: query swap partitions from /etc/fstab file"
2014-08-26 17:33:55 +02:00
# Check if third field contains 'swap'
2016-09-10 16:12:44 +02:00
FIND=$(${AWKBINARY} '{ if ($2=="swap" || $3=="swap") { print $1 }}' /etc/fstab | ${GREPBINARY} -v "^#")
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
FOUND=1
2015-05-26 11:12:36 +02:00
REAL=""
UUID=""
2015-12-21 21:17:15 +01:00
LogText "Swap partition found: ${I}"
2016-07-30 14:10:29 +02:00
# TODO Add a test if partition is not a normal partition (e.g. UUID=)
2014-09-04 20:38:57 +02:00
# Can be ^/dev/mapper/vg-name_lv-name
# Can be ^/dev/partition
2015-05-26 11:12:36 +02:00
2016-07-30 14:10:29 +02:00
# Test for UUID usage (e.g. UUID=uuid --> /dev/disk/by-uuid/<uuid>)
2017-03-06 08:41:21 +01:00
HAS_UUID=$(echo ${I} | ${GREPBINARY} "^UUID=")
2019-07-16 13:20:30 +02:00
if [ -n "${HAS_UUID}" ]; then
2017-03-06 08:41:21 +01:00
UUID=$(echo ${HAS_UUID} | ${AWKBINARY} -F= '{ print $2 }')
2015-12-21 21:17:15 +01:00
LogText "Result: Using ${UUID} as UUID"
2019-07-16 13:20:30 +02:00
if [ -n "${BLKIDBINARY}" ]; then
2016-09-08 21:04:17 +02:00
FIND2=$(${BLKIDBINARY} | ${AWKBINARY} '{ if ($2=="UUID=\"${UUID}\"") print $1 }' | ${SEDBINARY} 's/:$//')
2019-07-16 13:20:30 +02:00
if [ -n "${FIND2}" ]; then
2016-07-30 14:10:29 +02:00
REAL="${FIND2}"
2015-05-26 11:12:36 +02:00
fi
2016-07-30 14:10:29 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: blkid binary not found, trying by checking device listing"
2015-05-26 11:12:36 +02:00
sFILE=""
if [ -L /dev/disk/by-uuid/${UUID} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found disk via /dev/disk/by-uuid listing"
2015-05-26 11:12:36 +02:00
ShowSymlinkPath /dev/disk/by-uuid/${UUID}
2019-07-16 13:20:30 +02:00
if [ -n "${sFILE}" ]; then
2015-05-26 11:12:36 +02:00
REAL="${sFILE}"
2015-12-21 21:17:15 +01:00
LogText "Result: disk is ${REAL}"
2015-05-26 11:12:36 +02:00
fi
2016-07-30 14:10:29 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no symlink found to /dev/disk/by-uuid/${UUID}"
2015-05-26 11:12:36 +02:00
fi
fi
fi
# Set real device
2016-09-10 16:12:44 +02:00
if [ -z "${REAL}" ]; then
2015-05-26 11:12:36 +02:00
REAL="${I}"
fi
2015-12-21 21:17:15 +01:00
Report "swap_partition[]=${I},${REAL},"
2014-08-26 17:33:55 +02:00
done
if [ ${FOUND} -eq 1 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Query swap partitions (fstab)" --result "${STATUS_OK}" --color GREEN
2017-04-30 17:59:35 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Query swap partitions (fstab)" --result "${STATUS_NONE}" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: no swap partitions found in /etc/fstab"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FILE-6336
# Description : Check swap mount options
2015-06-17 17:06:51 +02:00
# Examples : [partition] swap swap defaults 0 0
# [partition] none swap sw 0 0
2014-08-26 17:33:55 +02:00
if [ -f /etc/fstab ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6336 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking swap mount options"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-02 14:00:36 +02:00
# Swap partitions should be mounted with 'sw' or 'swap'
2015-12-21 21:17:15 +01:00
LogText "Test: check swap partitions with incorrect mount options"
2016-09-10 16:12:44 +02:00
FIND=$(${AWKBINARY} '{ if ($3=="swap" && ($4!~/sw/ && $4!="defaults")) { print $1 }}' /etc/fstab)
if [ -z "${FIND}" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Testing swap partitions" --result "${STATUS_OK}" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: all swap partitions have correct options (sw or swap)"
2016-09-10 16:12:44 +02:00
else
2021-01-05 11:53:11 +01:00
Display --indent 2 --text "- Testing swap partitions" --result "${STATUS_CHECK_NEEDED}" --color YELLOW
2015-12-21 21:17:15 +01:00
LogText "Result: possible incorrect mount options used for mounting swap partition (${FIND})"
2019-12-18 12:17:46 +01:00
#ReportWarning "${TEST_NO}" "Possible incorrect mount options used for swap partition (${FIND})"
ReportSuggestion "${TEST_NO}" "Check your /etc/fstab file for swap partition mount options"
2015-12-21 21:17:15 +01:00
LogText "Notes: usually swap partition have 'sw' or 'swap' in the options field (4th)"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
2016-07-11 16:48:25 +02:00
#
2016-07-11 19:57:45 +02:00
# Test : FILE-6344
# Description : Check proc mount options (Linux >=3.3 only)
2021-06-21 14:53:43 +02:00
# hidepid textual values available kernel >= 5.8 only)
2016-07-11 16:48:25 +02:00
# Examples : proc /proc proc defaults,hidepid=2 0 0
# Goal : Users should not be able to see processes of other users
2016-09-10 16:12:44 +02:00
if [ "${OS}" = "Linux" -a -f ${ROOTDIR}proc/version ]; then
2016-08-25 15:31:33 +02:00
LINUX_KERNEL_MAJOR=$(echo $OS_KERNELVERSION | ${AWKBINARY} -F. '{print $1}')
LINUX_KERNEL_MINOR=$(echo $OS_KERNELVERSION | ${AWKBINARY} -F. '{print $2}')
2019-07-16 13:20:30 +02:00
if [ -n "${LINUX_KERNEL_MAJOR}" -a -n "${LINUX_KERNEL_MINOR}" ]; then
2023-04-26 23:38:42 +02:00
if [ ${LINUX_KERNEL_MAJOR} -ge 3 -a ${LINUX_KERNEL_MINOR} -ge 3 ]; then
PREQS_MET="YES";
elif [ ${LINUX_KERNEL_MAJOR} -ge 4 ]; then
PREQS_MET="YES";
else
PREQS_MET="NO";
fi
2016-07-11 19:57:45 +02:00
else
PREQS_MET="NO";
fi
fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6344 --os Linux --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking proc mount options"
2016-07-11 16:48:25 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
# Proc should be mounted with 'hidepid=2' or 'hidepid=1' at least
2021-06-21 14:53:43 +02:00
# https://www.kernel.org/doc/html/latest/filesystems/proc.html#chapter-4-configuring-procfs
2016-07-11 16:48:25 +02:00
LogText "Test: check proc mount with incorrect mount options"
2023-04-23 23:38:21 +02:00
FIND=$(${MOUNTBINARY} | ${GREPBINARY} -E "${ROOTDIR}proc " | ${GREPBINARY} -E -o "hidepid=([0-9]|[a-z][a-z]*)")
2021-06-21 14:53:43 +02:00
if [ "${FIND}" = "hidepid=4" -o "${FIND}" = "hidepid=ptraceable" ]; then # https://lwn.net/Articles/817137/
2016-09-05 19:28:44 +02:00
Display --indent 2 --text "- Testing /proc mount (hidepid)" --result "${STATUS_OK}" --color GREEN
2021-06-21 14:53:43 +02:00
LogText "Result: proc mount mounted with ${FIND}"
2016-09-05 19:28:44 +02:00
AddHP 3 3
2021-06-21 14:53:43 +02:00
elif [ "${FIND}" = "hidepid=2" -o "${FIND}" = "hidepid=invisible" ]; then
2016-09-05 19:28:44 +02:00
Display --indent 2 --text "- Testing /proc mount (hidepid)" --result "${STATUS_OK}" --color GREEN
2021-06-21 14:53:43 +02:00
LogText "Result: proc mount mounted with ${FIND}"
AddHP 3 3
elif [ "${FIND}" = "hidepid=1" -o "${FIND}" = "hidepid=noaccess" ]; then
Display --indent 2 --text "- Testing /proc mount (hidepid)" --result "${STATUS_OK}" --color GREEN
LogText "Result: proc mount mounted with ${FIND}"
2016-09-05 19:28:44 +02:00
AddHP 2 3
elif [ -z "${FIND}" ]; then
# HIDEPID1_SUGGESTION=" (or at least hidepid=1)"
AddHP 0 3
Display --indent 2 --text "- Testing /proc mount (hidepid)" --result "${STATUS_SUGGESTION}" --color YELLOW
LogText "Result: /proc filesystem is not mounted with option hidepid=1 or hidepid=2"
# TODO ReportSuggestion "${TEST_NO}" "Consider mounting /proc via /etc/fstab with mount option hidepid=2" "/proc" "-"
2016-07-11 16:48:25 +02:00
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FILE-6354
# Description : Search files within /tmp which are older than 3 months
2017-04-30 17:59:35 +02:00
if [ -d ${ROOTDIR}tmp ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6354 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Searching for old files in /tmp"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2017-04-30 17:59:35 +02:00
LogText "Test: Searching for old files in ${ROOTDIR}tmp"
# Search for files only in ${ROOTDIR}tmp, with an access time older than X days
FIND=$(${FINDBINARY} ${ROOTDIR}tmp -xdev -type f -atime +${TMP_OLD_DAYS} 2> /dev/null | ${SEDBINARY} 's/ /!space!/g')
if IsEmpty "${FIND}"; then
Display --indent 2 --text "- Checking for old files in ${ROOTDIR}tmp" --result "${STATUS_OK}" --color GREEN
LogText "Result: no files found in ${ROOTDIR}tmp which are older than 3 months"
2016-09-10 16:12:44 +02:00
else
2017-04-30 17:59:35 +02:00
Display --indent 2 --text "- Checking for old files in ${ROOTDIR}tmp" --result "${STATUS_FOUND}" --color RED
COUNT=0
for ITEM in ${FIND}; do
FILE=$(echo ${ITEM} | ${SEDBINARY} 's/!space!/ /g')
2015-12-21 21:17:15 +01:00
LogText "Old temporary file: ${FILE}"
2017-04-30 17:59:35 +02:00
COUNT=$((COUNT + 1))
2014-08-26 17:33:55 +02:00
done
2017-04-30 17:59:35 +02:00
LogText "Result: found old files in ${ROOTDIR}tmp, which were not modified in the last ${TMP_OLD_DAYS} days"
LogText "Advice: check and clean up unused files in ${ROOTDIR}tmp. Old files can fill up a disk or contain"
2015-12-21 21:17:15 +01:00
LogText "private information and should be deleted it not being used actively. Use a tool like lsof to"
LogText "see which programs possibly are using a particular file. Some systems can cleanup temporary"
LogText "directories by setting a boot option."
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Check ${COUNT} files in ${ROOTDIR}tmp which are older than ${TMP_OLD_DAYS} days"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FILE-6362
# Description : Check for sticky bit on /tmp
2017-04-30 17:59:35 +02:00
if [ -d ${ROOTDIR}tmp -a ! -L ${ROOTDIR}tmp ]; then PREQS_MET="YES"; SKIPREASON=""; else PREQS_MET="NO"; SKIPREASON="No /tmp or /tmp is symlinked"; fi
2016-08-24 11:36:16 +02:00
Register --test-no FILE-6362 --preqs-met ${PREQS_MET} --skip-reason "${SKIPREASON}" --weight L --network NO --category security --description "Checking /tmp sticky bit"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
# Depending on OS, number of field with 'tmp' differs
2017-04-30 17:59:35 +02:00
FIND=$(${LSBINARY} -ld ${ROOTDIR}tmp | ${AWKBINARY} '$1 ~ /[tT]/ { print 1 }')
2016-08-24 11:36:16 +02:00
if [ "${FIND}" = "1" ]; then
2017-04-30 17:59:35 +02:00
Display --indent 2 --text "- Checking ${ROOTDIR}tmp sticky bit" --result "${STATUS_OK}" --color GREEN
LogText "Result: sticky bit found on ${ROOTDIR}tmp directory"
2014-08-26 17:33:55 +02:00
AddHP 3 3
2016-08-24 11:36:16 +02:00
else
2017-04-30 17:59:35 +02:00
Display --indent 2 --text "- Checking ${ROOTDIR}tmp sticky bit" --result "${STATUS_WARNING}" --color RED
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Set the sticky bit on ${ROOTDIR}tmp, to prevent users deleting (by other owned) files in the /tmp directory." "/tmp" "text:Set sticky bit"
2014-08-26 17:33:55 +02:00
AddHP 0 3
fi
2016-08-24 11:36:16 +02:00
unset FIND
else
LogText "Result: Sticky bit test (on /tmp) skipped. Possible reason: missing directory, or symlinked directory, or test skipped."
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
2018-01-24 17:08:21 +01:00
#
# Test : FILE-6363
# Description : Check for sticky bit on /var/tmp
if [ -d ${ROOTDIR}var/tmp -a ! -L ${ROOTDIR}var/tmp ]; then PREQS_MET="YES"; SKIPREASON=""; else PREQS_MET="NO"; SKIPREASON="No /var/tmp or /var/tmp is symlinked"; fi
Register --test-no FILE-6363 --preqs-met ${PREQS_MET} --skip-reason "${SKIPREASON}" --weight L --network NO --category security --description "Checking /var/tmp sticky bit"
if [ ${SKIPTEST} -eq 0 ]; then
# Depending on OS, number of field with 'tmp' differs
FIND=$(${LSBINARY} -ld ${ROOTDIR}var/tmp | ${AWKBINARY} '$1 ~ /[tT]/ { print 1 }')
if [ "${FIND}" = "1" ]; then
Display --indent 2 --text "- Checking ${ROOTDIR}var/tmp sticky bit" --result "${STATUS_OK}" --color GREEN
LogText "Result: sticky bit found on ${ROOTDIR}var/tmp directory"
AddHP 3 3
else
Display --indent 2 --text "- Checking ${ROOTDIR}var/tmp sticky bit" --result "${STATUS_WARNING}" --color RED
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Set the sticky bit on ${ROOTDIR}var/tmp, to prevent users deleting (by other owned) files in the /var/tmp directory." "/var/tmp" "text:Set sticky bit"
2018-01-24 17:08:21 +01:00
AddHP 0 3
fi
unset FIND
else
LogText "Result: Sticky bit test (on /var/tmp) skipped. Possible reason: missing directory, or symlinked directory, or test skipped."
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FILE-6366
# Description : Check for noatime option
# More info : especially useful for profile 'desktop' and 'server-storage'
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : FILE-6368
# Description : Checking Linux root file system ACL support
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6368 --os Linux --weight L --network NO --root-only YES --category security --description "Checking ACL support on root file system"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
FOUND=0
2016-05-11 15:16:28 +02:00
LogText "Test: Checking acl option on ext[2-4] root file system"
2016-09-10 16:12:44 +02:00
FIND=$(${MOUNTBINARY} | ${AWKBINARY} '{ if ($3=="/" && $5~/ext[2-4]/) { print $6 } }' | ${GREPBINARY} acl)
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found ACL option"
2014-08-26 17:33:55 +02:00
FOUND=1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: mount point probably mounted with defaults"
LogText "Test: Checking device which holds root file system"
2014-08-26 17:33:55 +02:00
# Get device on which root file system is mounted. Use /dev/root if it exists, or
# else check output of mount
2016-09-10 16:12:44 +02:00
if [ -b ${ROOTDIR}dev/root ]; then
FIND1="${ROOTDIR}dev/root"
else
2014-10-30 18:09:03 +01:00
# Only determine device if it is EXT2/3/4
2017-03-06 08:41:21 +01:00
#FIND1=$(mount | ${GREPBINARY} "on / " | ${AWKBINARY} '{ if ($5~/ext[2-4]/) { print $1 }}')
2016-09-10 16:12:44 +02:00
FIND1=$(${MOUNTBINARY} -t ext2,ext3,ext4 | ${GREPBINARY} "on / " | ${AWKBINARY} '{ print $1 }')
2014-08-26 17:33:55 +02:00
fi
2014-10-30 18:09:03 +01:00
# Trying to determine default mount options from EXT2/EXT3/EXT4 file systems
2019-07-16 13:20:30 +02:00
if [ -n "${FIND1}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found ${FIND1}"
LogText "Test: Checking default options on ${FIND1}"
2016-09-10 16:12:44 +02:00
FIND2=$(${TUNE2FSBINARY} -l ${FIND1} 2> /dev/null | ${GREPBINARY} "^Default mount options" | ${GREPBINARY} "acl")
2019-07-16 13:20:30 +02:00
if [ -n "${FIND2}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found ACL option in default mount options"
2014-08-26 17:33:55 +02:00
FOUND=1
2017-04-30 17:59:35 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no ACL option found in default mount options list"
2014-08-26 17:33:55 +02:00
fi
2017-04-30 17:59:35 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: No file system found with root file system"
2014-08-26 17:33:55 +02:00
fi
fi
2016-05-11 15:16:28 +02:00
LogText "Test: Checking acl option on xfs root file system"
2023-04-23 23:38:21 +02:00
FIND=$(${MOUNTBINARY} | ${AWKBINARY} '{ if ($3=="/" && $5~/xfs/) { print $6 } }' | ${GREPBINARY} -E 'no_acl|no_user_xattr')
2016-09-10 16:12:44 +02:00
if [ -z "${FIND}" ]; then
2016-05-11 15:16:28 +02:00
FOUND=1
# some other tests to do ?
fi
2014-08-26 17:33:55 +02:00
if [ ${FOUND} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: ACL option NOT enabled on root file system"
LogText "Additional information: if file access need to be more restricted, ACLs could be used. Install the acl utilities and remount the file system with the acl option"
LogText "Activate acl support on and active file system with mount -o remount,acl / and add the acl option to the fstab file"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- ACL support root file system" --result "${STATUS_DISABLED}" --color YELLOW
2014-08-26 17:33:55 +02:00
AddHP 0 1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: ACL option enabled on root file system"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- ACL support root file system" --result "${STATUS_ENABLED}" --color GREEN
2014-08-26 17:33:55 +02:00
AddHP 3 3
fi
fi
#
#################################################################################
#
# Test : FILE-6372
# Description : Check / mount options for Linux
# Notes :
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6372 --os Linux --weight L --network NO --category security --description "Checking / mount options"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2017-03-01 16:11:17 +01:00
if [ -f ${ROOTDIR}etc/fstab ]; then
FIND=$(${GREPBINARY} -w "/" ${ROOTDIR}etc/fstab | ${GREPBINARY} -v "^#" | ${CUTBINARY} -f1 -d"#" | ${AWKBINARY} '{ if ($2=="/") { print $4 }}')
2016-08-25 15:31:33 +02:00
NODEV=$(echo ${FIND} | ${AWKBINARY} '{ if ($1 ~ "nodev") { print "YES" } else { print "NO" } }')
NOEXEC=$(echo ${FIND} | ${AWKBINARY} '{ if ($1 ~ "noexec") { print "YES" } else { print "NO" } }')
NOSUID=$(echo ${FIND} | ${AWKBINARY} '{ if ($1 ~ "nosuid") { print "YES" } else { print "NO" } }')
2014-08-26 17:33:55 +02:00
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: mount system / is configured with options: ${FIND}"
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "defaults" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Mount options of /" --result "${STATUS_OK}" --color GREEN
2016-07-31 17:35:35 +02:00
else
2021-01-05 11:53:11 +01:00
Display --indent 2 --text "- Mount options of /" --result "${STATUS_NON_DEFAULT}" --color YELLOW
2014-08-26 17:33:55 +02:00
fi
2017-03-01 16:11:17 +01:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no mount point / or expected options found"
2014-08-26 17:33:55 +02:00
fi
fi
fi
#
#################################################################################
#
# Test : FILE-6374
2015-09-03 15:44:10 +02:00
# Description : Check mount options for Linux
# Notes : This test determines if the mount point exists. If it does not exist as mount point, yet it is an directory,
# you might consider to make it a separate mount point with restrictions.
#
# Depending on the primary goals of a machine, some mount points might be too restrictive. Before applying any
# mount flags, test them on a similar or cloned test system.
#
# ---------------------------------------------------------
# Mount point nodev noexec nosuid
# /boot v v v
2020-03-19 15:31:20 +01:00
# /dev v v
2016-05-11 15:57:36 +02:00
# /dev/shm v v v
2015-09-03 15:44:10 +02:00
# /home v v
2020-03-19 15:31:20 +01:00
# /run v v
2015-09-03 15:44:10 +02:00
# /tmp v v v
2020-03-19 15:31:20 +01:00
# /var v v
2015-09-03 15:44:10 +02:00
# /var/log v v v
# /var/log/audit v v v
2016-05-11 15:57:36 +02:00
# /var/tmp v v v
2015-09-03 15:44:10 +02:00
# ---------------------------------------------------------
2020-03-19 15:31:20 +01:00
FILESYSTEMS_TO_CHECK="/boot:nodev,noexec,nosuid /dev:noexec,nosuid /dev/shm:nosuid,nodev,noexec /home:nodev,nosuid /run:nodev,nosuid /tmp:nodev,noexec,nosuid /var:nodev,nosuid /var/log:nodev,noexec,nosuid /var/log/audit:nodev,noexec,nosuid /var/tmp:nodev,noexec,nosuid"
2019-10-08 15:10:02 +02:00
Register --test-no FILE-6374 --os Linux --weight L --network NO --category security --description "Linux mount options"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2019-09-12 16:34:45 +02:00
if [ -f ${ROOTDIR}etc/fstab ]; then
2015-09-03 15:44:10 +02:00
for I in ${FILESYSTEMS_TO_CHECK}; do
2016-09-08 21:04:17 +02:00
FILESYSTEM=$(echo ${I} | ${CUTBINARY} -d: -f1)
EXPECTED_FLAGS=$(echo ${I} | ${CUTBINARY} -d: -f2 | ${SEDBINARY} 's/,/ /g')
2019-04-08 11:07:41 +02:00
FS_FSTAB=$(${AWKBINARY} -v fs=${FILESYSTEM} '{ if ($2==fs) { print $3 } }' ${ROOTDIR}etc/fstab)
2016-08-29 19:30:48 +02:00
if [ "${FS_FSTAB}" = "glusterfs" ]; then
2016-09-08 21:04:17 +02:00
EXPECTED_FLAGS=$(echo ${EXPECTED_FLAGS} | ${SEDBINARY} 's/\<\(nodev\|nosuid\)\> *//g')
2016-09-10 16:12:44 +02:00
if [ -z "${EXPECTED_FLAGS}" ]; then
2016-08-29 19:30:48 +02:00
FS_FSTAB=""
fi
fi
2020-04-01 16:18:03 +02:00
if [ -z "${FS_FSTAB}" ]; then # not found in fstab, check if mounted otherwise
2020-03-19 15:31:20 +01:00
FS_FSTAB=$(mount | ${AWKBINARY} -v fs=${FILESYSTEM} '{ if ($3==fs) { print $6 } }')
FOUND_FLAGS=$(mount | ${AWKBINARY} -v fs=${FILESYSTEM} '{ if ($1~"[^#]" && $3==fs) { print $6 } }' | ${SEDBINARY} 's/,/ /g' | ${TRBINARY} '\n' ' ')
else
FOUND_FLAGS=$(${AWKBINARY} -v fs=${FILESYSTEM} '{ if ($1~"[^#]" && $2==fs) { print $4 } }' ${ROOTDIR}etc/fstab | ${SEDBINARY} 's/,/ /g' | ${TRBINARY} '\n' ' ')
fi
2019-07-16 13:20:30 +02:00
if [ -n "${FS_FSTAB}" ]; then
2019-09-12 16:34:45 +02:00
# In awk using caret/circumflex as first character between brackets, means 'not' (instead of beginning of line)
2015-12-21 21:17:15 +01:00
LogText "File system: ${FILESYSTEM}"
LogText "Expected flags: ${EXPECTED_FLAGS}"
LogText "Found flags: ${FOUND_FLAGS}"
2015-09-03 15:44:10 +02:00
PARTIALLY_HARDENED=0
FULLY_HARDENED=1
for FLAG in ${EXPECTED_FLAGS}; do
2017-03-06 08:41:21 +01:00
FLAG_AVAILABLE=$(echo ${FOUND_FLAGS} | ${GREPBINARY} ${FLAG})
2019-04-08 11:07:41 +02:00
if [ -z "${FLAG_AVAILABLE}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Could not find mount option ${FLAG} on file system ${FILESYSTEM}"
2015-09-03 15:44:10 +02:00
FULLY_HARDENED=0
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: GOOD, found mount option ${FLAG} on file system ${FILESYSTEM}"
2015-09-03 15:44:10 +02:00
PARTIALLY_HARDENED=1
fi
done
if [ ${FULLY_HARDENED} -eq 1 ]; then
2019-09-12 16:34:45 +02:00
LogText "Result: marked ${FILESYSTEM} as fully hardened"
2021-03-02 23:31:41 +01:00
Display --indent 2 --text "- Mount options of ${FILESYSTEM}" --result "${STATUS_HARDENED}" --color GREEN
2015-09-03 15:44:10 +02:00
AddHP 5 5
elif [ ${PARTIALLY_HARDENED} -eq 1 ]; then
2019-09-12 16:34:45 +02:00
LogText "Result: marked ${FILESYSTEM} as partially hardened"
2021-03-02 23:31:41 +01:00
Display --indent 2 --text "- Mount options of ${FILESYSTEM}" --result "${STATUS_PARTIALLY_HARDENED}" --color YELLOW
2014-08-26 17:33:55 +02:00
AddHP 4 5
2015-09-03 15:44:10 +02:00
else
2019-09-12 16:34:45 +02:00
if ContainsString "defaults" "${FOUND_FLAGS}"; then
LogText "Result: marked ${FILESYSTEM} options as default (not hardened)"
2021-01-05 11:53:11 +01:00
Display --indent 2 --text "- Mount options of ${FILESYSTEM}" --result "${STATUS_DEFAULT}" --color YELLOW
2015-09-03 15:44:10 +02:00
AddHP 3 5
2016-09-10 16:12:44 +02:00
else
2019-09-12 16:34:45 +02:00
LogText "Result: marked ${FILESYSTEM} options as non-default (unclear about hardening)"
2021-01-05 11:53:11 +01:00
Display --indent 2 --text "- Mount options of ${FILESYSTEM}" --result "${STATUS_NON_DEFAULT}" --color YELLOW
2015-09-03 15:44:10 +02:00
AddHP 4 5
fi
2014-08-26 17:33:55 +02:00
fi
2017-04-30 17:59:35 +02:00
else
2019-09-12 16:34:45 +02:00
LogText "Result: file system ${FILESYSTEM} not found in ${ROOTDIR}etc/fstab"
2014-08-26 17:33:55 +02:00
fi
2015-09-03 15:44:10 +02:00
done
2014-08-26 17:33:55 +02:00
fi
2020-10-19 15:02:48 +02:00
NMOUNTS=$(mount | ${WCBINARY} -l)
NDEVMOUNTS=$(mount | ${AWKBINARY} '{print $6}' | ${GREPBINARY} -v nodev | ${WCBINARY} -l)
NEXECMOUNTS=$(mount | ${AWKBINARY} '{print $6}' | ${GREPBINARY} -v noexec | ${WCBINARY} -l)
NSUIDMOUNTS=$(mount | ${AWKBINARY} '{print $6}' | ${GREPBINARY} -v nosuid | ${WCBINARY} -l)
2023-04-23 23:38:21 +02:00
NWRITEANDEXECMOUNTS=$(mount | ${AWKBINARY} '{print $6}' | ${GREPBINARY} -v noexec | ${GREPBINARY} -E -v '^\(ro[,)]' | ${WCBINARY} -l)
2020-03-25 08:18:16 +01:00
LogText "Result: Total without nodev:${NDEVMOUNTS} noexec:${NEXECMOUNTS} nosuid:${NSUIDMOUNTS} ro or noexec (W^X): ${NWRITEANDEXECMOUNTS}, of total ${NMOUNTS}"
Display --indent 2 --text "- Total without nodev:${NDEVMOUNTS} noexec:${NEXECMOUNTS} nosuid:${NSUIDMOUNTS} ro or noexec (W^X): ${NWRITEANDEXECMOUNTS} of total ${NMOUNTS}"
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
2016-05-11 15:20:08 +02:00
#
2016-05-11 15:57:36 +02:00
# Test : FILE-6376
2016-05-11 15:20:08 +02:00
# Description : Bind mount the /var/tmp directory to /tmp
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6376 --os Linux --weight L --network NO --category security --description "Determine if /var/tmp is bound to /tmp"
2016-05-11 15:20:08 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2017-04-30 17:59:35 +02:00
if [ -f ${ROOTDIR}etc/fstab ]; then
FIND=$(${AWKBINARY} '{ if ($2=="/var/tmp") { print $4 } }' ${ROOTDIR}etc/fstab)
2016-08-25 15:31:33 +02:00
BIND=$(echo ${FIND} | ${AWKBINARY} '{ if ($1 ~ "bind") { print "YES" } else { print "NO" } }')
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2016-05-11 15:20:08 +02:00
LogText "Result: mount system /var/tmp is configured with options: ${FIND}"
if [ "${BIND}" = "YES" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- /var/tmp is bound to /tmp" --result "${STATUS_OK}" --color GREEN
2016-05-11 15:20:08 +02:00
LogText "Result : /var/tmp is bind to /tmp"
2016-09-10 16:12:44 +02:00
else
2021-01-05 11:53:11 +01:00
Display --indent 2 --text "- /var/tmp is not bound to /tmp" --result "${STATUS_NON_DEFAULT}" --color YELLOW
2016-05-11 15:20:08 +02:00
LogText "Result: /var/tmp is not bind to /tmp"
fi
2016-09-10 16:12:44 +02:00
else
2016-05-11 15:20:08 +02:00
LogText "Result: no mount point /var/tmp or expected options found"
2016-05-11 15:57:36 +02:00
if IsVerbose; then Display --indent 2 --text "- /var/tmp is not bound to /tmp" --result "INFO" --color WHITE; fi
2016-05-11 15:20:08 +02:00
fi
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6378 TODO
2014-08-26 17:33:55 +02:00
# Description : Check for nodirtime option
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6380 TODO
2014-08-26 17:33:55 +02:00
# Description : Check for relatime
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6390 TODO
2014-08-26 17:33:55 +02:00
# Description : Check writeback/journalling mode (ext3)
# More info : data=writeback | data=ordered | data=journal
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2020-03-28 20:23:00 +01:00
# Test : FILE-6394
2014-08-26 17:33:55 +02:00
# Description : Check vm.swappiness (Linux)
2020-03-28 20:23:00 +01:00
Register --test-no FILE-6394 --os Linux --weight L --network NO --category security --description "Determine level of swappiness."
if [ ${SKIPTEST} -eq 0 ]; then
SWAPLEVEL=$(${CAT_BINARY} /proc/sys/vm/swappiness)
LogText "Test: checking level of vm.swappiness: ${SWAPLEVEL}"
2020-04-01 16:18:03 +02:00
PHYSDISK=$(${LSBLKBINARY} | ${GREPBINARY} -E 'disk|SWAP' | ${GREPBINARY} -B1 SWAP | ${HEADBINARY} -n1 | ${AWKBINARY} '{print $1}')
2020-03-28 20:23:00 +01:00
if [ ${SWAPLEVEL} -gt 60 ]; then
LogText "Result: vm.swappiness=${SWAPLEVEL} meaning that swapping is more frequent than default."
2020-04-01 16:18:03 +02:00
# Check if swap is on a HDD or SDD for frequent swapping
if [ -d "/sys/block/${PHYSDISK}" ]; then
HDDORSDD=$(${CAT_BINARY} "/sys/block/${PHYSDISK}/queue/rotational")
2020-03-28 20:23:00 +01:00
if [ ${HDDORSDD} -eq 1 ]; then
ReportSuggestion "${TEST_NO}" "vm.swappiness set to: ${SWAPLEVEL} > 60 (default) - consider installing an SSD for swap partition for better performance."
fi
fi
elif [ ${SWAPLEVEL} -eq 0 ]; then
LogText "Result: vm.swappiness=${SWAPLEVEL} meaning swapping is disabled."
ReportSuggestion "${TEST_NO}" "vm.swappiness set to: ${SWAPLEVEL}. Consider setting value to minimum of 1 for minimizing swappiness, but not quite disabling it. Will prevent OOM killer from killing processes when running out of physical memory."
2020-04-01 16:18:03 +02:00
elif [ ${SWAPLEVEL} -eq 1 ]; then
2020-03-28 20:23:00 +01:00
LogText "Result: vm.swappiness=${SWAPLEVEL} meaning that swapping can still occur but at very minimum."
elif [ ${SWAPLEVEL} -eq 10 ]; then
LogText "Result: vm.swappiness=${SWAPLEVEL} which is the preferred setting for database servers."
elif [ ${SWAPLEVEL} -lt 60 ]; then
LogText "Result: vm.swappiness=${SWAPLEVEL} meaning that swapping is less frequent than default. This is only recommended for servers."
else
LogText "Result: vm.swappiness=${SWAPLEVEL} which is the standard level of swappiness and works well for desktop systems."
fi
2020-04-01 16:18:03 +02:00
if IsVerbose; then Display --indent 2 --text "- Swappiness: ${SWAPLEVEL}" --result "INFO" --color WHITE; fi
2020-03-28 20:23:00 +01:00
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2021-05-15 21:22:17 +02:00
# Test : FILE-6398
2014-08-26 17:33:55 +02:00
# Description : Check if JBD (Journal Block Device) driver is loaded
2021-05-15 21:22:17 +02:00
Register --test-no FILE-6398 --os Linux --weight L --network NO --category security --description "Checking if JBD (Journal Block Device) driver is loaded"
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking if JBD (Journal Block Device) driver is loaded"
NOTINUSE=0
2024-09-30 12:00:55 +02:00
# Only perform testing if we know that KRNL-5723 performed tests
if [ ${MONOLITHIC_KERNEL_TESTED} -eq 1 ]; then
# Cannot check if driver is loaded/present if kernel is monolithic
if [ ${MONOLITHIC_KERNEL} -eq 0 ]; then
JBD=$(${LSMODBINARY} | ${GREPBINARY} ^jbd)
if [ -n "${JBD}" ]; then
LogText "Result: JBD driver is loaded"
INUSE=$(echo ${JBD} | ${AWKBINARY} '{if ($3 -ne 0) {print $4}}')
if [ -n "${INUSE}" ]; then
LogText "Result: JBD driver is in use by drivers: ${INUSE}"
Report "JBD driver is in use by drivers: ${INUSE}"
Display --indent 2 --text "- JBD driver loaded and in use" --result "${STATUS_OK}" --color GREEN
else
NOTINUSE=1
LogText "Result: JBD driver loaded, but not in use"
Report "JBD driver is loaded, but not in use."
Display --indent 2 --text "- JBD driver loaded, but not in use" --result "${STATUS_SUGGESTION}" --color YELLOW
fi
2021-05-15 21:22:17 +02:00
else
2024-09-30 12:00:55 +02:00
NOTINUSE=2
LogText "Result: JBD driver not loaded"
Report "JBD driver not loaded."
Display --indent 2 --text "- JBD driver is not loaded" --result "${STATUS_CHECK_NEEDED}" --color YELLOW
fi
if [ ${NOTINUSE} -eq 1 ]; then
ReportSuggestion "${TEST_NO}" "The JBD (Journal Block Device) driver is loaded but not in use." "You are currently not using any filesystems with journaling, i.e. you have greater risk of data corruption in case of system crash."
elif [ ${NOTINUSE} -eq 2 ]; then
ReportSuggestion "${TEST_NO}" "The JBD (Journal Block Device) driver is not loaded." "Since boot-time, you have not been using any filesystems with journaling. Alternatively, reason could be driver is blacklisted."
2021-05-15 21:22:17 +02:00
fi
else
2024-09-30 12:00:55 +02:00
Display --indent 2 --text "- JBD driver: unable to check" --result "${STATUS_UNKNOWN}" --color YELLOW
LogText "Kernel is monolithic - cannot check if JBD driver is part of compiled kernel."
2021-05-15 21:22:17 +02:00
fi
else
2024-09-30 12:00:55 +02:00
Display --indent 2 --text "- JBD driver: test skipped" --result "${STATUS_UNKNOWN}" --color YELLOW
LogText "Test skipped as the kernel type (monolithic/modular) is unknown"
2021-05-15 21:22:17 +02:00
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : FILE-6410
# Description : Checking locate database (file index)
# Notes : Linux /var/lib/mlocate/mlocate.db or /var/lib/slocate/slocate.db
# or /var/cache/locate/locatedb
# FreeBSD /var/db/locate.database
if [ ! "${LOCATEBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6410 --preqs-met ${PREQS_MET} --os Linux --weight L --network NO --category security --description "Checking Locate database"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking locate database"
2014-08-26 17:33:55 +02:00
FOUND=0
2022-05-15 23:58:43 +02:00
LOCATE_DBS="${ROOTDIR}var/cache/locate/locatedb ${ROOTDIR}var/db/locate.database ${ROOTDIR}var/lib/locate/locatedb ${ROOTDIR}var/lib/locatedb ${ROOTDIR}var/lib/mlocate/mlocate.db ${ROOTDIR}var/lib/plocate/plocate.db ${ROOTDIR}var/lib/slocate/slocate.db"
2017-04-30 17:59:35 +02:00
for FILE in ${LOCATE_DBS}; do
if [ -f ${FILE} ]; then
LogText "Result: locate database found (${FILE})"
2014-08-26 17:33:55 +02:00
FOUND=1
2017-04-30 17:59:35 +02:00
LOCATE_DB="${FILE}"
else
LogText "Result: file ${FILE} not found"
2014-08-26 17:33:55 +02:00
fi
done
if [ ${FOUND} -eq 1 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Locate database" --result "${STATUS_FOUND}" --color GREEN
2015-12-21 21:17:15 +01:00
Report "locate_db=${LOCATE_DB}"
2017-04-30 17:59:35 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: database not found"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking Locate database" --result "${STATUS_NOT_FOUND}" --color YELLOW
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "The database required for 'locate' could not be found. Run 'updatedb' or 'locate.updatedb' to create this file."
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6420 TODO
2014-08-26 17:33:55 +02:00
# Description : Check automount process
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6422 TODO
2014-08-26 17:33:55 +02:00
# Description : Check automount maps (files or for example LDAP based)
# Notes : Warn when automounter is running
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6424 TODO
2014-08-26 17:33:55 +02:00
# Description : Check automount map files
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2017-04-30 17:59:35 +02:00
# Test : FILE-6425 TODO
2014-08-26 17:33:55 +02:00
# Description : Check mounted files systems via automounter
# Notes : Warn when no systems are mounted?
2016-05-11 16:02:46 +02:00
# Want to contribute to Lynis? Create this test
2016-07-11 10:24:38 +02:00
#
#################################################################################
#
# Test : FILE-6430
2016-07-11 11:18:53 +02:00
# Description : Disable mounting of some filesystems
# Rationale : Unless there is a specific reason to use a particular file system, disable it.
2019-12-18 19:20:48 +01:00
# Data : cramfs freevxfs hfs hfsplus jffs2 squashfs udf
2016-07-24 17:22:00 +02:00
Register --test-no FILE-6430 --weight L --network NO --category security --description "Disable mounting of some filesystems"
2016-07-11 10:24:38 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2019-07-16 13:20:30 +02:00
if [ -n "${LSMODBINARY}" -a -f /proc/modules ]; then
2016-07-11 19:57:45 +02:00
Display --indent 2 --text "- Disable kernel support of some filesystems"
2016-07-11 11:18:53 +02:00
LIST_FS_NOT_SUPPORTED="cramfs freevxfs hfs hfsplus jffs2 squashfs udf"
2016-07-11 19:57:45 +02:00
FOUND=0
AVAILABLE_FS=""
2016-07-30 16:41:11 +02:00
AVAILABLE_MODPROBE_FS=""
2016-07-11 10:24:38 +02:00
for FS in ${LIST_FS_NOT_SUPPORTED}; do
2016-07-11 19:57:45 +02:00
# Check if filesystem is present in modprobe output
2023-04-23 23:38:21 +02:00
FIND=$(${MODPROBEBINARY} -v -n ${FS} 2>/dev/null | ${GREPBINARY} -E "/${FS}.ko" | ${TAILBINARY} -1)
2019-07-16 13:20:30 +02:00
if [ -n "${FIND}" ]; then
2019-12-18 19:20:48 +01:00
LogText "Result: found ${FS} support in the kernel (output = ${FIND})"
2016-07-11 19:57:45 +02:00
Debug "Module ${FS} present in the kernel"
LogText "Test: Checking if ${FS} is active"
# Check if FS is present in lsmod output
2023-04-23 23:38:21 +02:00
FIND=$(${LSMODBINARY} | ${GREPBINARY} -E "^${FS}")
2017-04-30 17:59:35 +02:00
if IsEmpty "${FIND}"; then
2019-12-18 19:20:48 +01:00
LogText "Result: module ${FS} is currently not loaded in the kernel."
2016-07-11 19:57:45 +02:00
AddHP 2 3
2017-04-30 17:59:35 +02:00
if IsDebug; then Display --indent 6 --text "- Module ${FS} not loaded (lsmod)" --result OK --color GREEN; fi
2016-07-11 19:57:45 +02:00
else
LogText "Result: module ${FS} is loaded in the kernel"
Display --indent 4 --text "- Module $FS loaded in the kernel (lsmod)" --result "FOUND" --color WHITE
2021-01-08 00:29:06 +01:00
FOUND=1
AVAILABLE_MODPROBE_FS="${AVAILABLE_MODPROBE_FS}${FS} "
2016-07-11 19:57:45 +02:00
fi
2016-07-11 10:24:38 +02:00
else
2016-07-11 19:57:45 +02:00
AddHP 3 3
2017-04-30 17:59:35 +02:00
if IsDebug; then Display --indent 6 --text "- Module ${FS} not present in the kernel" --result OK --color GREEN; fi
2016-07-11 10:24:38 +02:00
fi
2020-07-02 18:22:03 +02:00
FIND=$(${LSBINARY} ${ROOTDIR}etc/modprobe.d/* 2> /dev/null)
if [ -n "${FIND}" ]; then
2024-05-24 08:18:16 +02:00
FIND1=$(${GREPBINARY} -E "^blacklist[[:space:]]+${FS}$" ${ROOTDIR}etc/modprobe.d/* | ${GREPBINARY} -v "#")
FIND2=$(${GREPBINARY} -E "^install[[:space:]]+${FS}[[:space:]]+/bin/(true|false)$" ${ROOTDIR}etc/modprobe.d/* | ${GREPBINARY} -v "#")
2021-10-26 10:53:33 +02:00
if [ -n "${FIND1}" ] || [ -n "${FIND2}" ]; then
Display --indent 4 --text "- Module $FS is blacklisted" --result "OK" --color GREEN
LogText "Result: module ${FS} is blacklisted"
fi
fi
2016-07-11 10:24:38 +02:00
done
2016-07-11 19:57:45 +02:00
if [ ${FOUND} -eq 1 ]; then
Display --indent 4 --text "- Discovered kernel modules: ${AVAILABLE_MODPROBE_FS}"
2019-12-18 19:20:48 +01:00
ReportSuggestion "${TEST_NO}" "Consider disabling unused kernel modules" "/etc/modprobe.d/blacklist.conf" "Add 'install MODULENAME /bin/true' (without quotes)"
2016-07-11 19:57:45 +02:00
fi
2016-07-11 10:24:38 +02:00
else
LogText "Test skipped lsmod binary not found or /proc/modules can not be opened"
fi
2016-07-30 16:41:11 +02:00
unset AVAILABLE_FS AVAILABLE_MODPROBE_FS
2016-07-11 10:24:38 +02:00
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
2016-04-28 12:31:57 +02:00
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#================================================================================
2016-03-13 16:03:46 +01:00
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com