v2ray-core icon indicating copy to clipboard operation
v2ray-core copied to clipboard

V2Ray should prevent DNS TTL attack

Open kaoet opened this issue 9 years ago • 5 comments

As you said in https://www.v2ray.com/chapter_02/03_routing.html

解析后的 IP 仅在路由选择时起作用,转发的数据包中依然使用原始域名

This leads to a serious problem! Consider the following server side route configuration:

{
  "domainStrategy": "IPIfNonMatch",
  "rules": [
    {
      "type": "field",
      "ip": "10.0.0.0/8",
      "outboundTag": "blocked"
    }
  ]
}

The purpose of the above is to prevent visiting private IPs. Now I publish my V2Ray server to some non-trusted entities for proxying. Then the following attack is possible:

  1. The attacker hosts a strange DNS server for some domain, e.g. "example.com".
  2. That DNS server returns "10.0.0.1" or "114.114.114.114" for "example.com" randomly, with TTL=0.
  3. The attacker continuously tries to connect to "example.com" via my V2Ray server.

Maybe after hundreds of times, the following race condition will be triggered:

  1. The V2Ray router resolves "example.com" to "114.114.114.114" and allows the connection.
  2. The outbound resolves "example.com" again, but with "10.0.0.1" as result.
  3. The attacker is now connected to "10.0.0.1", although it is forbidden in my route configuration.

kaoet avatar Aug 27 '17 01:08 kaoet

Personally I suggest using firewall for security purpose. You can run the server in a dedicated user and use iptables -m owner to drop the outgoing connections.

IbarakiKasen avatar Aug 27 '17 04:08 IbarakiKasen

There is nothing can be done on the V2Ray side. You may setup your own DNS rely server (say 1.1.1.1) which blocks such phishing domains, and then point V2Ray and/or system to use 1.1.1.1.

DarienRaymond avatar Aug 29 '17 14:08 DarienRaymond

@DarienRaymond Of course there are things V2Ray can do. Just use the same resolved ip in both routing and forwarding. It is a bug which needs to be fixed.

kaoet avatar Aug 30 '17 08:08 kaoet

@kaoet I think using original domain in forwarding is a documented feature instead of a bug.

Passing the domain to outbound relay will allow the relay server do the DNS resolve on its own, to obtain a answer based on the server location (GeoDNS) and the network stack it supports (some of my relay server support IPv6 while others don't). Together with the inbound option domainOverride, I can do this more aggressively in transparent proxy.

In your case maybe you want to reuse the resolved IP for freedom outbound, which is different from my use case. But it seems that there is also some load balancing mechanism in freedom for better handling domains that resolves to multiple IPs, which makes adding the feature more complex. Implementing this for a specific outbound type will increase the complexity of this project. Instead I always recommend using solid security tools on security needs (iptables/apparmor/selinux for limiting outbound connections, and fail2ban for banning malicious user).

IbarakiKasen avatar Aug 30 '17 09:08 IbarakiKasen

@kaoet The root cause here is an evil domain using localhost IPs. It should be prevented at DNS level. It is not V2Ray's goal to implement a fully functional and secure DNS server. If you need security on DNS, please set up your own DNS server.

DarienRaymond avatar Sep 05 '17 20:09 DarienRaymond