From 0cc65cc614b24a3109dad9cd91e0cd19f7a7d88e Mon Sep 17 00:00:00 2001 From: Narthorn Date: Tue, 30 Apr 2013 04:52:59 +0200 Subject: [PATCH] dns: Add --dns-hosts command-line option. The --dns switch adds firewall rules to intercept queries only for nameservers found in resolv.conf ; This command-line option allows the user to explicitly specify the nameservers to create firewall redirection rules for. This is useful when using a local DNS forwarder to redirect DNS queries to different nameservers. Example: We can use sshuttle to access a private subnet 172.30.0.0/16, which hosts a local DNS server resolving private domain names in that subnet. Currently, the only way to be able to resolve those domain names is to use the --dns switch. However, all DNS queries will then go through the remote nameserver, which might not be desirable especially if said nameserver does not know how to resolve every query. One solution is to run a local DNS forwarder, which knows that the private domain names can be resolved through a private IP, say 172.30.128.40. Now, we can run : sshuttle -r ssh.remoteserver.com -i 172.30.0.0/16 --dns-hosts 172.30.128.40 DNS queries for private domain names will get forwarded to 172.30.128.40, intercepted by the firewall rule and sent through the tunnel to the nameserver used by the remote endpoint (which might or might not be 172.30.128.40 !). Notes : * There is nothing preventing --dns-hosts from being used together with --dns, in which case the nameservers found in resolv.conf will also be added to the firewall rules as usual. This defeats the purpose of the example, however. There might be some weird use-case where this is useful ? * Since there is no control over which nameserver the query gets sent to after it has crossed the tunnel, the IPs specified in --dns-hosts are irrelevant (as long as they are the same as found in the DNS forwarder configuration). This might be a little counter-intuitive. --- client.py | 8 +++++--- main.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client.py b/client.py index a42fdf5..1cd6d6b 100644 --- a/client.py +++ b/client.py @@ -339,7 +339,8 @@ def onhostlist(hostlist): mux.callback() -def main(listenip, ssh_cmd, remotename, python, latency_control, dns, +def main(listenip, ssh_cmd, remotename, python, latency_control, + dns, dns_hosts, seed_hosts, auto_nets, subnets_include, subnets_exclude, syslog, daemon, pidfile): if syslog: @@ -380,11 +381,12 @@ def main(listenip, ssh_cmd, remotename, python, latency_control, dns, listenip = listener.getsockname() debug1('Listening on %r.\n' % (listenip,)) - if dns: + if dns or dns_hosts: dnsip = dnslistener.getsockname() debug1('DNS listening on %r.\n' % (dnsip,)) dnsport = dnsip[1] - dns_hosts = resolvconf_nameservers() + if dns: + dns_hosts += resolvconf_nameservers() else: dnsport = 0 dnslistener = None diff --git a/main.py b/main.py index b958e98..6493506 100755 --- a/main.py +++ b/main.py @@ -54,6 +54,7 @@ def parse_ipport(s): H,auto-hosts scan for remote hostnames and update local /etc/hosts N,auto-nets automatically determine subnets to route dns capture local DNS requests and forward to the remote DNS server +dns-hosts= capture DNS requests to these servers and forward (comma-separated) python= path to python interpreter on the remote server r,remote= ssh hostname (and optional username) of remote sshuttle server x,exclude= exclude this subnet (can be used more than once) @@ -67,7 +68,6 @@ def parse_ipport(s): V,version print sshuttle's version number syslog send log messages to syslog (default if you use --daemon) pidfile= pidfile name (only if using --daemon) [./sshuttle.pid] -dns-hosts= (internal use only) server (internal use only) firewall (internal use only) hostwatch (internal use only) @@ -113,6 +113,7 @@ def parse_ipport(s): remotename = opt.remote if remotename == '' or remotename == '-': remotename = None + nslist = re.split(r'[\s,]+', opt.dns_hosts.strip()) if opt.dns_hosts else [] if opt.seed_hosts and not opt.auto_hosts: o.fatal('--seed-hosts only works if you also use -H') if opt.seed_hosts: @@ -127,6 +128,7 @@ def parse_ipport(s): opt.python, opt.latency_control, opt.dns, + nslist, sh, opt.auto_nets, parse_subnets(includes),