lynis/include/parameters

332 lines
9.7 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 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.
#
#################################################################################
#
# Parameter checks
#
#################################################################################
#
# Check number of parameters submitted (at least one is needed)
PARAMCOUNT=$#
while [ $# -ge 1 ]; do
2014-11-14 16:15:35 +01:00
case $1 in
# Helpers first
audit)
CHECK_BINARIES=0
RUN_HELPERS=1
HELPER="audit"
RUN_PLUGINS=0
RUN_TESTS=0
if [ ! $2 = "" ]; then
case $2 in
"dockerfile")
if [ "$3" = "" ]; then
echo "${RED}Error: ${WHITE}Missing file name or URL${NORMAL}"
echo "Example: lynis audit dockerfile /root/Dockerfile"
ExitFatal
else
shift; shift
HELPER_PARAMS="$1 $2 $3"
HELPER="audit_dockerfile"
break
fi
;;
"system")
CHECK_BINARIES=1
HELPER=""
RUN_PLUGINS=1
RUN_TESTS=1
shift
#break
;;
esac
else
echo "${RED}Error: ${WHITE}Need a target to audit${NORMAL}"
echo " "
echo "Examples:"
echo "lynis audit dockerfile"
echo "lynis audit system"
ExitFatal
fi
#break
;;
2014-08-26 17:33:55 +02:00
2016-04-07 16:24:38 +02:00
show)
CHECK_BINARIES=0
RUN_HELPERS=1
HELPER="show"
RUN_PLUGINS=0
RUN_TESTS=0
QUIET=1
SHOW_PROGRAM_DETAILS=0
shift
HELPER_PARAMS="$1 $2"
break
#if [ ! $2 = "" ]; then
# shift
# HELPER_PARAMS="$1 $2"
# break
# else
# echo "${RED}Error: ${WHITE}Need more specifics for show${NORMAL}"
# echo " "
# echo "Examples:"
# echo "lynis show config"
# echo "lynis show plugins"
# echo "lynis show version"
# ExitFatal
#fi
;;
update)
CHECK_BINARIES=0
RUN_HELPERS=1
HELPER="update"
RUN_PLUGINS=0
RUN_TESTS=0
SHOW_PROGRAM_DETAILS=0
if [ ! $2 = "" ]; then
shift
HELPER_PARAMS="$1 $2"
break
else
echo "${RED}Error: ${WHITE}Need a target for update${NORMAL}"
echo " "
echo "Examples:"
echo "lynis update info"
echo "lynis update release"
ExitFatal
fi
;;
2014-08-26 17:33:55 +02:00
# Assign auditor to report
--auditor)
shift
AUDITORNAME=$1
;;
# Perform tests
-c | --check-all | --checkall)
CHECK=1
;;
# Cronjob support
--cronjob | --cron)
CRONJOB=1;
# Use some defaults (-c, -Q, no colors)
CHECK=1; QUICKMODE=1; NEVERBREAK=1
# Get rid of the colors
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;;
# Perform tests with additional debugging information on screen
--debug)
2014-11-14 16:15:35 +01:00
DEBUG=1
2014-08-26 17:33:55 +02:00
;;
2016-04-26 13:40:21 +02:00
# Developer mode (more details when creating tests)
--developer)
DEVELOPER_MODE=1
;;
2016-01-01 15:44:32 +01:00
# Display all available options with short alias
2014-11-14 16:15:35 +01:00
--dump-options | --dumpoptions)
2016-01-01 15:44:32 +01:00
OPTIONS="--auditor
--check-all_(-c) --config --cronjob_(--cron)
2016-01-01 15:44:32 +01:00
--debug
--help_(-h)
--info
--license-key --log-file
--manpage_(--man)
--no-colors --no-log
--pentest --profile --plugins-dir
--quiet_(-q) --quick_(-Q)
--report-file --reverse-colors
--tests --tests-category
--upload
--version_(-V) --view-categories"
2014-11-14 16:15:35 +01:00
for I in ${OPTIONS}; do
2016-01-01 15:44:32 +01:00
echo "${I}" | tr '_' ' '
2014-11-14 16:15:35 +01:00
done
ExitClean
;;
2014-08-26 17:33:55 +02:00
# View help
--help | -h)
VIEWHELP=1
;;
# View program/database information
--check-update | --check-updates | --info)
echo "This option is deprecated"
echo "Use: lynis update info"
ExitClean
2014-08-26 17:33:55 +02:00
;;
# License key for Lynis Enterprise
--license-key)
shift
LICENSE_KEY=$1
;;
# Adjust default logfile location
--logfile | --log-file)
shift
LOGFILE=$1
;;
# Don't use colors
2014-11-14 16:15:35 +01:00
--no-colors | --nocolors)
2014-08-26 17:33:55 +02:00
NORMAL=""; WARNING=""; SECTION=""; NOTICE=""; OK=""; BAD=""; CYAN=""; MAGENTA=""; PURPLE=""; YELLOW=""; WHITE=""; GREEN=""; RED=""
;;
# Disable logging
--no-log | --nolog)
LOGFILE="/dev/null"
;;
--pentest | --pen-test)
PENTESTINGMODE=1
;;
2014-08-26 17:33:55 +02:00
# Define a custom profile file
--profile)
shift
SEARCH_PROFILES=$1
2014-08-26 17:33:55 +02:00
;;
# Define a custom plugin directory
--plugindir | --plugin-dir | --plugins-dir)
2014-08-26 17:33:55 +02:00
shift
PLUGINDIR=$1
LASTCHAR=`echo $1 | awk '{ print substr($0, length($0))}'`
if [ "${LASTCHAR}" = "/" ]; then
echo "${RED}Error:${WHITE} plugin directory path should not end with a slash${NORMAL}"
ExitCustom 65
2014-08-26 17:33:55 +02:00
fi
if [ ! -d ${PLUGINDIR} ]; then
echo "${RED}Error:${WHITE} invalid plugin directory ${PLUGINDIR}${NORMAL}"
ExitCustom 66
2014-08-26 17:33:55 +02:00
fi
;;
# Quiet mode
-q | --quiet)
QUIET=1
# Run non-interactive
QUICKMODE=1
;;
# Non-interactive mode
-Q | --quick)
QUICKMODE=1
;;
2016-01-01 15:44:32 +01:00
# Define alternative report file
2014-11-14 16:15:35 +01:00
--report-file)
shift
REPORTFILE=$1
;;
2014-08-26 17:33:55 +02:00
# Strip the colors which aren't clearly visible on light backgrounds
--reverse-colors)
#NORMAL="";
SECTION="${NORMAL}";
NOTICE="${NORMAL}";
#OK="";
#BAD="";
CYAN="${NORMAL}";
GREEN="${NORMAL}";
YELLOW="${NORMAL}";
WHITE="${NORMAL}";
PURPLE="${NORMAL}";
#GREEN="";
#RED=""
;;
# Skip execution of plugins
--skip-plugins | --no-plugins)
RUN_PLUGINS=0
;;
2014-08-26 17:33:55 +02:00
# Only scan these tests
--tests)
shift
TESTS_TO_PERFORM=$1
;;
# Scan one or more categories only
--tests-category)
shift
TESTS_CATEGORY_TO_PERFORM=$1
;;
# Lynis Enterprise: upload data to central node
--upload)
UPLOAD_DATA=1
2014-08-26 17:33:55 +02:00
;;
2016-04-19 19:46:20 +02:00
--verbose)
VERBOSE=1
;;
2014-08-26 17:33:55 +02:00
# Version number
-V | --version)
2016-04-05 11:31:21 +02:00
echo "${PROGRAM_VERSION}"
2014-08-26 17:33:55 +02:00
exit 0
;;
--view-categories | --list-categories | --show-categories)
ViewCategories
exit 0
;;
# View man page
2014-11-14 16:15:35 +01:00
--view-manpage | --man | --manpage)
2014-08-26 17:33:55 +02:00
if [ -f lynis.8 ]; then
nroff -man lynis.8
exit 0
else
echo "Error: man page file not found (lynis.8)"
echo "If you are running an installed version of Lynis, use 'man lynis'"
exit 1
fi
;;
# Warnings
--warnings-only | --show-warnings-only)
SHOW_WARNINGS_ONLY=1
QUICKMODE=1
QUIET=1
;;
2014-08-26 17:33:55 +02:00
# Drop out when using wrong option(s)
*)
# Wrong option used, we bail out later
WRONGOPTION=1
WRONGOPTION_value=$1
;;
2014-09-25 16:55:23 +02:00
2014-11-14 16:15:35 +01:00
esac
shift
2014-09-25 16:55:23 +02:00
2014-08-26 17:33:55 +02:00
done
#================================================================================
# Lynis - Security Auditing and System Hardening for Linux and UNIX - https://cisofy.com