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.
#
#################################################################################
#
# Logging and related files
#
#################################################################################
#
2016-09-10 16:12:44 +02:00
LOG_FILES_LOCS="${ROOTDIR}var/log ${ROOTDIR}var/adm"
2014-08-26 17:33:55 +02:00
LOGROTATE_CONFIG_FOUND=0
LOGROTATE_TOOL=""
METALOG_RUNNING=0
RFC3195D_RUNNING=0
RSYSLOG_RUNNING=0
SOLARIS_LOGHOST_FOUND=0
SYSLOG_DAEMON_PRESENT=0
SYSLOG_DAEMON_RUNNING=0
SYSLOG_NG_RUNNING=0
SYSTEMD_JOURNAL_RUNNING=0
#
#################################################################################
#
InsertSection "Logging and files"
# Test : LOGG-2130
# Description : Check for a running syslog daemon
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2130 --weight L --network NO --category security --description "Check for running syslog daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for a logging daemon"
2016-09-10 16:12:44 +02:00
FIND=$(${PSBINARY} ax | ${EGREPBINARY} "syslogd|syslog-ng|metalog|systemd-journal" | ${GREPBINARY} -v "grep")
if [ -z "${FIND}" ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking for a running log daemon" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: Could not find a syslog daemon like syslog, syslog-ng, rsyslog, metalog, systemd-journal"
2014-09-15 12:01:09 +02:00
ReportSuggestion ${TEST_NO} "Check if any syslog daemon is running and correctly configured."
2016-08-10 07:12:46 +02:00
ReportWarning ${TEST_NO} "No syslog daemon found"
2014-09-15 12:01:09 +02:00
AddHP 0 3
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking for a running log daemon" --result "${STATUS_OK}" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Found a logging daemon"
2014-09-15 12:01:09 +02:00
SYSLOG_DAEMON_PRESENT=1
SYSLOG_DAEMON_RUNNING=1
AddHP 3 3
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2132
# Description : Check for a running syslog-ng daemon
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2132 --weight L --network NO --category security --description "Check for running syslog-ng daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for syslog-ng daemon in process list"
2014-09-19 01:17:05 +02:00
IsRunning syslog-ng
if [ ${RUNNING} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found syslog-ng in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking Syslog-NG status" --result "${STATUS_FOUND}" --color GREEN
2014-09-15 12:01:09 +02:00
SYSLOG_DAEMON_PRESENT=1
SYSLOG_NG_RUNNING=1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: Syslog-ng NOT found in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking Syslog-NG status" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-09-15 12:01:09 +02:00
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : LOGG-2134
# Description : Check for Syslog-NG configuration file consistency
if [ ! "${SYSLOGNGBINARY}" = "" -a ${SYSLOG_NG_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2134 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking Syslog-NG configuration file consistency"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
FIND=$(${SYSLOGNGBINARY} -s; echo $?)
2014-09-15 12:01:09 +02:00
if [ "${FIND}" = "0" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Syslog-NG configuration file seems to be consistent"
2016-06-18 11:14:01 +02:00
Display --indent 6 --text "- Checking Syslog-NG consistency" --result "${STATUS_OK}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: Syslog-NG configuration file seems NOT to be consistent"
2016-06-18 11:14:01 +02:00
Display --indent 6 --text "- Checking Syslog-NG consistency" --result "${STATUS_WARNING}" --color RED
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "Found one or more problems in Syslog-NG configuration file"
2014-09-15 12:01:09 +02:00
ReportSuggestion ${TEST_NO} "Check the Syslog-NG configuration file and/or run a manual consistency check with: syslog-ng -s"
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
2014-11-28 23:50:07 +01:00
#
# Test : LOGG-2136
# Description : Check for a running systemd-journal daemon
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2136 --weight L --network NO --category security --description "Check for running systemd journal daemon"
2014-11-28 23:50:07 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for systemd journal daemon in process list"
2014-11-28 23:50:07 +01:00
IsRunning systemd-journal
if [ ${RUNNING} -eq 1 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking systemd journal status" --result "${STATUS_FOUND}" --color GREEN
2014-11-28 23:50:07 +01:00
SYSTEMD_JOURNAL_RUNNING=1
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking systemd journal status" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-11-28 23:50:07 +01:00
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : LOGG-2210
# Description : Check for a running metalog daemon
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2210 --weight L --network NO --category security --description "Check for running metalog daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for metalog daemon in process list"
2014-09-19 01:17:05 +02:00
IsRunning metalog
if [ ${RUNNING} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found metalog in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking Metalog status" --result "${STATUS_FOUND}" --color GREEN
2014-09-15 12:01:09 +02:00
SYSLOG_DAEMON_PRESENT=1
METALOG_RUNNING=1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: metalog NOT found in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking Metalog status" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2230
# Description : Check for a running rsyslog daemon
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2230 --weight L --network NO --category security --description "Check for running RSyslog daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for RSyslog daemon in process list"
2014-09-19 01:17:05 +02:00
IsRunning rsyslogd
if [ ${RUNNING} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found rsyslogd in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking RSyslog status" --result "${STATUS_FOUND}" --color GREEN
2014-09-15 12:01:09 +02:00
SYSLOG_DAEMON_PRESENT=1
RSYSLOG_RUNNING=1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: rsyslogd NOT found in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking RSyslog status" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2240
# Description : Check for a running RFC 3195 compliant daemon (syslog via TCP)
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2240 --weight L --network NO --category security --description "Check for running RFC 3195 compliant daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching for RFC 3195 daemon (alias syslog reliable) in process list"
2014-09-19 01:17:05 +02:00
IsRunning rfc3195d
if [ ${RUNNING} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Found rfc3195d in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking RFC 3195 daemon status" --result "${STATUS_FOUND}" --color GREEN
2014-09-15 12:01:09 +02:00
SYSLOG_DAEMON_PRESENT=1
RFC3195D_RUNNING=1
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: rfc3195d NOT found in process list"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking RFC 3195 daemon status" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2138
# Description : Check for kernel log daemon (klogd) presence on Linux systems
2014-11-29 16:23:52 +01:00
# Notes : * When using rsyslog or systemd (systemd-journal), this process is not needed.
# * In combination with syslog-ng, klogd is still an addition to it, since it
# captures kernel related events and send them to syslog-ng.
# * This test should be below all other logging daemons
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2138 --os Linux --weight L --network NO --category security --description "Checking kernel logger daemon on Linux"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching kernel logger daemon (klogd)"
2014-11-29 16:23:52 +01:00
if [ ${RSYSLOG_RUNNING} -eq 0 -a ${SYSTEMD_JOURNAL_RUNNING} -eq 0 ]; then
2014-09-15 12:01:09 +02:00
# Search for klogd, but ignore other lines related to klogd (like dd with input/output file)
2016-08-25 15:31:33 +02:00
#FIND=`${PSBINARY} ax | ${GREPBINARY} "klogd" | ${GREPBINARY} -v "dd" | ${GREPBINARY} -v "grep"`
2014-09-19 01:17:05 +02:00
IsRunning klogd
if [ ${RUNNING} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: klogd running"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking klogd" --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 klogd found"
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking klogd" --result "${STATUS_NOT_FOUND}" --color RED
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "klogd is not running, which could lead to missing kernel messages in log files"
2014-09-15 12:01:09 +02:00
fi
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: test skipped, because other facility is being used to log kernel messages"
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2142
# Description : Check for minilogd presence on Linux systems
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2142 --os Linux --weight L --network NO --category security --description "Checking minilog daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Checking for unkilled minilogd instances"
2014-08-26 17:33:55 +02:00
# Search for minilogd. It shouldn't be running normally, if another syslog daemon is started
2014-09-19 01:17:05 +02:00
IsRunning minilogd
if [ ${RUNNING} -eq 0 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking minilogd instances" --result "${STATUS_NOT_FOUND}" --color WHITE
2015-12-21 21:17:15 +01:00
LogText "Result: No minilogd is running"
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking minilogd instances" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: minilogd found in process list"
2014-09-15 12:01:09 +02:00
# minilogd daemon seems to be running
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "minilogd is running, which should normally not be running"
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2146
# Description : Check for logrotate (/etc/logrotate.conf and logrotate.d)
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2146 --weight L --os Linux --network NO --category security --description "Checking logrotate.conf and logrotate.d"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
LogText "Test: Checking for ${ROOTDIR}etc/logrotate.conf"
if [ -f ${ROOTDIR}etc/logrotate.conf ]; then
2014-08-26 17:33:55 +02:00
LOGROTATE_CONFIG_FOUND=1
LOGROTATE_TOOL="logrotate"
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}etc/logrotate.conf found (file)"
2016-09-05 11:54:42 +02:00
else
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}etc/logrotate.conf NOT found"
2014-08-26 17:33:55 +02:00
fi
2016-09-05 11:54:42 +02:00
2016-09-10 16:12:44 +02:00
LogText "Test: Checking for ${ROOTDIR}etc/logrotate.d (directory)"
if [ -d ${ROOTDIR}etc/logrotate.d ]; then
2014-08-26 17:33:55 +02:00
LOGROTATE_CONFIG_FOUND=1
LOGROTATE_TOOL="logrotate"
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}etc/logrotate.d found"
2016-09-05 11:54:42 +02:00
else
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}etc/logrotate.conf found"
2014-08-26 17:33:55 +02:00
fi
2016-09-05 11:54:42 +02:00
2014-08-26 17:33:55 +02:00
if [ ${LOGROTATE_CONFIG_FOUND} -eq 1 ]; then
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking logrotate presence" --result "${STATUS_OK}" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: logrotate configuration found"
2016-09-05 11:54:42 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking logrotate presence" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: No logrotate configuration found"
2016-09-05 11:54:42 +02:00
ReportSuggestion ${TEST_NO} "Check if log files are properly rotated"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : LOGG-2148
# Description : Checking log files rotated with logrotate
2016-09-10 16:12:44 +02:00
if [ ! -z "${LOGROTATEBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2148 --weight L --preqs-met ${PREQS_MET} --network NO --category security --description "Checking logrotated files"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking which files are rotated with logrotate and if they exist"
2016-09-10 16:12:44 +02:00
FIND=$(${LOGROTATEBINARY} -d -v ${ROOTDIR}etc/logrotate.conf 2>&1 | ${EGREPBINARY} "considering log|skipping" | ${GREPBINARY} -v '*' | ${SORTBINARY} -u | ${AWKBINARY} '{ if ($2!="log") { print "File:"$2":does_not_exist" } else { print "File:"$3":exists" } }')
if [ -z "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: nothing found"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more files which are rotated via logrotate"
2014-09-15 12:01:09 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Output: ${I}"
2014-09-15 12:01:09 +02:00
done
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : LOGG-2150
# Description : Checking log directories rotated with logrotate
if [ ! "${LOGROTATEBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2150 --weight L --preqs-met ${PREQS_MET} --network NO --category security --description "Checking directories in logrotate 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 which directories can be found in logrotate configuration"
2016-09-08 21:04:17 +02:00
FIND=`${LOGROTATEBINARY} -d -v /etc/logrotate.conf 2>&1 | ${EGREPBINARY} "considering log|skipping" | ${GREPBINARY} -v '*' | ${SORTBINARY} -u | ${AWKBINARY} '{ if ($2=="log") { print $3 } }' | ${SEDBINARY} 's@/[^/]*$@@g' | ${SORTBINARY} -u`
2014-09-15 12:01:09 +02:00
if [ "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: nothing found"
2014-09-15 12:01:09 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more directories (via logrotate configuration)"
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 "Directory found: ${I}"
Report "log_directory[]=${I}"
2014-09-15 12:01:09 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Directory could not be found: ${I}"
2014-09-15 12:01:09 +02:00
fi
done
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : LOGG-2152
# Description : Check for Solaris 'loghost' entry in /etc/inet/hosts, or
# succesful resolving via DNS or any other name service.
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2152 --weight L --os Solaris --network NO --category security --description "Checking loghost"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-15 12:01:09 +02:00
# Try local hosts file
2015-12-21 21:17:15 +01:00
LogText "Result: Checking for loghost in /etc/inet/hosts"
2016-09-10 16:12:44 +02:00
FIND=$(${GREPBINARY} loghost /etc/inet/hosts | ${GREPBINARY} -v "^#")
if [ ! -z "${FIND}" ]; then
2014-09-15 12:01:09 +02:00
SOLARIS_LOGHOST_FOUND=1
2015-12-21 21:17:15 +01:00
LogText "Result: Found loghost entry in /etc/inet/hosts"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: No loghost entry found in /etc/inet/hosts"
2014-09-15 12:01:09 +02:00
# Try name resolving if no entry is present in local host file
2015-12-21 21:17:15 +01:00
LogText "Result: Checking for loghost via name resolving"
2016-08-25 15:31:33 +02:00
FIND=`getent hosts loghost | ${GREPBINARY} loghost`
2016-09-10 16:12:44 +02:00
if [ ! -z "${FIND}" ]; then
2014-09-15 12:01:09 +02:00
SOLARIS_LOGHOST_FOUND=1
2015-12-21 21:17:15 +01:00
LogText "Result: name resolving was succesful"
LogText "Output: ${FIND}"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: name resolving didn't find results"
2014-09-15 12:01:09 +02:00
fi
fi
2014-08-26 17:33:55 +02:00
if [ ${SOLARIS_LOGHOST_FOUND} -eq 1 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: loghost entry found and most likely used to send syslog messages"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking loghost entry" --result "${STATUS_OK}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking loghost entry" --result "${STATUS_WARNING}" --color RED
2015-12-21 21:17:15 +01:00
LogText "Result: No loghost entry found"
2016-08-10 07:24:10 +02:00
ReportWarning ${TEST_NO} "No loghost entry found"
2014-09-15 12:01:09 +02:00
ReportSuggestion ${TEST_NO} "Add a loghost entry to /etc/inet/hosts or other name services"
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2154
# Description : Check to see if remote logging is enabled
# Notes : prevent lines showing up with commands in it (like |mail)
if [ ${SYSLOG_DAEMON_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2154 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking syslog configuration file"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2014-09-15 12:01:09 +02:00
if [ ${SYSLOG_NG_RUNNING} -eq 1 ]; then
SYSLOGD_CONF="/etc/syslog-ng/syslog-ng.conf"
2016-09-10 16:12:44 +02:00
else
2014-09-15 12:01:09 +02:00
SYSLOGD_CONF="/etc/syslog.conf"
fi
if [ -f ${SYSLOGD_CONF} ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: check if logs are also logged to a remote logging host"
2016-09-10 16:12:44 +02:00
FIND=$(${EGREPBINARY} "@[a-zA-Z0-9]|destination\s.+(udp|tcp).+\sport" ${SYSLOGD_CONF} | ${GREPBINARY} -v "^#" | ${GREPBINARY} -v "[a-zA-Z0-9]@")
if [ ! -z "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: remote logging enabled"
2015-12-22 16:56:15 +01:00
REMOTE_LOGGING_ENABLED=1
else
# Search for configured destinations with an IP address or hostname, then determine which ones are used as a log destination
2016-09-10 16:12:44 +02:00
DESTINATIONS=$(${GREPBINARY} "^destination" ${SYSLOGD_CONF} | ${EGREPBINARY} "(udp|tcp)" | ${GREPBINARY} "port" | ${AWKBINARY} '{print $2}')
2015-12-22 16:56:15 +01:00
for DESTINATION in ${DESTINATIONS}; do
2016-09-10 16:12:44 +02:00
FIND2=$(${GREPBINARY} "log" | ${GREPBINARY} "source" | ${EGREPBINARY} "destination\(${DESTINATION}\)")
if [ ! -z "${FIND2}" = "" ]; then
2015-12-22 16:56:15 +01:00
LogText "Result: found destination ${DESTINATION} configured for remote logging"
REMOTE_LOGGING_ENABLED=1
fi
done
fi
if [ ${REMOTE_LOGGING_ENABLED} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: no remote logging found"
2014-09-15 12:01:09 +02:00
ReportSuggestion ${TEST_NO} "Enable logging to an external logging host for archiving purposes and additional protection"
AddHP 1 3
Display --indent 2 --text "- Checking remote logging" --result "NOT ENABLED" --color YELLOW
2016-09-10 16:12:44 +02:00
else
2015-12-22 16:56:15 +01:00
AddHP 5 5
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking remote logging" --result "${STATUS_ENABLED}" --color GREEN
2014-09-15 12:01:09 +02:00
fi
else
2015-12-21 21:17:15 +01:00
LogText "Result: test skipped, file ${SYSLOGD_CONF} not found"
2014-09-15 12:01:09 +02:00
fi
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2160
# Description : Check for /etc/newsyslog.conf (FreeBSD/OpenBSD)
2016-09-10 16:12:44 +02:00
if [ -f ${ROOTDIR}etc/newsyslog.conf ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2160 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking /etc/newsyslog.conf"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
LogText "Result: ${ROOTDIR}etc/newsyslog.conf found"
Display --indent 2 --text "- Checking ${ROOTDIR}etc/newsyslog.conf" --result "${STATUS_FOUND}" --color GREEN
2014-08-26 17:33:55 +02:00
LOGROTATE_CONFIG_FOUND=1
LOGROTATE_TOOL="newsyslog"
fi
#
#################################################################################
#
# Test : LOGG-2162
# Description : Check for directories in /etc/newsyslog.conf
if [ -f /etc/newsyslog.conf ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2162 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking directories in /etc/newsyslog.conf"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: parsing directories from /etc/newsyslog.conf file"
2016-09-10 16:12:44 +02:00
FIND=$(${AWKBINARY} '/^\// { print $1 }' /etc/newsyslog.conf | ${SEDBINARY} 's/\/*[a-zA-Z_.-]*$//g' | ${SORTBINARY} -u)
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
if [ -d ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: Directory ${I} found and exists"
Report "log_directory[]=${I}"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: Item ${I} is not a directory"
2014-08-26 17:33:55 +02:00
fi
done
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking log directories (newsyslog.conf)" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2164
# Description : Check for files in /etc/newsyslog.conf
2016-09-10 16:12:44 +02:00
if [ -f ${ROOTDIR}etc/newsyslog.conf ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2164 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking files specified /etc/newsyslog.conf"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-09-10 16:12:44 +02:00
LogText "Test: parsing files from ${ROOTDIR}etc/newsyslog.conf file"
FIND=$(${AWKBINARY} '/^\// { print $1 }' ${ROOTDIR}etc/newsyslog.conf | ${SORTBINARY} -u)
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
if [ -f ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: File ${I} found and exists"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: Item ${I} is not a file"
2014-08-26 17:33:55 +02:00
fi
done
2016-06-18 11:14:01 +02:00
Display --indent 4 --text "- Checking log files (newsyslog.conf)" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2170
# Description : Search available log paths
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2170 --weight L --network NO --category security --description "Checking log paths"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Searching log paths"
2014-08-26 17:33:55 +02:00
for I in ${LOG_FILES_LOCS}; do
if [ -d ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: directory ${I} exists"
Report "log_directory[]=${I}"
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: directory ${I} can't be found"
2014-08-26 17:33:55 +02:00
fi
done
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking log directories (static list)" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : LOGG-2180
# Description : Search open log file
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2180 --weight L --network NO --category security --description "Checking open log files"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: checking open log files with lsof"
2016-09-10 16:12:44 +02:00
if [ ! -z "${LSOFBINARY}" ]; then
FIND=$(${LSOFBINARY} -n 2>&1 | ${GREPBINARY} "log$" | ${EGREPBINARY} -v "WARNING|Output information" | ${AWKBINARY} '{ if ($5=="REG") { print $9 } }' | ${SORTBINARY} -u | ${GREPBINARY} -v "^$")
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Found logfile: ${I}"
Report "open_logfile[]=${I}"
2014-08-26 17:33:55 +02:00
done
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking open log files" --result "${STATUS_DONE}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: lsof not installed, skipping test"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking open log files" --result "${STATUS_SKIPPED}" --color YELLOW
2014-08-26 17:33:55 +02:00
# Add suggestion
fi
fi
#
#################################################################################
#
# Test : LOGG-2190
# Description : Checking deleted files
if [ ! "${LSOFBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
2016-07-24 17:22:00 +02:00
Register --test-no LOGG-2190 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking for deleted files in use"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2016-08-18 15:25:57 +02:00
EARLY_MYSQL=""
2016-03-22 03:28:21 +01:00
LogText "Test: checking deleted files that are still in use"
2016-05-02 19:12:55 +02:00
LSOF_GREP="WARNING|Output information"
2016-08-18 15:25:57 +02:00
# MySQL versions prior to 5.6 leave lots of deleted in-use files in /tmp, ignoring those
2016-08-25 15:31:33 +02:00
if [ ! -z "${DPKGBINARY}" ]; then EARLY_MYSQL=$(${DPKGBINARY} -l | ${EGREPBINARY} mysql-server-5.[0-5]); fi
2016-08-18 15:25:57 +02:00
if [ ! -z "${EARLY_MYSQL}" ]; then LSOF_GREP="${LSOF_GREP}|mysqld"; fi
# grsecurity causes Fail2Ban to hold onto deleted in-use files in /var/tmp
if [ ${GRSEC_FOUND} -eq 1 ]; then LSOF_GREP="${LSOF_GREP}|fail2ban"; fi
2016-05-02 19:12:55 +02:00
if [ ${OS_REDHAT_OR_CLONE} -eq 1 ]; then
2016-05-02 19:08:11 +02:00
# If lynis is run from /etc/cron.daily some deleted in-use files are kept in /tmp
2016-05-02 19:12:55 +02:00
LSOF_GREP="${LSOF_GREP}|anacron|awk|run-parts"
2016-03-22 03:28:21 +01:00
fi
2016-08-25 15:31:33 +02:00
FIND=$(${LSOFBINARY} -n +L 1 2>&1 | ${EGREPBINARY} -vw "${LSOF_GREP}" | ${AWKBINARY} '{ if ($5=="REG") { printf "%s(%s)\n", $10, $1 } }' | ${GREPBINARY} -v "^$" | ${SORTBINARY} -u)
2016-09-10 16:12:44 +02:00
if [ ! -z "${FIND}" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: found one or more files which are deleted, but still in use"
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
2015-12-21 21:17:15 +01:00
LogText "Found deleted file: ${I}"
Report "deleted_file[]=${I}"
2014-08-26 17:33:55 +02:00
done
Display --indent 2 --text "- Checking deleted files in use" --result "FILES FOUND" --color YELLOW
ReportSuggestion ${TEST_NO} "Check what deleted files are still in use and why."
2016-08-18 15:25:57 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: no deleted files found"
2016-06-18 11:14:01 +02:00
Display --indent 2 --text "- Checking deleted files in use" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
2016-08-22 12:21:43 +02:00
#
# Test : LOGG-2192
# Description : Check for open log files which are empty. This may indicate a problem with log rotation, or unused services
if [ ! "${LSOFBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no LOGG-2192 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking for open log files that are empty"
if [ ${SKIPTEST} -eq 0 ]; then
2016-08-25 15:31:33 +02:00
FIND=$(${LSOFBINARY} -n -w | ${AWKBINARY} '{if ($5=="REG" && $7=="0" && $9 ~ /log$/) {print $1","$9}}' | ${SORTBINARY} | uniq)
2016-08-22 12:21:43 +02:00
if [ ! -z "${FIND}" ]; then
for I in ${FIND}; do
LogText "Found an opened logfile that is empty: ${I}"
Report "open_empty_log_file[]=${I}"
done
else
LogText "Result: all opened log files are bigger than zero bytes in size"
fi
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
2015-12-21 21:17:15 +01:00
Report "log_rotation_config_found=${LOGROTATE_CONFIG_FOUND}"
Report "log_rotation_tool=${LOGROTATE_TOOL}"
2014-08-26 17:33:55 +02:00
2016-05-03 11:00:06 +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