1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Move in_port_range to shortport.port_range, expand portnumber to match ranges

This commit is contained in:
dmiller
2018-10-11 05:11:13 +00:00
parent 8c0880836c
commit 03639761c3
4 changed files with 88 additions and 94 deletions

View File

@@ -49,20 +49,16 @@ categories = {"intrusive", "brute"}
-- This portrule succeeds only when the open|filtered port is in the port range
-- which is specified by the ports script argument
portrule = function(host, port)
if not stdnse.get_script_args(SCRIPT_NAME .. ".ports") then
stdnse.debug3("Skipping '%s' %s, 'ports' argument is missing.",SCRIPT_NAME, SCRIPT_TYPE)
return false
end
local ports = stdnse.get_script_args(SCRIPT_NAME .. ".ports")
--print out a debug message if port 31337/udp is open
if port.number==31337 and port.protocol == "udp" and not(ports) then
stdnse.debug1("Port 31337/udp is open. Possibility of version detection and password bruteforcing using the backorifice-brute script")
if not ports then
stdnse.verbose1("Skipping '%s' %s, 'ports' argument is missing.",SCRIPT_NAME, SCRIPT_TYPE)
return false
end
return port.protocol == "udp" and stdnse.in_port_range(port, ports:gsub(",",",") ) and
-- ensure UDP
portarg = portarg:gsub("^[U:]*", "U:")
return port.protocol == "udp" and shortport.port_range(ports)(host, port) and
not(shortport.port_is_excluded(port.number,port.protocol))
end

View File

@@ -1,6 +1,7 @@
local comm = require "comm"
local nmap = require "nmap"
local stdnse = require "stdnse"
local shortport = require "shortport"
local table = require "table"
local U = require "lpeg-utility"
@@ -28,20 +29,15 @@ 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 )
if port.protocol == "tcp" then
if portarg then
return stdnse.in_port_range(port, portarg)
end
return true
if portarg then
if portarg == "common" then
portarg = "13,17,21-23,25,129,194,587,990,992,994,6667,6697"
end
return false
-- ensure TCP
portarg = portarg:gsub("^[T:]*", "T:")
portrule = shortport.port_range(portarg)
else
portrule = function(host, port) return port.protocol == "tcp" end
end