From 644901d1a5c1728f2d41a1ba3d86a059029b0b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Sat, 3 Aug 2024 10:08:23 +0800 Subject: [PATCH] Socks4a server: Check if the client sends an IP address as domain (#3628) Fixes https://github.com/XTLS/Xray-core/issues/3622 --- common/net/address.go | 5 +++++ proxy/socks/protocol.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/net/address.go b/common/net/address.go index a5f7c160..1567e4d1 100644 --- a/common/net/address.go +++ b/common/net/address.go @@ -121,6 +121,11 @@ func IPAddress(ip []byte) Address { } // DomainAddress creates an Address with given domain. +// This is an internal function that forcibly converts a string to domain. +// It's mainly used in test files and mux. +// Unless you have a specific reason, use net.ParseAddress instead, +// as this function does not check whether the input is an IP address. +// Otherwise, you will get strange results like domain: 1.1.1.1 func DomainAddress(domain string) Address { return domainAddress(domain) } diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index fe13f24f..9bccf607 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -74,7 +74,7 @@ func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer) if err != nil { return nil, errors.New("failed to read domain for socks 4a").Base(err) } - address = net.DomainAddress(domain) + address = net.ParseAddress(domain) } switch cmd {