mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Track NSE targets by IP first, then by targetname.
This commit is contained in:
10
nse_main.cc
10
nse_main.cc
@@ -629,10 +629,14 @@ static int run_main (lua_State *L)
|
|||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
set_hostinfo(L, target);
|
set_hostinfo(L, target);
|
||||||
lua_rawseti(L, targets_table, lua_rawlen(L, targets_table) + 1);
|
lua_rawseti(L, targets_table, lua_rawlen(L, targets_table) + 1);
|
||||||
if (TargetName != NULL && strcmp(TargetName, "") != 0)
|
/* Index this Target in NSE_CURRENT_HOSTS under targetname and IP so we can
|
||||||
|
* retrieve it later */
|
||||||
|
if (TargetName != NULL && strcmp(TargetName, "") != 0) {
|
||||||
lua_pushstring(L, TargetName);
|
lua_pushstring(L, TargetName);
|
||||||
else
|
lua_pushlightuserdata(L, target);
|
||||||
lua_pushstring(L, targetipstr);
|
lua_rawset(L, current_hosts); /* add to NSE_CURRENT_HOSTS */
|
||||||
|
}
|
||||||
|
lua_pushstring(L, targetipstr);
|
||||||
lua_pushlightuserdata(L, target);
|
lua_pushlightuserdata(L, target);
|
||||||
lua_rawset(L, current_hosts); /* add to NSE_CURRENT_HOSTS */
|
lua_rawset(L, current_hosts); /* add to NSE_CURRENT_HOSTS */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,16 +184,19 @@ Target *nseU_gettarget (lua_State *L, int idx)
|
|||||||
lua_getfield(L, idx, "ip");
|
lua_getfield(L, idx, "ip");
|
||||||
if (!(lua_isstring(L, -2) || lua_isstring(L, -1)))
|
if (!(lua_isstring(L, -2) || lua_isstring(L, -1)))
|
||||||
luaL_error(L, "host table does not have a 'ip' or 'targetname' field");
|
luaL_error(L, "host table does not have a 'ip' or 'targetname' field");
|
||||||
if (lua_isstring(L, -2)) /* targetname */
|
/* IP is preferred to targetname because it is more unique. Really, though, a
|
||||||
|
* user can scan the same IP or targetname multiple times, and NSE will get
|
||||||
|
* all mixed up. */
|
||||||
|
if (lua_isstring(L, -1)) /* ip */
|
||||||
{
|
{
|
||||||
nse_gettarget(L, -2); /* use targetname */
|
nse_gettarget(L, -1); /* use ip */
|
||||||
if (lua_islightuserdata(L, -1))
|
if (lua_islightuserdata(L, -1))
|
||||||
goto done;
|
goto done;
|
||||||
else
|
else
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
if (lua_isstring(L, -1)) /* ip */
|
if (lua_isstring(L, -2)) /* targetname */
|
||||||
nse_gettarget(L, -1); /* use ip */
|
nse_gettarget(L, -2); /* use targetname */
|
||||||
if (!lua_islightuserdata(L, -1))
|
if (!lua_islightuserdata(L, -1))
|
||||||
luaL_argerror(L, 1, "host is not being processed right now");
|
luaL_argerror(L, 1, "host is not being processed right now");
|
||||||
done:
|
done:
|
||||||
|
|||||||
Reference in New Issue
Block a user