Prevent NSE from connecting to the wrong AF: http://seclists.org/nmap-dev/2012/q3/871

This commit is contained in:
dmiller 2015-05-15 19:35:18 +00:00
parent 9781830ece
commit 6a8f12e165

View file

@ -478,7 +478,18 @@ static int l_connect (lua_State *L)
return nseU_safeerror(L, "sorry, you don't have OpenSSL");
#endif
error_id = getaddrinfo(addr, NULL, NULL, &dest);
/* If we're connecting by name, we should use the same AF as our scan */
struct addrinfo hints = {0};
/* First check if it's a numeric address */
hints.ai_flags = AI_NUMERICHOST;
error_id = getaddrinfo(addr, NULL, &hints, &dest);
if (error_id == EAI_NONAME) {
/* Nope, let's resolve it for the proper AF */
hints.ai_flags = 0;
hints.ai_family = o.af();
error_id = getaddrinfo(addr, NULL, &hints, &dest);
}
if (error_id)
return nseU_safeerror(L, gai_strerror(error_id));