Exclude the IP where sshuttle is really listening

We were always excluding 127.0.0.1/8 but sshuttle might be listening on
other IP, e.g., ::1 for IPv6 or any other defined with -l
This commit is contained in:
vieira 2016-07-24 21:58:20 +00:00
parent e0dfb95596
commit e9be2deea0
2 changed files with 10 additions and 1 deletions

View File

@ -549,6 +549,7 @@ def main(listenip_v6, listenip_v4,
listenip_v6 = None listenip_v6 = None
required.ipv6 = len(subnets_v6) > 0 or listenip_v6 is not None required.ipv6 = len(subnets_v6) > 0 or listenip_v6 is not None
required.ipv4 = len(subnets_v4) > 0 or listenip_v4 is not None
required.udp = avail.udp required.udp = avail.udp
required.dns = len(nslist) > 0 required.dns = len(nslist) > 0
@ -571,6 +572,14 @@ def main(listenip_v6, listenip_v4,
if listenip_v4 == "auto": if listenip_v4 == "auto":
listenip_v4 = ('127.0.0.1', 0) listenip_v4 = ('127.0.0.1', 0)
if required.ipv4 and \
not any(listenip_v4[0] == sex[1] for sex in subnets_v4):
subnets_exclude.append((socket.AF_INET, listenip_v4[0], 32))
if required.ipv6 and \
not any(listenip_v6[0] == sex[1] for sex in subnets_v6):
subnets_exclude.append((socket.AF_INET6, listenip_v6[0], 128))
if listenip_v6 and listenip_v6[1] and listenip_v4 and listenip_v4[1]: if listenip_v6 and listenip_v6[1] and listenip_v4 and listenip_v4[1]:
# if both ports given, no need to search for a spare port # if both ports given, no need to search for a spare port
ports = [0, ] ports = [0, ]

View File

@ -187,7 +187,7 @@ parser.add_argument(
"-x", "--exclude", "-x", "--exclude",
metavar="IP/MASK", metavar="IP/MASK",
action="append", action="append",
default=[parse_subnet('127.0.0.1/8')], default=[],
type=parse_subnet, type=parse_subnet,
help=""" help="""
exclude this subnet (can be used more than once) exclude this subnet (can be used more than once)