Commit 5a2fd66c authored by rui.zheng's avatar rui.zheng

merge master

parents cd842de2 124d0988
...@@ -94,16 +94,28 @@ func (h *httpHandler) Handle(conn net.Conn) { ...@@ -94,16 +94,28 @@ func (h *httpHandler) Handle(conn net.Conn) {
} }
if Debug { if Debug {
log.Logf("[http] %s %s - %s %s", req.Method, conn.RemoteAddr(), req.Host, req.Proto)
dump, _ := httputil.DumpRequest(req, false) 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 { if req.Method == "PRI" || (req.Method != http.MethodConnect && req.URL.Scheme != "http") {
log.Logf("[http] %s <- %s : Not an HTTP2 server", conn.RemoteAddr(), req.Host)
resp := "HTTP/1.1 400 Bad Request\r\n" + resp := "HTTP/1.1 400 Bad Request\r\n" +
"Proxy-Agent: gost/" + Version + "\r\n\r\n" "Proxy-Agent: gost/" + Version + "\r\n\r\n"
conn.Write([]byte(resp)) conn.Write([]byte(resp))
if Debug {
log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), req.Host, resp)
}
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 return
} }
...@@ -121,18 +133,7 @@ func (h *httpHandler) Handle(conn net.Conn) { ...@@ -121,18 +133,7 @@ func (h *httpHandler) Handle(conn net.Conn) {
} }
req.Header.Del("Proxy-Authorization") req.Header.Del("Proxy-Authorization")
req.Header.Del("Proxy-Connection") // 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
}
// try to get the actual host. // try to get the actual host.
if v := req.Header.Get("Gost-Target"); v != "" { if v := req.Header.Get("Gost-Target"); v != "" {
......
...@@ -261,6 +261,9 @@ func (c *socks4Connector) Connect(conn net.Conn, addr string) (net.Conn, error) ...@@ -261,6 +261,9 @@ func (c *socks4Connector) Connect(conn net.Conn, addr string) (net.Conn, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(taddr.IP) == 0 {
taddr.IP = net.IPv4(0, 0, 0, 0)
}
req := gosocks4.NewRequest(gosocks4.CmdConnect, req := gosocks4.NewRequest(gosocks4.CmdConnect,
&gosocks4.Addr{ &gosocks4.Addr{
......
...@@ -172,10 +172,12 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) { ...@@ -172,10 +172,12 @@ func (h *shadowHandler) getRequest(conn net.Conn) (host string, err error) {
buf := make([]byte, smallBufferSize) buf := make([]byte, smallBufferSize)
// read till we get possible domain length field // 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 { if _, err = io.ReadFull(conn, buf[:idType+1]); err != nil {
return return
} }
// clear timer
conn.SetReadDeadline(time.Time{})
var reqStart, reqEnd int var reqStart, reqEnd int
addrType := buf[idType] addrType := buf[idType]
......
...@@ -56,7 +56,7 @@ func (addr *Addr) Decode(b []byte) error { ...@@ -56,7 +56,7 @@ func (addr *Addr) Decode(b []byte) error {
addr.Port = binary.BigEndian.Uint16(b[0:2]) addr.Port = binary.BigEndian.Uint16(b[0:2])
addr.Host = net.IP(b[2 : 2+net.IPv4len]).String() 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 addr.Type = AddrDomain
} }
......
...@@ -81,10 +81,10 @@ ...@@ -81,10 +81,10 @@
"revisionTime": "2016-08-31T15:17:26Z" "revisionTime": "2016-08-31T15:17:26Z"
}, },
{ {
"checksumSHA1": "aIhLeVAIrsjs63CwqmU3+GU8yT4=", "checksumSHA1": "AqX1ZPaQtMCpfiTiA2zGmWadYl0=",
"path": "github.com/ginuerzh/gosocks4", "path": "github.com/ginuerzh/gosocks4",
"revision": "fc196f9d34e35f19a813bff2f092a275131c23bc", "revision": "c3a6700bad67bd29718fd19212b3dd934aea89b3",
"revisionTime": "2017-02-09T14:09:51Z" "revisionTime": "2017-09-04T03:46:09Z"
}, },
{ {
"checksumSHA1": "Onmjh8hT6pjAixkuGJN4KKAaTT4=", "checksumSHA1": "Onmjh8hT6pjAixkuGJN4KKAaTT4=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment