大家研究过如何把VPN转成sock5/http等代理吗

2013-02-01 15:18:20 +08:00
 liyafe1997
其实实现起来也很简单,写个简单的客户端软件就行了。
连接VPN,然后开个sock5代理,把数据转发过去就可以了。
但是似乎没有,不知道有人研究过吗。
这样开VPN就不用全局开了,可以单独在浏览器里面调用。
34344 次点击
所在节点    程序员
30 条回复
ywencn
2013-02-01 15:23:34 +08:00
应该用VPS来架吧。。怎么能用VPN
sNullp
2013-02-01 15:31:58 +08:00
除非你能控制VPN服务器,装个socks5,或者你有国外的服务器能开socks5代理,但既然有开了socks5的国外服务器,直接连就是了。
直接的“客户端转换”不可能。
我在海盗VPN内部开tor也是这个原因,不改路由表挂9050端口一样能翻墙。
vking
2013-02-01 15:35:47 +08:00
這還用研究?
xshell就有那功能。
TONYHEAD
2013-02-01 16:03:55 +08:00
如果可以做到客户端方面跟以前一样配置就好了,现在的方案都需要修改服务器端和客户端。
jackyz
2013-02-01 17:23:25 +08:00
原理上不难。

vpn 在客户端的表现形式就是一个网卡,凡是用你 socks5 程序的流量,都通过这个网卡往外发数据就是了。这么做的好处是可以利用 pac 之类的应用层规则,而不是 chnroute 这样的 ip 层规则,也不需要动网关配置。pobi 正在增加这个特性,进行中。
hfeeki
2013-02-01 17:28:21 +08:00
Reverse SSH Tunneling Network

Don’t have VPN access, but still want a secure way to connect between two networks? If so, please read below on how this can be done even if the remote site is blocking SSH with a firewall. This article assumes that you already have SSH servers setup on both remote and local sites. If not, It should be pretty straight forward to setup a SSH server on Windows with OpenSSH for windows or install on Linux with the below commands ran from the terminal window. The complete setup of SSH server is out of the scope of this article, so please refer to man pages or other online documentation.

#RedHat, Fedora, CentOS..most RPM based distros
yum install openssh-server openssh-client

#Ubuntu and other Debian based distros
sudo apt-get install ssh-server ssh-client

Setting up Remote SSH Servers connection to Local SSH Server

Here we are going to establish an SSH connection from the Remote Server to the Local Server. The following is the structure and break down of the command.

ssh -l <1> -nNT -f -R <2>:<3>:<4> <5> -p <6>

-l Login name
-f Requests ssh to go to background just before command execution.
-n This must be used when ssh is run in the background.
-N Do not execute a remote command.
-T Disable pseudo-tty allocation.
<1> Remote SSH Servers user account to login as
<2> local SSH Server listening port
<3> Remote SSH Server internal IP
<4> Remote SSH Server port
<5> local SSH Server public IP (This is NATed to internal SSH server on port 22)
<6> local SSH Server public port to listen on

EXAMPLE:

ssh -l jsmith -nNT -f -R 1100:192.168.2.11:22 1.1.1.1 -p 443

Establishing SSH Connection from Local SSH Server to Remote SSH Server

Now that we have the connection established from the Remote SSH Server to the Local SSH Server (now listening on port 1100) we can now login to the Remote SSH Server using the reverse SSH Tunnel. First verify that the tunnel is setup and listening on port 1100 on the Local SSH Server by running the following as root:

netstat -tupnl | grep :1100
#This should return with the following:
# tcp 0 127.0.0.1:1100 0.0.0.0:* LISTEN

Now that you have verified that the port is up and listening, run the following from the Local SSH Servers terminal:

ssh -D 192.168.1.11:1234 -p 1100 localhost

This will log you in to the Remote SSH Server and also setup another listening port (1234) to be used later for using Socks Proxy Connections. When prompted for password, login with the password of the Remote SSH Servers account. In this example it would be the password for the user jsmith.
Setup Port Forwarding for RDP on Local SSH Server

This one is a little tricky. We are going to now setup the Local SSH Server to Forward all requests it receives for port 3389, and send them through the Reverse SSH Tunnel (established on port 1100 of Local SSH Server) and onto the Remote App Server. From the terminal of the Local SSH Server, type in the following:

ssh -L 192.168.1.11:3389:192.168.2.10:3389 <local SSH Server user>@localhost -p 1100

Now check to see if port 3389 is listening on the Local SSH Server.

netstat -tupnl | grep :3389
#This should return with the following:
# tcp 0 127.0.0.1:3389 0.0.0.0:* LISTEN

Remote Desktop into Remote App Server via RDP from Local Workstation

Now that we have everything setup, you should be able to remote desktop into the Remote App Server by pointing your RDP client, on Local Workstation, to the IP address of the Local SSH Server (ie. 192.168.1.11)
Using Socks Proxy on Local Workstation to connect to Remote App Server

Earlier when we made our original connection to the Remote SSH Server, we used port (1234) for Local network to connect to. To bring up a web page that is running on any Remote Network Server, just configure your Local Workstation Browser for Socks 5 Proxy and put in the IP address of the Local SSH Server (192.168.1.11) and port (1234). Waalahh!! You have now setup a Reverse SSH Tunnel with the ability to RDP and bring up web pages on Remote Site.

Please comment with any questions you might have, corrections i need to make, or if you have a better way of doing it. I hope that i have explained this well enough to understand, but if not, please let me know.
hfeeki
2013-02-01 17:30:31 +08:00
哦,发错了地方。
dallaslu
2013-02-01 17:53:02 +08:00
两台电脑,一台连接 VPN,并开启 socks 代理服务软件。然后在另外一台电脑上用浏览器挂代理上网。
est
2013-02-01 18:01:42 +08:00
我2年前研究过。结论是:没有这样的现成软件

http://superuser.com/questions/263360/

OpenVPN协议非常蛋痛。建议不要去跳这个坑。
ratazzi
2013-02-01 18:53:39 +08:00
直接用 chnroutes 区分国内外多好,搞成代理还得一个一个设置
hfeeki
2013-02-01 20:56:37 +08:00
有了VPN,干吗还要SOCKs? 通过配置路由可以选择哪个网段走VPN,哪个网段不走VPN。你到底想达到什么目的呢?
anjianshi
2013-02-01 22:22:18 +08:00
估计楼主是认为浏览器插件(如autoproxy)比路由表靠谱,我以前就一直是这么认为的。不过自从我仔细看了chnroutes的原理,并使用了之后,我才真正体会到,什么叫“整个世界都清净了”。

优点:
1. 浏览器上的那些插件可以去掉了(插件越少,浏览器反应越快,chrome上的fq插件貌似偶尔还会出错)
2. 省心,不用访问速度一慢就惦记着切换代理状态
3. 访问速度更快。理论上,VPN比SSH速度快
4. 使用各种工具时也不用费心设置代理了(如:git, gem, npm等等)
5. chnroutes其实是比较可靠的。我开着QQ,淘宝旺旺,坚果云,然后开VPN,这几样都没受影响,不会掉线重连。

缺点:
1. 访问极个别网站,反应稍有变慢,原因还没找到。例如:v2ex工作空间
2. 要手动指定某个网站使用/不使用VPN不好操作。至少我没找出操作方法。
huazhouji
2013-02-01 23:11:52 +08:00
我觉得 @est 是对的 没有想的那么容易额
iambeginner
2013-02-02 14:53:34 +08:00
@anjianshi 非常赞同
用openvpn配脚本或pptp/l2tp配手工bat加载和停用路由表很方便 完全透明 不用为任何程序操心了
至于提到的2个缺点 我的解决方法是 查出网站ip 自己修改chnroute里面的路由表将ip(或ip段)加入或去除即可

对某些大量加载日本网站图片但下载实体文件必须是国内ip的站点非常好用
jackyz
2013-02-02 16:00:29 +08:00
@anjianshi @iambeginner

chnroute 是 ip 层的规则,确实省心,而且全局免配置,这是大优点。但要以 vpn 本身不受干扰为前提。如果 vpn 本身就不稳定的话,比如,时不时 reset 要重连什么的,最近比较多见,那就非常坑爹了。

这么做的两个主要动力分别是:

A。省,对没有被 gfw 的网站,是没有必要走 vpn 的,比如,图片,下载之类的,流量那是哗哗地走。尤其是对花钱的 fq 服务,这个比较有意义。如果能做到合理使用,基本上免费套餐的流量就够用了。而这在 chnroute 里是做不到的。

B。快,大部分情况下,如果直连能走通,怎么都比 fq 要快。而,一旦需要 fq 才能访问的,其实用哪种方式速度也差不了太多。理论上的差别,只是理论上的,实际用,真不明显。

对于自建 vpn fq 的同学来说。还有第三个动力:

C。特征小,这个很好懂,用得越少,越不容易被封。比如,我的 ssh-D 配合 pac 因为流量低,很少会遇到 reset 。换成 vpn 我也不希望那么容易就被封。



chnroute 和 pac 的共同问题是“静态规则”,必须手工调整,而且调整起来还很费事,发现问题,定位问题,手工添加,重新加载,测试,调整,这个过程偶尔做一做是很有趣,但是要老做的话,就很蛋疼了。

@est @huazhouji

在服务端确实超级难搞。在客户端真不难。vpn 说到底了也就是一块虚拟网卡,在发数据包时,指定用这个网卡地址做 localAdress 就是,啥多余的事情都不需要做。
est
2013-02-03 17:29:55 +08:00
@jackyz 这个额真的没那么简单。tcp over tcp效率很低的。openvpn有自己的window scaling算法用来优化ip传输。

我记得pptp有一部分握手是基于IP协议的。所以干脆搞了个TAP/TUN设备。

细节不是很清楚了。反正openvpn的普适性比tcp+udp的socks5高很多。也是个大坑。
jackyz
2013-02-03 17:47:13 +08:00
@est 晕死,“能联通”和“高效率地联通”肯定不是一码事。有关效率问题,可以看看这个项目的处理 https://github.com/apenwarr/sshuttle/ 提醒:这可能是一个坑,我刚刚才知道,还没来得及细看代码。
liyafe1997
2013-02-04 18:15:53 +08:00
@dallaslu @sNullp @TONYHEAD
大概就是这个思路。
全局代理是客户端干的事,那么自己开发一个客户端连接VPN,然后在本地开个sock5服务,让浏览器和自己开发的客户端用sock5传输数据不就可以了吗,关服务器端什么事呢?
sNullp
2013-02-04 19:40:08 +08:00
@liyafe1997 这样想确实是可行的。只是大概开发略有麻烦所以没有成品吧。VPN客户端毕竟比较特殊,它需要创建一个虚拟网卡(interface)来工作。
iskyzh
2015-03-14 19:55:08 +08:00
@jackyz 事实上似乎不行……
在Windows下连接上VPN,然后关闭了“使用远程默认网关”功能,Socket无法指定这个网卡发送出去……
发送会提示错误 ENETUNREACH...

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/59485

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX