mirror of
https://github.com/nmap/nmap.git
synced 2026-08-27 03:48:14 +00:00
o [NSE] Added host based registry, which allows scripts to share data between
scripts scanning a specific host. [Patrik]
This commit is contained in:
parent
9157bcf03c
commit
72af4637b0
4 changed files with 54 additions and 29 deletions
15
nse_main.lua
15
nse_main.lua
|
|
@ -219,6 +219,13 @@ local function tcopy (t)
|
|||
return tc;
|
||||
end
|
||||
|
||||
-- copies the host table while preserving the registry
|
||||
local function host_copy(t)
|
||||
local h = tcopy(t)
|
||||
h.registry = t.registry
|
||||
return h
|
||||
end
|
||||
|
||||
local REQUIRE_ERROR = {};
|
||||
rawset(stdnse, "silent_require", function (...)
|
||||
local status, mod = pcall(require, ...);
|
||||
|
|
@ -1179,18 +1186,18 @@ local function main (hosts, scantype)
|
|||
-- Check hostrules for this host.
|
||||
for j, host in ipairs(hosts) do
|
||||
for _, script in ipairs(scripts) do
|
||||
local thread = script:new_thread("hostrule", tcopy(host));
|
||||
local thread = script:new_thread("hostrule", host_copy(host));
|
||||
if thread then
|
||||
thread.args, thread.host = {n = 1, tcopy(host)}, host;
|
||||
thread.args, thread.host = {n = 1, host_copy(host)}, host;
|
||||
yield(thread);
|
||||
end
|
||||
end
|
||||
-- Check portrules for this host.
|
||||
for port in cnse.ports(host) do
|
||||
for _, script in ipairs(scripts) do
|
||||
local thread = script:new_thread("portrule", tcopy(host), tcopy(port));
|
||||
local thread = script:new_thread("portrule", host_copy(host), tcopy(port));
|
||||
if thread then
|
||||
thread.args, thread.host, thread.port = {n = 2, tcopy(host), tcopy(port)}, host, port;
|
||||
thread.args, thread.host, thread.port = {n = 2, host_copy(host), tcopy(port)}, host, port;
|
||||
yield(thread);
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue