wstunnel增加一个食用方法

大家好,继上一期wstunnel的使用,摸索了一下(这个工具类似ssh隧道),分享一下自己的食用方法:

  • 中转机设置:
    wstunnel server ws://0.0.0.0:port

port:防火墙要开通这个端口
ip:中转机ip

  • 远程pc(server)
    wstunnel client -R tcp://port2:ip1:port1 ws://ip:port

port2: 要映射到中转机的哪个端口
ip1: server上的本地ip或者回环地址,一般为 localhost
port1: server上的哪个端口要映射

  • 其他pc(client):
    wstunnel client -L tcp://port1:ip2:port2 ws://ip:port

port1: 本地要映射的端口
ip2: 中转机回环地址即可,一般为 localhost
port2: 要连接到中转机的哪个端口

上述ip、port、ip1、port1、ip2、port2对应即可实现远程桌面rdp连接,比如:

  • 中转机
wstunnel server wss://0.0.0.0:8888 --restrict-http-upgrade-path-prefix=helloworld

中转机启动8888端口监听来自任何ip的连接,–restrict-http-upgrade-path-prefix指定连接要配置路由(UUID最好),否则无法连接,官方解释如下:
只有在websocket升级期间使用此特定路径前缀时,服务器才会接受来自的连接。
如果在客户端中指定自定义路径前缀,并且希望服务器只允许使用此前缀,则很有用。
路径前缀充当对客户端进行身份验证的秘密
默认情况下禁用。接受所有路径前缀。可以多次指定

  • 远程pc(server)
wstunnel client -R tcp://6666:localhost:3389 wss://${中转机ip}:8888 --http-upgrade-path-prefix=helloworld

远程PC启动反向隧道6666端口(localhost:3389是本地rdp)映射到中转机,即6666端口是中转机上的端口,也就是远程PC:localhost:3389======>通过中转机8888端口隧道承载======>中转机:ip(ip省略):6666,–http-upgrade-path-prefix=helloworld为中转机上指定的路由

  • 其他pc(客户机):
wstunnel client -L tcp://1234:localhost:6666 wss://${中转机ip}:8888 --http-upgrade-path-prefix=helloworld

其他pc(客户机)启动本地1234端口监听本地rdp连接,连接中转机6666端口,即:客户机mstsc==>客户机 ip(ip省略):1234端口======>通过中转机8888端口隧道承载======>中转机:localhost:6666

大概是这样的:客户机mstsc ==> 客户机 ip(ip省略):1234端口 ======> 通过中转机8888端口隧道承载 ======> 中转机:localhost:6666 <====== 通过中转机8888端口隧道承载 <====== 远程PC:localhost:3389

  1. 中转机只需要一个小鸡,启动一个8888端口并开通防火墙,即可接受来自任意的连接
  2. 反代还在研究中,欢迎各位大佬交流学习心得
5 Likes

感谢大佬教程

2 Likes

wstunnel比frp等软件好的一点是,它支持协议伪装为wss。

wstunnel比v2ray好的一点是,它的tunnel是双向的。比如这篇文章中提到的-R选项。

当然,过nginx、过cloudflare自然也是包括的。

总而言之,wstunnel是v2ray的一个非常重要的补充。

大佬,这块反代我一直没搞定,不明白怎么配置,求指点

  1. vps上执行如下命令:

    ./wstunnel server wss://[::]:9999 --restrict-http-upgrade-path-prefix wstunnel

  2. client本地执行如下命令:

    wstunnel client wss://${vpsIP}:9999/wstunnel -R 'tcp://[::]:8001:localhost:8002' --http-upgrade-path-prefix wstunnel

  3. client本地执行如下命令:

    python3 -m http.server -b 127.0.0.1 8002

  4. 然后在任意地方执行如下命令,就能访问了:

    curl http://${vpsIP}:8001

大佬,我是想问如何使用域名,比如我有个域名在cloudflare,然后vps上有个server在nginx或者其他反代工具背后,nginx上有个cloudflare的源服务器证书,那么此时我wss使用的是另外的证书或者使用该证书这2种情况下,我该怎么配置 :rofl:

1 Like
1 Like

感谢大佬,牛,我还一直在想如何加入域名,因为我服务端用的wss://所以一直ssl验证失败,豁然开朗,感谢感谢 :+1: