A lightweight utility to tunnel TCP connections over full-duplex WebSocket-free HTTP 1.1 POST streams. The client keeps a single HTTP tunnel to the server and multiplexes multiple TCP connections as channels on that tunnel.
go build -o tcp2http .Start the server:
./tcp2http server \
-listen :18080 \
-target 127.0.0.1:22Start the client:
./tcp2http client \
-listen :6000 \
-up http://server:18080/up \
-down http://server:18080/downThen connect any TCP client to 127.0.0.1:6000. Each new TCP connection becomes a new channel inside the shared HTTP tunnel.
-listen(default:6000): local TCP listen address.-up(required): HTTP upload URL, e.g.http://server:18080/up.-down(required): HTTP download URL, e.g.http://server:18080/down.-session-header(defaultX-Session-ID): header used to correlate the up/down streams.-H-up(repeatable): add HTTP header to the upload request, formatKey: Value.-H-down(repeatable): add HTTP header to the download request, formatKey: Value.-multipart(defaulttrue): wrap the upload stream in multipart/form-data.-multipart-form(defaultfile): multipart form field name.-multipart-file(defaultupload.bin): multipart file name.-buf(default4096): buffer size for TCP reads.-hb(default100ms): heartbeat interval on the HTTP tunnel;0disables.-padding-mode(defaultnone):none,per-packet, orinterval.-padding-interval(default500ms): padding interval whenpadding-mode=interval.-padding-size(default4096): padding payload size.-http-timeout(default0): HTTP client timeout;0means no timeout.-log-heartbeat(defaultfalse): include heartbeat frames in logs.-log-level(defaultinfo):debug,info,warn,error, oroff.
-listen(default:18080): HTTP listen address.-up-path(default/up): upload path.-down-path(default/down): download path.-session-header(defaultX-Session-ID): header used to correlate the up/down streams.-target(default127.0.0.1:22): target TCP address for each channel.-buf(default4096): buffer size for TCP reads.-hb(default100ms): heartbeat interval on the HTTP tunnel;0disables.-padding-mode(defaultnone):none,per-packet, orinterval.-padding-interval(default500ms): padding interval whenpadding-mode=interval.-padding-size(default4096): padding payload size.-accept-multipart(defaulttrue): accept multipart/form-data uploads.-multipart-form(defaultfile): multipart form field name to read.-wait-peer-timeout(default30s): wait time for peer stream to connect.-log-level(defaultinfo):debug,info,warn,error, oroff.
ZJU WebVPN only allows HTTP/HTTPS traffic, so you can use tcp2http to tunnel your SSH or other TCP connections over it:
Server (inside ZJU Campus Network):
./tcp2http server \
-listen :18080 \
-target 127.0.0.1:1022 \
-up-path /up \
-down-path /down \
-buf 8192 \
-hb 100ms \
-padding-mode=interval -padding-interval 10ms -padding-size 4096We enable padding to avoid the impact of the 4KB download buffer in the webvpn web server.
You can try different padding settings to find the best performance.
Client:
./tcp2http client \
-listen :6000 \
-up "https://webvpn.zju.edu.cn/http-18080/{{Server URL encrypted by WebVPN}}/up" \
-down "https://webvpn.zju.edu.cn/http-18080/{{Server URL encrypted by WebVPN}}/down" \
-H-up "Cookie: wengine_vpn_ticketwebvpn_zju_edu_cn={{Your WebVPN Cookie Here}}" \
-H-down "Cookie: wengine_vpn_ticketwebvpn_zju_edu_cn={{Your WebVPN Cookie Here}}" \
-buf 8192 \
-multipart=true \
-hb 100ms \
-padding-mode=noneWe disable padding on the client side since the webvpn server does not have upload buffer.
Then you can connect to localhost:6000 in client side to access your SSH server inside ZJU Campus Network.
For encryption of the server URL and obtaining WebVPN cookies, please refer to eWloYW8/ZJUWebVPN.