HackingScripts/unix-privesc-check.sh

138 lines
3.3 KiB
Bash
Raw Permalink Normal View History

2020-01-28 22:15:42 +01:00
#!/bin/sh
2021-05-03 22:35:31 +02:00
# $Revision$
2020-01-28 22:15:42 +01:00
#
# This program is free software; you can redistribute it and/or modify
2021-05-03 22:35:31 +02:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2020-01-28 22:15:42 +01:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
2021-05-03 22:35:31 +02:00
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020-01-28 22:15:42 +01:00
#
2021-05-03 22:35:31 +02:00
# (c) Tim Brown, 2012
# <mailto:timb@nth-dimension.org.uk>
# <http://www.nth-dimension.org.uk/> / <http://www.machine.org.uk/>
2020-01-28 22:15:42 +01:00
2021-05-03 22:35:31 +02:00
. lib/misc/stdio
2020-01-28 22:15:42 +01:00
2021-05-03 22:35:31 +02:00
header () {
VERSION="2.1"
SVNVERSION="$Revision$" # Don't change this line. Auto-updated.
SVNVNUM="`echo $SVNVERSION | sed \"s/[^0-9]//g\"`"
if [ -n "${SVNVNUM}" ]; then
VERSION="${VERSION}-svn-${SVNVNUM}"
2020-01-28 22:15:42 +01:00
fi
2021-05-03 22:35:31 +02:00
printf "unix-privesc-check v${VERSION} ( http://code.google.com/p/unix-privesc-check )\n\n"
2020-01-28 22:15:42 +01:00
}
2021-05-03 22:35:31 +02:00
version () {
header
preamble
printf "Brought to you by:\n"
cat doc/AUTHORS
exit 1
2020-01-28 22:15:42 +01:00
}
2021-05-03 22:35:31 +02:00
preamble () {
printf "Shell script to check for simple privilege escalation vectors on UNIX systems.\n\n"
2020-01-28 22:15:42 +01:00
}
2021-05-03 22:35:31 +02:00
usage () {
header
preamble
printf "Usage: ${0}\n"
printf "\n"
printf "\t--help\tdisplay this help and exit\n"
printf "\t--version\tdisplay version and exit\n"
printf "\t--color\tenable output coloring\n"
printf "\t--verbose\tverbose level (0-2, default: 1)\n"
printf "\t--type\tselect from one of the following check types:\n"
for checktype in lib/checks/enabled/*
2020-01-28 22:15:42 +01:00
do
2021-05-03 22:35:31 +02:00
printf "\t\t`basename ${checktype}`\n"
2020-01-28 22:15:42 +01:00
done
2021-05-03 22:35:31 +02:00
printf "\t--checks\tprovide a comma separated list of checks to run, select from the following checks:\n"
for check in lib/checks/*
2020-01-28 22:15:42 +01:00
do
2021-05-03 22:35:31 +02:00
if [ "`basename \"${check}\"`" != "enabled" ]
then
printf "\t\t`basename ${check}`\n"
2020-01-28 22:15:42 +01:00
fi
done
2021-05-03 22:35:31 +02:00
exit 1
}
2020-01-28 22:15:42 +01:00
2021-05-03 22:35:31 +02:00
# TODO make it use lib/misc/validate
CHECKS=""
TYPE="all"
COLORING="0"
VERBOSE="1"
while [ -n "${1}" ]
do
case "${1}" in
--help|-h)
usage
;;
--version|-v|-V)
version
;;
--color)
COLORING="1"
;;
--verbose)
shift
VERBOSE="${1}"
;;
--type|-t)
shift
TYPE="${1}"
;;
--checks|-c)
shift
CHECKS="${1}"
;;
esac
shift
done
header
if [ "${VERBOSE}" != "0" -a "${VERBOSE}" != "1" -a "${VERBOSE}" != "2" ]
then
stdio_message_error "upc" "the provided verbose level ${VERBOSE} is invalid - use 0, 1 or 2 next time"
VERBOSE="1"
fi
if [ -n "${CHECKS}" ]
then
for checkfilename in `printf "${CHECKS}" | tr -d " " | tr "," " "`
2020-01-28 22:15:42 +01:00
do
2021-05-03 22:35:31 +02:00
if [ ! -e "lib/checks/${checkfilename}" ]
then
stdio_message_error "upc" "the provided check name '${checkfilename}' does not exist"
2020-01-28 22:15:42 +01:00
else
2021-05-03 22:35:31 +02:00
. "lib/checks/${checkfilename}"
`basename "${checkfilename}"`_init
`basename "${checkfilename}"`_main
`basename "${checkfilename}"`_fini
2020-01-28 22:15:42 +01:00
fi
done
else
2021-05-03 22:35:31 +02:00
if [ ! -d "lib/checks/enabled/${TYPE}" ]
then
stdio_message_error "upc" "the provided check type '${TYPE}' does not exist"
2020-01-28 22:15:42 +01:00
else
2021-05-03 22:35:31 +02:00
for checkfilename in lib/checks/enabled/${TYPE}/*
do
. "${checkfilename}"
`basename "${checkfilename}"`_init
`basename "${checkfilename}"`_main
`basename "${checkfilename}"`_fini
2020-01-28 22:15:42 +01:00
done
fi
fi
2021-05-03 22:35:31 +02:00
exit 0