Skip to content

DNS over SOCKS #341

Open

Description

@tw-datascientist

Hi

I would like to suggest the addition of SOCKS5 proxy support for TCP and UDP.

This would be beneficial for routing DNS traffic through an internal network.

Is there interest in this? I would like to discuss this further.

Activity

  1. ibauersachs commented on Sep 23, 2024

    @ibauersachs
    Member

    Hey,

    Sure, support for this would be welcome.

    However, I don't want a dependency on another library and ideally it would be possible to reuse existing APIs of dnsjava (TcpIoClient/UdpIoClient).

    Feel free to create a PR, but I won't be able to review anything in the following weeks.

    Thanks,
    Ingo

  2. tw-datascientist commented on Sep 24, 2024

    @tw-datascientist
    Author

    Sounds good.

    My plan is to add an additional constructor for SimpleResolver to pass the necessary parameters and add the SOCKS Handshake here in SimpleResolver.java in the sendAsync method.

    CompletableFuture<byte[]> result;
    if (tcp) {
         // add SOCKS5 Handshake for TCP
         result =
             ioClientFactory
                 .createOrGetTcpClient()
                 .sendAndReceiveTcp(localAddress, address, query, out, timeoutValue);
    } else {
         // add SOCKS5 Handshake for UDP
         result =
             ioClientFactory
                 .createOrGetUdpClient()
                 .sendAndReceiveUdp(localAddress, address, query, out, udpSize, timeoutValue);
    }
    

    Yes. I should be able to use the ioClientFactory for the SOCKS Handshake for TCP and UDP and implement it without any additional dependencies.

    I'll prepare a PR.

  3. ibauersachs commented on Oct 1, 2024

    @ibauersachs
    Member

    Please try to avoid any changes in SimpleResolver. If the handshake is in the IoClients anyway, I don't think it would be neccessary.

  4. tw-datascientist commented on Oct 2, 2024

    @tw-datascientist
    Author

    Hi @ibauersachs,

    I have a first working solution. master...tw-datascientist:dnsjava:master

    Yes, I plan to refactor the changes into the IoClients. Handling UDP is tricky. I have to strip the SOCKS UDP header from the UDP reply. And the TCP connection to setup the UDP associate have to stay open till the UDP transmission has finished. Otherwise I get java.net.PortUnreachableException.

    Oct  2 14:46:43 (1727880403.768883) sockd[33]: info: pass(1): tcp/accept [: 172.30.0.2.49904 172.30.0.3.1080
    Oct  2 14:46:43 (1727880403.769914) sockd[16]: info: pass(1): udp/udpassociate [: 0.0.0.0.0 172.30.0.3.10000
    Oct  2 14:46:43 (1727880403.774654) sockd[37]: info: pass(1): udp/udpassociate -: 172.30.0.2.60384 172.30.0.3.10000 -> 172.30.0.3.60384 1.1.1.1.53 (39)
    Oct  2 14:46:43 (1727880403.785650) sockd[37]: info: pass(2): udp/udpreply -: 1.1.1.1.53 172.30.0.3.60384 -> 172.30.0.3.10000 172.30.0.2.60384 (55)
    Oct  2 14:46:43 (1727880403.786366) sockd[37]: info: pass(1): udp/udpassociate ]: 65/1 -> 172.30.0.2.60384 172.30.0.3.10000 -> 49/1, 39/1 -> 172.30.0.3.60384 1.1.1.1.53 -> 55/1: local client closed.  Session duration: 0s
    Oct  2 14:46:43 (1727880403.786378) sockd[37]: info: pass(1): tcp/accept ]: 65 -> 172.30.0.2.49904 172.30.0.3.1080 -> 39: local client closed.  Session duration: 0s
    

    My guess is that the best approach is to move this logic into the processReadyKey method in NioUdpClient.java.

  5. tw-datascientist commented on Oct 3, 2024

    @tw-datascientist
    Author

    I refactored the changes into the IoClients.

    master...tw-datascientist:dnsjava:master

  6. linked a pull request that will close this issueNew Feature: DNS over SOCKS #347on Dec 15, 2024
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions