GOST (GO Simple Tunnel)

repository·master·Indexed 12 days ago

https://github.com/ginuerzh/gost

A versatile, secure tunnel implementation written in Go. GOST supports a wide array of proxy protocols including HTTP, SOCKS5, and Shadowsocks, and enables complex proxy chains, port forwarding, and transparent proxying. It provides a flexible architecture with Connector and Transporter interfaces, custom authentication via the Authenticator interface, and dynamic bypass filtering for IPs, CIDRs, and domains.

Tokens
36.2K
Snippets
169
Records
187
Agent score
92%

What's inside GOST

  1. Configure multi-level forward proxies (Proxy Chains)

    master

    GOST allows you to create a proxy chain by using multiple -F (forward) flags. The request is forwarded through the chain in the order the flags are provided. Each node in the chain can be a different protocol (HTTP, SOCKS5, Shadowsocks, etc.).

    # Chain: Local :8080 -> QUIC node -> SOCKS5+WSS node -> HTTP2 node -> final destination
    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
  2. Configure forwarding proxies and proxy chains

    master

    GOST allows you to forward requests to another proxy using the -F flag. You can chain multiple proxies together to create a proxy chain.

    • Single Forwarding: Forward all traffic from local port 8080 to a specific proxy at 192.168.1.1:8081.
    • Authenticated Forwarding: Provide credentials for the forwarding proxy.
    • Proxy Chains: Specify multiple -F flags. GOST will process the request through the chain in the order the flags are provided, eventually reaching the final destination.
    ### Single forwarding proxy
    ```bash
    gost -L=:8080 -F=192.168.1.1:8081

    Authenticated forwarding proxy

    gost -L=:8080 -F=http://admin:123456@192.168.1.1:8081

    Multi-level proxy chain

    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
  3. Install GOST

    master

    You can install GOST using several methods depending on your environment:

    • Binary Files: Download pre-compiled binaries from the GitHub releases page.
    • Source Compilation: Clone the repository and build using Go.
    • Docker: Run the official image.
    • Homebrew: Available for macOS/Linux via brew.
    • Snap: Available for Ubuntu via snap.
    ### Source Compilation
    ```bash
    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

    Snap

    sudo snap install core
    sudo snap install gost
  4. Perform Local TCP/UDP port forwarding

    master

    Forward traffic from a local port to a remote destination, optionally through a proxy chain.

    • TCP: Use -L=tcp://:local_port/remote_host:remote_port.
    • UDP: Use -L=udp://:local_port/remote_host:remote_port. You can set a timeout using the ttl parameter (default is 60s).

    Note for UDP: If using a proxy chain, the last node must be a GOST SOCKS5 proxy to support UDP-over-TCP.

    # Local TCP forwarding
    gost -L=tcp://:2222/192.168.1.1:22
    
    # Local UDP forwarding with 60s timeout
    gost -L=udp://:5353/192.168.1.1:53?ttl=60
  5. Use GOST as a standard HTTP or SOCKS5 proxy

    master

    To run GOST as a simple proxy server without any forwarding chains, use the -L flag to specify the listening address and protocol.

    • Standard HTTP/SOCKS5: Listen on port 8080.
    • With Authentication: Set credentials in the format user:password@host:port.
    • Multi-port Listening: You can specify multiple -L flags to listen on different protocols and ports simultaneously.
    ### Standard HTTP/SOCKS5 proxy
    ```bash
    gost -L=:8080

    Proxy with authentication

    gost -L=admin:123456@localhost:8080

    Multi-port listening

    gost -L=http2://:443 -L=socks5://:1080 -L=ss://aes-128-cfb:123456@:8338
  6. Use Shadowsocks and obfs4 protocols

    master

    GOST supports Shadowsocks and obfs4 for obfuscated tunneling.

    Shadowsocks

    Supports both standard TCP and UDP relay. For UDP relay, use the ssu protocol prefix.

    obfs4

    When the obfs4 server starts, it prints a connection string to the console. Use this exact string for the client -F parameter.

    ### Shadowsocks TCP
    ```bash
    # Server
    gost -L=ss://chacha20:123456@:8338
    # Client
    gost -L=:8080 -F=ss://chacha20:123456@server_ip:8338

    Shadowsocks UDP Relay

    # Server
    gost -L=ssu://chacha20:123456@:8338

    obfs4

    # Server
    gost -L=obfs4://:443
    
    # Client (using the string printed by server)
    gost -L=:8888 -F='obfs4://server_ip:443?cert=4UbQjIfjJEQHPOs8vs5sagrSXx1gfrDCGdVh2hpIPSKH0nklv1e4f29r7jb91VIrq4q5Jw&iat-mode=0'
  7. Use HTTP2, QUIC, and KCP modes

    master

    GOST supports several specialized transport modes:

    HTTP2

    Supports two modes:

    1. Proxy Mode: Acts as a standard HTTP2 proxy (compatible with HTTPS). Use http2://.
    2. Channel Mode: Acts as a tunnel for other protocols. Use h2://.

    QUIC

    Based on quic-go. Note: QUIC mode can only be used as the first node in a proxy chain.

    KCP

    Based on kcp-go and kcptun. Note: KCP mode can only be used as the first node in a proxy chain. You can specify a configuration file using the c parameter.

    SSH

    Supports two modes:

    1. Forwarding Mode: Used with local/remote TCP forwarding. Use forward+ssh://.
    2. Channel Mode: Acts as a tunnel. Use ssh://. You can set a heartbeat interval with the ping parameter (in seconds).
    ### HTTP2 Proxy Mode
    ```bash
    # Server
    gost -L=http2://:443
    # Client
    gost -L=:8080 -F=http2://server_ip:443

    QUIC

    # Server
    gost -L=quic://:6121
    # Client
    gost -L=:8080 -F=quic://server_ip:6121

    KCP

    # Server
    gost -L=kcp://:8388
    # Client with custom config
    gost -L=:8080 -F=kcp://server_ip:8388?c=/path/to/conf/file

    SSH Channel Mode

    # Server
    gost -L=ssh://:2222
    # Client with 60s heartbeat
    gost -L=:8080 -F=ssh://server_ip:2222?ping=60
  8. Configure TLS certificates

    master

    GOST has built-in TLS certificates. To use your own:

    1. Place cert.pem (public key) and key.pem (private key) in the current working directory.
    2. Or, specify the paths via parameters.

    Clients can use the secure parameter for verification or the ca parameter for Certificate Pinning.

    # Server with custom certs
    gost -L="http2://:443?cert=/path/to/my/cert/file&key=/path/to/my/key/file"
    
    # Client with server verification
    gost -L=:8080 -F="http2://server_domain_name:443?secure=true"
    
    # Client with Certificate Pinning
    gost -L=:8080 -F="http2://:443?ca=ca.pem"
  9. Perform Remote TCP/UDP port forwarding

    master

    Expose a port on a remote machine and forward its traffic to a destination through a proxy chain. Use the rtcp (remote TCP) and rudp (remote UDP) prefixes.

    Note for UDP: If using a proxy chain, the last node must be a GOST SOCKS5 proxy to support UDP-over-TCP.

    # Remote TCP forwarding
    gost -L=rtcp://:2222/192.168.1.1:22 [-F=...]
    
    # Remote UDP forwarding
    gost -L=rudp://:5353/192.168.1.1:53?ttl=60 [-F=...]
  10. Perform local and remote port forwarding (TCP/UDP)

    master

    GOST supports port forwarding for both TCP and UDP protocols.

    Local Port Forwarding (TCP/UDP)

    Maps a local port to a remote destination through a proxy chain.

    • TCP: gost -L=tcp://:local_port/remote_host:remote_port.
    • UDP: gost -L=udp://:local_port/remote_host:remote_port?ttl=seconds.
      • The ttl parameter sets the timeout for the forwarding channel (default is 60s).
      • Note: When forwarding UDP through a proxy chain, the last node in the chain must be a SOCKS5 proxy to support UDP-over-TCP.

    Remote Port Forwarding (TCP/UDP)

    Exposes a remote port to a local destination through a proxy chain.

    • TCP: gost -L=rtcp://:remote_port/remote_host:remote_port.
    • UDP: gost -L=rudp://:remote_port/remote_host:remote_port?ttl=seconds.
      • Note: Similar to local UDP forwarding, the last node in the chain must be a SOCKS5 proxy.

    SSH Integration

    If the last node in the chain is an SSH forwarding type, GOST can leverage native SSH local/remote port forwarding features.

    ### Local TCP forwarding
    ```bash
    gost -L=tcp://:2222/192.168.1.1:22

    Local UDP forwarding

    gost -L=udp://:5353/192.168.1.1:53?ttl=60

    Remote TCP forwarding

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

    Remote UDP forwarding

    gost -L=rudp://:5353/192.168.1.1:53?ttl=60 -F=socks5://172.24.10.1:1080
  11. Use SSH for tunneling

    master

    GOST supports SSH in two modes:

    1. Forward Tunnel: Used for local/remote TCP port forwarding. Use the forward+ssh:// prefix.
    2. Transport Tunnel: A dedicated transport mode using the ssh:// prefix. The client supports a ping parameter for heartbeat detection (in seconds).
    # SSH Forward Tunnel (Server)
    gost -L=forward+ssh://:2222
    
    # SSH Forward Tunnel (Client)
    gost -L=rtcp://:1222/:22 -F=forward+ssh://server_ip:2222
    
    # SSH Transport Tunnel (Server)
    gost -L=ssh://:2222
    
    # SSH Transport Tunnel (Client with heartbeat)
    gost -L=:8080 -F=ssh://server_ip:2222?ping=60
  12. Set up a standard HTTP/SOCKS5 proxy

    master

    To start a simple proxy server listening on a specific port without a forward proxy, use the -L flag. You can also add authentication using the username:password@host:port format or by pointing to a secrets file.

    # Standard HTTP/SOCKS5 proxy on port 8080
    gost -L=:8080
    
    # Proxy with authentication
    gost -L=admin:123456@localhost:8080
    
    # Proxy using multiple authentication credentials from a file
    gost -L=localhost:8080?secrets=secrets.txt