Skip to content

systemd-resolved causes dns leaks when connected via vpn #7182

Closed

Description

@PureRumble

openvpn-config-files.zip

Submission type

  • Bug report

systemd version the issue has been seen with

systemd 234

Used distribution

Ubuntu 17.10

In case of bug report: Expected behaviour you didn't see

My system should send dns lookups to the dns server provided by my vpn service only.

In case of bug report: Unexpected behaviour you saw

My system sends dns lookups to my local ISPs dns server when connected to my vpn service.

In case of bug report: Steps to reproduce the problem

  1. Install OpenVPN
  1. Connect to a vpn service (such as the highly popular Private Internet Access) using OpenVPN and the vpn service's vpn config files (see attachments for instance) openvpn-config-files.zip
  1. Go to dnsleak.com. Note that there are DNS query leaks to your ISPs DNS server.

My limited understanding of tcp/udp, http/https and vpn tells me that when a network interface is connected to a vpn server then the main principle to follow is that every single outgoing ip package should (after having been packaged into a new tcp/udp stream) be relayed to the vpn server.

So why is it that (if my understanding is correct) we have a system here responsible for dns lookups that chooses to ignore the fact that a vpn connection is in use and instead relays lookup requests to the local dns server?

Why is this problem being ignored instead of being dealt with immediately? Isn't this an extremely serious security related bug? Yes I know lots and lots of people use VPN services for illegal file sharing and looking at beautiful people pursing various stages of undress (and other things...), but it is also being used in oppressive countries such as Iran by politically active people to regain some level of privacy and peace of mind when they take their share of internet material and communication that is deemed as "unfavorable" by the state.

I shiver to think of the poor soul that gets a knock on the door early in the morning by a secret police representative who would like to ask a few questions about his political ideologies and asks him to come to the station for a "pleasant chat". Why did this happen? Because someone thought that vpn communication on his system follows the principle that all traffic should go through the vpn service.

Activity

  1. boucman commented on Oct 25, 2017

    @boucman
    Contributor

    the principle that every packet should go through the VPN is not always true. What if you have multiple VPN ?

    A very common VPN setup (my setup) is to have normal internet traffic be directly sent to the internet and only have packets internal to the corporate network go to the corporate network.

    the core answer here is that the VPN is just a network interface like any other, and what decides what packet goes through the VPN and what packet goes out is decided by the kernel routing table

    Now, who sets up the kernel routing table can vary quite a bit, but IIRC it's openvpn's responsability. So it's probably an openvpn configuration problem

  2. PureRumble commented on Oct 26, 2017

    @PureRumble
    Author

    Nearly every time someone purchases a VPN service or sets up a VPN server they want all traffic (including dns lookups) to go through the VPN server, and this is especially true for novice users. You are the one describing special cases (multiple vpn connections, personal traffic and corporate vpn traffic, etc.).

    Thus I believe common sense dictates that the default behavior of any system/module/etc involved in the process of DNS lookups coupled with a VPN connection should be that DNS lookups are relayed to the VPN server too.

    Now you say the fault lies with OpenVPN not configuring the kernel routing table correctly, but it's strange that this wasn't an issue with OpenVPN until systemd-resolved came along. Specifically, OpenVPN had no such issues with the DNS server dnsmasq. Did OpenVPN configure the the kernel routing table correctly for dnsmasq all these years as opposed to for systemd-resolved?

    I'm not an expert in this field, but other sources suggest that this is caused by a bug/design flaw in systemd-resolved. The following link for instance raises some what seem to be serious concerns that suggest this problem isn't only limited to OpenVPN as you suggest: https://lists.dns-oarc.net/pipermail/dns-operations/2016-June/014964.html. I'll quote some of its criticism of systemd-resolved here:

    • "It is yet another program/daemon that runs races with other software in controlling /etc/resolv.conf. Eg VPN software adding nameservers."

    • "It sends out a DNS queries over all its obtained DNS servers all the time. This means DNS queries for split-DNS view resources leak all over the internet."

    So if I'm not mistaken then this is a problem caused by systemd-resolved. If this is true, my question still stands: is anything going to be done to fix this problem, and why isn't this considered to be a serious security flaw since it breaks all common sense that your system should by default spout out dns lookups to your ISP's DNS server when you're connected to a VPN service?

  3. snabb commented on Oct 28, 2017

    @snabb

    This is a duplicate of: #6076

    Also related: #5755

    Looks like the author insists nothing is broken. Situation is hopeless.

  4. flo-wer commented on Oct 28, 2017

    @flo-wer

    I suppose you are using the script from update-systemd-resolved than make sure to set DOMAIN-ROUTE to . see Usage.
    For this special syntax see: systemd.network#Domains=
    This should ensure that all DNS lookups are routed exclusive over the VPN interface.

  5. PureRumble commented on Oct 29, 2017

    @PureRumble
    Author

    Thanks for your help @flo-wer but no, I'm not using that script. It's 400 lines long. What does it do? Is it safe? Will it break something? Why do I need a 400 lines long script to do something as essential as relaying all traffic through my VPN connection? This should be doable out-of-the-box and should in fact be the default behavior.

  6. PureRumble commented on Oct 29, 2017

    @PureRumble
    Author

    @snabb, thank you for your referral. I cam up empty handed when I did a search among the project's issues (using GitHub's search feature) before posting my own. I have now posted our "grievances" in the issue you referred to too.

  7. flo-wer commented on Oct 29, 2017

    @flo-wer

    I can understand your criticism of systemd-resolved, but it's not the primary fault of systemd-resolved per se, as it can handle your use case.

    The problem is, that systemd-resolved only talks over D-Bus to receive name servers. So you either make direct D-Bus calls or you use a third party tool to make this communication easier.

    The posted script is such a tool who works as a callback from openVPN and sends the name server over D-Bus to systemd-resolved. Note that I haven't used this script nor reviewed it, I only studied the man page.

    Another way is using NetworkManager to handle the VPN, as NM supports ipv4.dns-priority to filter name servers per interface and will only pass the appropriate information to systemd-resolved. Note that there was a bug, that should be fixed recently: https://bugzilla.gnome.org/show_bug.cgi?id=783569, NetworkManager/NetworkManager@70792e5, that prevented this from working.

  8. xpcone commented on Nov 18, 2017

    @xpcone

    still open issue with Network-Manager 1.8.4 and unfixed ...

  9. poettering commented on Dec 8, 2017

    @poettering
    Member

    Hmm, can you please provide "systemd-resolve --status" for your system?

    By default, systemd-resolved will send lookup request to every interface that has at least one DNS server configured in parallel, but takes any per-interface configured search and routing domains into account. This is done in the following way:

    1. if the domain to lookup matches against no configured search/routing domain, the request is sent to all interfaces in parallel.
    2. if the domain matches at least one configured search/routing domain, then the request is sent to all interfaces that have a matching search/routing domain.

    Now, if you have a VPN set up then conceptually two approachs might make sense:

    1. You are like me, have a company VPN, and only want redhat.com DNS traffic to go to that VPN, but nothing else. The algorithm above works out-of-the-box for that.
    2. You are like you, and want that all DNS traffic goes through your VPN. In that case, simply define "." as route domain (that is: the root level domain, i.e. the domain that is suffix for everything, and hence everything matches against it) for your VPN interface, and it will become a "magnet" for all traffic.

    I am pretty sure both usecases are fully valid. One is more "corporate" the other more "privacy-minded". We can't really know which one is the right one, we default to the "corporate" one though. To switch to the "privacy-minded" one, just include "." in the search domains for that interface and you should be good.

    Does that make sense?

  10. Gullumluvl commented on Apr 2, 2018

    @Gullumluvl

    Hi everyone, I also suffer from this issue, and I am also quite inclined to rant about it...
    I simply couldn't find how to configure systemd-resolved.service so that it's not showing my ISP box as the first DNS server. Here is the output of systemd-resolve --status, where you can see 192.168.1.254 as the first entry for interface eno1 (ethernet?):

    Global
             DNS Servers: 208.67.222.222
                          208.67.220.220
                          8.26.56.26
              DNSSEC NTA: 10.in-addr.arpa
                          16.172.in-addr.arpa
                          168.192.in-addr.arpa
                          17.172.in-addr.arpa
                          18.172.in-addr.arpa
                          19.172.in-addr.arpa
                          20.172.in-addr.arpa
                          21.172.in-addr.arpa
                          22.172.in-addr.arpa
                          23.172.in-addr.arpa
                          24.172.in-addr.arpa
                          25.172.in-addr.arpa
                          26.172.in-addr.arpa
                          27.172.in-addr.arpa
                          28.172.in-addr.arpa
                          29.172.in-addr.arpa
                          30.172.in-addr.arpa
                          31.172.in-addr.arpa
                          corp
                          d.f.ip6.arpa
                          home
                          internal
                          intranet
                          lan
                          local
                          private
                          test
    
    Link 5 (tun0)
          Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
             DNS Servers: 208.67.222.222
                          208.67.220.220
                          8.26.56.26
                          193.234.3.1
                          108.59.1.193
              DNS Domain: ~.
    
    Link 3 (wlp2s0b1)
          Current Scopes: none
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
    
    Link 2 (eno1)
          Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
             DNS Servers: 192.168.1.254
                          208.67.222.222
                          208.67.220.220
                          8.26.56.26
              DNS Domain: lan
    
    

    I tried various things, like first symlinking /etc/resolv.conf to /etc/systemd/resolvconf/resolv.conf, and also editing the file /etc/systemd/resolved.conf to add the line

    DNS=208.67.222.222 208.67.220.220 8.26.56.26
    

    (see man resolved.conf)

    but no change in the output of systemd-resolve --status...

    However, regarding my openvpn client setup, I tried adding this line in the config file, as you mention in your previous comment:

    dhcp-option DOMAIN-ROUTE .
    

    as well as using the recommended script update-systemd-resolved (which by the way is packaged for ubuntu), and it seems to fix my DNS leaks.

    HOWEVER, I still have interrogation, because the ouput of systemd-resolve --status still shows my ISP box, and because the openvpn connection logs seem to still create a route to my ISP box:

    upon running openvpn client.conf (suspicious parts in bold):

    ...
    Mon Apr 2 19:24:41 2018 ROUTE_GATEWAY 192.168.1.254/255.255.255.0 IFACE=eno1 HWADDR=d4:be:d9:62:7c:4c
    Mon Apr 2 19:24:41 2018 TUN/TAP device tun0 opened
    Mon Apr 2 19:24:41 2018 TUN/TAP TX queue length set to 100
    Mon Apr 2 19:24:41 2018 do_ifconfig, tt->did_ifconfig_ipv6_setup=0
    Mon Apr 2 19:24:41 2018 /sbin/ip link set dev tun0 up mtu 1500
    Mon Apr 2 19:24:41 2018 /sbin/ip addr add dev tun0 193.234.3.56/26 broadcast 193.234.3.63
    Mon Apr 2 19:24:41 2018 /etc/openvpn/update-systemd-resolved tun0 1500 1553 193.234.3.56 255.255.255.192 init
    <14>Apr 2 19:24:41 update-systemd-resolved: Link 'tun0' coming up
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding IPv4 DNS Server 208.67.222.222
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding IPv4 DNS Server 208.67.220.220
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding IPv4 DNS Server 8.26.56.26
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding DNS Routed Domain .
    <12>Apr 2 19:24:41 update-systemd-resolved: Not a recognized DHCP setting: 'DISABLE-NBT'
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding IPv4 DNS Server 193.234.3.1
    <14>Apr 2 19:24:41 update-systemd-resolved: Adding IPv4 DNS Server 108.59.1.193
    <14>Apr 2 19:24:41 update-systemd-resolved: SetLinkDNS(5 5 2 4 208 67 222 222 2 4 208 67 220 220 2 4 8 26 56 26 2 4 193 234 3 1 2 4 108 59 1 193)
    <14>Apr 2 19:24:41 update-systemd-resolved: SetLinkDomains(5 1 . true)
    Mon Apr 2 19:24:41 2018 /sbin/ip route add 193.180.119.7/32 via 192.168.1.254
    Mon Apr 2 19:24:41 2018 /sbin/ip route add 0.0.0.0/1 via 193.234.3.1
    Mon Apr 2 19:24:41 2018 /sbin/ip route add 128.0.0.0/1 via 193.234.3.1
    Mon Apr 2 19:24:41 2018 Initialization Sequence Completed

    I might very well have wrongly understood it, because I am totally lost in all those routing concepts, but could you clarify that in the above output, my box is only used as gateway, not DNS server?

    Thanks a lot.

  11. poettering commented on Dec 4, 2018

    @poettering
    Member

    Closing this, as @PureRumble never responded. Moreover, I am pretty sure this is ultimately a duplicate of #10830, let's close this hence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions