From b14bba972f2131e2e9e033881120255b4685f26a Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 7 Apr 2026 19:59:48 +0000 Subject: [PATCH] Fix error when comm.opencon fails and banner is an oops object --- scripts/ssh-hostkey.nse | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/ssh-hostkey.nse b/scripts/ssh-hostkey.nse index 5b5069777..da9f2dfad 100644 --- a/scripts/ssh-hostkey.nse +++ b/scripts/ssh-hostkey.nse @@ -274,11 +274,13 @@ local function portaction(host, port) -- Since the fetch_host_key functions don't indicate what failed, we could -- waste a lot of time on e.g. tcpwrapped port 22 -- Using opencon instead of get_banner to avoid trying SSL first in some cases - local status, banner = comm.opencon(host, port, nil, {recv_before=true}) - if not string.match(banner, "^SSH") then + local sock, banner = comm.opencon(host, port, nil, {recv_before=true}) + if not (sock and string.match(banner, "^SSH")) then + stdnse.debug2("Banner: %s", banner) stdnse.debug1("Service does not appear to be SSH: quitting.") return nil end + sock:close() end local output_tab = {} local keys = {}