From a8c8fe0ca5797449a02ac60e4e2804358512c6d0 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Thu, 17 Aug 2017 11:05:04 +0800 Subject: [PATCH 1/7] snapcraft.yaml: change confinement from strict to classic --- snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index b6dd77e..cb55b7e 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -5,7 +5,7 @@ description: | A simple tunnel written in golang grade: stable -confinement: strict +confinement: classic apps: gost: From 91b966b28a740d7f07b165812213abada43b1841 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Fri, 18 Aug 2017 09:43:38 +0800 Subject: [PATCH 2/7] snapcraft.yaml: change confinement from strict to classic --- snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index cb55b7e..b6dd77e 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -5,7 +5,7 @@ description: | A simple tunnel written in golang grade: stable -confinement: classic +confinement: strict apps: gost: From df0533546449b85cbf4e7a5d53aae5200a00224b Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Thu, 24 Aug 2017 17:27:13 +0800 Subject: [PATCH 3/7] fix #149 --- http.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/http.go b/http.go index 166e555..f839d2f 100644 --- a/http.go +++ b/http.go @@ -94,16 +94,17 @@ func (h *httpHandler) Handle(conn net.Conn) { } if Debug { - log.Logf("[http] %s %s - %s %s", req.Method, conn.RemoteAddr(), req.Host, req.Proto) dump, _ := httputil.DumpRequest(req, false) - log.Logf(string(dump)) + log.Logf("[http] %s -> %s\n%s", conn.RemoteAddr(), req.Host, string(dump)) } - if req.Method == "PRI" && req.ProtoMajor == 2 { - log.Logf("[http] %s <- %s : Not an HTTP2 server", conn.RemoteAddr(), req.Host) + if req.Method == "PRI" || (req.Method != http.MethodConnect && req.URL.Scheme != "http") { resp := "HTTP/1.1 400 Bad Request\r\n" + "Proxy-Agent: gost/" + Version + "\r\n\r\n" conn.Write([]byte(resp)) + if Debug { + log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), req.Host, resp) + } return } From 4b6ba653acb426252facedfe3f5645cc578cd319 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Tue, 29 Aug 2017 13:32:41 +0800 Subject: [PATCH 4/7] fix HTTP request handler --- http.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/http.go b/http.go index f839d2f..6688ce7 100644 --- a/http.go +++ b/http.go @@ -108,6 +108,17 @@ func (h *httpHandler) Handle(conn net.Conn) { return } + if !Can("tcp", req.Host, h.options.Whitelist, h.options.Blacklist) { + log.Logf("[http] Unauthorized to tcp connect to %s", req.Host) + b := []byte("HTTP/1.1 403 Forbidden\r\n" + + "Proxy-Agent: gost/" + Version + "\r\n\r\n") + conn.Write(b) + if Debug { + log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), req.Host, string(b)) + } + return + } + u, p, _ := basicProxyAuth(req.Header.Get("Proxy-Authorization")) if Debug && (u != "" || p != "") { log.Logf("[http] %s - %s : Authorization: '%s' '%s'", conn.RemoteAddr(), req.Host, u, p) @@ -122,18 +133,7 @@ func (h *httpHandler) Handle(conn net.Conn) { } req.Header.Del("Proxy-Authorization") - req.Header.Del("Proxy-Connection") - - if !Can("tcp", req.Host, h.options.Whitelist, h.options.Blacklist) { - log.Logf("[http] Unauthorized to tcp connect to %s", req.Host) - b := []byte("HTTP/1.1 403 Forbidden\r\n" + - "Proxy-Agent: gost/" + Version + "\r\n\r\n") - conn.Write(b) - if Debug { - log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), req.Host, string(b)) - } - return - } + // req.Header.Del("Proxy-Connection") // forward http request lastNode := h.options.Chain.LastNode() From b139c3bdac65a465ad29e0e8d7d9c633b2ec3786 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Mon, 4 Sep 2017 11:47:58 +0800 Subject: [PATCH 5/7] fix socks4 --- socks.go | 3 +++ vendor/github.com/ginuerzh/gosocks4/socks4.go | 2 +- vendor/vendor.json | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/socks.go b/socks.go index 858e725..1bb4533 100644 --- a/socks.go +++ b/socks.go @@ -261,6 +261,9 @@ func (c *socks4Connector) Connect(conn net.Conn, addr string) (net.Conn, error) if err != nil { return nil, err } + if len(taddr.IP) == 0 { + taddr.IP = net.IPv4(0, 0, 0, 0) + } req := gosocks4.NewRequest(gosocks4.CmdConnect, &gosocks4.Addr{ diff --git a/vendor/github.com/ginuerzh/gosocks4/socks4.go b/vendor/github.com/ginuerzh/gosocks4/socks4.go index 52b32e4..2377ac5 100644 --- a/vendor/github.com/ginuerzh/gosocks4/socks4.go +++ b/vendor/github.com/ginuerzh/gosocks4/socks4.go @@ -56,7 +56,7 @@ func (addr *Addr) Decode(b []byte) error { addr.Port = binary.BigEndian.Uint16(b[0:2]) addr.Host = net.IP(b[2 : 2+net.IPv4len]).String() - if b[2]|b[3]|b[4] == 0 { + if b[2]|b[3]|b[4] == 0 && b[5] != 0 { addr.Type = AddrDomain } diff --git a/vendor/vendor.json b/vendor/vendor.json index 3691d4f..017937c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -81,10 +81,10 @@ "revisionTime": "2016-08-31T15:17:26Z" }, { - "checksumSHA1": "aIhLeVAIrsjs63CwqmU3+GU8yT4=", + "checksumSHA1": "AqX1ZPaQtMCpfiTiA2zGmWadYl0=", "path": "github.com/ginuerzh/gosocks4", - "revision": "fc196f9d34e35f19a813bff2f092a275131c23bc", - "revisionTime": "2017-02-09T14:09:51Z" + "revision": "c3a6700bad67bd29718fd19212b3dd934aea89b3", + "revisionTime": "2017-09-04T03:46:09Z" }, { "checksumSHA1": "4JEexBJToQeQm7fAo2PHVdCU3zM=", From badf099a782f408f40c669a00ac912106c075c59 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Mon, 4 Sep 2017 20:33:08 +0800 Subject: [PATCH 6/7] version 2.4 --- gost.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gost.go b/gost.go index ca73555..75b8db9 100644 --- a/gost.go +++ b/gost.go @@ -14,7 +14,7 @@ import ( ) // Version is the gost version. -const Version = "2.4-rc2" +const Version = "2.4" // Debug is a flag that enables the debug log. var Debug bool From 124d0988b266773a0d30dd85c32d6539d3ba6791 Mon Sep 17 00:00:00 2001 From: "rui.zheng" Date: Mon, 11 Sep 2017 10:01:30 +0800 Subject: [PATCH 7/7] fix #158, ss: clear timer after obtaining the request --- ss.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ss.go b/ss.go index e66a1d0..3cc702d 100644 --- a/ss.go +++ b/ss.go @@ -172,10 +172,12 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) { buf := make([]byte, smallBufferSize) // read till we get possible domain length field - conn.SetReadDeadline(time.Now().Add(30 * time.Second)) + conn.SetReadDeadline(time.Now().Add(ReadTimeout)) if _, err = io.ReadFull(conn, buf[:idType+1]); err != nil { return } + // clear timer + conn.SetReadDeadline(time.Time{}) var reqStart, reqEnd int addrType := buf[idType]