mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Fix a bug which caused some NSE scripts to fail, due to the absence of
the NSE SCRIPT_NAME environment variable when the scripts are loaded. Reported by Michael Pattrick.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Nmap Changelog ($Id$); -*-text-*-
|
# Nmap Changelog ($Id$); -*-text-*-
|
||||||
|
|
||||||
|
o [NSE] Fixed a bug which caused some NSE scripts to fail, due to the
|
||||||
|
absence of the NSE SCRIPT_NAME environment variable when the scripts
|
||||||
|
are loaded. Michael Pattrick reported the problem. [Djalal]
|
||||||
|
|
||||||
o Fixed some inconsistencies in nmap-os-db reported by Xavier Sudre
|
o Fixed some inconsistencies in nmap-os-db reported by Xavier Sudre
|
||||||
from netVigilance.
|
from netVigilance.
|
||||||
|
|
||||||
|
|||||||
@@ -1252,6 +1252,8 @@ action refer to <xref linkend="nse-tutorial-action"/>.
|
|||||||
<literal>"prerule"</literal>, <literal>"hostrule"</literal>,
|
<literal>"prerule"</literal>, <literal>"hostrule"</literal>,
|
||||||
<literal>"portrule"</literal> or
|
<literal>"portrule"</literal> or
|
||||||
<literal>"postrule"</literal>.
|
<literal>"postrule"</literal>.
|
||||||
|
This variable is only available after the evaluation of
|
||||||
|
the rule functions.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|||||||
16
nse_main.lua
16
nse_main.lua
@@ -303,6 +303,7 @@ do
|
|||||||
local script_type = assert(NSE_SCRIPT_RULES[rule]);
|
local script_type = assert(NSE_SCRIPT_RULES[rule]);
|
||||||
if not self[rule] then return nil end -- No rule for this script?
|
if not self[rule] then return nil end -- No rule for this script?
|
||||||
local file_closure = self.file_closure;
|
local file_closure = self.file_closure;
|
||||||
|
-- Rebuild the environment for the running thread.
|
||||||
local env = {
|
local env = {
|
||||||
SCRIPT_PATH = self.filename,
|
SCRIPT_PATH = self.filename,
|
||||||
SCRIPT_NAME = self.short_basename,
|
SCRIPT_NAME = self.short_basename,
|
||||||
@@ -366,10 +367,15 @@ do
|
|||||||
"Warning: Loading '%s' -- the recommended file extension is '.nse'.",
|
"Warning: Loading '%s' -- the recommended file extension is '.nse'.",
|
||||||
filename);
|
filename);
|
||||||
end
|
end
|
||||||
|
local basename = match(filename, "[/\\]([^/\\]-)$") or filename;
|
||||||
|
local short_basename = match(filename, "[/\\]([^/\\]-)%.nse$") or
|
||||||
|
match(filename, "[/\\]([^/\\]-)%.[^.]*$") or
|
||||||
|
filename;
|
||||||
local file_closure = assert(loadfile(filename));
|
local file_closure = assert(loadfile(filename));
|
||||||
-- Give the closure its own environment, with global access
|
-- Give the closure its own environment, with global access
|
||||||
local env = {
|
local env = {
|
||||||
filename = filename,
|
SCRIPT_PATH = filename,
|
||||||
|
SCRIPT_NAME = short_basename,
|
||||||
dependencies = {},
|
dependencies = {},
|
||||||
};
|
};
|
||||||
setmetatable(env, {__index = _G});
|
setmetatable(env, {__index = _G});
|
||||||
@@ -412,11 +418,9 @@ do
|
|||||||
-- Return the script
|
-- Return the script
|
||||||
local script = {
|
local script = {
|
||||||
filename = filename,
|
filename = filename,
|
||||||
basename = match(filename, "[/\\]([^/\\]-)$") or filename,
|
basename = basename,
|
||||||
short_basename = match(filename, "[/\\]([^/\\]-)%.nse$") or
|
short_basename = short_basename,
|
||||||
match(filename, "[/\\]([^/\\]-)%.[^.]*$") or
|
id = match(filename, "^.-[/\\]([^\\/]-)%.nse$") or short_basename,
|
||||||
filename,
|
|
||||||
id = match(filename, "^.-[/\\]([^\\/]-)%.nse$") or filename,
|
|
||||||
file_closure = file_closure,
|
file_closure = file_closure,
|
||||||
prerule = prerule,
|
prerule = prerule,
|
||||||
hostrule = hostrule,
|
hostrule = hostrule,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ else
|
|||||||
portrule = function() return false end
|
portrule = function() return false end
|
||||||
action = function() end
|
action = function() end
|
||||||
stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.",
|
stdnse.print_debug( 3, "Skipping %s script because OpenSSL is missing.",
|
||||||
filename)
|
SCRIPT_NAME)
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user