利用gost访问内网HTTP服务

1,170 views
Skip to first unread message

Rain Zen

unread,
Oct 9, 2016, 1:18:23 AM10/9/16
to go-gost
gost在2.1中增加了远程端口转发功能,可以将内网的端口直接映射到外网的一个指定端口。
不过TCP的远程端口转发有一些限制,每当有连接连到了外网的映射端口上时,这个监听端口就会关闭,等待内网的gost再主动建立连接重新开启外网端口监听。
这样就使得此功能的使用受限,只能用来转发类似于SSH这种使用单连接的服务,而像HTTP这种需要建立很多连接的服务就不可用了。

gost 2.2中增加了对HTTP2的支持,由于HTTP2可以多路复用,特别是针对HTTP,可以用单一连接来传输多组请求。那么我们就可以利用HTTP2来实现在外网也能访问到内网的HTTP服务。


假设有一台公网的机器A,IP是 1.2.3.4
内网的机器B,IP是:192.168.1.100


具体做法(有点绕):

先在公网机器A上跑gost:
gost -L http2://:443

在内网机器B上跑gost(注意这个gost一定要是http2模式):
gost -L http2://:8080

重要的一步, 在内网机器B上开启TCP远程端口转发:
gost -L rtcp://:1443/:8080 -F http2://1.2.3.4:443

上面这一步就是将内网机器B上的HTTP2代理端口直接映射到外网服务器上的1443端口,那么访问外网服务的1443端口就相当于访问内网的8080端口,也就相当于在外网直接访问到内网的HTTP2代理。

假设在机器B所在的网络中有一台路由器,IP为192.168.1.1,我们想在另外一台电脑C上(可以访问机器A的1443端口)访问这个内网路由器的管理界面:

在电脑C上跑gost:
gost -L :8888 -F http2://1.2.3.4:1443

这一步就相当于直接使用内网机器B上的HTTP2代理(8080端口),那么也就可以访问到机器B所在网络的任何服务了,
在机器C上把浏览器代理设为localhost:8888,在浏览器中直接打开192.168.1.1就可以访问到路由器的管理界面了。





ginuerzh

unread,
Feb 12, 2017, 11:58:19 PM2/12/17
to go-gost
This is the English translation of the post:

The remote TCP port forwarding feature has been added into gost 2.1, you can directly map a service behind firewall to a designated port of the external network.
However, there are some limitations. This feature is based on standard SOCKS5 BIND command, and one tunnel per connection. So a single connection service (such as ssh) can work well, but services such as HTTP, which require many connections, are not available.

Gost 2.2 has supported HTTP2, then we can use HTTP2 to achieve this function:

Suppose there is a host A in public network, IP: 1.2.3.4
another host B behind firewall can access host A, IP: 192.168.1.10

On server side (host A):
gost -L socks://:1080

On client side (host B):
gost -L http2://:8080 (a standalone http2 server)
gost -L rtcp://:1443/:8080 -F socks://1.2.3.4:1080 (mapping the http2 service behind firewall to public network on port 1443)

Then on host C(may be host A or any other hosts that can access port 1443 of host A):
gost -L :8888 -F http2://1.2.3.4:1443 (standard HTTP/SOCKS5 proxy)

You can now access any services (such as  HTTP server) on the network where host B is located via the proxy on server C (port 8888).

Or map a specific service to local host:
gost -L tcp://:8888/192.168.1.1:80 -F http2://1.2.3.4:1443 (assume a web server hosts on 192.168.1.1:80)

howi...@gmail.com

unread,
Nov 6, 2017, 10:10:20 AM11/6/17
to go-gost
2.4版本内网机器B会在本地监听1443端口,而不是远程机器A上,是什么原因?socks5就正常

在 2016年10月9日星期日 UTC+8下午1:18:23,ginuerzh写道:

ginuerzh

unread,
Nov 6, 2017, 8:50:30 PM11/6/17
to go-gost
2.4版本中HTTP2有所改变,原本的http2://模式只具备标准代理功能,不能用作tunnel模式,新增的h2:// 和 h2c://是专门用作tunnel模式,rtcp要用h2://方式

2.4中增加了对SSH协议的支持,建议使用SSH tunnel,更简单,效率也更高:

gost -L forward+ssh://:2222

gost -L rtcp://:1443/:8080 -F forward+ssh://server:2222



在 2017年11月6日星期一 UTC+8下午11:10:20,howi...@gmail.com写道:

Smallville L

unread,
Nov 11, 2017, 4:46:59 AM11/11/17
to go-gost
很赞的功能,

在 2017年11月7日星期二 UTC+8上午9:50:30,ginuerzh写道:
Reply all
Reply to author
Forward
0 new messages