2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
2020-03-20 14:50:25 +01:00
# Copyright 2007-2020, 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.
#
#################################################################################
#
# Home directories
#
#################################################################################
#
InsertSection "Home directories"
#
#################################################################################
#
# Ignore some top level directories (not the sub directories below)
IGNORE_HOME_DIRS="/bin /boot /cdrom /dev /etc /home /lib /lib64 /media /mnt
/opt /proc /sbin /selinux /srv /sys /tmp /usr /var"
#
#################################################################################
#
# Test : HOME-9302
# Description : Create list with home directories
2016-07-24 17:22:00 +02:00
Register --test-no HOME-9302 --weight L --network NO --category security --description "Create list with home directories"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-15 12:01:09 +02:00
# Read sixth field of /etc/passwd
2019-07-14 13:27:08 +02:00
LogText "Test: query ${ROOTDIR}etc/passwd to obtain home directories"
FIND=$(${AWKBINARY} -F: '{ if ($1 !~ "#") print $6 }' ${ROOTDIR}etc/passwd | ${SORTBINARY} -u)
2014-09-15 12:01:09 +02:00
for I in ${FIND}; do
if [ -d ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found home directory: ${I} (directory exists)"
Report "home_directory[]=${I}"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: found home directory: ${I} (directory does not exist)"
2014-09-15 12:01:09 +02:00
fi
done
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
2019-03-25 13:44:25 +01:00
#
# Test : HOME-9304
# Description : Check if users' home directories permissions are 750 or more restrictive
Register --test-no HOME-9304 --weight L --network NO --category security --description "Check if users' home directories permissions are 750 or more restrictive"
if [ ${SKIPTEST} -eq 0 ]; then
# Check if users' home directories permissions are 750 or more restrictive
FOUND=0
2019-10-16 16:14:44 +02:00
USERDATA=$(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }')
2019-12-06 15:35:46 +01:00
while read -r LINE; do
2019-03-25 13:44:25 +01:00
USER=$(echo ${LINE} | ${CUTBINARY} -d: -f1)
2019-12-13 12:59:43 +01:00
DIR=$(echo ${LINE} | ${CUTBINARY} -d: -f6)
LogText "Test: checking directory '${DIR}' for user '${USER}'"
2019-07-26 11:59:03 +02:00
if [ -d "${DIR}" ]; then
WRITE_GROUP_PERM=$(${LSBINARY} -ld ${DIR} | ${CUTBINARY} -f1 -d" " | ${CUTBINARY} -c6)
OTHER_PERMS=$(${LSBINARY} -ld ${DIR} | ${CUTBINARY} -f1 -d" " | ${CUTBINARY} -c8-10)
2019-03-25 13:44:25 +01:00
if [ ! ${WRITE_GROUP_PERM} = "-" -o ! ${OTHER_PERMS} = "---" ]; then
2019-07-26 11:59:03 +02:00
LogText "Result: permissions of home directory ${DIR} of user ${USER} are not strict enough. Should be 750 or more restrictive. Change with: chmod 750 ${DIR}"
2019-03-25 13:44:25 +01:00
FOUND=1
2019-07-26 11:59:03 +02:00
else
LogText "Result: permissions of home directory ${DIR} of user ${USER} are fine"
2019-03-25 13:44:25 +01:00
fi
fi
2019-10-16 16:14:44 +02:00
done << EOF
2019-12-06 15:35:46 +01:00
${USERDATA}
2019-10-16 16:14:44 +02:00
EOF
2019-07-14 13:27:08 +02:00
2019-03-25 13:44:25 +01:00
if [ ${FOUND} -eq 1 ]; then
2019-07-26 11:59:03 +02:00
Display --indent 2 --text "- Permissions of home directories" --result "${STATUS_WARNING}" --color RED
2019-12-13 12:59:43 +01:00
ReportSuggestion "${TEST_NO}" "Double check the permissions of home directories as some might be not strict enough."
2019-03-25 13:44:25 +01:00
else
2019-07-26 11:59:03 +02:00
Display --indent 2 --text "- Permissions of home directories" --result "${STATUS_OK}" --color GREEN
2019-12-13 12:59:43 +01:00
LogText "Result: OK, all permissions of the home directories are 750 or more restrictive"
2019-03-25 13:44:25 +01:00
fi
fi
#
#################################################################################
#
# Test : HOME-9306
# Description : Check if users own their home directories
Register --test-no HOME-9306 --weight L --network NO --category security --description "Check if users own their home directories"
if [ ${SKIPTEST} -eq 0 ]; then
# Check if users own their home directories
FOUND=0
2019-12-06 15:35:46 +01:00
USERDATA=$(${EGREPBINARY} -v '^(daemon|git|halt|root|shutdown|sync)' ${ROOTDIR}etc/passwd | ${AWKBINARY} -F: '($7 !~ "/(false|nologin)$") { print }')
while read -r LINE; do
2019-03-25 13:44:25 +01:00
USER=$(echo ${LINE} | ${CUTBINARY} -d: -f1)
2019-12-13 12:59:43 +01:00
DIR=$(echo ${LINE} | ${CUTBINARY} -d: -f6)
LogText "Test: checking directory '${DIR}' for user '${USER}'"
if [ -d "${DIR}" ]; then
2019-03-25 13:44:25 +01:00
OWNER=$(ls -ld ${DIR} | awk -F" " '{ print $3 }')
2019-07-26 11:59:03 +02:00
if [ ! "${OWNER}" = "${USER}" ]; then
2019-12-13 12:59:43 +01:00
LogText "Result: the home directory ${DIR} of user ${USER} is owned by ${OWNER}. Correct: chown ${USER} ${DIR}"
2019-03-25 13:44:25 +01:00
FOUND=1
2019-07-26 11:59:03 +02:00
else
LogText "Result: ownership of home directory ${DIR} for user ${USER} looks to be correct"
2019-03-25 13:44:25 +01:00
fi
fi
2019-10-16 16:14:44 +02:00
done << EOF
2019-12-06 15:35:46 +01:00
${USERDATA}
2019-10-16 16:14:44 +02:00
EOF
2019-07-14 13:27:08 +02:00
2019-03-25 13:44:25 +01:00
if [ ${FOUND} -eq 1 ]; then
2019-07-26 11:59:03 +02:00
Display --indent 2 --text "- Ownership of home directories" --result "${STATUS_WARNING}" --color RED
2019-12-13 12:59:43 +01:00
ReportSuggestion "${TEST_NO}" "Double check the ownership of home directories as some might be incorrect."
2019-03-25 13:44:25 +01:00
else
2019-07-26 11:59:03 +02:00
Display --indent 2 --text "- Ownership of home directories" --result "${STATUS_OK}" --color GREEN
2019-12-13 12:59:43 +01:00
LogText "Result: OK, all users own their home directories"
2019-03-25 13:44:25 +01:00
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : HOME-9310
# Description : Check for suspicious shell history files
2016-07-24 17:22:00 +02:00
Register --test-no HOME-9310 --weight L --network NO --category security --description "Checking for suspicious shell history files"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2019-07-16 13:20:30 +02:00
if [ -n "${HOMEDIRS}" ]; then
2014-09-15 12:01:09 +02:00
if [ "${OS}" = "Solaris" ]; then
# Solaris doesn't support -maxdepth
2016-09-10 16:12:44 +02:00
FIND=$(${FINDBINARY} ${HOMEDIRS} -name ".*history" ! -type f -print)
else
FIND=$(${FINDBINARY} ${HOMEDIRS} -maxdepth 1 -name ".*history" ! -type f -print)
2014-09-15 12:01:09 +02:00
fi
2016-09-10 16:12:44 +02:00
if [ -z "${FIND}" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_OK}" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Ok, history files are type 'file'."
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: the following files seem to be of the wrong file type:"
LogText "Output: ${FIND}"
LogText "Info: above files could be redirected files to avoid logging and should be investigated"
2019-12-18 12:17:46 +01:00
ReportWarning "${TEST_NO}" "Incorrect file type found for shell history file"
2014-09-15 12:01:09 +02:00
fi
2019-12-13 12:59:43 +01:00
LogText "Remark: History files are normally of the type 'file'. Symbolic links and other types are suspicious."
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_SKIPPED}" --color WHITE
2019-12-13 12:59:43 +01:00
LogText "Result: Homedirs is empty, therefore test will be skipped"
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : HOME-9314
# Description : Check if non local paths are found in PATH, which can be a risk, but also bad for performance
# (like searching on a filer, instead of local disk)
2016-07-24 17:22:00 +02:00
#Register --test-no HOME-9314 --weight L --network NO --category security --description "Create list with home directories"
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : HOME-9350
# Description : Scan home directories for specific files, used in different tests later
# Notes : For performance reasons we combine the scanning of different files, so inode caching is used
# as much as possible for every find command
2018-01-23 15:00:34 +01:00
# Profile opt : ignore-home-dir (multiple lines allowed), ignores home directory
2019-07-16 13:20:30 +02:00
if [ -n "${REPORTFILE}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no HOME-9350 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Collecting information from home directories"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2018-01-26 13:00:24 +01:00
IGNORE_HOME_DIRS=$(${GREPBINARY} "^ignore-home-dir=" ${REPORTFILE} | ${AWKBINARY} -F= '{ print $2 }')
2016-09-10 16:12:44 +02:00
if [ -z "${IGNORE_HOME_DIRS}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: IGNORE_HOME_DIRS empty, no paths excluded"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Output: ${IGNORE_HOME_DIRS}"
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
#
#================================================================================
2016-03-13 16:03:46 +01:00
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com