Skip to content

remove coloring optional. This closes #36 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions bashcheck
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
#!/bin/bash


color_FAIL="\033[91m"
color_NORM="\033[39m"
color_LightYellow="\033[93m"
color_LightGreen="\033[92m"
color_LightMagenta="\033[95m"
color_LightCyan="\033[96m"

while :; do
case $1 in
-n|--nocolor)
unset color_FAIL
unset color_NORM
unset color_LightYellow
unset color_LightGreen
unset color_LightMagenta
unset color_LightCyan
;;
*) break
esac
shift
done

warn() {
if [ "$scary" == "1" ]; then
echo -e "\033[91mVulnerable to $1\033[39m"
echo -e "${color_FAIL}Vulnerable to $1${color_NORM}"
else
echo -e "\033[93mFound non-exploitable $1\033[39m"
echo -e "${color_LightYellow}Found non-exploitable $1${color_NORM}"
fi
}

good() {
echo -e "\033[92mNot vulnerable to $1\033[39m"
echo -e "${color_LightGreen}Not vulnerable to $1${color_NORM}"
}

tmpdir=`mktemp -d -t tmp.XXXXXXXX`

[ -n "$1" ] && bash=$(which $1) || bash=$(which bash)
echo -e "\033[95mTesting $bash ..."
echo -e "${color_LightMagenta}Testing $bash ..."
$bash -c 'echo "Bash version $BASH_VERSION"'
echo -e "\033[39m"
echo -e "${color_NORM}"

#r=`a="() { echo x;}" $bash -c a 2>/dev/null`
if [ -n "$(env 'a'="() { echo x;}" $bash -c a 2>/dev/null)" ]; then
echo -e "\033[91mVariable function parser active, maybe vulnerable to unknown parser bugs\033[39m"
echo -e "${color_FAIL}Variable function parser active, maybe vulnerable to unknown parser bugs${color_NORM}"
scary=1
elif [ -n "$(env 'BASH_FUNC_a%%'="() { echo x;}" $bash -c a 2>/dev/null)" ]; then
echo -e "\033[92mVariable function parser pre/suffixed [%%, upstream], bugs not exploitable\033[39m"
echo -e "${color_LightGreen}Variable function parser pre/suffixed [%%, upstream], bugs not exploitable${color_NORM}"
scary=0
elif [ -n "$(env 'BASH_FUNC_a()'="() { echo x;}" $bash -c a 2>/dev/null)" ]; then
echo -e "\033[92mVariable function parser pre/suffixed [(), redhat], bugs not exploitable\033[39m"
echo -e "${color_LightGreen}Variable function parser pre/suffixed [(), redhat], bugs not exploitable${color_NORM}"
scary=0
elif [ -n "$(env '__BASH_FUNC<a>()'="() { echo x;}" $bash -c a 2>/dev/null)" ]; then
echo -e "\033[92mVariable function parser pre/suffixed [__BASH_FUNC<..>(), apple], bugs not exploitable\033[39m"
echo -e "${color_LightGreen}Variable function parser pre/suffixed [__BASH_FUNC<..>(), apple], bugs not exploitable${color_NORM}"
scary=0
else
echo -e "\033[92mVariable function parser inactive, bugs not exploitable\033[39m"
echo -e "${color_LightGreen}Variable function parser inactive, bugs not exploitable${color_NORM}"
scary=0
fi

Expand Down Expand Up @@ -68,7 +91,7 @@ $bash -c "`for i in {1..200}; do echo -n "for x$i in; do :;"; done; for i in {1.
if [ $? != 0 ]; then
warn "CVE-2014-7187 (nested loops off by one)"
else
echo -e "\033[96mTest for CVE-2014-7187 not reliable without address sanitizer\033[39m"
echo -e "${color_LightCyan}Test for CVE-2014-7187 not reliable without address sanitizer${color_NORM}"
fi

$($bash -c "f(){ x(){ _;};x(){ _;}<<a;}" 2>/dev/null)
Expand Down