Search code examples
gossltcpproxy

Golang tcp-tls over socks5 proxy client


I create a dialer via

dialer := &net.Dialer{}

and a TLS dialer via

tlsDialer := &tls.Dialer{
    NetDialer: dialer,
    Config:    &tls.Config{InsecureSkipVerify: true},
}

Then I create a socks5 proxy dialer by using

proxyDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:1080", nil, proxy.Direct)

How can I connect remote server though the socks5 proxy?
In other way, how to nest three dialer in the order of net.Dialer->tls.Dialer->proxy.Dialer and finally using proxyDialer.Dial("tcp", "remote:port") to connect the server?

My Env:

  • OS: Windows 10 x64
  • Golang: 1.16 (no CGO)

Any help would be greatly appreciated :) First time asking question in SOF, if I missed sth to say pls tell me :)


Solution

  • Thanks for @Steffen Ullrich

    A Dialer is used to establish a connection - but there is only a single connection to establish. Create the connection using proxyDialer, then use tls.Client on the connection given by proxyDialer to "upgrade" it to a tls.Conn.

    Just "upgrade" proxy connection to tls

    proxyDialer, err := proxy.SOCKS5("tcp", "proxyserver:1080", nil, proxy.Direct)
    conn, err = proxyDialer.Dial("tcp", "server:port")
    conn = tls.Client(conn, &tls.Config{InsecureSkipVerify: true})