mirror of
https://github.com/nmap/nmap.git
synced 2025-12-13 03:09:02 +00:00
[NSE] Cache the Portmapper list into the NSE registry
This commit is contained in:
@@ -96,8 +96,8 @@ require("datafiles")
|
|||||||
-- encoding an decoding
|
-- encoding an decoding
|
||||||
-- Revised 03/13/2010 - v0.3 - re-worked library to be OO
|
-- Revised 03/13/2010 - v0.3 - re-worked library to be OO
|
||||||
-- Revised 04/18/2010 - v0.4 - Applied patch from Djalal Harouni with improved
|
-- Revised 04/18/2010 - v0.4 - Applied patch from Djalal Harouni with improved
|
||||||
-- error checking and re-designed Comm class. see:
|
-- error checking and re-designed Comm class. see:
|
||||||
-- http://seclists.org/nmap-dev/2010/q2/232
|
-- http://seclists.org/nmap-dev/2010/q2/232
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +108,6 @@ RPC_args = {
|
|||||||
["mountd"] = { ver = 'mount.version' },
|
["mountd"] = { ver = 'mount.version' },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- Defines the order in which to try to connect to the RPC programs
|
-- Defines the order in which to try to connect to the RPC programs
|
||||||
-- TCP appears to be more stable than UDP in most cases, so try it first
|
-- TCP appears to be more stable than UDP in most cases, so try it first
|
||||||
local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbind'].proto] and
|
local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbind'].proto] and
|
||||||
@@ -118,6 +117,9 @@ local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbi
|
|||||||
-- used to cache the contents of the rpc datafile
|
-- used to cache the contents of the rpc datafile
|
||||||
local RPC_PROGRAMS
|
local RPC_PROGRAMS
|
||||||
|
|
||||||
|
-- local mutex to synchronize I/O operations on nmap.registry[host.ip]['portmap']
|
||||||
|
local mutex = nmap.mutex("rpc")
|
||||||
|
|
||||||
-- Supported protocol versions
|
-- Supported protocol versions
|
||||||
RPC_version = {
|
RPC_version = {
|
||||||
["rpcbind"] = { min=2, max=2 },
|
["rpcbind"] = { min=2, max=2 },
|
||||||
@@ -1581,7 +1583,9 @@ Helper = {
|
|||||||
stdnse.print_debug("rpc.Helper.RpcInfo: %s", result)
|
stdnse.print_debug("rpc.Helper.RpcInfo: %s", result)
|
||||||
return status, result
|
return status, result
|
||||||
end
|
end
|
||||||
|
mutex "lock"
|
||||||
status, result = portmap:Dump(comm)
|
status, result = portmap:Dump(comm)
|
||||||
|
mutex "done"
|
||||||
comm:Disconnect()
|
comm:Disconnect()
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
stdnse.print_debug("rpc.Helper.RpcInfo: %s", result)
|
stdnse.print_debug("rpc.Helper.RpcInfo: %s", result)
|
||||||
@@ -1800,8 +1804,15 @@ Portmap =
|
|||||||
--
|
--
|
||||||
Dump = function(self, comm)
|
Dump = function(self, comm)
|
||||||
local status, data, packet, response, pos, header
|
local status, data, packet, response, pos, header
|
||||||
if ( self.program_table ) then
|
local program_table = setmetatable({}, { __mode = 'v' })
|
||||||
return true, self.program_table
|
|
||||||
|
if nmap.registry[comm.ip] == nil then
|
||||||
|
nmap.registry[comm.ip] = {}
|
||||||
|
end
|
||||||
|
if nmap.registry[comm.ip]['portmap'] == nil then
|
||||||
|
nmap.registry[comm.ip]['portmap'] = {}
|
||||||
|
elseif next(nmap.registry[comm.ip]['portmap']) ~= nil then
|
||||||
|
return true, nmap.registry[comm.ip]['portmap']
|
||||||
end
|
end
|
||||||
|
|
||||||
packet = comm:EncodePacket( nil, RPC.Procedure[comm.version].DUMP, { type=RPC.AuthType.NULL }, data )
|
packet = comm:EncodePacket( nil, RPC.Procedure[comm.version].DUMP, { type=RPC.AuthType.NULL }, data )
|
||||||
@@ -1842,8 +1853,6 @@ Portmap =
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.program_table = {}
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local vfollows
|
local vfollows
|
||||||
local program, version, protocol, port
|
local program, version, protocol, port
|
||||||
@@ -1864,18 +1873,18 @@ Portmap =
|
|||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
end
|
end
|
||||||
|
|
||||||
self.program_table[program] = self.program_table[program] or {}
|
program_table[program] = program_table[program] or {}
|
||||||
self.program_table[program][protocol] = self.program_table[program][protocol] or {}
|
program_table[program][protocol] = program_table[program][protocol] or {}
|
||||||
self.program_table[program][protocol]["port"] = port
|
program_table[program][protocol]["port"] = port
|
||||||
self.program_table[program][protocol]["version"] = self.program_table[program][protocol]["version"] or {}
|
program_table[program][protocol]["version"] = program_table[program][protocol]["version"] or {}
|
||||||
table.insert( self.program_table[program][protocol]["version"], version )
|
table.insert( program_table[program][protocol]["version"], version )
|
||||||
-- parts of the code rely on versions being in order
|
-- parts of the code rely on versions being in order
|
||||||
-- this way the highest version can be chosen by choosing the last element
|
-- this way the highest version can be chosen by choosing the last element
|
||||||
table.sort( self.program_table[program][protocol]["version"] )
|
table.sort( program_table[program][protocol]["version"] )
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, self.program_table
|
nmap.registry[comm.ip]['portmap'] = program_table
|
||||||
|
return true, nmap.registry[comm.ip]['portmap']
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Queries the portmapper for the port of the selected program,
|
--- Queries the portmapper for the port of the selected program,
|
||||||
|
|||||||
Reference in New Issue
Block a user