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.
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# NFS
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
InsertSection "NFS"
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
NFS_DAEMON_RUNNING=0
|
|
|
|
NFS_EXPORTS_EMPTY=0
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
# Test : STRG-1902
|
|
|
|
# Description : Check rpcinfo
|
2014-09-15 12:01:09 +02:00
|
|
|
if [ ! "${RPCINFOBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking rpcinfo registered programs"
|
2014-08-26 17:33:55 +02:00
|
|
|
FIND=`${RPCINFOBINARY} -p 2> /dev/null | tr -s ' ' ','`
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "rpcinfo: ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
2016-06-18 11:14:01 +02:00
|
|
|
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
|
2014-09-15 12:01:09 +02:00
|
|
|
if [ ! "${RPCINFOBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking NFS registered versions"
|
2014-08-26 17:33:55 +02:00
|
|
|
FIND=`${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $2 } }' | uniq | sort`
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found version: ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
2016-06-18 11:14:01 +02:00
|
|
|
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
|
2015-09-07 17:35:07 +02:00
|
|
|
if [ ! "${RPCINFOBINARY}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking NFS registered protocols"
|
2014-08-26 17:33:55 +02:00
|
|
|
FIND=`${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $3 } }' | uniq | sort`
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found protocol: ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Output: no NFS protocols found"
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check port number
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking NFS registered ports"
|
2014-08-26 17:33:55 +02:00
|
|
|
FIND=`${RPCINFOBINARY} -p 2> /dev/null | ${AWKBINARY} '{ if ($5=="nfs") { print $3 } }' | uniq | sort`
|
|
|
|
for I in ${FIND}; do
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found port: ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Output: no NFS port number found"
|
2014-08-26 17:33:55 +02:00
|
|
|
fi
|
2016-06-18 11:14:01 +02:00
|
|
|
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
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: Checking running NFS daemon"
|
2016-08-25 15:31:33 +02:00
|
|
|
FIND=`${PSBINARY} ax | ${GREPBINARY} "nfsd" | ${GREPBINARY} -v "grep"`
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ "${FIND}" = "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Output: NFS daemon is not running"
|
2016-06-18 11:14:01 +02:00
|
|
|
Display --indent 2 --text "- Check running NFS daemon" --result "${STATUS_NOT_FOUND}" --color WHITE
|
2014-08-26 17:33:55 +02:00
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Output: NFS daemon is running"
|
2016-06-18 11:14:01 +02:00
|
|
|
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
|
2016-07-24 17:22:00 +02:00
|
|
|
#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
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Test: check /etc/exports"
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ -f /etc/exports ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: /etc/exports exists"
|
2016-08-25 15:31:33 +02:00
|
|
|
FIND=`${GREPBINARY} -v "^$" /etc/exports | ${GREPBINARY} -v "^#" | sed 's/ /!space!/g'`
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ ! "${FIND}" = "" ]; then
|
|
|
|
for I in ${FIND}; do
|
|
|
|
I=`echo ${I} | sed 's/!space!/ /g'`
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Found line: ${I}"
|
2014-08-26 17:33:55 +02:00
|
|
|
done
|
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: /etc/exports does not contain exported file systems"
|
2014-08-26 17:33:55 +02:00
|
|
|
NFS_EXPORTS_EMPTY=1
|
|
|
|
fi
|
2016-06-18 11:14:01 +02:00
|
|
|
Display --indent 4 --text "- Checking /etc/exports" --result "${STATUS_FOUND}" --color GREEN
|
2014-08-26 17:33:55 +02:00
|
|
|
else
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: file /etc/exports does not exist"
|
2016-06-18 11:14:01 +02:00
|
|
|
Display --indent 4 --text "- Checking /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
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2016-06-18 11:14:01 +02:00
|
|
|
Display --indent 6 --text "- Checking empty /etc/exports" --result "${STATUS_SUGGESTION}" --color YELLOW
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: /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
|
2016-07-24 17:22:00 +02:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
#LogText "Test: "
|
2016-08-25 15:31:33 +02:00
|
|
|
sFIND=`${SHOWMOUNTBINARY} -e | ${AWKBINARY} '{ print $2 }' | sed '1d'| ${GREPBINARY} "\*"`
|
2014-08-26 17:33:55 +02:00
|
|
|
if [ "${sFIND}" != "" ]; then
|
2015-12-21 21:17:15 +01:00
|
|
|
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
|
2015-12-21 21:17:15 +01:00
|
|
|
LogText "Result: only some clients are allowed to access a NFS share"
|
2016-06-18 11:14:01 +02:00
|
|
|
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
|
|
|
|
#
|
|
|
|
#################################################################################
|
|
|
|
#
|
|
|
|
|
2016-04-28 12:31:57 +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
|