1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-20 14:39:02 +00:00

[NSE] Patch to allow virtual hosts (specified by name on the command line)

which resolve to the same IP to have script output placed under the correct
(virtual) host.  Previously, all script output would be "randomly but
deterministically" placed under one of these hosts.  Other problems include
having port information changed for only one of the virtual hosts.
This commit is contained in:
batrick
2009-08-28 02:48:56 +00:00
parent f54bb442c4
commit b61ed83e14
2 changed files with 32 additions and 10 deletions

View File

@@ -445,12 +445,19 @@ static int run_main (lua_State *L)
for (std::vector<Target *>::iterator ti = targets->begin(); for (std::vector<Target *>::iterator ti = targets->begin();
ti != targets->end(); ti++) ti != targets->end(); ti++)
{ {
Target *target = (Target *) *ti;
const char *TargetName = target->TargetName();
const char *targetipstr = target->targetipstr();
lua_newtable(L); lua_newtable(L);
set_hostinfo(L, (Target *) *ti); set_hostinfo(L, target);
lua_rawseti(L, 3, lua_objlen(L, 3) + 1); lua_rawseti(L, 3, lua_objlen(L, 3) + 1);
lua_rawgeti(L, LUA_REGISTRYINDEX, current_hosts); lua_rawgeti(L, LUA_REGISTRYINDEX, current_hosts);
lua_pushlightuserdata(L, (void *) *ti); if (TargetName != NULL && strcmp(TargetName, "") != 0)
lua_setfield(L, -2, (*ti)->targetipstr()); lua_pushstring(L, TargetName);
else
lua_pushstring(L, targetipstr);
lua_pushlightuserdata(L, target);
lua_rawset(L, -3);
lua_pop(L, 1); /* current_hosts */ lua_pop(L, 1); /* current_hosts */
} }

View File

@@ -328,18 +328,33 @@ static int l_mutex (lua_State *L)
Target *get_target (lua_State *L, int index) Target *get_target (lua_State *L, int index)
{ {
int top = lua_gettop(L);
Target *target; Target *target;
luaL_checktype(L, index, LUA_TTABLE); luaL_checktype(L, index, LUA_TTABLE);
lua_getfield(L, index, "targetname");
lua_getfield(L, index, "ip"); lua_getfield(L, index, "ip");
if (!lua_isstring(L, -1)) if (!(lua_isstring(L, -2) || lua_isstring(L, -1)))
luaL_error(L, "host table does not contain 'ip' string field"); luaL_error(L, "host table does not have a 'ip' or 'targetname' field");
lua_rawgeti(L, LUA_REGISTRYINDEX, current_hosts); lua_rawgeti(L, LUA_REGISTRYINDEX, current_hosts);
lua_pushvalue(L, -2); /* target ip string */ if (lua_isstring(L, -3)) /* targetname */
lua_rawget(L, -2); {
if (!lua_islightuserdata(L, -1)) lua_pushvalue(L, -3);
luaL_argerror(L, 1, "host is not being processed right now"); lua_rawget(L, -2);
if (lua_islightuserdata(L, -1))
goto done;
else
lua_pop(L, 1);
}
if (lua_isstring(L, -2)) /* ip */
{
lua_pushvalue(L, -2); /* ip */
lua_rawget(L, -2);
if (!lua_islightuserdata(L, -1))
luaL_argerror(L, 1, "host is not being processed right now");
}
done:
target = (Target *) lua_touserdata(L, -1); target = (Target *) lua_touserdata(L, -1);
lua_pop(L, 3); /* target ip string, current_hosts, target luserdata */ lua_settop(L, top); /* reset stack */
return target; return target;
} }