1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-03 05:09:14 +00:00

Avoid bloating the registry by using variables to transfer information from

the hostrule to the action function.
This commit is contained in:
henri
2011-06-20 21:06:14 +00:00
parent 44bccc4152
commit b2d1ac7580
3 changed files with 22 additions and 69 deletions

View File

@@ -35,6 +35,8 @@ require 'stdnse'
local NUMPROBES = 6
local ipidseqport
--- Pcap check function
-- @return Destination and source IP addresses and TCP ports
local check = function(layer3)
@@ -175,16 +177,6 @@ local getport = function(host)
return port.number
end
--- Sets probe port number in registry
-- @param host Host object
-- @param port Port number
local setreg = function(host, port)
if not nmap.registry[host.ip] then
nmap.registry[host.ip] = {}
end
nmap.registry[host.ip]['ipidseqprobe'] = port
end
hostrule = function(host)
if not nmap.is_privileged() then
nmap.registry[SCRIPT_NAME] = nmap.registry[SCRIPT_NAME] or {}
@@ -202,12 +194,8 @@ hostrule = function(host)
if not host.interface then
return false
end
local port = getport(host)
if not port then
return false
end
setreg(host, port)
return true
ipidseqport = getport(host)
return (ipidseqport ~= nil)
end
action = function(host)
@@ -215,7 +203,6 @@ action = function(host)
local ipids = {}
local sock = nmap.new_dnet()
local pcap = nmap.new_socket()
local port = nmap.registry[host.ip]['ipidseqprobe']
local saddr = packet.toip(host.bin_ip_src)
local daddr = packet.toip(host.bin_ip)
local try = nmap.new_try()
@@ -224,11 +211,11 @@ action = function(host)
try = nmap.new_try(function() sock:ip_close() end)
pcap:pcap_open(host.interface, 104, false, "tcp and dst host " .. saddr .. " and src host " .. daddr .. " and src port " .. port)
pcap:pcap_open(host.interface, 104, false, "tcp and dst host " .. saddr .. " and src host " .. daddr .. " and src port " .. ipidseqport)
pcap:set_timeout(host.times.timeout * 1000)
local tcp = genericpkt(host, port)
local tcp = genericpkt(host, ipidseqport)
while i <= NUMPROBES do
try(sock:ip_send(tcp.buf))
@@ -254,7 +241,7 @@ action = function(host)
local output = ipidseqclass(ipids)
if nmap.debugging() > 0 then
output = output .. " [used port " .. port .. "]"
output = output .. " [used port " .. ipidseqport .. "]"
end
return output