1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Track NSE targets by IP first, then by targetname.

This commit is contained in:
dmiller
2017-08-07 14:25:14 +00:00
parent a66e75173e
commit e0dcb3b8a9
2 changed files with 14 additions and 7 deletions

View File

@@ -629,9 +629,13 @@ static int run_main (lua_State *L)
lua_newtable(L);
set_hostinfo(L, target);
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);
else
lua_pushlightuserdata(L, target);
lua_rawset(L, current_hosts); /* add to NSE_CURRENT_HOSTS */
}
lua_pushstring(L, targetipstr);
lua_pushlightuserdata(L, target);
lua_rawset(L, current_hosts); /* add to NSE_CURRENT_HOSTS */

View File

@@ -184,16 +184,19 @@ Target *nseU_gettarget (lua_State *L, int idx)
lua_getfield(L, idx, "ip");
if (!(lua_isstring(L, -2) || lua_isstring(L, -1)))
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))
goto done;
else
lua_pop(L, 1);
}
if (lua_isstring(L, -1)) /* ip */
nse_gettarget(L, -1); /* use ip */
if (lua_isstring(L, -2)) /* targetname */
nse_gettarget(L, -2); /* use targetname */
if (!lua_islightuserdata(L, -1))
luaL_argerror(L, 1, "host is not being processed right now");
done: