Skip to content

Instantly share code, notes, and snippets.

@affix
Last active July 3, 2024 12:17
Show Gist options
  • Save affix/d982e9b7d2d268f3f6b14771aeae01cd to your computer and use it in GitHub Desktop.
Save affix/d982e9b7d2d268f3f6b14771aeae01cd to your computer and use it in GitHub Desktop.
A simple regreSSHion (CVE-2024-6387) checker written in bash. This makes use of nc however if nc is unavailable it reverts to making use of /dev/tcp
#!/bin/bash
# Copyright 2024 Keiran 'Affix' Smith
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
safe_ver=(
"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.10"
"SSH-2.0-OpenSSH_9.3p1 Ubuntu-3ubuntu3.6"
"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.3"
"SSH-2.0-OpenSSH_9.3p1 Ubuntu-1ubuntu3.6"
"SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3"
"SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u"
)
echo "Super simple regreSSHion (CVE-2024-6387) checker"
echo "Written by Keiran 'Affix' Smith <opensource_at_keiran.scot>"
if [ $# -ne 1 ]; then
echo "Usage: $0 <IP/domain>"
exit 1
fi
usenc=1
if ! [ -x "$(command -v nc)" ]; then
echo 'Error: nc is not installed, Using /dev/tcp' >&2
usenc=0
fi
doCheck() {
versionstr=""
if ! [ usenc ]; then
versionstr=$(echo "" > /dev/tcp/$1/22 | head -n 1)
else
versionstr=$(echo "" | nc -w 2 $1 22 | head -n 1)
fi
version=$(echo $versionstr | awk '{print $1}' | cut -d '_' -f 2 | cut -d 'p' -f 1 | tr -d $'\r')
if [ -z "$version" ]; then
return
fi
if [[ ${safe_ver[@]} =~ $versionstr ]]; then
return
fi
if [ 1 -eq $(echo "$version <= 4.4" | bc -l) ]; then
echo -e "\e[1m\e[31m[VULNERABLE] $i\t: $version : $versionstr\e[0m"
return
fi
if [ 1 -eq "$(echo "$version >= 8.5" | bc -l)" ]; then
if [ 1 -eq "$(echo "$version < 9.8" | bc -l)" ]; then
echo -e "\e[1m\e[31m[VULNERABLE] $1\t: $version : $versionstr\e[0m"
return
fi
fi
}
for i in `dig +short A $1`; do
doCheck $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment