V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
liyafe1997
V2EX  ›  程序员

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

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

    vpn 在客户端的表现形式就是一个网卡,凡是用你 socks5 程序的流量,都通过这个网卡往外发数据就是了。这么做的好处是可以利用 pac 之类的应用层规则,而不是 chnroute 这样的 ip 层规则,也不需要动网关配置。pobi 正在增加这个特性,进行中。
    hfeeki
        6
    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
        7
    hfeeki  
       2013-02-01 17:30:31 +08:00
    哦,发错了地方。
    dallaslu
        8
    dallaslu  
       2013-02-01 17:53:02 +08:00
    两台电脑,一台连接 VPN,并开启 socks 代理服务软件。然后在另外一台电脑上用浏览器挂代理上网。
    est
        9
    est  
       2013-02-01 18:01:42 +08:00
    我2年前研究过。结论是:没有这样的现成软件

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

    OpenVPN协议非常蛋痛。建议不要去跳这个坑。
    ratazzi
        10
    ratazzi  
       2013-02-01 18:53:39 +08:00
    直接用 chnroutes 区分国内外多好,搞成代理还得一个一个设置
    hfeeki
        11
    hfeeki  
       2013-02-01 20:56:37 +08:00
    有了VPN,干吗还要SOCKs? 通过配置路由可以选择哪个网段走VPN,哪个网段不走VPN。你到底想达到什么目的呢?
    anjianshi
        12
    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
        13
    huazhouji  
       2013-02-01 23:11:52 +08:00
    我觉得 @est 是对的 没有想的那么容易额
    iambeginner
        14
    iambeginner  
       2013-02-02 14:53:34 +08:00 via iPhone
    @anjianshi 非常赞同
    用openvpn配脚本或pptp/l2tp配手工bat加载和停用路由表很方便 完全透明 不用为任何程序操心了
    至于提到的2个缺点 我的解决方法是 查出网站ip 自己修改chnroute里面的路由表将ip(或ip段)加入或去除即可

    对某些大量加载日本网站图片但下载实体文件必须是国内ip的站点非常好用
    jackyz
        15
    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
        16
    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
        17
    jackyz  
       2013-02-03 17:47:13 +08:00
    @est 晕死,“能联通”和“高效率地联通”肯定不是一码事。有关效率问题,可以看看这个项目的处理 https://github.com/apenwarr/sshuttle/ 提醒:这可能是一个坑,我刚刚才知道,还没来得及细看代码。
    liyafe1997
        18
    liyafe1997  
    OP
       2013-02-04 18:15:53 +08:00
    @dallaslu @sNullp @TONYHEAD
    大概就是这个思路。
    全局代理是客户端干的事,那么自己开发一个客户端连接VPN,然后在本地开个sock5服务,让浏览器和自己开发的客户端用sock5传输数据不就可以了吗,关服务器端什么事呢?
    sNullp
        19
    sNullp  
       2013-02-04 19:40:08 +08:00
    @liyafe1997 这样想确实是可行的。只是大概开发略有麻烦所以没有成品吧。VPN客户端毕竟比较特殊,它需要创建一个虚拟网卡(interface)来工作。
    iskyzh
        20
    iskyzh  
       2015-03-14 19:55:08 +08:00
    @jackyz 事实上似乎不行……
    在Windows下连接上VPN,然后关闭了“使用远程默认网关”功能,Socket无法指定这个网卡发送出去……
    发送会提示错误 ENETUNREACH...
    z5n0w
        21
    z5n0w  
       2015-05-13 18:40:12 +08:00
    tinyproxy 绑定在tun0上
    xav1er
        22
    xav1er  
       2015-06-02 23:23:12 +08:00
    @dallaslu 这样好像不可以
    dallaslu
        23
    dallaslu  
       2015-06-03 01:09:36 +08:00
    dadawolf
        24
    dadawolf  
       2016-09-01 16:28:06 +08:00
    vpn 转化 socks5 也并非不可能,给我一个 vpn 线路的 ip,用户名,密码 我就能转换成 socks5 软件能识别得到,欢迎测试
    wsczh
        25
    wsczh  
       2016-09-23 14:41:41 +08:00
    @dadawolf 我们也想实现您说的这点( vpn 与 socks 连接),请问您已实现了吗? 我们可提供 vpn 进行测试,请问如何联系。我的 QQ:2650249406
    hilow
        26
    hilow  
       2016-11-29 16:22:04 +08:00
    我也想要这个功能。
    pptp 或者 openvpn 都会在系统加网卡,改路由,很容易出一些异常网络问题。
    yov123456
        27
    yov123456  
       2016-12-18 15:57:04 +08:00 via iPhone
    我想把学校的 vpn 转成 http 代理😂
    hanbingtel
        28
    hanbingtel  
       2017-07-20 02:36:47 +08:00
    随便新建个虚拟机或则容器之类的,
    开启个 socks5 或则 http 代理服务。
    已 vpn 客户端的身份进行连接,
    就可以达到 vpn 和 socks5 或 http 代理的转换了。
    varphp
        29
    varphp  
       2018-12-28 00:48:28 +08:00
    我要挖坟了 这么多年了还没解决掉
    varphp
        30
    varphp  
       2018-12-28 00:49:16 +08:00
    我研究好多天了 也没解决 蛋疼 估计还是要动驱动这块
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   952 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:12 · PVG 05:12 · LAX 14:12 · JFK 17:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.