-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jan Klopper <[email protected]> Co-authored-by: ammar92 <[email protected]> Co-authored-by: Jeroen Dekkers <[email protected]>
- Loading branch information
1 parent
f7e68e6
commit 9c9cfe7
Showing
9 changed files
with
156 additions
and
4 deletions.
There are no files selected for viewing
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
CVE-2024-6387 checker | ||
Author: Mischa van Geelen <@rickgeex> | ||
""" | ||
|
||
from collections.abc import Iterable | ||
|
||
from boefjes.job_models import NormalizerOutput | ||
from octopoes.models import Reference | ||
from octopoes.models.ooi.findings import CVEFindingType, Finding | ||
from packaging.version import Version | ||
|
||
VULNERABLE_VERSIONS = [ | ||
"SSH-2.0-OpenSSH_8.5", | ||
"SSH-2.0-OpenSSH_8.6", | ||
"SSH-2.0-OpenSSH_8.7", | ||
"SSH-2.0-OpenSSH_8.8", | ||
"SSH-2.0-OpenSSH_8.9", | ||
"SSH-2.0-OpenSSH_9.0", | ||
"SSH-2.0-OpenSSH_9.1", | ||
"SSH-2.0-OpenSSH_9.2", | ||
"SSH-2.0-OpenSSH_9.3", | ||
"SSH-2.0-OpenSSH_9.4", | ||
"SSH-2.0-OpenSSH_9.5", | ||
"SSH-2.0-OpenSSH_9.6", | ||
"SSH-2.0-OpenSSH_9.7", | ||
] | ||
|
||
|
||
def is_vulnerable(banner: str) -> bool: | ||
if not any(version in banner for version in VULNERABLE_VERSIONS): | ||
return False | ||
|
||
if banner.startswith("SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u"): | ||
_, security_update = banner.split("deb12u") | ||
if Version(security_update) >= Version("3"): | ||
return False | ||
elif banner.startswith("SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu"): | ||
_, security_update = banner.split("3ubuntu") | ||
if Version(security_update) >= Version("13.3"): | ||
return False | ||
elif banner.startswith("SSH-2.0-OpenSSH_9.3p1 Ubuntu-1ubuntu"): | ||
_, security_update = banner.split("1ubuntu") | ||
if Version(security_update) >= Version("3.6"): | ||
return False | ||
elif banner.startswith("SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu"): | ||
_, security_update = banner.split("3ubuntu") | ||
if Version(security_update) >= Version("0.10"): | ||
return False | ||
|
||
return True | ||
|
||
|
||
def run(input_ooi: dict, raw: bytes) -> Iterable[NormalizerOutput]: | ||
ooi = Reference.from_str(input_ooi["primary_key"]) | ||
|
||
banner = raw.decode() | ||
|
||
if banner.startswith("SSH-2.0-OpenSSH") and is_vulnerable(banner): | ||
finding_type = CVEFindingType(id="CVE-2024-6387") | ||
finding = Finding( | ||
finding_type=finding_type.reference, | ||
ooi=ooi, | ||
description="Service is most likely vulnerable to CVE-2024-6387", | ||
) | ||
yield finding_type | ||
yield finding |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "kat_cve_2024_6387_normalize", | ||
"consumes": [ | ||
"openkat/service-banner" | ||
], | ||
"description": "Checks service banner for CVE-2024-6387, enable service banner boefje to get the service banner", | ||
"produces": [ | ||
"Finding", | ||
"CVEFindingType" | ||
] | ||
} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "service_banner", | ||
"name": "Service banner download", | ||
"description": "Downloads service banners from the target hosts", | ||
"consumes": [ | ||
"IPPort" | ||
], | ||
"scan_level": 2 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import socket | ||
|
||
from boefjes.job_models import BoefjeMeta | ||
|
||
TIMEOUT = 1.0 | ||
|
||
|
||
def get_sock(ip, port, timeout): | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.settimeout(timeout) | ||
try: | ||
sock.connect((ip, port)) | ||
return sock | ||
except Exception: | ||
return None | ||
|
||
|
||
def get_banner(sock): | ||
if not sock: | ||
return [({"boefje/error"}, "Unable to connect to the service")] | ||
try: | ||
sock.settimeout(TIMEOUT) | ||
banner = sock.recv(1024) | ||
try: | ||
banner = banner.decode().strip() | ||
except UnicodeDecodeError: | ||
banner = banner.decode("latin1").strip() | ||
sock.close() | ||
return [({"openkat/service-banner"}, banner)] | ||
except Exception as e: | ||
return [({"boefje/error"}, f"Unable to get banner. {str(e)}")] | ||
|
||
|
||
def run(boefje_meta: BoefjeMeta) -> list[tuple[set, str | bytes]]: | ||
input_ = boefje_meta.arguments["input"] # input is IPPort | ||
port = input_["port"] | ||
ip = input_["address"]["address"] | ||
|
||
sock = get_sock(ip, port, TIMEOUT) | ||
|
||
return get_banner(sock) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from boefjes.plugins.kat_cve_2024_6387.normalize import is_vulnerable | ||
|
||
|
||
def test_is_vulnerable(): | ||
for version in [ | ||
"SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3", | ||
"SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u10", | ||
"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.3", | ||
"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.4", | ||
"SSH-2.0-OpenSSH_9.3p1 Ubuntu-1ubuntu3.6", | ||
"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.10", | ||
]: | ||
assert not is_vulnerable(version) | ||
|
||
for version in [ | ||
"SSH-2.0-OpenSSH_8.9p1", | ||
"SSH-2.0-OpenSSH_9.2p1", | ||
"SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u2", | ||
"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13", | ||
"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.7", | ||
"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3", | ||
]: | ||
assert is_vulnerable(version) |