A tool for TCP tunneling over WebSockets with integrated in-memory SSH and bidirectional port forwarding.
WSTunnel provides a robust way to tunnel TCP services through restricted network environments using the WebSocket protocol.
- Network Reach-through: Project local assets through public WebSocket gateways, bypassing NAT and complex firewall topologies.
- Secure Command Execution: Execute authenticated remote operations over WebSocket transport via integrated SSHD.
- Bidirectional Parity: High-performance port forwarding for both inbound and outbound traffic.
- Efficient Concurrency: Built with Kotlin Coroutines for maximum throughput with minimal resource overhead.
┌─────────────┐ WebSocket ┌─────────────┐
│ Client │◄──────────────────────────►│ Server │
│ (Behind │ Tunnel Connection │ (Public │
│ Firewall) │ │ Access) │
└─────────────┘ └─────────────┘
│ │
│ Forward Listen│
▼ ▼
┌─────────────┐ ┌─────────────┐
│ Local │ │ Remote │
│ Service │ │ Client │
└─────────────┘ └─────────────┘
- WebSocket Transport: Native bypass of HTTP proxies and stateful firewalls.
- Integrated SSH Server: Apache SSHD implementation supporting Interactive Shell, SFTP, SCP, and all standard SSH port forwarding modes.
- Multiplexed Tunnels: Handle unlimited concurrent connections over a single stream.
- Resilient Connectivity: Automatic reconnection logic for unstable network conditions.
- Docker Ready: Optimized for rapid deployment in containerized environments with non-root security defaults.
Execute the build process to generate the application artifact.
git clone <repository-url>
cd wstunnel
./gradlew buildFatJarThe executable payload is located at: build/libs/wstunnel.jar.
# Image Initialization
docker build -t wstunnel .
# Gateway Deployment
docker run -p 8080:8080 wstunnel server -p 8080
# Node Execution
docker run wstunnel client -S ws://your-server.com -l 8090 -f 3000Establish a public WebSocket gateway for incoming tunnel requests.
java -jar wstunnel.jar server [OPTIONS]-p, --port: Interface port (Default: 8080, Env:WSTUN_SERVER_PORT).-a, --host: Binding address (Default: 0.0.0.0, Env:WSTUN_SERVER_HOST).
Initialize the tunnel and establish connectivity to the gateway.
java -jar wstunnel.jar client -S <SERVER_URL> [TUNNEL_OPTIONS]Required Directive:
-S, --serverUrl: Gateway URL (ws:// or wss://).
Tunnel Configuration:
-l, --listen: Listen modeport[;host[;id]].-f, --forward: Forward modeport[;host[;id]].--lsshd: Initialize SSH server[port[;host[;id]]].
Project an internal web service (port 3000) through a public gateway.
# Gateway Node
java -jar wstunnel.jar server -p 8080
# Internal Node
java -jar wstunnel.jar client -S ws://gateway.com:8080 -l 8090 -f 3000Establish an authenticated entry point behind a restrictive firewall.
java -jar wstunnel.jar client \
-S ws://gateway.com \
--lsshd 2222 \
--sshd-login admin \
--sshd-password secretStandard SSH tunneling is often restricted by network security policies or requires complex infrastructure. WSTunnel's Integrated SSHD flips the status:
- Client-Side Execution: The SSH server runs within your protected environment. No public SSH daemon required.
- Tunnel Encapsulation: SSH traffic is transparently carried over WebSocket.
- Runtime Credentials: Define access via CLI flags. Eliminate
authorized_keysmanagement. - Dynamic Multiplexing: Use native SSH capabilities (
-D,-L,-R) over the WebSocket stream.
# Target Node (Internal Network)
java -jar wstunnel.jar client -S ws://gateway.com --lsshd "0;127.0.0.1;target-id"
# Operator Node
java -jar wstunnel.jar client -S ws://gateway.com -f "4444;127.0.0.1;target-id"
# Establish SOCKS5 Proxy
ssh -D 1080 -N user@localhost -p 4444You now have a dynamic SOCKS5 gateway into the target network.
| Credential Configuration | Behavioral Outcome |
|---|---|
| None Provided | Unrestricted access (Open) |
| Login Only | Username verification; any password accepted |
| Password Only | Password verification; any username accepted |
| Full Set | Strict Username and Password verification |
| Variable | Description |
|---|---|
WSTUN_SERVER_PORT |
Gateway Port (Default: 8080) |
WSTUN_SERVER_HOST |
Gateway Host (Default: 0.0.0.0) |
WSTUN_SERVER_URL |
Target Server URL |
WSTUN_LISTEN_SSHD |
SSHD Configuration (port[;host[;id]]) |
WSTUN_SSHD_LOGIN |
SSHD Username |
WSTUN_SSHD_PASSWORD |
SSHD Password |
WSTunnel is in active development. Observe the following operational boundaries:
- Authentication Gap: The gateway server currently lacks a native auth layer. Access is open to any node with the URL.
- Ephemeral Host Keys: SSH host keys regenerate on restart. This triggers host identification warnings.
- Transport Protocol: Always utilize
wss://for production environments to ensure TLS encryption. - External Rate Limiting: Internal throttling is not yet implemented. Use external load balancers for protection.
- Build Strategy:
./gradlew buildFatJar - Verification:
./gradlew test - License: MIT