lynis/include/tests_file_integrity

344 lines
17 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
# Copyright 2007-2019, 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.
#
#################################################################################
#
2016-09-10 16:12:44 +02:00
AIDECONFIG=""
CSF_CONFIG="${ROOTDIR}etc/csf/csf.conf"
FILE_INT_TOOL=""
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=0 # Boolean, file integrity tool found
#
#################################################################################
#
InsertSection "Software: file integrity"
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking file integrity tools"
#
#################################################################################
#
2014-08-26 17:33:55 +02:00
# Test : FINT-4310
# Description : Check if AFICK is installed
Register --test-no FINT-4310 --weight L --network NO --category security --description "AFICK availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking AFICK binary"
2019-07-15 19:39:04 +02:00
if [ -n "${AFICKBINARY}" ]; then
LogText "Result: AFICK is installed (${AFICKBINARY})"
Report "file_integrity_tool[]=afick"
FILE_INT_TOOL="afick"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- AFICK" --result "${STATUS_FOUND}" --color GREEN
2016-09-10 16:12:44 +02:00
else
LogText "Result: AFICK is not installed"
if IsVerbose; then Display --indent 4 --text "- AFICK" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4314
# Description : Check if AIDE is installed
Register --test-no FINT-4314 --weight L --network NO --category security --description "AIDE availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking AIDE binary"
2019-07-15 19:39:04 +02:00
if [ -n "${AIDEBINARY}" ]; then
LogText "Result: AIDE is installed (${AIDEBINARY})"
Report "file_integrity_tool[]=aide"
FILE_INT_TOOL="aide"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- AIDE" --result "${STATUS_FOUND}" --color GREEN
2016-09-10 16:12:44 +02:00
else
LogText "Result: AIDE is not installed"
if IsVerbose; then Display --indent 4 --text "- AIDE" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4315
# Description : Check AIDE configuration file
2019-07-16 13:20:30 +02:00
if [ -n "${AIDEBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FINT-4315 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check AIDE configuration file"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2019-07-15 19:39:04 +02:00
AIDE_CONFIG_LOCS="${ROOTDIR}etc ${ROOTDIR}etc/aide ${ROOTDIR}usr/local/etc"
LogText "Test: search for aide.conf in ${AIDE_CONFIG_LOCS}"
2014-08-26 17:33:55 +02:00
for I in ${AIDE_CONFIG_LOCS}; do
2019-07-15 19:39:04 +02:00
if [ -f "${I}/aide.conf" ]; then
Lots of cleanups (#366) * Description fix: SafePerms works on files not dirs. All uses of SafePerms are on files (and indeed, it would reject directories which would have +x set). * Lots of whitespace cleanups. Enforce everywhere(?) the same indentations for if/fi blocks. The standard for the Lynis codebase is 4 spaces. But sometimes it's 1, sometimes 3, sometimes 8. These patches standardize all(?) if blocks but _not_ else's (which are usually indented 2, but sometimes zero); I was too lazy to identify those (see below). This diff is giant, but should not change code behavior at all; diff -w shows no changes apart from whitespace. FWIW I identified instances to check by using: perl -ne 'if ($oldfile ne $ARGV) { $.=1; $oldfile=$ARGV; }; chomp; if ($spaces) { next unless /^( *)([^ ]+)/; $newspaces=length($1); $firsttok = $2; next unless defined($firsttok); $offset = ($firsttok eq "elif" ? 0 : 4); if ($newspaces != $spaces + $offset) { print "$ARGV:$ifline\n$ARGV:$.:$_\n\n" }; $ifline=""; $spaces=""; } if (/^( *)if (?!.*[; ]fi)/) { $ifline = "$.:$_"; $spaces = length($1); }' $(find . -type f -print0 | xargs -0 file | egrep shell | cut -d: -f1) Which produced output like: ./extras/build-lynis.sh:217: if [ ${VERSION_IN_SPECFILE} = "" -o ! "${VERSION_IN_SPECFILE}" = "${LYNIS_VERSION}" ]; then ./extras/build-lynis.sh:218: echo "[X] Version in specfile is outdated" ./plugins/plugin_pam_phase1:69: if [ -d ${PAM_DIRECTORY} ]; then ./plugins/plugin_pam_phase1:70: LogText "Result: /etc/pam.d exists" ...There's probably formal shellscript-beautification tools that I'm oblivious about. * More whitespace standardization. * Fix a syntax error. This looks like an if [ foo -o bar ]; was converted to if .. elif, but incompletely. * Add whitespace before closing ]. Without it, the shell thinks the ] is part of the last string, and emits warnings like: .../lynis/include/tests_authentication: line 1028: [: missing `]'
2017-03-07 20:23:08 +01:00
LogText "Result: found aide.conf in directory ${I}"
AIDECONFIG="${I}/aide.conf"
2014-08-26 17:33:55 +02:00
fi
done
2016-09-10 16:12:44 +02:00
if [ -z "${AIDECONFIG}" ]; then
Display --indent 6 --text "- AIDE config file" --result "${STATUS_NOT_FOUND}" --color RED
ReportWarning "${TEST_NO}" "No AIDE configuration file was found, needed for AIDE functionality"
2016-07-26 14:58:04 +02:00
else
LogText "Checking configuration file ${AIDECONFIG} for errors"
FIND=$(${AIDEBINARY} --config=${AIDECONFIG} -D)
if [ $? -eq 0 ]; then
Display --indent 6 --text "- AIDE config file" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
Display --indent 6 --text "- AIDE config file" --result "${STATUS_WARNING}" --color YELLOW
2016-07-26 14:35:47 +02:00
ReportSuggestion "${TEST_NO}" "Check the AIDE configuration file as it may contain errors"
fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
2019-08-26 08:02:11 +02:00
#
# Test : FINT-4316
# Description : Presence of AIDE database and size check
if [ -n "${AIDEBINARY}" -a -n "${AIDECONFIG}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FINT-4316 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Presence of AIDE database and size check"
if [ ${SKIPTEST} -eq 0 ]; then
AIDE_DB=$(${GREPBINARY} ^database= ${AIDECONFIG} | ${SEDBINARY} "s/.*://")
if case ${AIDE_DB} in @@*) ;; *) false;; esac; then
I=$(${GREPBINARY} "@@define.*DBDIR" ${AIDECONFIG} | ${AWKBINARY} '{print $3}')
AIDE_DB=$(echo ${AIDE_DB} | ${SEDBINARY} "s#.*}#${I}#")
fi
LogText "Test: search for AIDE database on disk ${AIDE_DB}"
if [ ! -e "${AIDE_DB}" ]; then
Display --indent 6 --text "- AIDE database" --result "${STATUS_NOT_FOUND}" --color RED
LogText "Result: AIDE database ${AIDE_DB} does not exist"
ReportWarning "${TEST_NO}" "No AIDE database was found, needed for AIDE functionality"
else
LogText "Checking database size ${AIDE_DB}"
if [ -s "${AIDE_DB}" ]; then
Display --indent 6 --text "- AIDE database" --result "${STATUS_FOUND}" --color GREEN
LogText "Result: AIDE database ${AIDE_DB} exist and has a size greater than zero"
else
Display --indent 6 --text "- AIDE database" --result "${STATUS_WARNING}" --color YELLOW
LogText "Result: AIDE database ${AIDE_DB} exist but has a size of zero"
ReportSuggestion "${TEST_NO}" "Check the AIDE database as it may contain errors"
fi
fi
unset AIDE_DB I
fi
#
#################################################################################
2014-08-26 17:33:55 +02:00
#
# Test : FINT-4318
# Description : Check if Osiris is installed
Register --test-no FINT-4318 --weight L --network NO --category security --description "Osiris availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking Osiris binary"
2019-07-16 13:20:30 +02:00
if [ -n "${OSIRISBINARY}" ]; then
LogText "Result: Osiris is installed (${OSIRISBINARY})"
Report "file_integrity_tool[]=osiris"
FILE_INT_TOOL="osiris"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- Osiris" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
LogText "Result: Osiris is not installed"
if IsVerbose; then Display --indent 4 --text "- Osiris" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4322
# Description : Check if Samhain is installed
Register --test-no FINT-4322 --weight L --network NO --category security --description "Samhain availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking Samhain binary"
2019-07-16 13:20:30 +02:00
if [ -n "${SAMHAINBINARY}" ]; then
LogText "Result: Samhain is installed (${SAMHAINBINARY})"
Report "file_integrity_tool[]=samhain"
FILE_INT_TOOL="samhain"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- Samhain" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
LogText "Result: Samhain is not installed"
if IsVerbose; then Display --indent 4 --text "- Samhain" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4326
# Description : Check if Tripwire is installed
Register --test-no FINT-4326 --weight L --network NO --category security --description "Tripwire availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking Tripwire binary"
2019-07-16 13:20:30 +02:00
if [ -n "${TRIPWIREBINARY}" ]; then
LogText "Result: Tripwire is installed (${TRIPWIREBINARY})"
Report "file_integrity_tool[]=tripwire"
FILE_INT_TOOL="tripwire"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- Tripwire" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
LogText "Result: Tripwire is not installed"
if IsVerbose; then Display --indent 4 --text "- Tripwire" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4328
# Description : Check if OSSEC system integrity tool is running
Register --test-no FINT-4328 --weight L --network NO --category security --description "OSSEC syscheck daemon running"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking if OSSEC syscheck daemon is running"
2019-07-15 19:34:37 +02:00
if IsRunning "ossec-syscheckd"; then
LogText "Result: syscheck (OSSEC) active"
Report "file_integrity_tool[]=ossec"
FILE_INT_TOOL="ossec-syscheck"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- OSSEC (syscheck)" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
2019-07-15 19:34:37 +02:00
LogText "Result: syscheck (OSSEC) is not active"
if IsVerbose; then Display --indent 4 --text "- OSSEC" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : FINT-4330
# Description : Check if mtree is installed
# Note : Usually on BSD and similar
Register --test-no FINT-4330 --weight L --network NO --category security --description "mtree availability"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking mtree binary"
2019-07-15 19:39:04 +02:00
if [ -n "${MTREEBINARY}" ]; then
LogText "Result: mtree is installed (${MTREEBINARY})"
Report "file_integrity_tool[]=mtree"
FILE_INT_TOOL="mtree"
2014-08-26 17:33:55 +02:00
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- mtree" --result "${STATUS_FOUND}" --color GREEN
2016-07-26 14:58:04 +02:00
else
LogText "Result: mtree is not installed"
if IsVerbose; then Display --indent 4 --text "- mtree" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
fi
fi
#
#################################################################################
#
# Test : FINT-4334
# Description : Check if LFD is used (part of CSF suite)
if [ -f ${CSF_CONFIG} ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FINT-4334 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check lfd daemon status"
if [ ${SKIPTEST} -eq 0 ]; then
Display --indent 4 --text "- lfd (CSF)" --result "${STATUS_FOUND}" --color GREEN
LogText "Test: determine lfd status"
if IsRunning "lfd - sleeping"; then
LogText "Result: lfd daemon is running (CSF)"
Report "file_integrity_tool[]=csf-lfd"
Display --indent 6 --text "- LFD (CSF) daemon" --result "${STATUS_RUNNING}" --color GREEN
FILE_INT_TOOL="csf-lfd"
FILE_INT_TOOL_FOUND=1
2016-07-26 14:58:04 +02:00
else
Display --indent 6 --text "- LFD (CSF) daemon" --result "${STATUS_NOT_RUNNING}" --color YELLOW
fi
fi
#
#################################################################################
#
# Test : FINT-4336
# Description : Check if LFD is enabled (part of CSF suite)
if [ -f ${CSF_CONFIG} ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FINT-4336 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check lfd configuration status"
if [ ${SKIPTEST} -eq 0 ]; then
# LFD configuration parameters
2016-09-10 16:12:44 +02:00
ENABLED=$(${GREPBINARY} "^LF_DAEMON = \"1\"" ${CSF_CONFIG})
2019-07-15 19:39:04 +02:00
if [ -n "${ENABLED}" ]; then
LogText "Result: lfd service is configured to run"
Display --indent 6 --text "- Configuration status" --result "${STATUS_ENABLED}" --color GREEN
2016-09-10 16:12:44 +02:00
else
LogText "Result: lfd service is configured NOT to run"
Display --indent 6 --text "- Configuration status" --result "${STATUS_DISABLED}" --color YELLOW
fi
2016-09-10 16:12:44 +02:00
ENABLED=$(${GREPBINARY} "^LF_DIRWATCH =" ${CSF_CONFIG} | ${AWKBINARY} '{ print $3 }' | ${SEDBINARY} 's/\"//g')
2019-07-16 13:20:30 +02:00
if [ ! "${ENABLED}" = "0" -a -n "${ENABLED}" ]; then
LogText "Result: lfd directory watching is enabled (value: ${ENABLED})"
Display --indent 6 --text "- Temporary directory watches" --result "${STATUS_ENABLED}" --color GREEN
2016-09-10 16:12:44 +02:00
else
LogText "Result: lfd directory watching is disabled"
Display --indent 6 --text "- Temporary directory watches" --result "${STATUS_DISABLED}" --color YELLOW
fi
2016-09-10 16:12:44 +02:00
ENABLED=$(${GREPBINARY} "^LF_DIRWATCH_FILE =" ${CSF_CONFIG} | ${AWKBINARY} '{ print $3 }' | ${SEDBINARY} 's/\"//g')
2019-07-16 13:20:30 +02:00
if [ ! "${ENABLED}" = "0" -a -n "${ENABLED}" ]; then
Display --indent 6 --text "- Directory/File watches" --result "${STATUS_ENABLED}" --color GREEN
2016-09-10 16:12:44 +02:00
else
Display --indent 6 --text "- Directory/File watches" --result "${STATUS_DISABLED}" --color YELLOW
2014-08-26 17:33:55 +02:00
fi
fi
#
2016-02-29 23:27:07 +01:00
#################################################################################
#
2016-03-01 16:30:48 +01:00
# Test : FINT-4338
2016-02-29 23:27:07 +01:00
# Description : Check if osquery system integrity tool is running
Register --test-no FINT-4338 --weight L --network NO --category security --description "osqueryd syscheck daemon running"
2016-02-29 23:27:07 +01:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking if osqueryd syscheck daemon is running"
2019-07-15 19:39:04 +02:00
if IsRunning "osqueryd"; then
2016-02-29 23:27:07 +01:00
LogText "Result: syscheck (osquery) installed"
Report "file_integrity_tool[]=osquery"
2016-02-29 23:27:07 +01:00
FILE_INT_TOOL="osquery"
FILE_INT_TOOL_FOUND=1
Display --indent 4 --text "- osquery daemon (syscheck)" --result "${STATUS_FOUND}" --color GREEN
2016-09-10 16:12:44 +02:00
else
2016-02-29 23:27:07 +01:00
LogText "Result: syscheck (osquery) not installed"
if IsVerbose; then Display --indent 4 --text "- osquery daemon (syscheck)" --result "${STATUS_NOT_FOUND}" --color WHITE; fi
fi
fi
#
#################################################################################
#
# Test : FINT-4402 (was FINT-4316)
# Description : Check if AIDE is configured to use SHA256 or SHA512 checksums
2019-07-16 13:20:30 +02:00
if [ ! "${AIDEBINARY}" = "" -a -n "${AIDECONFIG}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no FINT-4402 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "AIDE configuration: Checksums (SHA256 or SHA512)"
if [ ${SKIPTEST} -eq 0 ]; then
2016-07-28 10:38:10 +02:00
FIND=$(${GREPBINARY} -v "^#" ${AIDECONFIG} | ${EGREPBINARY} "= .*(sha256|sha512)")
2016-09-10 16:12:44 +02:00
if [ -z "${FIND}" ]; then
LogText "Result: No SHA256 or SHA512 found for creating checksums"
Display --indent 6 --text "- AIDE config (Checksum)" --result Suggestion --color YELLOW
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Use SHA256 or SHA512 to create checksums in AIDE"
AddHP 1 3
2016-07-26 14:58:04 +02:00
else
LogText "Result: Found SHA256 or SHA512 found for creating checksums"
Display --indent 6 --text "- AIDE config (Checksum)" --result "${STATUS_OK}" --color GREEN
AddHP 2 2
2016-02-29 23:27:07 +01:00
fi
fi
2014-08-26 17:33:55 +02:00
#
#################################################################################
#
# Test : FINT-4350
# Description : Check if at least one file integrity tool is installed
Register --test-no FINT-4350 --weight L --network NO --category security --description "File integrity software installed"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Check if at least on file integrity tool is available/installed"
2014-08-26 17:33:55 +02:00
if [ ${FILE_INT_TOOL_FOUND} -eq 1 ]; then
LogText "Result: found at least one file integrity tool"
Display --indent 2 --text "- Checking presence integrity tool" --result "${STATUS_FOUND}" --color GREEN
2014-08-26 17:33:55 +02:00
AddHP 5 5
2016-07-26 14:58:04 +02:00
else
LogText "Result: No file integrity tools found"
Display --indent 2 --text "- Checking presence integrity tool" --result "${STATUS_NOT_FOUND}" --color YELLOW
2019-12-18 12:17:46 +01:00
ReportSuggestion "${TEST_NO}" "Install a file integrity tool to monitor changes to critical and sensitive files"
2014-08-26 17:33:55 +02:00
AddHP 0 5
fi
fi
#
#################################################################################
#
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#================================================================================
# Lynis - Copyright 2007-2019 Michael Boelen, CISOfy - https://cisofy.com