GO Simple Tunnel - a simple tunnel written in golang
 
 
Go to file
guoguangwu fd57e80709 chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
.config add reloader for authenticator 2019-01-09 22:36:44 +08:00
.github/workflows add goreleaser github action 2023-01-31 21:33:14 +08:00
cmd/gost chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
examples update:update package 2021-12-16 22:38:27 +08:00
snap v2.11.5 2023-01-20 14:43:13 +08:00
.dockerignore add timeout for Connectors 2018-12-22 23:10:55 +08:00
.gitignore add goreleaser github action 2023-01-31 21:33:14 +08:00
.goreleaser.yaml add goreleaser github action 2023-01-31 21:33:14 +08:00
.travis.yml add more test cases for socks5 2018-12-31 20:44:20 +08:00
Dockerfile go1.20 2023-02-04 18:37:14 +08:00
LICENSE add missing files 2017-08-04 14:26:30 +08:00
Makefile go1.19 2022-08-18 18:21:21 +08:00
README.md go1.20 2023-02-04 18:37:14 +08:00
README_en.md go1.20 2023-02-04 18:37:14 +08:00
auth.go fix HTTP Host header 2019-06-03 16:14:49 +08:00
auth_test.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
bypass.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
bypass_test.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
chain.go fix issue #883 2022-11-16 14:30:42 +08:00
client.go update:update package 2021-12-16 22:38:27 +08:00
common_test.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
dns.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
docker-compose.yaml Build go binaries without QEMU 2020-04-14 21:43:16 +08:00
forward.go fix issue #883 2022-11-16 14:30:42 +08:00
forward_test.go add ssu connector 2020-02-02 15:32:49 +08:00
ftcp.go add ssu connector 2020-02-02 15:32:49 +08:00
go.mod update golang.org/x/crypto v0.5.0 to 0.17.0 2024-02-02 17:20:02 +08:00
go.sum update golang.org/x/crypto v0.5.0 to 0.17.0 2024-02-02 17:20:02 +08:00
gost.go fix issue #883 2022-11-16 14:30:42 +08:00
gost.png update snapcraft build 2022-04-13 17:09:01 +08:00
handler.go #889: add http tunnel mode for HTTP handler 2022-11-16 15:21:01 +08:00
handler_test.go add more test cases for socks5 2018-12-31 20:44:20 +08:00
hosts.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
hosts_test.go add more test cases for socks5 2018-12-31 20:44:20 +08:00
http.go fix 2024-02-02 17:20:25 +08:00
http2.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
http2_test.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
http_test.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
kcp.go update kcp 2022-04-13 21:06:29 +08:00
kcp_test.go fix tests 2019-06-21 21:30:48 +08:00
log.go add comment, fix golint 2017-08-12 19:55:35 +08:00
mux.go fix issue https://github.com/ginuerzh/gost/issues/617 2020-12-06 18:22:53 +08:00
node.go support vsock 2023-10-10 19:27:13 +08:00
node_test.go add stop for live reloading 2018-11-29 22:09:10 +08:00
obfs.go Do not exit the server loop on obfs4 connection errors 2023-01-19 14:43:10 +08:00
obfs_test.go add more test cases 2019-01-05 13:21:33 +08:00
permissions.go add test files 2017-08-13 09:30:18 +08:00
permissions_test.go Change + to space to allows nice + be in the url 2017-04-10 13:25:43 +02:00
quic.go go1.20 2023-02-04 18:37:14 +08:00
quic_test.go fix tests 2019-06-21 21:30:48 +08:00
redirect.go update func calls 2020-02-09 10:32:34 +08:00
redirect_other.go fix redirect on non linux OS 2020-02-02 16:09:16 +08:00
relay.go update:update package 2021-12-16 22:38:27 +08:00
reload.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
resolver.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
resolver_test.go fix test cases 2020-02-02 15:33:26 +08:00
selector.go add proxyAgent options for http/http2 handler 2022-08-18 20:03:03 +08:00
selector_test.go add max_fails & fail_timeout options support for port forwarding 2019-06-20 10:47:58 +08:00
server.go fix #870 2022-08-31 17:52:52 +08:00
signal.go fix compile error 2017-03-03 21:57:10 +08:00
signal_unix.go update snapcraft build 2022-04-13 17:09:01 +08:00
sni.go update:update package 2021-12-16 22:38:27 +08:00
sni_test.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
sockopts_linux.go feat: add bind interface 2022-04-19 20:02:16 +08:00
sockopts_other.go Add older style build comment 2022-08-18 13:09:38 +08:00
socks.go toSocksAddr supports IPv6 2023-01-19 14:46:23 +08:00
socks_test.go add reloader for authenticator 2019-01-09 22:36:44 +08:00
ss.go update:update package 2021-12-16 22:38:27 +08:00
ss_test.go add chain.DialContext 2020-02-08 15:02:04 +08:00
ssh.go chore: remove refs to deprecated io/ioutil 2024-02-02 17:22:04 +08:00
ssh_test.go fix tests 2019-06-21 21:30:48 +08:00
tcp.go add ssu connector 2020-02-02 15:32:49 +08:00
tls.go fix issue https://github.com/ginuerzh/gost/issues/617 2020-12-06 18:22:53 +08:00
tls_test.go fix tests 2019-06-21 21:30:48 +08:00
tuntap.go rm shadowstream used in tuntap 2020-05-23 11:19:22 +08:00
tuntap_darwin.go fix tun for darwin 2020-02-03 21:05:42 +08:00
tuntap_linux.go go1.19 2022-08-18 18:21:21 +08:00
tuntap_unix.go tap: make net parameter optional (#472) 2020-01-22 10:39:23 +08:00
tuntap_windows.go surround interface name with double quote in case of name have space 2022-04-07 22:08:00 +08:00
udp.go reduce buffer allocation 2020-02-29 15:45:58 +08:00
vsock.go support vsock 2023-10-10 19:27:13 +08:00
ws.go fix issue https://github.com/ginuerzh/gost/issues/617 2020-12-06 18:22:53 +08:00
ws_test.go fix tests 2019-06-21 21:30:48 +08:00
wss_test.go fix tests 2019-06-21 21:30:48 +08:00

README_en.md

gost - GO Simple Tunnel

A simple security tunnel written in Golang

GoDoc Go Report Card codecov GitHub release Docker gost

Features

Wiki: v2.gost.run

Telegram group: https://t.me/gogost

Google group: https://groups.google.com/d/forum/go-gost

Installation

Binary files

https://github.com/ginuerzh/gost/releases

From source

git clone https://github.com/ginuerzh/gost.git
cd gost/cmd/gost
go build

Docker

docker run --rm ginuerzh/gost -V

Homebrew

brew install gost

Ubuntu store

sudo snap install core
sudo snap install gost

Getting started

No forward proxy

  • Standard HTTP/SOCKS5 proxy
gost -L=:8080
  • Proxy authentication
gost -L=admin:123456@localhost:8080
  • Multiple sets of authentication information
gost -L=localhost:8080?secrets=secrets.txt

The secrets parameter allows you to set multiple authentication information for HTTP/SOCKS5 proxies, the format is:

# username password

test001 123456
test002 12345678
  • Listen on multiple ports
gost -L=http2://:443 -L=socks5://:1080 -L=ss://aes-128-cfb:123456@:8338

Forward proxy

gost -L=:8080 -F=192.168.1.1:8081
  • Forward proxy authentication
gost -L=:8080 -F=http://admin:123456@192.168.1.1:8081

Multi-level forward proxy

gost -L=:8080 -F=quic://192.168.1.1:6121 -F=socks5+wss://192.168.1.2:1080 -F=http2://192.168.1.3:443 ... -F=a.b.c.d:NNNN

Gost forwards the request to a.b.c.d:NNNN through the proxy chain in the order set by -F, each forward proxy can be any HTTP/HTTPS/HTTP2/SOCKS4/SOCKS5/Shadowsocks type.

Local TCP port forwarding

gost -L=tcp://:2222/192.168.1.1:22 [-F=...]

The data on the local TCP port 2222 is forwarded to 192.168.1.1:22 (through the proxy chain). If the last node of the chain (the last -F parameter) is a SSH forwad tunnel, then gost will use the local port forwarding function of SSH directly:

gost -L=tcp://:2222/192.168.1.1:22 -F forward+ssh://:2222

Local UDP port forwarding

gost -L=udp://:5353/192.168.1.1:53?ttl=60 [-F=...]

The data on the local UDP port 5353 is forwarded to 192.168.1.1:53 (through the proxy chain). Each forwarding channel has a timeout period. When this time is exceeded and there is no data interaction during this time period, the channel will be closed. The timeout value can be set by the ttl parameter. The default value is 60 seconds.

NOTE: When forwarding UDP data, if there is a proxy chain, the end of the chain (the last -F parameter) must be gost SOCKS5 proxy, gost will use UDP-over-TCP to forward data.

Remote TCP port forwarding

gost -L=rtcp://:2222/192.168.1.1:22 [-F=... -F=socks5://172.24.10.1:1080]

The data on 172.24.10.1:2222 is forwarded to 192.168.1.1:22 (through the proxy chain). If the last node of the chain (the last -F parameter) is a SSH tunnel, then gost will use the remote port forwarding function of SSH directly:

gost -L=rtcp://:2222/192.168.1.1:22 -F forward+ssh://:2222

Remote UDP port forwarding

gost -L=rudp://:5353/192.168.1.1:53?ttl=60 [-F=... -F=socks5://172.24.10.1:1080]

The data on 172.24.10.1:5353 is forwarded to 192.168.1.1:53 (through the proxy chain). Each forwarding channel has a timeout period. When this time is exceeded and there is no data interaction during this time period, the channel will be closed. The timeout value can be set by the ttl parameter. The default value is 60 seconds.

NOTE: When forwarding UDP data, if there is a proxy chain, the end of the chain (the last -F parameter) must be gost SOCKS5 proxy, gost will use UDP-over-TCP to forward data.

HTTP2

Gost HTTP2 supports two modes:

  • As a standard HTTP2 proxy, and backwards-compatible with the HTTPS proxy.

  • As a transport tunnel.

Standard proxy

Server:

gost -L=http2://:443

Client:

gost -L=:8080 -F=http2://server_ip:443?ping=30
Tunnel

Server:

gost -L=h2://:443

Client:

gost -L=:8080 -F=h2://server_ip:443

QUIC

Support for QUIC is based on library quic-go.

Server:

gost -L=quic://:6121

Client:

gost -L=:8080 -F=quic://server_ip:6121

NOTE: QUIC node can only be used as the first node of the proxy chain.

KCP

Support for KCP is based on libraries kcp-go and kcptun.

Server:

gost -L=kcp://:8388

Client:

gost -L=:8080 -F=kcp://server_ip:8388

Gost will automatically load kcp.json configuration file from current working directory if exists, or you can use the parameter to specify the path to the file.

gost -L=kcp://:8388?c=/path/to/conf/file

NOTE: KCP node can only be used as the first node of the proxy chain.

SSH

Gost SSH supports two modes:

  • As a forward tunnel, used by local/remote TCP port forwarding.

  • As a transport tunnel.

Forward tunnel

Server:

gost -L=forward+ssh://:2222

Client:

gost -L=rtcp://:1222/:22 -F=forward+ssh://server_ip:2222
Transport tunnel

Server:

gost -L=ssh://:2222

Client:

gost -L=:8080 -F=ssh://server_ip:2222?ping=60

The client supports the ping parameter to enable heartbeat detection (which is disabled by default). Parameter value represents heartbeat interval seconds.

Transparent proxy

Iptables-based transparent proxy

gost -L=redirect://:12345 -F=http2://server_ip:443

obfs4

Contributed by @isofew.

Server:

gost -L=obfs4://:443

When the server is running normally, the console prints out the connection address for the client to use:

obfs4://:443/?cert=4UbQjIfjJEQHPOs8vs5sagrSXx1gfrDCGdVh2hpIPSKH0nklv1e4f29r7jb91VIrq4q5Jw&iat-mode=0

Client:

gost -L=:8888 -F='obfs4://server_ip:443?cert=4UbQjIfjJEQHPOs8vs5sagrSXx1gfrDCGdVh2hpIPSKH0nklv1e4f29r7jb91VIrq4q5Jw&iat-mode=0'

Encryption Mechanism

HTTP

For HTTP, you can use TLS to encrypt the entire communication process, the HTTPS proxy:

Server:

gost -L=http+tls://:443

Client:

gost -L=:8080 -F=http+tls://server_ip:443

HTTP2

Gost HTTP2 proxy mode only supports the use of TLS encrypted HTTP2 protocol, does not support plaintext HTTP2.

Gost HTTP2 tunnel mode supports both encryption (h2) and plaintext (h2c) modes.

SOCKS5

Gost supports the standard SOCKS5 protocol methods: no-auth (0x00) and user/pass (0x02), and extends two methods for data encryption: tls(0x80) and tls-auth(0x82).

Server:

gost -L=socks://:1080

Client:

gost -L=:8080 -F=socks://server_ip:1080

If both ends are gosts (as example above), the data transfer will be encrypted (using tls or tls-auth). Otherwise, use standard SOCKS5 for communication (no-auth or user/pass).

Shadowsocks

Support for shadowsocks is based on library shadowsocks-go.

Server:

gost -L=ss://aes-128-cfb:123456@:8338

Client:

gost -L=:8080 -F=ss://aes-128-cfb:123456@server_ip:8338
Shadowsocks UDP relay

Currently, only the server supports UDP Relay.

Server:

gost -L=ssu://aes-128-cfb:123456@:8338

TLS

There is built-in TLS certificate in gost, if you need to use other TLS certificate, there are two ways:

  • Place two files cert.pem (public key) and key.pem (private key) in the current working directory, gost will automatically load them.

  • Use the parameter to specify the path to the certificate file:

gost -L="http2://:443?cert=/path/to/my/cert/file&key=/path/to/my/key/file"

Client can specify secure parameter to perform server's certificate chain and host name verification:

gost -L=:8080 -F="http2://server_domain_name:443?secure=true"

Client can specify a CA certificate to allow for Certificate Pinning:

gost -L=:8080 -F="http2://:443?ca=ca.pem"

Certificate Pinning is contributed by @sheerun.