No description
Find a file
Romain GERARD 8ca1ed9fb3 Perf improvements: Use default os setting for socket recv buffer size
+ This commit 8e38589efb (diff-8c54fc2d40ad45803c6889efbb0192bbR278) introduce a default fixed size read buffer which is too low for most modern system. Thus it induce a lot of unecessary syscall and cpu usage.
  Use the default OS settings in order to let the user control it with
  ie: /proc/sys/net/ipv4/tcp_rmem


Former-commit-id: 1fc22266bf6cda96ec8c43b52cc6da527db35173
Former-commit-id: f9cbaa2ce612df6cbfc88963a32b0a0e38c1e13e [formerly 18c0558ec79d6a82ef242b114a63738a81329ec5] [formerly 5aa78fa4a16ac891f169a02275d147ec12fc336f [formerly 32204a8d46a8f4d06e40c15380e68afa4dd1f294 [formerly 32204a8d46a8f4d06e40c15380e68afa4dd1f294 [formerly 32204a8d46a8f4d06e40c15380e68afa4dd1f294 [formerly 11e560d1fae42a64cd645e79343209e6559473d9]]]]]
Former-commit-id: 8e4ccba7062154cdaba142c6110b32b05ca08e37 [formerly a7d2f3299f4c67ea0ec9d20cbf2780382258e143]
Former-commit-id: c9ebc4a70b48e7433d65af79ef161d2b0d510f61
Former-commit-id: b5056ca3dda1f23f3bc5d8e093772874b5666fbb
Former-commit-id: 7a25a6703c1c0396425d40f4080162b43179b96d
Former-commit-id: c6d4da14dfcbb373dcb3341f246bd6675f44e4e7 [formerly 5f081b250a55f9fa091a8f13927e4c2d7980ef2a]
Former-commit-id: 886b1fa73005e8167949ede1391086d3f6ed3e00
2020-01-04 15:43:05 +01:00
app Listen to TCP/UDP & mutiple -L command line arguments 2019-10-08 20:52:15 +02:00
src Perf improvements: Use default os setting for socket recv buffer size 2020-01-04 15:43:05 +01:00
test ground 0 2016-05-11 23:39:02 +02:00
.dockerignore Add travis 2017-12-05 12:32:35 +01:00
.gitignore ground 0 2016-05-11 23:39:02 +02:00
.travis.yml Add travis 2017-12-05 12:32:35 +01:00
default.nix New dockerfile 2019-10-24 18:20:35 +02:00
Dockerfile New dockerfile 2019-10-24 18:20:35 +02:00
Dockerfile.old New dockerfile 2019-10-24 18:20:35 +02:00
LICENSE ground 0 2016-05-11 23:39:02 +02:00
logo_wstunnel.png Maj logo 2016-08-26 20:57:10 +02:00
README.md fixed two small errors (#31) 2019-10-31 11:29:38 +01:00
Setup.hs ground 0 2016-05-11 23:39:02 +02:00
stack.yaml Update dependencies 2019-10-24 13:46:58 +02:00
wstunnel.cabal Disable parralel GC as it is counter productive 2019-10-08 20:52:15 +02:00

wstunnel logo

Description

Most of the time when you are using a public network, you are behind some kind of firewall or proxy. One of their purpose is to constrain you to only use certain kind of protocols. Nowadays, the most widespread protocol is http and is de facto allowed by third party equipment.

This tool understands this fact and uses the websocket protocol which is compatible with http in order to bypass firewalls and proxies. Wstunnel allows you to tunnel what ever traffic you want.

My inspiration came from this project but as I don't want to install npm and nodejs to use this tool, I remade it in Haskell and improved it.

What to expect:

  • Good error messages and debug informations
  • Static tunneling (TCP and UDP)
  • Dynamic tunneling (socks5 proxy)
  • Support for http proxy (when behind one)
  • Support for tls/https server (with embedded self signed certificate, see comment in the example section)
  • Standalone binary for linux x86_64 (so just cp it where you want)
  • Standalone archive for windows

Binaries

P.S: Please do not pay attention to Main.hs because as I hate to write command line code this file is crappy

Command line

Use the websockets protocol to tunnel {TCP,UDP} traffic
wsTunnelClient <---> wsTunnelServer <---> RemoteHost
Use secure connection (wss://) to bypass proxies

wstunnel [OPTIONS] ws[s]://wstunnelServer[:port]
Client options:
  -L --localToRemote=[BIND:]PORT:HOST:PORT  Listen on local and forwards
                                            traffic from remote
  -D --dynamicToRemote=[BIND:]PORT          Listen on local and dynamically
                                            (with socks5 proxy) forwards
                                            traffic from remote
  -u --udp                                  forward UDP traffic instead of
                                            TCP
  -p --httpProxy=USER:PASS@HOST:PORT        If set, will use this proxy to
                                            connect to the server
Server options:
     --server                               Start a server that will forward
                                            traffic for you
  -r --restrictTo=HOST:PORT                 Accept traffic to be forwarded
                                            only to this service
Common options:
  -v --verbose                              Print debug information
  -q --quiet                                Print only errors
  -h --help                                 Display help message
  -V --version                              Print version information

Examples

Simplest one

On your remote host, start the wstunnel's server by typing this command in your terminal

wstunnel --server ws://0.0.0.0:8080

This will create a websocket server listening on any interface on port 8080. On the client side use this command to forward traffic through the websocket tunnel

wstunnel -D 8888 ws://myRemoteHost:8080

This command will create a sock5 server listening on port 8888 of a loopback interface and will forward traffic.

Ex: With firefox you can setup a proxy using this tunnel, by setting in networking preferences 127.0.0.1:8888 and selecting socks5 proxy

As proxy command for SSH

You can specify stdio as source port on the client side if you wish to use wstunnel as part of a proxy command for ssh

ssh -o ProxyCommand="wstunnel -L stdio:%h:%p ws://localhost:8080" my-server

When behind a corporate proxy

An other useful example is when you want to bypass an http proxy (a corporate proxy for example) The most reliable way to do it is to use wstunnel as described below

Start your wstunnel server with tls activated

wstunnel --server wss://0.0.0.0:443 -r 127.0.0.1:22

The server will listen on any interface using port 443 (https) and restrict traffic to be forwarded only to the ssh daemon.

Be aware that the server will use self signed certificate with weak cryptographic algorithm. It was made in order to add the least possible overhead while still being compliant with tls.

Do not rely on wstunnel to protect your privacy, as it only forwards traffic that is already secure by design (ex: https)

Now on the client side start the client with

wstunnel -L 9999:127.0.0.1:22 -p mycorporateproxy:8080 wss://myRemoteHost:443

It will start a tcp server on port 9999 that will contact the corporate proxy, negotiate a tls connection with the remote host and forward traffic to the ssh daemon on the remote host.

You may now access your server from your local machine on ssh by using

ssh -p 9999 login@127.0.0.1

Wireguard and wstunnel

https://kirill888.github.io/notes/wireguard-via-websocket/

How to Build

Install the stack tool https://docs.haskellstack.org/en/stable/README/ or if you are a believer

curl -sSL https://get.haskellstack.org/ | sh

and run those commands at the root of the project

stack init
stack install

TODO

  • Add sock5 proxy
  • Add better logging
  • Add better error handling
  • Add httpProxy authentification
  • Add Reverse tunnel
  • Add more tests for socks5 proxy