Last active
July 4, 2024 07:05
-
-
Save swachchhanda000/0a0ffc8d7514fcb997ecadf71baae196 to your computer and use it in GitHub Desktop.
Bash script to detect regreSSHion (CVE-2024-6387)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for each_entry in $(type -a sshd | awk '{print $NF}' | uniq); do | |
version_string=$(strings "$each_entry" | grep -o "OpenSSH_[0-9]\+\.[0-9]\+p[0-9]\+" | uniq) | |
if [ -n "$version_string" ]; then | |
version=$(echo "$version_string" | sed -E 's/OpenSSH_([0-9]+\.[0-9]+)p[0-9]+/\1/') | |
major_version=$(echo $version | cut -d '.' -f 1) | |
minor_version=$(echo $version | cut -d '.' -f 2) | |
if [ "$major_version" -lt 4 ] || ([ "$major_version" -eq 4 ] && [ "$minor_version" -lt 4 ]); then | |
status="YES (Unless patched for CVE-2006-5051 and CVE-2008-4109)" | |
elif ([ "$major_version" -eq 4 ] && [ "$minor_version" -ge 4 ]) || ([ "$major_version" -ge 5 ] && [ "$major_version" -lt 8 ]) || ([ "$major_version" -eq 8 ] && [ "$minor_version" -lt 5 ]); then | |
status="NO" | |
elif ([ "$major_version" -eq 8 ] && [ "$minor_version" -ge 5 ]) || ([ "$major_version" -eq 9 ] && [ "$minor_version" -le 7 ]); then | |
status="YES" | |
else | |
status="Unknown" | |
fi | |
echo "Found OpenSSH version: $version in $each_entry" | |
echo "Vulnerability Status: $status" | |
if [ "$status" == "YES" ]; then | |
echo "Patch Immediately to OpenSSH 9.8/9.8p1" | |
fi | |
else | |
echo "No match found for $each_entry" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment