diff --git a/CHANGELOG b/CHANGELOG index 18c201659..0f0896bfb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ #Nmap Changelog ($Id$); -*-text-*- +o [NSE][GH#2175] Fixed NSE so it will not consolidate all port script output + for targets which share an IP (e.g. HTTP vhosts) under one target. [Daniel Miller] + o [Zenmap][GH#2157] Fixed an issue where a failure to execute Nmap would result in a Zenmap crash with "TypeError: coercing to Unicode" exception. diff --git a/nse_nmaplib.cc b/nse_nmaplib.cc index ed8c24b3c..d333712ec 100644 --- a/nse_nmaplib.cc +++ b/nse_nmaplib.cc @@ -153,6 +153,7 @@ static void push_osmatch_table(lua_State *L, const FingerMatch *match, * points to nil! * */ void set_hostinfo(lua_State *L, Target *currenths) { + nseU_setpfield(L, -1, "_Target", (void *)currenths); nseU_setsfield(L, -1, "ip", currenths->targetipstr()); nseU_setsfield(L, -1, "name", currenths->HostName()); nseU_setsfield(L, -1, "targetname", currenths->TargetName()); diff --git a/nse_utility.cc b/nse_utility.cc index 058878fb5..0ccd2d7f3 100644 --- a/nse_utility.cc +++ b/nse_utility.cc @@ -74,6 +74,13 @@ void nseU_setbfield (lua_State *L, int idx, const char *field, int b) lua_setfield(L, idx, field); } +void nseU_setpfield (lua_State *L, int idx, const char *field, void * p) +{ + idx = lua_absindex(L, idx); + lua_pushlightuserdata(L, p); + lua_setfield(L, idx, field); +} + void nseU_appendfstr (lua_State *L, int idx, const char *fmt, ...) { va_list va; @@ -180,10 +187,16 @@ Target *nseU_gettarget (lua_State *L, int idx) Target *target; idx = lua_absindex(L, idx); luaL_checktype(L, idx, LUA_TTABLE); + lua_getfield(L, idx, "_Target"); lua_getfield(L, idx, "targetname"); 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_islightuserdata(L, -3)) /* _Target */ + { + lua_pop(L, 2); /* pop ip and targetname, leaving _Target on top */ + goto done; + } /* 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. */ diff --git a/nse_utility.h b/nse_utility.h index 98bc5147d..59e93e541 100644 --- a/nse_utility.h +++ b/nse_utility.h @@ -73,6 +73,13 @@ void nseU_setifield (lua_State *L, int idx, const char *field, lua_Integer value */ void nseU_setbfield (lua_State *L, int idx, const char *field, int value); +/* void nseU_setpfield (lua_State *L, int idx, [-0, +0, e] + * const char *field, void *p) + * + * Sets the field for table at index idx to lightuserdata p. + */ +void nseU_setpfield (lua_State *L, int idx, const char *field, void * p); + /* void nseU_appendfstr (lua_State *L, int idx, [-0, +0, m] * const char *fmt, ...) *