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.
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Scheduled tasks
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
InsertSection "Scheduled tasks"
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
ATD_RUNNING=0
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Test : SCHD-7704
|
|
|
|
# Description : Check crontab / cronjobs
|
|
|
|
Register --test-no SCHD-7704 --weight L --network NO --description "Check crontab/cronjobs"
|
|
|
|
if [ ${SKIPTEST} -eq 0 ]; then
|
|
|
|
FindCronJob()
|
|
|
|
{
|
|
|
|
sCRONJOBS=`egrep '^([0-9*])' $1 | tr '\t' ' ' | tr -s ' ' | tr ' ' ','`
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -f /etc/crontab ]; then
|
|
|
|
FindCronJob /etc/crontab
|
|
|
|
for I in ${sCRONJOBS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found cronjob (/etc/crontab): ${I}"
|
|
|
|
Report "cronjob[]=${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
CRON_DIRS="/etc/cron.d"
|
|
|
|
for I in ${CRON_DIRS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: checking directory ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ -d ${I} ]; then
|
2014-09-09 14:49:37 +02:00
|
|
|
FileIsReadable ${I}
|
|
|
|
if [ ${CANREAD} -eq 1 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: found directory ${I}"
|
|
|
|
LogText "Test: searching files in ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
FIND=`find ${I} -type f -print`
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: no files found in ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: found one or more files in ${I}. Analyzing files.."
|
2014-09-09 14:49:37 +02:00
|
|
|
for J in ${FIND}; do
|
|
|
|
FindCronJob ${J}
|
|
|
|
for K in ${sCRONJOBS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: Found cronjob (${I}): ${K}"
|
2014-09-09 14:49:37 +02:00
|
|
|
done
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: done with analyzing files in ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: can not read file or directory ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
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
|
|
|
|
|
|
|
|
CRON_DIRS="/etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly"
|
|
|
|
for I in ${CRON_DIRS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: checking directory ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ -d ${I} ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: found directory ${I}"
|
|
|
|
LogText "Test: searching files in ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
FIND=`find ${I} -type f -print | grep -v ".placeholder"`
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: no files found in ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: found one or more files in ${I}. Analyzing files.."
|
2014-08-26 17:33:55 +02:00
|
|
|
for J in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: Found cronjob (${I}): ${J}"
|
|
|
|
Report "cronjob[]=${J}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: done with analyzing files in ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
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
|
|
|
|
|
|
|
|
# /var/spool/cron/* and /var/spool/cron/crontabs/*
|
|
|
|
# Search only in one tree, to avoid searching the tree twice
|
|
|
|
if [ -d /var/spool/cron/crontabs ]; then
|
|
|
|
FIND=`find /var/spool/cron/crontabs -type f -print`
|
|
|
|
for I in ${FIND}; do
|
|
|
|
FindCronJob ${I}
|
|
|
|
for J in ${sCRONJOBS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found cronjob (/var/spool/cron/crontabs): ${I} (${J})"
|
|
|
|
Report "cronjob[]=${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
|
|
|
if [ -d /var/spool/cron ]; then
|
|
|
|
FIND=`find /var/spool/cron -type f -print`
|
|
|
|
for I in ${FIND}; do
|
|
|
|
FindCronJob ${I}
|
|
|
|
for J in ${sCRONJOBS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found cronjob (/var/spool/cron): ${I} (${J})"
|
|
|
|
LogText "cronjob[]=${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Anacron
|
|
|
|
if [ "${OS}" = "Linux" ]; then
|
|
|
|
if [ -f /etc/anacrontab ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: checking anacrontab"
|
2014-08-26 17:33:55 +02:00
|
|
|
sANACRONJOBS=`egrep '^([0-9@])' /etc/anacrontab | tr '\t' ' ' | tr -s ' ' | tr ' ' ','`
|
|
|
|
for J in ${sANACRONJOBS}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found anacron job (/etc/anacrontab): ${J}"
|
|
|
|
Report "cronjob[]=${J}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
Display --indent 2 --text "- Checking crontab/cronjob" --result DONE --color GREEN
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Test : SCHD-7718
|
|
|
|
# Description : Check atd status
|
|
|
|
Register --test-no SCHD-7718 --weight L --network NO --description "Check at users"
|
|
|
|
if [ ${SKIPTEST} -eq 0 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking atd status"
|
2015-07-22 17:37:11 +02:00
|
|
|
FIND=`${PSBINARY} ax | grep "/atd" | grep -v "grep"`
|
|
|
|
if [ ! "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: at daemon active"
|
2015-07-22 17:37:11 +02:00
|
|
|
Display --indent 2 --text "- Checking atd status" --result RUNNING --color GREEN
|
|
|
|
ATD_RUNNING=1
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: at daemon not active"
|
2015-07-22 17:37:11 +02:00
|
|
|
Display --indent 2 --text "- Checking atd status" --result "NOT RUNNING" --color WHITE
|
|
|
|
fi
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Test : SCHD-7720
|
|
|
|
# Description : Check at users
|
|
|
|
# Notes : if at.allow exists, only users listed can schedule at jobs
|
|
|
|
# if at.allow does not exist, but at.deny does, everyone
|
|
|
|
# except the listed ones can schedule jobs. If both can't be
|
|
|
|
# found, only root can schedule jobs.
|
|
|
|
if [ ${ATD_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
|
|
|
|
Register --test-no SCHD-7720 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check at users"
|
|
|
|
if [ ${SKIPTEST} -eq 0 ]; then
|
|
|
|
AT_UNKNOWN=0
|
|
|
|
case ${OS} in
|
2014-09-09 14:49:37 +02:00
|
|
|
FreeBSD) AT_ALLOW="/var/at/at.allow"; AT_DENY="/var/at/at.deny" ;;
|
|
|
|
HPUX) AT_ALLOW="/usr/lib/cron/at.allow"; AT_DENY="/usr/lib/cron/at.deny" ;;
|
|
|
|
Linux) AT_ALLOW="/etc/at.allow"; AT_DENY="/etc/at.deny" ;;
|
|
|
|
OpenBSD) AT_ALLOW="/var/cron/at.allow"; AT_DENY="/var/cron/at.deny" ;;
|
|
|
|
SunOS) AT_ALLOW="/etc/cron.d/at.allow"; AT_DENY="/etc/cron.d/at.deny" ;;
|
2015-12-21 21:17:15 +01:00
|
|
|
*) AT_UNKNOWN=1; LogText "Test skipped, files for at unknown" ;;
|
2014-09-09 14:49:37 +02:00
|
|
|
esac
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ ${AT_UNKNOWN} -eq 0 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: checking for file ${AT_ALLOW}"
|
2014-09-09 14:49:37 +02:00
|
|
|
if [ -f ${AT_ALLOW} ]; then
|
|
|
|
FileIsReadable ${AT_ALLOW}
|
|
|
|
if [ ${CANREAD} -eq 1 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: file ${AT_ALLOW} exists, only listed users can schedule at jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
FIND=`cat ${AT_ALLOW} | sort`
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: File empty, no users are allowed to schedule at jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
else
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Allowed at user: ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: can not read ${AT_ALLOW} (no permission)"
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: file ${AT_ALLOW} does not exist"
|
|
|
|
LogText "Test: checking for file ${AT_DENY}"
|
2014-09-09 14:49:37 +02:00
|
|
|
if [ -f ${AT_DENY} ]; then
|
2014-09-15 10:52:06 +02:00
|
|
|
FileIsReadable ${AT_DENY}
|
|
|
|
if [ ${CANREAD} -eq 1 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: file ${AT_DENY} exists, only non listed users can schedule at jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
FIND=`cat ${AT_DENY} | sort`
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: file is empty, no users are denied access to schedule jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
else
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Denied at user: ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: can not read ${AT_DENY} (no permission)"
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: both ${AT_ALLOW} and ${AT_DENY} do not exist"
|
|
|
|
LogText "Note: only root can schedule at jobs"
|
2014-09-15 10:52:06 +02:00
|
|
|
AddHP 1 1
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
Display --indent 4 --text "- Checking at users" --result DONE --color GREEN
|
|
|
|
else
|
2014-08-26 17:33:55 +02:00
|
|
|
Display --indent 4 --text "- Checking at users" --result SKIPPED --color YELLOW
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Test : SCHD-7724
|
|
|
|
# Description : Check scheduled at jobs
|
|
|
|
if [ ${ATD_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
|
|
|
|
Register --test-no SCHD-7724 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check at jobs"
|
|
|
|
if [ ${SKIPTEST} -eq 0 ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Check scheduled at jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
FIND=`atq | grep -v "no files in queue" | ${AWKBINARY} '{gsub("\t"," ");print}' | sed 's/ /!space!/g'`
|
|
|
|
if [ ! "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: found one or more jobs"
|
2014-09-09 14:49:37 +02:00
|
|
|
for I in ${FIND}; do
|
|
|
|
I=`echo ${I} | sed 's/!space!/ /g'`
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found at job: ${I}"
|
2014-09-09 14:49:37 +02:00
|
|
|
done
|
2014-08-26 17:33:55 +02:00
|
|
|
Display --indent 4 --text "- Checking at jobs" --result FOUND --color GREEN
|
2014-09-09 14:49:37 +02:00
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: no pending at jobs"
|
2014-08-26 17:33:55 +02:00
|
|
|
Display --indent 4 --text "- Checking at jobs" --result NONE --color GREEN
|
2014-09-09 14:49:37 +02:00
|
|
|
fi
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
|
|
|
|
wait_for_keypress
|
|
|
|
|
|
|
|
#
|
|
|
|
#================================================================================
|
2015-12-21 21:17:15 +01:00
|
|
|
# Lynis - Copyright 2007-2016, Michael Boelen, CISOfy - https://cisofy.com
|