Fix: socks4 server handshake (#2700)

This commit is contained in:
yaling888 2023-04-25 20:16:11 +08:00 committed by GitHub
parent 6eee226965
commit 48b77b2847
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -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 */