Total Pageviews

Monday, 5 October 2020

利用tcp-over-http翻墙

 

This program is just a proxy server which multiplexes TCP connections into an HTTPS. The primary purpose is to make all connections look like legitimate ones for firewalls (including DPI).

The closest analog is shadowsocks.

The only reason why I wrote this is that I want to have better control on how the connections are masked/multiplexed.

Current status

This software is unstable and non-unique. The code is broken in many places and follows the worst coding practices. It is not recommended to use this piece.

Setup

First, clone the repo and build all binaries (go install ./...). You may install it with go get github.com/neex/tcp-over-http as well, but the idea that you won't need source modifications is way too optimistic.

Server (do this before your trip)

  1. Buy a domain name (e.g. example.com).
  2. Rent a VPS. Make sure not to use any popular VPS provider (e.g. DigitalOcean/Vultr/Scaleway) as they're banned in some countries almost completely.
  3. Set up DNS A record pointing to the VPS.
  4. Get a LetsEncrypt certificate using certbot (apt install certbot && certbot -d example.com).
  5. Get something legitimate-looking to place on your website, like free bootstrap template.
  6. Create a config for the server part in /etc/tcp-over-http.yaml, it should look like this:
    listen_addr: ':443'
    static_dir: /var/www/html/
    dial_timeout: 2m
    token: put-a-random-token-here
    domain: example.com
    #redirector_addr: ':80'
    cert_path: /etc/letsencrypt/live/example.com/fullchain.pem
    key_path: /etc/letsencrypt/live/example.com/privkey.pem
  7. Create systemd module in /etc/systemd/system/tcp-over-http.service:
    [Unit]
    Description=TCP over HTTP
    
    [Service]
    Type=simple
    Restart=always
    ExecStart=/usr/local/bin/tcp_over_http_server /etc/tcp-over-http.yaml
    LimitNOFILE=100000
    
    [Install]
    WantedBy=multi-user.target
  8. Do systemctl daemon-reload && systemctl start tcp-over-http.
  9. Debug errors in journalctl, if any.

Client (test this before your trip)

  1. Create a client config, should like like:

    address: "https://<example.com>/establish/<token-from-server-config>"
    dns_override: <vps ip>:443
    remote_timeout: 30s
    connect_timeout: 10s
    max_connection_multiplex: 1000
    keep_alive_timeout: 10s
  2. Start the client using something like

    tcp_over_http --config ./client.yaml proxy :12321 --direct-dial '127.0.0.1|localhost'

    This command starts socks5 server on :12321, which runs through the tunnel.

  3. Under linux, you can setup an interface that proxies the connections. Do it like this:

    sudo ip tuntap add user <your username> mode tun hui0
    sudo ip link set hui0 up

    After that, run tcp-over-http with --tun hui0 flag. No server reconfiguration is required.

    Note that this is not an actual VPN. The connections are intercepted and proxies as TCP/UDP streams.

    Also, you will need to set up routes correctly.

from https://github.com/neex/tcp-over-http
------

我的补充说明:
登陆linux vps.
首先安装go环境。然后,
git clone https://github.com/neex/tcp-over-http tcp-over-http-by-neex
cd tcp-over-http-by-neex
go install ./...
可执行文件tcp_over_http_server就会生成在$GOBIN/下。

创建配置文件:
nano /etc/tcp-over-http.yaml
其内容为:
listen_addr: ':443'
static_dir: /var/www/html/
dial_timeout: 2m
token: ur-token
domain: urdomain.com
#redirector_addr: ':80'
cert_path: /root/.acme.sh/urdomain.com/fullchain.cer
key_path: /root/.acme.sh/urdomain.com/urdomain.com.key
(当然你要先去注册域名urdomain.com,并在linux vps上,用acme.sh生成其证书。这里监听的端口必须为443.
如果你的nginx监听了443端口,比如这里https://briteming.blogspot.com/2020/10/wssocks.html,我的nginx监听了443端口,我就把它改为监听447端口。
又比如这里https://briteming.blogspot.com/2020/10/v2raytls.html,v2ray服务器端原本监听443端口,我就把它改为监听445端口.
又比如这里https://briteming.blogspot.com/2019/01/v2ray-websocket-web-nginx.html,我的nginx监听了443端口,我就把它改为监听448端口。
所有其他监听443端口的程序都必须改为监听443以外的某个端口。

然后,
nano /etc/systemd/system/tcp-over-http.service
其内容为:

[Unit]

After=network.target


[Service]

ExecStart=/root/go/gopath/bin/tcp_over_http_server /etc/tcp-over-http.yaml

Restart=always


[Install]

WantedBy=multi-user.target


然后运行:

systemctl start tcp-over-http

systemctl enable tcp-over-http

服务器端搭建完成。


在本地机器mac上。

首先安装go环境。然后,
git clone https://github.com/neex/tcp-over-http tcp-over-http-by-neex
cd tcp-over-http-by-neex
go install ./...
(此步要挂个vpn,方能安装成功。比如挂上minivtun vpn)

可执行文件tcp_over_http就会生成在$GOBIN/下。

然后创建配置文件tcp-over-http-client.yaml,内容为:

address: "https://urdomain.com/establish/ur-token"

dns_override: ur-vps-public-ip:443

remote_timeout: 30s

connect_timeout: 10s

max_connection_multiplex: 1000

keep_alive_timeout: 10s


然后运行:

tcp_over_http --config tcp-over-http-client.yaml proxy :12321 --direct-dial '127.0.0.1|localhost'


不要关闭此终端,设置浏览器的socks5代理服务器地址为127.0.0.1 ,端口为12321 ,浏览器即可翻墙。


项目地址:https://github.com/neex/tcp-over-http

https://github.com/neex/tcp-over-http/issues/2








No comments:

Post a Comment