From 48b77b28475d717eb6280c01f5e25c7f36b49b9d Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Tue, 25 Apr 2023 20:16:11 +0800 Subject: [PATCH] Fix: socks4 server handshake (#2700) --- transport/socks4/socks4.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport/socks4/socks4.go b/transport/socks4/socks4.go index 964b232..5397a40 100644 --- a/transport/socks4/socks4.go +++ b/transport/socks4/socks4.go @@ -68,8 +68,8 @@ func ServerHandshake(rw io.ReadWriter, authenticator auth.Authenticator) (addr s return } - dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() + dstAddr := r.ReadIPv4() if isReservedIP(dstAddr) { var target []byte if target, err = readUntilNull(rw); err != nil { @@ -96,8 +96,8 @@ func ServerHandshake(rw io.ReadWriter, authenticator auth.Authenticator) (addr s reply := protobytes.BytesWriter(make([]byte, 0, 8)) reply.PutUint8(0) // reply code reply.PutUint8(code) // result code - reply.PutSlice(dstAddr.AsSlice()) reply.PutUint16be(dstPort) + reply.PutSlice(dstAddr.AsSlice()) _, wErr := rw.Write(reply.Bytes()) if err == nil { @@ -128,7 +128,7 @@ func ClientHandshake(rw io.ReadWriter, addr string, command Command, userID stri req.PutUint8(Version) req.PutUint8(command) req.PutUint16be(uint16(port)) - req.Write(ip.AsSlice()) + req.PutSlice(ip.AsSlice()) req.PutString(userID) req.PutUint8(0) /* NULL */