lynis/include/tests_storage_nfs

184 lines
8.4 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.
#
#################################################################################
#
# NFS
#
#################################################################################
#
InsertSection "NFS"
#
#################################################################################
#
NFS_DAEMON_RUNNING=0
NFS_EXPORTS_EMPTY=0
#
#################################################################################
#
# Test : STRG-1902
# Description : Check rpcinfo
2017-04-23 20:06:54 +02:00
if [ ! -z "${RPCINFOBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1902 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check rpcinfo registered programs"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking rpcinfo registered programs"
FIND=$(${RPCINFOBINARY} -p 2> /dev/null | ${TRBINARY} -s ' ' ',')
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
LogText "rpcinfo: ${I}"
2014-08-26 17:33:55 +02:00
done
Display --indent 2 --text "- Query rpc registered programs" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : STRG-1904
# Description : Check nfs versions in rpcinfo
2017-04-23 20:06:54 +02:00
if [ ! -z "${RPCINFOBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1904 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check nfs rpc"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking NFS registered versions"
FIND=$(${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $2 } }' | uniq | sort)
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
LogText "Found version: ${I}"
2014-08-26 17:33:55 +02:00
done
Display --indent 2 --text "- Query NFS versions" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : STRG-1906
# Description : Check nfs protocols (TCP/UDP) and port in rpcinfo
2017-04-23 20:06:54 +02:00
if [ ! -z "${RPCINFOBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1906 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check nfs rpc"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking NFS registered protocols"
FIND=$(${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $3 } }' | uniq | sort)
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
LogText "Found protocol: ${I}"
2014-08-26 17:33:55 +02:00
done
2017-04-23 20:06:54 +02:00
if [ -z "${FIND}" ]; then
LogText "Output: no NFS protocols found"
2014-08-26 17:33:55 +02:00
fi
# Check port number
LogText "Test: Checking NFS registered ports"
FIND=$(${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $3 } }' | uniq | sort)
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
LogText "Found port: ${I}"
2014-08-26 17:33:55 +02:00
done
2017-04-23 20:06:54 +02:00
if [ -z "${FIND}" ]; then
LogText "Output: no NFS port number found"
2014-08-26 17:33:55 +02:00
fi
Display --indent 2 --text "- Query NFS protocols" --result "${STATUS_DONE}" --color GREEN
2014-08-26 17:33:55 +02:00
fi
#
#################################################################################
#
# Test : STRG-1920
# Description : Check for running NFS daemons
Register --test-no STRG-1920 --weight L --network NO --category security --description "Checking NFS daemon"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: Checking running NFS daemon"
FIND=$(${PSBINARY} ax | ${GREPBINARY} "nfsd" | ${GREPBINARY} -v "grep")
2017-04-23 20:06:54 +02:00
if [ -z "${FIND}" ]; then
LogText "Output: NFS daemon is not running"
Display --indent 2 --text "- Check running NFS daemon" --result "${STATUS_NOT_FOUND}" --color WHITE
2017-04-23 20:06:54 +02:00
else
LogText "Output: NFS daemon is running"
Display --indent 2 --text "- Check running NFS daemon" --result "${STATUS_FOUND}" --color GREEN
2014-08-26 17:33:55 +02:00
NFS_DAEMON_RUNNING=1
fi
fi
#
#################################################################################
#
# Test : STRG-1924
# Description : Check missing nfs in rpcinfo while NFS is running
#Register --test-no STRG-1924 --weight L --network NO --category security --description "Checking NFS daemon"
2014-08-26 17:33:55 +02:00
#if [ ${SKIPTEST} -eq 0 ]; then
#
#################################################################################
#
# Test : STRG-1926
# Description : Check NFS exports
if [ ${NFS_DAEMON_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1926 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking NFS exports"
2015-09-07 17:35:07 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
LogText "Test: check /etc/exports"
2017-04-23 20:06:54 +02:00
if [ -f ${ROOTDIR}etc/exports ]; then
LogText "Result: ${ROOTDIR}etc/exports exists"
FIND=$(${GREPBINARY} -v "^$" ${ROOTDIR}etc/exports | ${GREPBINARY} -v "^#" | ${SEDBINARY} 's/ /!space!/g')
if [ ! -z "${FIND}" ]; then
2014-08-26 17:33:55 +02:00
for I in ${FIND}; do
I=$(echo ${I} | ${SEDBINARY} 's/!space!/ /g')
LogText "Found line: ${I}"
2014-08-26 17:33:55 +02:00
done
2017-04-23 20:06:54 +02:00
else
LogText "Result: ${ROOTDIR}etc/exports does not contain exported file systems"
2014-08-26 17:33:55 +02:00
NFS_EXPORTS_EMPTY=1
fi
2017-04-23 20:06:54 +02:00
Display --indent 4 --text "- Checking ${ROOTDIR}etc/exports" --result "${STATUS_FOUND}" --color GREEN
else
LogText "Result: file /etc/exports does not exist"
2017-04-23 20:06:54 +02:00
Display --indent 4 --text "- Checking ${ROOTDIR}etc/exports" --result "${STATUS_NOT_FOUND}" --color WHITE
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : STRG-1928
# Description : Check for empty exports file while NFS is running
2015-09-07 17:35:07 +02:00
if [ ${NFS_DAEMON_RUNNING} -eq 1 ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1928 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Checking empty /etc/exports"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
if [ ${NFS_EXPORTS_EMPTY} -eq 1 ]; then
Display --indent 6 --text "- Checking empty /etc/exports" --result "${STATUS_SUGGESTION}" --color YELLOW
2017-04-23 20:06:54 +02:00
LogText "Result: ${ROOTDIR}etc/exports seems to have no exported file systems"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "/etc/exports has no exported file systems, while NFS daemon is running. Check if NFS needs to run on this system"
fi
fi
#
#################################################################################
#
# Test : STRG-1930
# Description : Check client access to nfs share
if [ ${NFS_DAEMON_RUNNING} -eq 1 -a ${NFS_EXPORTS_EMPTY} -eq 0 -a ! "${SHOWMOUNTBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no STRG-1930 --preqs-met ${PREQS_MET} --weight L --network NO --category security --description "Check client access to nfs share"
2014-08-26 17:33:55 +02:00
if [ ${SKIPTEST} -eq 0 ]; then
2017-04-23 20:06:54 +02:00
sFIND=$(${SHOWMOUNTBINARY} -e | ${AWKBINARY} '{ print $2 }' | ${SEDBINARY} '1d' | ${GREPBINARY} "\*")
if [ ! -z "${sFIND}" ]; then
LogText "Result: all client are allowed to access a NFS share in /etc/exports"
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking NFS client access" --result "ALL CLIENTS" --color YELLOW
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Specify clients that are allowed to access a NFS share /etc/exports"
AddHP 2 3
else
LogText "Result: only some clients are allowed to access a NFS share"
Display --indent 4 --text "- Checking NFS client access" --result "${STATUS_OK}" --color GREEN
2014-08-26 17:33:55 +02:00
AddHP 3 3
fi
fi
#
#################################################################################
#
WaitForKeyPress
2014-08-26 17:33:55 +02:00
#
#================================================================================
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com