Golang通过socks5代理客户端实现tcp-tls

huangapple go评论68阅读模式
英文:

Golang tcp-tls over socks5 proxy client

问题

我通过以下方式创建了一个拨号器:

dialer := &net.Dialer{}

并通过以下方式创建了一个TLS拨号器:

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

然后,我使用以下方式创建了一个SOCKS5代理拨号器:

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

如何通过SOCKS5代理连接远程服务器呢?
换句话说,如何按照"net.Dialer->tls.Dialer->proxy.Dialer"的顺序嵌套三个拨号器,并最终使用"proxyDialer.Dial("tcp", "remote:port")"连接服务器?

我的环境:

  • 操作系统:Windows 10 x64
  • Golang版本:1.16(没有CGO)

非常感谢您的帮助!这是我第一次在SOF上提问,如果我有遗漏的地方,请告诉我 Golang通过socks5代理客户端实现tcp-tls

英文:

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 Golang通过socks5代理客户端实现tcp-tls
First time asking question in SOF, if I missed sth to say pls tell me Golang通过socks5代理客户端实现tcp-tls

答案1

得分: 1

感谢@Steffen Ullrich

拨号器用于建立连接 - 但只有一个连接需要建立。使用proxyDialer创建连接,然后使用tls.Client在proxyDialer提供的连接上进行“升级”为tls.Conn。

只需将代理连接“升级”为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})
英文:

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})

huangapple
  • 本文由 发表于 2022年2月19日 13:51:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/71182538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定