ZmnSCPxj / clboss

Automated Core Lightning Node Manager
MIT License
214 stars 32 forks source link

Implement DNS-over-TCP / HTTPS #4

Open ZmnSCPxj opened 4 years ago

ZmnSCPxj commented 4 years ago

Currently we just use dig. The big issue with dig is that it has no option I can find where it can be asked to do a DNS-over-TCP query via a SOCKS5 proxy (i.e. tor). It can work with torify but that increases our dependencies, and does not necessarily work for all proxy settings.

We may want to implement DNS-over-TCP directly, if only because we can tunnel that over a SOCKS5 proxy so that DNS seed queries can hide the IP of the user at least. DNS-over-TCP is preferred if we have a Tor proxy since Tor will do end-to-end encryption anyway, but we also want to avoid DNS attacks even if the user does not use Tor, which is why we might want to use DNS-over-HTTPS instead. However, I have no idea if lseed supports HTTPS, or if using a recursive resolver will let me paper over that lack if lseed does not support DNS-over-HTTPS. Probably @cdecker knows.

For now CLBOSS uses digwith atorify if it works, and if always-use-proxy is set, requires torify always.

Saibato commented 4 years ago

The Tor socks proxy can not return SRV records if u ask to resolve a seeder name,, so u get with high probability only the first entry from the DNS call the exit node does or a faked one from a rogue exit and not a list of addresses we used to get from the UDP call.

The Tor socks proxy will just return an open TCP socket to the first A or AAAA entry the exit found by his DNS call. so unless u don't know exactly the SRV name ( derived from the node id) u cant use V3 addresses since they can not be easy mapped in in ipv6 address returns. ( btw that was what i had preferred for core instead of ADDRv2 since we could have mapped one V3 address in three AAAA answers and use seemingly the old DNS way to seed, now we have BIP155 and are forced to use direct node calls or HTTPS what identify us like a cookie)

But if u know the SRV or V3 address name u could also direct call the node and stay in the Tor net and never exit Tor.

So, if we trust seeders we could use there fixed V3 addresses they give us hard coded like there fqdn in bitcoin core or in our case the SRV name that encoded the v3 and call one of them. by chance. And find other nodes by the gossip.

Alternatively u could use a service like https://developers.cloudflare.com/1.1.1.1/fun-stuff/dns-over-tor but that in combination with https make not much sense for privacy, since https can identify u like a cookie does. And cloudfare could answer anything, so...

But if the goal is to get random private seeds and the seeders should not know they are called, I guess any use of DNS over Tor or else is not the best idea, or I change Tor a bit and implement in The socks service SRV returns.

    case PROXY_SOCKS5_WANT_CONNECT_OK:
      /* response is variable length. BND.ADDR, etc, isn't needed
       * (don't bother with buf_pullup()), but make sure to eat all
       * the data used */

      /* wait for address type field to arrive */
      if (datalen < 4)
        return 0;

      switch (data[3]) {
        case 0x01: /* ip4 */
          addrlen = 4;
          break;
        case 0x04: /* ip6 */
          addrlen = 16;
          break;
        case 0x03: /* fqdn (can this happen here?) */
          if (datalen < 5)
            return 0;
          addrlen = 1 + data[4];
          break;
        default:
          *reason = tor_strdup("invalid response to connect request");
          return -1;
      }

-- fqdn (can this happen here?) That i could maybe change. But what would be my incentive to do that?

ZmnSCPxj commented 4 years ago

My understanding is that we can talk directly to the resolver over Tor, e.g. not send lseed.bitoinstats.com to our proxy, instead something like send 1.1.1.1 to our proxy, which resolves to Cloudflare, then ask Cloudflare with the DNS protocol over TCP to resolve lseed.bitcoinstats.com to 5 SRV addresses. This seems to be what lnd does for its seeds I think.

Cloudflare learns IP of the Tor exit node and not our IP. Tor exit node knows someone is asking for Lightning seeds but not know who. Tor exit node can still mess with our DNS query and instead of sending out the actual query can answer itself with its own curated list of Lightning seeds, but cannot use targeted attacks (onion == not know source), it can only use this for everyone (and if there are many exit nodes, chances of this is low, we hope).

If we use DNS-over-HTTPS to talk to Cloudflare via a Tor tunnel (as described above), Tor exit node cannot read our talking with Cloudflare and cannot make above lseed-replacement attack (it cannot see it is DNS query). I think, we can always just make up a new HTTPS identity each time (is not that default of libCURL?).

(My understanding of DNS is not good, so maybe I misunderstand above, sorry, please teach me if it is not correct understanding.)

Of course now we trust Cloudflare to not give poisoned lseed DNS (which is why there is ConnectFinderByHarcoded haha).

But I find ISP DNS seems worse in practice. I cannot get any SRV from lseed.darosior.ninja via ISP DNS of my ISPs (all of them), and also cannot get via 1.1.1.1, I can only get replies from lseed.darosior.ninja if using Google 8.8.8.8. SRV from lseed.bitcoinstats.com is reliable on ISP DNS (most of them, but one ISP does not work) but much slower (!!) than over 1.1.1.1 or 8.8.8.8, ISP WTF?

Maybe also possible to use a Tor tunnel to DNS-over-TCP or DNS-over-HTTPS with the seeds directly, not certain if lseed runs those however...

Saibato commented 4 years ago

Tor exit node cannot read our talking with Cloudflare

are we sure to have the pub of cloudflare?

Tyi: https://www.zdnet.com/article/a-mysterious-group-has-hijacked-tor-exit-nodes-to-perform-ssl-stripping-attacks/

I.e. What LND does in regards to Tor i refuse to comment here that would be too sarcastic, I can only state if users use Tor they good advised to use at least c-ln.

If the game is rigged its rigged, to seed of DNS was anyway never the best idea. But to have and had seeding in core over Tor's exits nodes was even more :woman_facepalming: ooopss.

Of course now we trust Cloudflare to not give poisoned lseed DNS (which is why there is ConnectFinderByHarcoded haha).

At least cloudflare has now an onion addr

https://dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion 

To not have to use 1.1.1.1 But that onion is only reachable by HTTPS so wtf. Classic HTTPS and Tor makes for me absolutely no sense, if u want privacy. And since they also registered 1.0.0.127 who will not think hmm....

We hope at least what is in tor stay;s in Tor, so hardcoded v3's addresses updated with new releases like the FQDN of the seeders in cores chainparams.cpp should be fine.

In general i see a timing correlation problem if u follow certain predictable patterns of connect even in Tor, so even bogus relays as exist could be a problem. So one should never call more than one seeder node to get gossip. And this node should be selected and gossip randomly.

Maybe also possible to use a Tor tunnel to DNS-over-TCP or DNS-over-HTTPS with the seeds directly, not certain if lseed runs those however...

btw tyi There was lately a discussion in core over the related issue DNSSEC https://github.com/bitcoin/bitcoin/issues/19714 And pls look at https://blog.circuitsofimagination.com/2018/11/08/dns-o-t-dnssec-dns-o-h.html

But please also note its all just an other layer of disguise the fact that any PK leaks like cookie and keys must have been registered and have a second key. So welcome to govcoin.

I see it that way, the app u build from source or download, is for u the "bitcoin" or "LN". If that is rigged u screwed anyway and u will never know the difference.

Fixed V3 or ip4/6 addresses in the releases sources and app signed by PGP ( no registry and also PK but at least some chain of evolving trust and if u met the in RL and exchanged sym keys, not that rigged ) of the dev and with public multiple mirrors of hash signatures of those sources and apps should be enough and leak the least and seeding over DNS chould just be an option but never be the default. imho.

cannot see it is DNS query). I think, we can always just make up a new HTTPS identity each time (is not that default of libCURL?). (My understanding of DNS is not good, so maybe I misunderstand above, sorry, please teach me if it is not correct understanding.)

Btw. I wished many more dev that had to do server or scaling stuff had so much understanding like u in that, But its i guess a generation questions and the devs the system had allowed to grow we have now have forgotten or where never advised to the buried shit in the basement, that's only in so far a fault if some knew and did fuckups on purpose. For instance, if ur identity is gone its gone and even it it was just once at the startup or seeding or first contact, done is done, the sophisticated security Theater after, is irrelevant since some have big storage capacities and time. In general one could say, decent nerdy IQ was for long not the preferred metric to have success or be promoted to key IT positions, since Stop Genesis was a program they followed strictly. PK or HTTPS or DNS/DNSSEC are concepts after wwii that gave us great peace but are as rigged from day one as rigged can be and ppl like Turing bite even in the words sense for that in the apple, bcs they and other knew what Colossus was capable of, even then.

https://web.archive.org/web/20130521211106/http://www.mathcomp.leeds.ac.uk/turing2012/Images/Turing_Zuse.pdf