1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-04 04:26:33 +00:00

Require trailing '/' to match a directory name with --script. See #2051

This commit is contained in:
dmiller
2020-08-28 15:06:10 +00:00
parent 8417aa5576
commit a0b05c0f4f
4 changed files with 14 additions and 6 deletions

View File

@@ -2285,7 +2285,7 @@ way.</para>
<varlistentry>
<term>
<option>--script <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>|<replaceable>expression</replaceable><optional>,...</optional></option>
<option>--script <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>/|<replaceable>expression</replaceable><optional>,...</optional></option>
<indexterm><primary><option>--script</option></primary></indexterm>
</term>
@@ -2329,7 +2329,7 @@ executable, followed by <filename>../share/nmap</filename> (not searched on Wind
</para>
<para>
When a directory name is given, Nmap loads every file in the directory
When a directory name ending in <literal>/</literal> is given, Nmap loads every file in the directory
whose name ends with <filename>.nse</filename>. All other files are
ignored and directories are not searched recursively. When a filename is
given, it does not have to have the <filename>.nse</filename> extension;

View File

@@ -627,7 +627,7 @@ Black Hat Briefings in 2010.</para>
<varlistentry>
<term>
<indexterm><primary><option>--script</option></primary></indexterm>
<option>--script <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>|<replaceable>expression</replaceable><optional>,...</optional></option></term>
<option>--script <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>/|<replaceable>expression</replaceable><optional>,...</optional></option></term>
<listitem>
@@ -676,7 +676,7 @@ executable, followed by <filename>../share/nmap</filename> (not searched on Wind
</para>
<para>
When a directory name is given, Nmap loads every file in the directory
When a directory name ending in <literal>/</literal> is given, Nmap loads every file in the directory
whose name ends with <filename>.nse</filename>. All other files are
ignored and directories are not searched recursively. When a filename is
given, it does not have to have the <filename>.nse</filename> extension;

View File

@@ -271,7 +271,8 @@ static int l_protect_xml(lua_State *L)
static int nse_fetch (lua_State *L, int (*fetch)(char *, size_t, const char *))
{
char path[MAXPATHLEN];
switch (fetch(path, sizeof(path), luaL_checkstring(L, 1)))
const char *input = luaL_checkstring(L, 1);
switch (fetch(path, sizeof(path), input))
{
case 0: // no such path
lua_pushnil(L);
@@ -282,7 +283,12 @@ static int nse_fetch (lua_State *L, int (*fetch)(char *, size_t, const char *))
lua_pushstring(L, path);
break;
case 2: // directory returned
lua_pushliteral(L, "directory");
if (input[strlen(input) - 1] == '/') {
lua_pushliteral(L, "directory");
}
else {
lua_pushliteral(L, "bare_directory");
}
lua_pushstring(L, path);
break;
default:

View File

@@ -817,6 +817,8 @@ local function get_chosen_scripts (rules)
if not (cnse.scriptversion and rule == "version") then
error("'"..rule.."' did not match a category, filename, or directory");
end
elseif t == "bare_directory" then
error("directory '"..path.."' found, but will not match without '/'")
elseif t == "file" and not files_loaded[path] then
script_params.selection = "file path";
script_params.verbosity = true;