diff --git a/scripts/netbus-version.nse b/scripts/netbus-version.nse index c8332fc8d..a6ff9bfb7 100644 --- a/scripts/netbus-version.nse +++ b/scripts/netbus-version.nse @@ -1,10 +1,12 @@ local nmap = require "nmap" +local match = require "match" local shortport = require "shortport" local stdnse = require "stdnse" description = [[ -Extends version detection to detect NetBuster, a honeypot service -that mimes NetBus. +Attempts to identify NetBuster 1.31 using its version-query response. +The fingerprint requires eight response bytes. An unavailable or +incomplete response does not identify the service as NetBuster. ]] --- @@ -12,43 +14,67 @@ that mimes NetBus. -- nmap -sV -p 12345 --script netbus-version -- -- @output --- 12345/tcp open netbus Netbuster (honeypot) +-- 12345/tcp open netbus NetBuster 1.31 (honeypot) author = "Toni Ruottu" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" categories = {"version"} - portrule = shortport.version_port_or_service ({}, "netbus", {"tcp"}) -action = function( host, port ) - +action = function(host, port) local socket = nmap.new_socket() socket:set_timeout(5000) - local status, err = socket:connect(host, port) - if not status then - return - end - local buffer, _ = stdnse.make_buffer(socket, "\r") - _ = buffer() - if not (_ and _:match("^NetBus")) then - stdnse.debug1("Not NetBus") + + local function finish(reason, err) + socket:close() + if err then + stdnse.debug1("%s: %s", reason, err) + else + stdnse.debug1("%s", reason) + end return nil end - socket:send("Password;0;\r") - --NetBus answers to auth - if buffer() ~= nil then - return + local status, response = socket:connect(host, port) + if not status then + return finish("connection_failed", response) end - --NetBuster does not + -- Unlike make_buffer, receive_buf does not return an unterminated tail + -- as a successful record when the read fails. + status, response = socket:receive_buf("\r", false) + if not status then + return finish("banner_receive_failed", response) + end + if not response:match("^NetBus") then + return finish("unrelated_banner") + end + + -- NetBus ignores nbver, but answers GetInfo (including an explicit denial + -- when password protected). NetBuster answers the first query. Sending both + -- avoids a timeout on NetBus without shortening the response deadline. + status, response = socket:send("nbver\rGetInfo\r") + if not status then + return finish("version_send_failed", response) + end + + -- NetBuster 1.31 replies with 1.31--, without a + -- terminator. Use only its eight-byte prefix (verified on 1.31); + -- it does not parse the full counter or infer an end from a read failure. + status, response = socket:receive_buf(match.numbytes(8), true) + if not status then + return finish("version_receive_failed", response) + end + if not response:match("^1%.31%-[0-4]%-%d$") then + return finish("fingerprint_mismatch") + end + + socket:close() port.version.name = "netbus" port.version.product = "NetBuster" + port.version.version = "1.31" port.version.extrainfo = "honeypot" - port.version.version = nil nmap.set_port_version(host, port) - return + return nil end - -