GithubHelp home page GithubHelp logo

robertogallardo / wstun Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mdslab/wstun

0.0 0.0 0.0 143 KB

Tunnels and reverse tunnels over WebSocket

License: Apache License 2.0

JavaScript 93.45% Shell 5.52% Dockerfile 1.03%

wstun's Introduction

WSTUN - Tunnels and Reverse Tunnels over WebSocket for Node.js

npm version

Overview

A set of Node.js tools to establish TCP tunnels (or TCP reverse tunnels) over WebSocket connections for circumventing the problem of directly connect to hosts behind a strict firewall or without public IP. It also supports WebSocket Secure (wss) connections.

Installation

npm install @mdslab/wstun

Usage (from a Node.js application)

Instantiation of a tunnel server

var wstun = require("@mdslab/wstun");

// without security
server = new wstun.server();

// or with security (<PRIVATE-KEY-PATH> and <PUBLIC-KEY-PATH> are the paths of the private and public keys in .pem formats)
server = new wstun.server({ssl:true, key:"<PRIVATE-KEY-PATH>", cert:"<PUBLIC-KEY-PATH>"});

//start the server (<PORT> is the listening port)
server.start(<PORT>)

Implementation of a tunnel client

var wstun = require("@mdslab/wstun");

client = new wstun.client();

// without security
wstunHost = 'ws://wstunServerIP:wstunPort';

// or with security 
wstunHost = 'wss://wstunServerIP:wstunPort';

// <localPort> is the port on the localhost on which the tunneled service will be reachable
// <remoteHost>:<remotePort> is the endpoint of the service to be tunneled
client.start(<localPort>, wstunHost, '<remoteHost>:<remotePort>');

Instantiation of a reverse tunnel server

var wstun = require("@mdslab/wstun");

// without security
reverse_server = new wstun.server_reverse();

// or with security (<PRIVATE-KEY-PATH> and <PUBLIC-KEY-PATH> are the paths of the private and public keys in .pem formats)
reverse_server = new wstun.server_reverse({ssl:true, key:"<PRIVATE-KEY-PATH>", cert:"<PUBLIC-KEY-PATH>"});

//start the server (<PORT> is the listening port)
reverse_server.start(<PORT>);

Implementation of a reverse tunnel client

var wstun = require("reverse-wstunnel");

reverse_client = new wstun.client_reverse();

// without security
wstunHost = 'ws://wstunServerIP:wstunPort';

// or with security 
wstunHost = 'wss://wstunServerIP:wstunPort';

// <publicPort> is the port on the reverse tunnel server on which the tunneled service will be reachable
// <remoteHost>:<remotePort> is the endpoint of the service to be reverse tunneled
reverse_client.start(<publicPort>, wstunHost, '<remoteHost>:<remotePort>');

Usage (from command line)

A command line tool (wstun.js) is also available in the bin directory.

Examples about how to run a tunnel server:

//without security
./wstun.js -s 8080

//with security
./wstun.js -s 8080 --ssl=true --key="<PRIVATE-KEY-PATH>" --cert="<PUBLIC-KEY-PATH>"

Examples about how to run a tunnel client:

//without security
./wstun.js -t 33:2.2.2.2:33 ws://wstunServerIP:8080 

//with security
./wstun.js -t 33:2.2.2.2:33 wss://wstunServerIP:8080

In both examples, connections to localhost:33 on the client will be tunneled to 2.2.2.2:33 through the Websocket connection with the server. Note that the decision about the final destination of the tunnel is up to the client. Alternatively, it is possible to lock the final destination of the tunnel on the server side.

Examples about how to run a tunnel server locking the final tunnel destination:

//without security 
./wstun.js -s 8080 -t 2.2.2.2:33

//with security
./wstun.js -s 8080 -t 2.2.2.2:33 --ssl=true --key="<PRIVATE-KEY-PATH>" --cert="<PUBLIC-KEY-PATH>"

Examples about how to run a tunnel client when the final tunnel destination has been locked by the server:

//without security
./wstun.js -t 33 ws://wstunServerIP:8080 

//with security
./wstun.js -t 33 wss://wstunServerIP:8080

Examples about how to run a reverse tunnel server:

//without security
./wstun.js -r -s 8080

//with security
./wstun.js -r -s 8080 --ssl=true --key="<PRIVATE-KEY-PATH>" --cert="<PUBLIC-KEY-PATH>"

Examples about how to run a reverse tunnel client:

//without security
./wstun.js -r6666:2.2.2.2:33 ws://server:8080

//with security 
./wstun.js -r6666:2.2.2.2:33 wss://server:8080

In the above examples, the client asks the server to open a TCP server on port 6666 and all connections on this port are tunneled to the client that is directely connected to 2.2.2.2:33.

Logging system

WSTUN uses Log4js library to manage its logs in /var/log/wstun/

wstun's People

Contributors

alotronto avatar flongo82 avatar leemoonsoo avatar mhzed avatar npeditto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.