diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index e3f582dfa..b8764d451 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -8,7 +8,6 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/bitmask" "v2ray.com/core/common/buf" - "v2ray.com/core/common/dice" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" ) @@ -65,12 +64,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea buffer.Clear() addr, port, err := addrParser.ReadAddressPort(buffer, br) - if err != nil { - // Invalid address. Continue to read some bytes to confuse client. - nBytes := dice.Roll(32) + 1 - buffer.Clear() - buffer.AppendSupplier(buf.ReadFullFrom(br, int32(nBytes))) return nil, nil, newError("failed to read address").Base(err) } diff --git a/proxy/vmess/encoding/server.go b/proxy/vmess/encoding/server.go index 4c5c76dc9..a035a693a 100644 --- a/proxy/vmess/encoding/server.go +++ b/proxy/vmess/encoding/server.go @@ -15,7 +15,6 @@ import ( "v2ray.com/core/common/bitmask" "v2ray.com/core/common/buf" "v2ray.com/core/common/crypto" - "v2ray.com/core/common/dice" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/serial" @@ -175,20 +174,6 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request // 1 bytes reserved request.Command = protocol.RequestCommand(buffer.Byte(37)) - var invalidRequestErr error - defer func() { - if invalidRequestErr != nil { - randomLen := dice.Roll(64) + 1 - // Read random number of bytes for prevent detection. - buffer.AppendSupplier(buf.ReadFullFrom(decryptor, int32(randomLen))) // nolint: errcheck - } - }() - - if request.Security == protocol.SecurityType_UNKNOWN || request.Security == protocol.SecurityType_AUTO { - invalidRequestErr = newError("unknown security type") - return nil, invalidRequestErr - } - switch request.Command { case protocol.RequestCommandMux: request.Address = net.DomainAddress("v1.mux.cool") @@ -197,13 +182,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request if addr, port, err := addrParser.ReadAddressPort(buffer, decryptor); err == nil { request.Address = addr request.Port = port - } else { - invalidRequestErr = newError("invalid address").Base(err) - return nil, invalidRequestErr } - default: - invalidRequestErr = newError("invalid request command: ", request.Command) - return nil, invalidRequestErr } if padingLen > 0 { @@ -229,6 +208,10 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request return nil, newError("invalid remote address") } + if request.Security == protocol.SecurityType_UNKNOWN || request.Security == protocol.SecurityType_AUTO { + return nil, newError("unknown security type: ", request.Security) + } + return request, nil }