Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socks5, Tor & potential DNS leaks #147

Closed
awfm9 opened this issue Feb 18, 2013 · 2 comments
Closed

Socks5, Tor & potential DNS leaks #147

awfm9 opened this issue Feb 18, 2013 · 2 comments

Comments

@awfm9
Copy link

awfm9 commented Feb 18, 2013

Me reporting.

For some reason, I can't reproduce this reliably, but I do get the following message frequently:

"Your application (using socks4/5 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see Socks and DNS."

Now, I don't know whether Electrum is really leaking DNS instead of directing it through Tor (which would be really bad for anonymity) or whether there is simply some cache or some IPs hard-coded into the client.

However, I would suggest that, either way, there should be proper DNS requestn done through the Socks proxy in all cases, so that this message never shows up in the Tor logs. This would both be better for anonymity purposes and help people to feel safer when using Electrum as a bitcoin-qt alternative.

Regards.

@novusordo
Copy link

This should be handled in lib/socks.py. Here are the parts I'm looking at.

Line 207:

        try:
            ipaddr = socket.inet_aton(destaddr)
            req = req + chr(0x01).encode() + ipaddr
        except socket.error:
            # Well it's not an IP number,  so it's probably a DNS name.
            if self.__proxy[3]:
                # Resolve remotely
                ipaddr = None
                req = req + chr(0x03).encode() + chr(len(destaddr)).encode() + destaddr
            else:
                # Resolve locally
                ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
                req = req + chr(0x01).encode() + ipaddr

Line 273:

        # Check if the destination address provided is an IP address
        rmtrslv = False
        try:
            ipaddr = socket.inet_aton(destaddr)
        except socket.error:
            # It's a DNS name. Check where it should be resolved.
            if self.__proxy[3]:
                ipaddr = struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01)
                rmtrslv = True
            else:
                ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
        # Construct the request packet
        req = struct.pack(">BBH", 0x04, 0x01, destport) + ipaddr

Line 290:

        # DNS name if remote resolving is required
        # NOTE: This is actually an extension to the SOCKS4 protocol
        # called SOCKS4A and may not be supported in all cases.
        if rmtrslv:
            req = req + destaddr + chr(0x00).encode()
        self.sendall(req)
        # Get the response from the server
        resp = self.__recvall(8)
        if resp[0:1] != chr(0x00).encode():
            # Bad data
            self.close()
            raise GeneralProxyError((1,_generalerrors[1]))
        if resp[1:2] != chr(0x5A).encode():
            # Server returned an error
            self.close()
            if ord(resp[1:2]) in (91, 92, 93):
                self.close()
                raise Socks4Error((ord(resp[1:2]), _socks4errors[ord(resp[1:2]) - 90]))
            else:
                raise Socks4Error((94, _socks4errors[4]))

@ecdsa
Copy link
Member

ecdsa commented Oct 1, 2013

I suppose this could fix it:
http://stackoverflow.com/questions/13184205/dns-over-proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants