2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
2021-01-07 15:22:19 +01:00
# Copyright 2007-2021, 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.
#
#################################################################################
#
# Report
#
#################################################################################
#
2019-07-14 15:11:45 +02:00
# Add additional data fields to the report file at the end of the scan
2019-05-16 15:23:23 +02:00
Report "dhcp_client_running=${DHCP_CLIENT_RUNNING}"
Report "arpwatch_running=${ARPWATCH_RUNNING}"
# Report firewall installed for now, if we found one active. Next step would be determining binaries first and apply additional checks.
Report "firewall_active=${FIREWALL_ACTIVE}"
Report "firewall_empty_ruleset=${FIREWALL_EMPTY_RULESET}"
Report "firewall_installed=${FIREWALL_ACTIVE}"
2019-07-16 13:20:30 +02:00
if [ -n "${INSTALLED_PACKAGES}" ]; then Report "installed_packages_array=${INSTALLED_PACKAGES}"; fi
2019-05-16 15:23:23 +02:00
Report "package_audit_tool=${PACKAGE_AUDIT_TOOL}"
Report "package_audit_tool_found=${PACKAGE_AUDIT_TOOL_FOUND}"
Report "vulnerable_packages_found=${VULNERABLE_PACKAGES_FOUND}"
2019-07-14 15:11:45 +02:00
#
#################################################################################
#
2015-01-30 18:09:18 +01:00
# Hardening Index
2019-07-14 15:11:45 +02:00
#
2019-05-16 15:23:23 +02:00
# Goal:
# Provide a visual way to show how much the system is hardened
#
# Important:
# The index gives a simplified version of the measures taken on the system.
# It should be used to get a first impression about the state of the system or to compare similar systems.
# Getting the maximum score (100 or full bar) does not indicate that the system is fully secured.
# If no hardening has been found, set value to 1
if [ ${HPPOINTS} -eq 0 ]; then HPPOINTS=1; HPTOTAL=100; fi
HPINDEX=$((HPPOINTS * 100 / HPTOTAL))
HPAOBLOCKS=$((HPPOINTS * 20 / HPTOTAL))
# Set color related to rating
if [ ${HPINDEX} -lt 50 ]; then
HPCOLOR="${RED}"
HIDESCRIPTION="System has not or a low amount been hardened"
elif [ ${HPINDEX} -gt 49 -a ${HPINDEX} -lt 80 ]; then
HPCOLOR="${YELLOW}"
HIDESCRIPTION="System has been hardened, but could use additional hardening"
elif [ ${HPINDEX} -gt 79 -a ${HPINDEX} -lt 90 ]; then
HPCOLOR="${GREEN}"
HIDESCRIPTION="System seem to be decent hardened"
elif [ ${HPINDEX} -gt 89 ]; then
HPCOLOR="${GREEN}"
HIDESCRIPTION="System seem to be well hardened"
fi
case ${HPAOBLOCKS} in
0) HPBLOCKS="#"; HPEMPTY=" " ;;
1) HPBLOCKS="#"; HPEMPTY=" " ;;
2) HPBLOCKS="##"; HPEMPTY=" " ;;
3) HPBLOCKS="###"; HPEMPTY=" " ;;
4) HPBLOCKS="####"; HPEMPTY=" " ;;
5) HPBLOCKS="#####"; HPEMPTY=" " ;;
6) HPBLOCKS="######"; HPEMPTY=" " ;;
7) HPBLOCKS="#######"; HPEMPTY=" " ;;
8) HPBLOCKS="########"; HPEMPTY=" " ;;
9) HPBLOCKS="#########"; HPEMPTY=" " ;;
10) HPBLOCKS="##########"; HPEMPTY=" " ;;
11) HPBLOCKS="###########"; HPEMPTY=" " ;;
12) HPBLOCKS="############"; HPEMPTY=" " ;;
13) HPBLOCKS="#############"; HPEMPTY=" " ;;
14) HPBLOCKS="##############"; HPEMPTY=" " ;;
15) HPBLOCKS="###############"; HPEMPTY=" " ;;
16) HPBLOCKS="################"; HPEMPTY=" " ;;
17) HPBLOCKS="#################"; HPEMPTY=" " ;;
18) HPBLOCKS="##################"; HPEMPTY=" " ;;
19) HPBLOCKS="###################"; HPEMPTY=" " ;;
20) HPBLOCKS="####################"; HPEMPTY="" ;;
esac
HPGRAPH="[${HPCOLOR}${HPBLOCKS}${NORMAL}${HPEMPTY}]"
LogText "Hardening index : [${HPINDEX}] [${HPBLOCKS}${HPEMPTY}]"
LogText "Hardening strength: ${HIDESCRIPTION}"
2019-07-14 15:11:45 +02:00
#
#################################################################################
#
2015-09-11 14:54:38 +02:00
# Only show overview if not running in quiet mode
if [ ${QUIET} -eq 0 ]; then
echo ""; echo "================================================================================"
2016-04-05 11:31:21 +02:00
echo ""; echo " -[ ${WHITE}${PROGRAM_NAME} ${PROGRAM_VERSION} Results${NORMAL} ]-"
2015-09-11 14:54:38 +02:00
echo "";
if [ ${SHOW_REPORT} -eq 1 ]; then
2016-04-28 12:32:18 +02:00
LogTextBreak
2015-09-11 14:54:38 +02:00
2015-01-30 18:09:18 +01:00
# Show test results overview
2019-07-14 15:11:45 +02:00
if [ -z "${CONTROL_URL_PROTOCOL}" ]; then CONTROL_URL_PROTOCOL="https"; fi
if [ -z "${CONTROL_URL_PREPEND}" ]; then CONTROL_URL_PREPEND="cisofy.com/lynis/controls/"; fi
if [ -z "${CONTROL_URL_APPEND}" ]; then CONTROL_URL_APPEND="/"; fi
if [ -z "${CUSTOM_URL_PROTOCOL}" ]; then CUSTOM_URL_PROTOCOL="https"; fi
if [ -z "${CUSTOM_URL_PREPEND}" ]; then CUSTOM_URL_PREPEND="your-domain.example.org/controls/"; fi
if [ -z "${CUSTOM_URL_APPEND}" ]; then CUSTOM_URL_APPEND="/"; fi
2015-01-30 18:09:18 +01:00
# Show warnings from logfile
2017-10-26 08:23:15 +02:00
SWARNINGS=$(${GREPBINARY} 'Warning: ' ${LOGFILE} | sed 's/ /!space!/g')
2016-09-24 15:34:05 +02:00
if [ -z "${SWARNINGS}" ]; then
2016-04-19 12:04:08 +02:00
echo " ${OK}Great, no warnings${NORMAL}"; echo ""
2017-04-30 17:59:35 +02:00
else
2015-09-10 09:18:03 +02:00
echo " ${WARNING}Warnings${NORMAL} (${TOTAL_WARNINGS}):"
2015-01-30 18:09:18 +01:00
echo " ${WHITE}----------------------------${NORMAL}"
for WARNING in ${SWARNINGS}; do
2016-09-24 15:16:41 +02:00
SOLUTION=""
SHOWWARNING=$(echo ${WARNING} | sed 's/!space!/ /g' | sed 's/^.* Warning: //' | sed 's/\[details:\(.*\)\] \[solution:\(.*\)\]//' | sed 's/test://')
2017-03-27 17:15:02 +02:00
ADDLINK=$(echo ${WARNING} | sed 's/!space!/ /g' | sed 's/^.* Warning: \(.*\)\[test://' | sed 's/\]\(.*\)]//' | ${AWKBINARY} -F: '{print $1}')
2016-09-24 15:27:42 +02:00
DETAILS=$(echo ${WARNING} | sed 's/!space!/ /g' | sed 's/^.* Warning: \(.*\)\[details://' | sed 's/\]\(.*\)]//')
2016-09-24 15:16:41 +02:00
SUGGESTION_PIECES=$(echo ${WARNING} | sed 's/\[/ [/g')
for PIECE in ${SUGGESTION_PIECES}; do
if [ -z "${SOLUTION}" ]; then
SEARCH=$(echo ${PIECE} | grep "^\[solution:")
if [ $? -eq 0 ]; then SOLUTION=$(echo ${SEARCH} | sed 's/!space!/ /g' | sed 's/solution://' | sed 's/text://' | tr -d '[]'); fi
fi
done
IS_CUSTOM=$(echo ${ADDLINK} | grep "^CUST")
2016-04-19 12:04:08 +02:00
echo " ${RED}!${NORMAL} ${SHOWWARNING}"
2019-07-16 13:20:30 +02:00
if [ ! "${DETAILS}" = "-" -a -n "${DETAILS}" ]; then echo " - Details : ${CYAN}${DETAILS}${NORMAL}"; fi
2016-09-24 15:16:41 +02:00
if [ ${SHOW_REPORT_SOLUTION} -eq 1 -a ! "${SOLUTION}" = "-" ]; then echo " - Solution : ${SOLUTION}"; fi
2016-09-24 15:34:05 +02:00
if [ -z "${IS_CUSTOM}" ]; then
2016-02-15 12:39:06 +01:00
echo " ${CONTROL_URL_PROTOCOL}://${CONTROL_URL_PREPEND}${ADDLINK}${CONTROL_URL_APPEND}"
2017-04-30 17:59:35 +02:00
else
2016-02-15 12:39:06 +01:00
echo " ${CUSTOM_URL_PROTOCOL}://${CUSTOM_URL_PREPEND}${ADDLINK}${CUSTOM_URL_APPEND}"
2015-01-30 18:09:18 +01:00
fi
echo ""
done
fi
2014-08-26 17:33:55 +02:00
2015-01-30 18:09:18 +01:00
# Show suggestions from logfile
2020-11-09 05:17:03 +01:00
SUGGESTIONS=$(${GREPBINARY} 'Suggestion: ' ${LOGFILE} | sed 's/ /!space!/g')
2015-01-30 18:09:18 +01:00
2020-11-09 05:17:03 +01:00
if [ -z "${SUGGESTIONS}" ]; then
2015-01-30 18:09:18 +01:00
echo " ${OK}No suggestions${NORMAL}"; echo ""
2017-04-30 17:59:35 +02:00
else
2015-09-10 09:18:03 +02:00
echo " ${YELLOW}Suggestions${NORMAL} (${TOTAL_SUGGESTIONS}):"
2015-01-30 18:09:18 +01:00
echo " ${WHITE}----------------------------${NORMAL}"
2020-11-09 05:17:03 +01:00
for SUGGESTION in ${SUGGESTIONS}; do
2016-08-13 11:18:34 +02:00
SOLUTION=""
2016-09-24 15:34:05 +02:00
SHOWSUGGESTION=$(echo ${SUGGESTION} | sed 's/!space!/ /g' | sed 's/^.* Suggestion: //' | sed 's/\[details:\(.*\)\] \[solution:\(.*\)\]//' | sed 's/test://')
2017-03-27 17:15:02 +02:00
ADDLINK=$(echo ${SUGGESTION} | sed 's/!space!/ /g' | sed 's/^.* Suggestion: \(.*\)\[test://' | sed 's/\]\(.*\)]//' | ${AWKBINARY} -F: '{print $1}')
2016-09-24 15:34:05 +02:00
DETAILS=$(echo ${SUGGESTION} | sed 's/!space!/ /g' | sed 's/^.* Suggestion: \(.*\)\[details://' | sed 's/\]\(.*\)]//')
2016-08-13 11:18:34 +02:00
SUGGESTION_PIECES=$(echo ${SUGGESTION} | sed 's/\[/ [/g')
for PIECE in ${SUGGESTION_PIECES}; do
if [ -z "${SOLUTION}" ]; then
SEARCH=$(echo ${PIECE} | grep "^\[solution:")
if [ $? -eq 0 ]; then SOLUTION=$(echo ${SEARCH} | sed 's/!space!/ /g' | sed 's/solution://' | sed 's/text://' | tr -d '[]'); fi
fi
done
2017-03-06 08:41:21 +01:00
IS_CUSTOM=$(echo ${ADDLINK} | grep "^CUST")
2016-04-19 12:04:08 +02:00
echo " ${YELLOW}*${NORMAL} ${SHOWSUGGESTION}"
2019-07-16 13:20:30 +02:00
if [ ! "${DETAILS}" = "-" -a -n "${DETAILS}" ]; then echo " - Details : ${CYAN}${DETAILS}${NORMAL}"; fi
2016-08-13 11:18:34 +02:00
if [ ${SHOW_REPORT_SOLUTION} -eq 1 -a ! "${SOLUTION}" = "-" ]; then echo " - Solution : ${SOLUTION}"; fi
2016-09-24 15:34:05 +02:00
if [ -z "${IS_CUSTOM}" ]; then
2016-04-19 12:04:08 +02:00
echo " ${GRAY}${CONTROL_URL_PROTOCOL}://${CONTROL_URL_PREPEND}${ADDLINK}${CONTROL_URL_APPEND}${NORMAL}"
2017-04-30 17:59:35 +02:00
else
2016-04-19 12:04:08 +02:00
echo " ${GRAY}${CUSTOM_URL_PROTOCOL}://${CUSTOM_URL_PREPEND}${ADDLINK}${CUSTOM_URL_APPEND}${NORMAL}"
2015-01-30 18:09:18 +01:00
fi
2016-04-19 12:04:08 +02:00
echo ""
2015-01-30 18:09:18 +01:00
done
fi
2016-07-05 10:40:07 +02:00
# Show tip on how to continue (next steps)
2020-11-09 05:17:03 +01:00
if [ ! "${SWARNINGS}" = "" -o ! "${SUGGESTIONS}" = "" ]; then
2015-01-30 18:09:18 +01:00
echo " ${CYAN}Follow-up${NORMAL}:"
echo " ${WHITE}----------------------------${NORMAL}"
2016-08-26 14:05:20 +02:00
echo " ${WHITE}-${NORMAL} Show details of a test (lynis show details TEST-ID)"
echo " ${WHITE}-${NORMAL} Check the logfile for all details (less ${LOGFILE})"
2015-01-30 18:09:18 +01:00
echo " ${WHITE}-${NORMAL} Read security controls texts (https://cisofy.com)"
2016-08-26 14:05:20 +02:00
if [ ${UPLOAD_DATA} -eq 0 ]; then echo " ${WHITE}-${NORMAL} Use --upload to upload data to central system (Lynis Enterprise users)"; fi
2015-01-30 18:09:18 +01:00
echo ""
fi
echo "================================================================================"
2015-04-07 17:18:54 +02:00
echo ""
echo " ${WHITE}Lynis security scan details${NORMAL}:"
2014-08-26 17:33:55 +02:00
echo ""
2015-01-30 18:09:18 +01:00
echo " ${CYAN}Hardening index${NORMAL} : ${WHITE}${HPINDEX}${NORMAL} ${HPGRAPH}"
echo " ${CYAN}Tests performed${NORMAL} : ${WHITE}${CTESTS_PERFORMED}${NORMAL}"
2019-03-14 12:31:39 +01:00
if [ ${SKIP_PLUGINS} -eq 0 ]; then
echo " ${CYAN}Plugins enabled${NORMAL} : ${WHITE}${N_PLUGIN_ENABLED}${NORMAL}"
else
echo " ${CYAN}Plugins enabled${NORMAL} : ${WHITE}Skipped${NORMAL}"
fi
2015-04-07 17:18:54 +02:00
echo ""
2016-04-15 20:07:20 +02:00
echo " ${WHITE}Components${NORMAL}:"
2015-04-07 17:18:54 +02:00
if [ ${FIREWALL_ACTIVE} -eq 1 ]; then FIREWALL="${GREEN}V"; else FIREWALL="${RED}X"; fi
if [ ${MALWARE_SCANNER_INSTALLED} -eq 1 ]; then MALWARE="${GREEN}V"; else MALWARE="${RED}X"; fi
2016-04-15 20:07:20 +02:00
if [ ${IDS_IPS_TOOL_FOUND} -eq 1 ]; then IDSIPS="${GREEN}V"; else IDSIPS="${RED}X"; fi
2015-04-07 17:18:54 +02:00
2016-04-15 20:07:20 +02:00
echo " - Firewall [${FIREWALL}${NORMAL}]"
2016-07-26 15:33:52 +02:00
#echo " - Integrity monitoring [${IDSIPS}${NORMAL}]"
2016-04-15 20:07:20 +02:00
#echo " - Intrusion software [${IDSIPS}${NORMAL}]"
echo " - Malware scanner [${MALWARE}${NORMAL}]"
2015-04-07 17:18:54 +02:00
2015-01-30 18:09:18 +01:00
echo ""
2019-08-21 13:41:23 +02:00
echo " ${SECTION}Scan mode${NORMAL}:"
2019-08-21 13:59:28 +02:00
if [ ${DEVOPS_MODE} -eq 1 ]; then
echo " Normal [ ] Forensics [ ] Integration [V] Pentest [ ]"
elif [ ${FORENSICS_MODE} -eq 1 ]; then
echo " Normal [ ] Forensics [V] Integration [ ] Pentest [ ]"
2019-08-21 13:41:23 +02:00
elif [ ${PENTESTINGMODE} -eq 1 ]; then
if [ ${PRIVILEGED} -eq 0 ]; then
2019-08-21 13:59:28 +02:00
echo " Normal [ ] Forensics [ ] Integration [ ] Pentest [V] (running non-privileged)"
2019-08-21 13:41:23 +02:00
else
2019-08-21 13:59:28 +02:00
echo " Normal [ ] Forensics [ ] Integration [ ] Pentest [V] (running privileged)"
2019-08-21 13:41:23 +02:00
fi
else
2019-08-21 13:59:28 +02:00
echo " Normal [V] Forensics [ ] Integration [ ] Pentest [ ]"
2019-08-21 13:41:23 +02:00
fi
echo ""
2019-03-14 12:31:39 +01:00
echo " ${SECTION}Lynis modules${NORMAL}:"
2015-10-01 22:40:49 +02:00
if [ ${COMPLIANCE_TESTS_PERFORMED} -eq 1 ]; then
if [ ${COMPLIANCE_FINDINGS_FOUND} -eq 0 ]; then COMPLIANCE="${GREEN}V"; else COMPLIANCE="${RED}X"; fi
2017-04-30 17:59:35 +02:00
else
COMPLIANCE="${YELLOW}?"
2015-10-01 22:40:49 +02:00
fi
2019-03-14 12:31:39 +01:00
echo " - Compliance status [${COMPLIANCE}${NORMAL}]"
echo " - Security audit [${GREEN}V${NORMAL}]"
echo " - Vulnerability scan [${GREEN}V${NORMAL}]"
2015-01-30 18:09:18 +01:00
echo ""
echo " ${SECTION}Files${NORMAL}:"
echo " - Test and debug information : ${WHITE}${LOGFILE}${NORMAL}"
echo " - Report data : ${WHITE}${REPORTFILE}${NORMAL}"
2014-08-26 17:33:55 +02:00
echo ""
echo "================================================================================"
2015-01-30 18:09:18 +01:00
if [ ${PROGRAM_LV} -gt ${PROGRAM_AC} ]; then
2016-06-18 11:15:11 +02:00
echo " ${NOTICE}Notice: ${WHITE}${PROGRAM_NAME} ${GEN_UPDATE_AVAILABLE}${NORMAL}"
echo " ${GEN_CURRENT_VERSION} : ${WHITE}${PROGRAM_AC}${NORMAL} ${GEN_LATEST_VERSION} : ${WHITE}${PROGRAM_LV}${NORMAL}"
2015-01-30 18:09:18 +01:00
echo "================================================================================"
2017-04-30 17:59:35 +02:00
else
2015-01-30 18:09:18 +01:00
###########################################################################################
#
# Software quality program
# Only provide this hint when the tool is at the latest version
#
###########################################################################################
if [ ! "${PROGRAM_LV}" = "0" -a ! "${REPORTFILE}" = "" -a ! "${REPORTFILE}" = "/dev/null" ]; then
# Determine if the quality of the program can be increased by filtering out the exceptions
2017-03-06 08:41:21 +01:00
FIND=$(${GREPBINARY} "^exception" ${REPORTFILE})
2019-07-14 15:11:45 +02:00
if [ -n "${FIND}" ]; then
2015-01-30 18:09:18 +01:00
echo ""
2016-06-18 11:15:11 +02:00
echo " ${RED}${NOTE_EXCEPTIONS_FOUND}${NORMAL}"
echo " ${WHITE}${NOTE_EXCEPTIONS_FOUND_DETAILED}!${NORMAL}"
2015-01-30 18:09:18 +01:00
echo ""
2016-06-18 11:15:11 +02:00
echo " ${CYAN}${GEN_WHAT_TO_DO}:${NORMAL}"
echo " ${TEXT_YOU_CAN_HELP_LOGFILE} (${LOGFILE})."
2015-01-30 18:09:18 +01:00
echo " Go to https://cisofy.com/contact/ and send your file to the e-mail address listed"
echo ""
echo "================================================================================"
fi
2014-08-26 17:33:55 +02:00
fi
fi
2015-01-30 18:09:18 +01:00
# Display what tests are skipped in non-privileged scan for awareness
if [ ${PENTESTINGMODE} -eq 1 -a ! "${SKIPPED_TESTS_ROOTONLY}" = "" ]; then
echo ""
2016-06-18 11:15:11 +02:00
echo " ${PURPLE}${NOTE_SKIPPED_TESTS_NON_PRIVILEGED}${NORMAL}"
2015-01-30 18:09:18 +01:00
2017-03-06 08:41:21 +01:00
FIND=$(echo ${SKIPPED_TESTS_ROOTONLY} | sed 's/ /:space:/g')
2015-01-30 18:09:18 +01:00
# Split entries
2017-03-06 08:41:21 +01:00
FIND=$(echo ${FIND} | sed 's/====/ /g')
2015-01-30 18:09:18 +01:00
# Display found entries
2017-04-30 17:59:35 +02:00
for ITEM in ${FIND}; do
OUTPUT=$(echo ${ITEM} | sed 's/:space:/ /g')
echo " ${OUTPUT}"
2015-01-30 18:09:18 +01:00
done
echo ""
echo "================================================================================"
fi
2014-09-08 15:19:13 +02:00
2016-07-26 16:00:36 +02:00
echo ""
2014-08-26 17:33:55 +02:00
fi
2015-01-30 18:09:18 +01:00
fi
2015-06-11 20:50:19 +02:00
# Report data, even if it is not displayed on screen
2016-01-07 12:56:46 +01:00
Report "hardening_index=${HPINDEX}"
2015-06-11 20:50:19 +02:00
2015-01-30 18:09:18 +01:00
if [ ${QUIET} -eq 0 ]; then
2016-07-26 16:00:36 +02:00
echo " ${WHITE}${PROGRAM_NAME}${NORMAL} ${PROGRAM_VERSION}"
echo ""
echo " Auditing, system hardening, and compliance for UNIX-based systems"
echo " (Linux, macOS, BSD, and others)"
2015-10-01 22:40:49 +02:00
echo ""
2016-04-05 11:31:21 +02:00
echo " ${PROGRAM_COPYRIGHT}"
echo " ${WHITE}${PROGRAM_EXTRAINFO}${NORMAL}"
2016-01-07 12:56:46 +01:00
echo ""
2014-08-26 17:33:55 +02:00
echo "================================================================================"
fi
#
#================================================================================
2016-03-13 16:03:46 +01:00
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com