diff --git a/client.go b/client.go index 32c0994..a24aaa2 100644 --- a/client.go +++ b/client.go @@ -222,6 +222,7 @@ type ConnectOptions struct { UserAgent string NoTLS bool NoDelay bool + Host string HeaderConfig map[string]string } @@ -277,9 +278,16 @@ func NoDelayConnectOption(b bool) ConnectOption { } } -// HeaderConnectOption specifies the NoDelay option for ss.Connect. +// HeaderConnectOption specifies the Header option for ss.Connect. func HeaderConnectOption(HeaderConfig map[string]string) ConnectOption { return func(opts *ConnectOptions) { opts.HeaderConfig = HeaderConfig } } + +// HostConnectOption specifies the host for connect. +func HostConnectOption(host string) ConnectOption { + return func(opts *ConnectOptions) { + opts.Host = host + } +} diff --git a/cmd/gost/main.go b/cmd/gost/main.go index 7aea15b..60df030 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -41,8 +41,8 @@ func init() { flag.Parse() if printVersion { - fmt.Fprintf(os.Stdout, "gost %s (%s %s/%s)\n", - gost.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH) + fmt.Fprintf(os.Stdout, "gost %s (%s %s/%s)\nEnhanced:\n%s\n", + gost.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH, gost.Enhanced) os.Exit(0) } diff --git a/cmd/gost/route.go b/cmd/gost/route.go index efa30db..15e6f30 100644 --- a/cmd/gost/route.go +++ b/cmd/gost/route.go @@ -301,6 +301,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) { gost.NoTLSConnectOption(node.GetBool("notls")), gost.NoDelayConnectOption(node.GetBool("nodelay")), gost.HeaderConnectOption(headerCfg), + gost.HostConnectOption(node.Get("host")), } sshConfig := &gost.SSHConfig{} diff --git a/gost.go b/gost.go index 8d39945..5e9ba0a 100644 --- a/gost.go +++ b/gost.go @@ -20,7 +20,11 @@ import ( ) // Version is the gost version. -const Version = "2.11.2-EvanMod-v1.1" +const Version = "2.11.2-EvanMod-v1.2" +const Enhanced = "Add parameter sni for all tls\n" + + "Add parameter header=header.txt for custom header process\n" + + "Add parameter host for http connect" +const ProxyAgent = "nginx" // Debug is a flag that enables the debug log. var Debug bool diff --git a/http.go b/http.go index d001793..8c59ad8 100644 --- a/http.go +++ b/http.go @@ -52,6 +52,10 @@ func (c *httpConnector) ConnectContext(ctx context.Context, conn net.Conn, netwo ua = DefaultUserAgent } + if opts.Host != "" { + address = opts.Host + } + conn.SetDeadline(time.Now().Add(timeout)) defer conn.SetDeadline(time.Time{}) @@ -182,7 +186,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) { ProtoMinor: 1, Header: http.Header{}, } - resp.Header.Add("Proxy-Agent", "gost/"+Version) + resp.Header.Add("Proxy-Agent", ProxyAgent) if !Can("tcp", host, h.options.Whitelist, h.options.Blacklist) { log.Logf("[http] %s - %s : Unauthorized to tcp connect to %s", @@ -296,7 +300,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) { if req.Method == http.MethodConnect { b := []byte("HTTP/1.1 200 Connection established\r\n" + - "Proxy-Agent: gost/" + Version + "\r\n\r\n") + "Proxy-Agent: " + ProxyAgent + "\r\n\r\n") if Debug { log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), conn.LocalAddr(), string(b)) } diff --git a/http2.go b/http2.go index 8c675bc..d651e16 100644 --- a/http2.go +++ b/http2.go @@ -372,7 +372,7 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) { log.Logf("[http2] %s - %s\n%s", r.RemoteAddr, laddr, string(dump)) } - w.Header().Set("Proxy-Agent", "gost/"+Version) + w.Header().Set("Proxy-Agent", ProxyAgent) if !Can("tcp", host, h.options.Whitelist, h.options.Blacklist) { log.Logf("[http2] %s - %s : Unauthorized to tcp connect to %s", @@ -768,7 +768,7 @@ func (l *h2Listener) handleFunc(w http.ResponseWriter, r *http.Request) { dump, _ := httputil.DumpRequest(r, false) log.Log("[http2]", string(dump)) } - w.Header().Set("Proxy-Agent", "gost/"+Version) + w.Header().Set("Proxy-Agent", ProxyAgent) conn, err := l.upgrade(w, r) if err != nil { log.Logf("[http2] %s - %s %s %s %s: %s", diff --git a/strong_mod.sh b/strong_mod.sh new file mode 100644 index 0000000..34b9591 --- /dev/null +++ b/strong_mod.sh @@ -0,0 +1,2 @@ +sed -b -i s/\*gost./*evan./g $1 +sed -b -i s/]gost./]evan./g $1 diff --git a/ws.go b/ws.go index 7cc1684..6e2a958 100644 --- a/ws.go +++ b/ws.go @@ -170,8 +170,13 @@ func (tr *mwsTransporter) initSession(addr string, conn net.Conn, opts *Handshak if path == "" { path = defaultWSPath } - url := url.URL{Scheme: "ws", Host: opts.Host, Path: path} - conn, err := websocketClientConn(url.String(), conn, nil, wsOptions) + urlObj := url.URL{Scheme: "ws", Host: opts.Host, Path: path} + + urlStr, errUnescape := url.QueryUnescape(urlObj.String()) + if errUnescape != nil { + log.Logf("[ws] URL QueryUnescape Error URL.String() -> %s", urlObj.String()) + } + conn, err := websocketClientConn(urlStr, conn, nil, wsOptions) if err != nil { return nil, err } @@ -330,8 +335,12 @@ func (tr *mwssTransporter) initSession(addr string, conn net.Conn, opts *Handsha if path == "" { path = defaultWSPath } - url := url.URL{Scheme: "wss", Host: opts.Host, Path: path} - conn, err := websocketClientConn(url.String(), conn, tlsConfig, wsOptions) + urlObj := url.URL{Scheme: "wss", Host: opts.Host, Path: path} + urlStr, errUnescape := url.QueryUnescape(urlObj.String()) + if errUnescape != nil { + log.Logf("[ws] URL QueryUnescape Error URL.String() -> %s", urlObj.String()) + } + conn, err := websocketClientConn(urlStr, conn, tlsConfig, wsOptions) if err != nil { return nil, err }