Simple SSH port forward in Golang

前端 未结 4 923
忘掉有多难
忘掉有多难 2020-12-28 09:45

I\'m trying to create (and later close) a simple TCP port forward over SSH with Go. I\'m new to Golang and statically typed languages. (Coming from Ruby.)

In a termi

4条回答
  •  没有蜡笔的小新
    2020-12-28 10:09

    I'v finished a simple SSH port forward tool called mallory. It provides HTTP proxy instead of SOCKS proxy, which is really similar to ssh -D.

    The core code is similar to damick's answer.

    1. Create ClientConfig
    2. ssh.Dial to remote SSH server with the config and return Client
    3. Now you can use Client.Dial to forward anything you like.

      Dial initiates a connection to the addr from the remote host. The resulting connection has a zero LocalAddr() and RemoteAddr().

    4. If you want to serve a SOCKS proxy server, use Client.Dial to connect to the remote server.

提交回复
热议问题