lynis/include/tests_homedirs

115 lines
5.3 KiB
Plaintext
Raw Normal View History

2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
2018-01-11 09:50:26 +01:00
# Copyright 2007-2018, 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
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
LogText "Test: query /etc/passwd to obtain home directories"
2016-09-10 16:12:44 +02:00
FIND=$(${AWKBINARY} -F: '{ if ($1 !~ "#") print $6 }' /etc/passwd | ${SORTBINARY} -u)
2014-09-15 12:01:09 +02:00
for I in ${FIND}; do
if [ -d ${I} ]; then
LogText "Result: found home directory: ${I} (directory exists)"
Report "home_directory[]=${I}"
2016-09-10 16:12:44 +02:00
else
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
#
#################################################################################
#
# Test : HOME-9310
# Description : Check for suspicious shell history files
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
2016-09-10 16:12:44 +02:00
if [ ! -z "${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
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_OK}" --color GREEN
LogText "Result: Ok, history files are type 'file'."
2016-09-10 16:12:44 +02:00
else
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_WARNING}" --color RED
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"
ReportWarning ${TEST_NO} "Incorrect file type found for shell history file"
2014-09-15 12:01:09 +02:00
fi
LogText "Remarks: History files are normally of the type 'file'. Symbolic links and other types can be riskful."
2016-09-10 16:12:44 +02:00
else
Display --indent 2 --text "- Checking shell history files" --result "${STATUS_SKIPPED}" --color WHITE
LogText "Result: Homedirs is empty, 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)
#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
# Profile opt : ignore-home-dir (multiple lines allowed), ignores home directory
2016-09-10 16:12:44 +02:00
if [ ! -z "${REPORTFILE}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
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
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
LogText "Result: IGNORE_HOME_DIRS empty, no paths excluded"
2016-09-10 16:12:44 +02:00
else
LogText "Output: ${IGNORE_HOME_DIRS}"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#================================================================================
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com