1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Update banner.nse to use script-args

Added 2 args:

banner.timeout is a timespec for how long to wait for output. Default is
still 5s.

banner.ports is a ports list for limiting which ports to connect to. The
default is still all ports, but using banner.ports=common will limit to
some common ports that always return a banner.

Originally committed by dmiller but recommitted by david after recovery
from backup.
This commit is contained in:
david
2013-04-12 17:29:17 +00:00
parent 201a5130a2
commit 3b728a40df

View File

@@ -14,6 +14,10 @@ increase in the level of verbosity requested on the command line.
-- @output
-- 21/tcp open ftp
-- |_ banner: 220 FTP version 1.0\x0D\x0A
-- @arg banner.ports Which ports to grab. Same syntax as -p option. Use
-- "common" to only grab common text-protocol banners.
-- Default: all ports.
-- @arg banner.timeout How long to wait for a banner. Default: 5s
author = "jah"
@@ -22,12 +26,21 @@ categories = {"discovery", "safe"}
local portarg = stdnse.get_script_args(SCRIPT_NAME .. ".ports")
if portarg == "common" then
portarg = "13,17,21-23,25,129,194,587,990,992,994,6667,6697"
end
---
-- Script is executed for any TCP port.
portrule = function( host, port )
return port.protocol == "tcp"
if port.protocol == "tcp" then
if portarg then
return stdnse.in_port_range(port, portarg)
end
return true
end
return false
end
@@ -50,7 +63,8 @@ end
function grab_banner(host, port)
local opts = {}
opts.timeout = get_timeout()
opts.timeout = stdnse.parse_timespec(stdnse.get_script_args(SCRIPT_NAME .. ".timeout"))
opts.timeout = (opts.timeout or 5) * 1000
opts.proto = port.protocol
local status, response = comm.get_banner(host.ip, port.number, opts)
@@ -67,17 +81,6 @@ function grab_banner(host, port)
end
---
-- Returns a number of milliseconds for use as a socket timeout value (defaults to 5 seconds).
--
-- @return Number of milliseconds.
function get_timeout()
return 5000
end
---
-- Formats the banner for printing to the port script result.
--