Bind to source with -e, not only -S. Fixes #2122
Some checks are pending
nmap multiplatform autobuilds / build (arm64, gcc, ubuntu-latest-gcc-arm64, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, freebsd-15-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, macos-15-clang, macos-15) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, macos-26-clang, macos-26) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, netbsd-10-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, openbsd-7-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, solaris-11-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, ubuntu-latest-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (egcc, openbsd-7-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, freebsd-15-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, netbsd-10-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, solaris-11-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, ubuntu-latest-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (msvc, windows-latest-msvc, windows-latest) (push) Waiting to run

This commit is contained in:
dmiller 2026-07-20 15:48:57 +00:00
parent 3be44941fe
commit eb79c42b05
4 changed files with 9 additions and 22 deletions

View file

@ -417,15 +417,14 @@ static nse_nsock_udata *check_nsock_udata (lua_State *L, int idx, bool open)
throw an error if that's not possible. */
if (nu->proto == IPPROTO_UDP) {
nsock_pool nsp;
struct sockaddr_storage ss;
size_t sslen;
nsp = get_pool(L);
nu->nsiod = nsock_iod_new(nsp, NULL);
if (nu->source_addr.ss_family != AF_UNSPEC) {
nsock_iod_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);
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
}
if (o.ipoptionslen)
@ -544,13 +543,11 @@ static int connect (lua_State *L, int status, lua_KContext ctx)
if (nu->nsiod != NULL)
close_internal(L, nu);
nu->nsiod = nsock_iod_new(nsp, NULL);
struct sockaddr_storage ss;
size_t sslen;
if (nu->source_addr.ss_family != AF_UNSPEC) {
nsock_iod_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);
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
}
if (o.ipoptionslen)

View file

@ -433,8 +433,7 @@ static void init_socket(int sd, const HostScanStats *hss, UltraScanInfo *USI) {
}
#endif
if (o.spoofsource && !bind_failed) {
o.SourceSockAddr(&ss, &sslen);
if (!bind_failed && 0 == o.SourceSockAddr(&ss, &sslen)) {
if (::bind(sd, (struct sockaddr*)&ss, sslen) != 0) {
error("%s: Problem binding source address (%s), errno: %d", __func__, inet_socktop_safe(&ss), socket_errno());
perror("bind");

View file

@ -2139,8 +2139,7 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
if ((svc->niod = nsock_iod_new(nsp, svc)) == NULL) {
fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
}
if (o.spoofsource) {
o.SourceSockAddr(&ss, &ss_len);
if (0 == svc->target->SourceSockAddr(&ss, &ss_len)) {
nsock_iod_set_localaddr(svc->niod, &ss, ss_len);
}
if (o.ipoptionslen)

View file

@ -1566,15 +1566,7 @@ bool setTargetNextHopMAC(Target *target) {
}
int nmap_route_dst(const struct sockaddr_storage *dst, struct route_nfo *rnfo) {
struct sockaddr_storage spoofss;
size_t spoofsslen;
if (o.spoofsource) {
o.SourceSockAddr(&spoofss, &spoofsslen);
return route_dst(dst, rnfo, o.device, &spoofss);
} else {
return route_dst(dst, rnfo, o.device, NULL);
}
return route_dst(dst, rnfo, o.device, o.SourceSockAddr());
}