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

Provide a new nsock_setup_udp function to create a UDP socket without connecting it. Provide an NSE interface to the function. Add broadcast.nse, a script that receives UDP broadcasts with an unconnected socket.

This commit is contained in:
david
2010-10-01 06:26:22 +00:00
parent df99409651
commit 87ee8343f3
2 changed files with 52 additions and 0 deletions

View File

@@ -727,6 +727,42 @@ int l_get_ssl_certificate (lua_State *L)
}
#endif
static int l_setup (lua_State *L)
{
static const int families[] = { AF_INET, AF_INET6 };
static const char *const fam_op[] = {"ipv4", "ipv6", NULL};
nsock_pool nsp;
nse_nsock_udata *nu;
const char *proto;
int af;
af = families[luaL_checkoption(L, 2, NULL, fam_op)];
proto = luaL_checkstring(L, 3);
if (strcmp(proto, "udp") != 0)
return luaL_argerror(L, 2, "must be \"udp\"");
nsp = get_pool(L);
nu = check_nsock_udata(L, 1, 0);
nu->nsiod = nsi_new(nsp, NULL);
if (nu->source_addr.ss_family != AF_UNSPEC) {
nsi_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
} else if (o.spoofsource) {
struct sockaddr_storage ss;
size_t sslen;
o.SourceSockAddr(&ss, &sslen);
nsi_set_localaddr(nu->nsiod, &ss, sslen);
}
if (o.ipoptionslen)
nsi_set_ipoptions(nu->nsiod, o.ipoptions, o.ipoptionslen);
nsock_setup_udp(nsp, nu->nsiod, callback, nu->timeout, nu, af);
return yield(L, nu, "SETUP", TO, 0, NULL);
}
/* Set the local address for socket operations. The two optional parameters
after the first (which is the socket object) are a string representing a
numeric address, and a port number. If either optional parameter is omitted
@@ -987,6 +1023,7 @@ LUALIB_API int luaopen_nsock (lua_State *L)
"return receive_buf;\n";
static const luaL_Reg l_nsock[] = {
{"setup", l_setup},
{"bind", l_bind},
{"send", l_send},
{"receive", l_receive},

15
scripts/broadcast.nse Normal file
View File

@@ -0,0 +1,15 @@
description = ""
categories = {}
prerule = function() return true end
action = function()
local s, status, data
s = nmap.new_socket()
s:bind("255.255.255.255", 67)
s:setup("ipv4", "udp")
status, data = s:receive()
return data
end