All Projects → drowzy → ssh_tunnel

drowzy / ssh_tunnel

Licence: MIT license
No description or website provided.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to ssh tunnel

holepunch-client
Totally self-contained SSH reverse tunnel written in Go
Stars: ✭ 64 (+128.57%)
Mutual labels:  ssh-tunnel
jumper
Automated Reverse TCP tunneling using a digitalocean instance and aploium's shootback repo (https://github.com/aploium/shootback)
Stars: ✭ 14 (-50%)
Mutual labels:  ssh-tunnel
vex
reverse HTTP proxy tunnel via secure SSH connections.
Stars: ✭ 20 (-28.57%)
Mutual labels:  ssh-tunnel
tunman
Comprehensive solution for SSH tunnels - respawning, healthchecking/monitoring
Stars: ✭ 43 (+53.57%)
Mutual labels:  ssh-tunnel
Fenix
A simple and visual static web server with collaboration features.
Stars: ✭ 1,559 (+5467.86%)
Mutual labels:  ssh-tunnel
Glider
glider is a forward proxy with multiple protocols support, and also a dns/dhcp server with ipset management features(like dnsmasq).
Stars: ✭ 1,710 (+6007.14%)
Mutual labels:  ssh-tunnel
Mole
CLI application to create ssh tunnels focused on resiliency and user experience.
Stars: ✭ 1,520 (+5328.57%)
Mutual labels:  ssh-tunnel
Algo
Set up a personal VPN in the cloud
Stars: ✭ 24,275 (+86596.43%)
Mutual labels:  ssh-tunnel
rsp
Rapid SSH Proxy
Stars: ✭ 223 (+696.43%)
Mutual labels:  ssh-tunnel
libssh2-tunnel-example
Example of permanent SSH tunnel using libssh2
Stars: ✭ 18 (-35.71%)
Mutual labels:  ssh-tunnel
sshtun
Go package to create SSH tunnels
Stars: ✭ 62 (+121.43%)
Mutual labels:  ssh-tunnel

SSHTunnel

Create SSH tunnels in Elixir

Documentation for SSHTunnel is available online.

Installation

Add SSHTunnel to your mix.exs and run mix deps.get

def deps do
  [
    {:ssh_tunnel, "~> 0.1.3"}
  ]
end

Usage

SSHTunnel can be used to create forwarded SSH channels, similair to channels created using :ssh_connection. Sending messages can be done using :ssh_connection.send/3.

SSHTunnel also provide on-demand created tunnels, this is eqvivalent to using ssh -nNT -L 8080:sshserver.example.com:80 [email protected]. The tunnel process will forward messages from a TCP client to a ssh connection and back.

As channels

  • directtcp-ip
msg = "GET / HTTP/1.1\r\nHost: localhost:8080\r\nUser-Agent: ssht/0.1.1\r\nAccept: */*\r\n\r\n"

{:ok, pid} = SSHTunnel.connect(host: "sshserver.example.com", user: "user", password: "password")
{:ok, ch} = SSHTunnel.direct_tcpip(pid, {"127.0.0.1", 8080}, {"sshserver.example.com", 80})
:ok = :ssh_connection.send(pid, ch, msg)
receive do
  {:ssh_cm, _, {:data, channel, _, data}} -> IO.puts("Data: #{(data)}")
end
  • streamlocal forward
msg = "GET /images/json HTTP/1.1\r\nHost: /var/run/docker.sock\r\nAccept: */*\r\n\r\n"

{:ok, pid} = SSHTunnel.connect(host: "sshserver.example.com", user: "user", password: "password")
{:ok, ch} = SSHTunnel.stream_local_forward(pid, "/var/run/docker.sock")
:ok = :ssh_connection.send(pid, ch, msg)

receive do
  {:ssh_cm, _, {:data, channel, _, data}} -> IO.puts("Data: #{(data)}")
end

Tunnels

  • directtcp-ip
{:ok, ssh_ref} = SSHTunnel.connect(host: "sshserver.example.com", user: "user", password: "password")

# Will start a tcp server listening on port 8080.
# Any TCP messages received on `127.0.0.1:8080` will be forwarded to `sshserver.example.com:80`
{:ok, pid} = SSHTunnel.start_tunnel(pid, {:tcpip, {8080, {"sshserver.example.com", 80}}})

# Send a TCP message
%HTTPoison.Response{body: body} = HTTPoison.get!("127.0.0.1:8080")
IO.puts("Received body: #{body})
  • streamlocal forward
{:ok, ssh_ref} = SSHTunnel.connect(host: "sshserver.example.com", user: "user", password: "password")

# Will start a tcp server listening on the provided path.
# Any TCP messages received on `/path/to/socket.socket` will be forwarded to the `/path/`to/remote.sock` on sshserver.example.com
{:ok, pid} = SSHTunnel.start_tunnel(pid, {:local, {"/path/to/socket.sock", {"sshserver.example.com", "/path/to/remote.sock"}}})

# Send a TCP message
%HTTPoison.Response{body: body} = HTTPoison.get!("http+unix://#{URI.encode_www_form("/path/to/socket.sock")}")
IO.puts("Received body: #{body})

It is also possible to mix and match:

# From a local port to a remote socket
{:ok, pid} = SSHTunnel.start_tunnel(pid, {:tcpip, {8080, {"sshserver.example.com", "/path/to/remote.sock"}}})

# From a local socket to a remote port
{:ok, pid} = SSHTunnel.start_tunnel(pid, {:local, {"/path/to/socket.sock", {"sshserver.example.com", 80}}})

Testing

mix test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].