#!/usr/bin/env bash

function check_glibc_version {

	typeset version=$( ldd --version | head -1 |  sed 's/^.*) //' )
	echo "version of GLIBC: ${version}"
	#test if the version is vulnerable
	typeset -i subversion=$( echo ${version} | cut -d'.' -f 2- )
	if [[ "${subversion}" -ge 2 && "${subversion}" -le 16 ]]
	then
		echo -e "\033[33mThis version may be vulnerable to GHOST\033[0m"
	else
		echo -e "\033[32mThis version is not vulnerable to GHOST\033[0m"
	fi
}

#CVE-2015-0235
function check_ghost {

	typeset scriptDir=$( dirname "${0}" )

	echo ""
	echo "Testing GLIBC GHOST with ${scriptDir}/ghost-cve-2015-0235 executable"

	if [[ ! -x ghost-cve-2015-0235 ]]
	then
		chmod u+x ghost-cve-2015-0235
	fi

	${scriptDir}/ghost-cve-2015-0235
	if [[ "${?}" -ne 0 ]]
	then
		return 1
	fi

	return 0
}

#Print the used BASH and the version
check_glibc_version
#Test ghost buffer overflow
check_ghost
exit $?

#!/usr/bin/env bash

function check_glibc_version {

	typeset version=$( ldd --version | head -1 |  sed 's/^.*) //' )
	echo "version of GLIBC: ${version}"
	#test if the version is vulnerable
	typeset -i subversion=$( echo ${version} | cut -d'.' -f 2 )
	if [[ "${subversion}" -ge 2 && "${subversion}" -le 16 ]]
	then
		echo -e "\033[33mThis version may be vulnerable to GHOST\033[0m"
	else
		echo -e "\033[32mThis version is not vulnerable to GHOST\033[0m"
	fi
}

#CVE-2015-0235
function check_ghost {

	typeset scriptDir=$( dirname "${0}" )

	echo ""
	echo "Testing GLIBC GHOST with ${scriptDir}/ghost-cve-2015-0235 executable"

	if [[ ! -x ghost-cve-2015-0235 ]]
	then
		chmod u+x ghost-cve-2015-0235
	fi

	${scriptDir}/ghost-cve-2015-0235
	if [[ "${?}" -ne 0 ]]
	then
		return 1
	fi

	return 0
}

#Print the used BASH and the version
check_glibc_version
#Test ghost buffer overflow
check_ghost
exit $?

Fix glibc version checking for debian subversion
Fix glibc version checking for debian subversion