From b11fcf0ac23358319a1f64e2d0659cee58f0a9c7 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: Fri, 2 Aug 2024 14:02:09 +0000 Subject: [PATCH] SOCKS4a: Check if the client sends an IP address as domain Fix #3622 --- proxy/socks/protocol.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index fe13f24f9d54..4d31810ae990 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -69,12 +69,20 @@ func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer) if _, err := ReadUntilNull(reader); /* user id */ err != nil { return nil, err } + // Sock4a domain if address.IP()[0] == 0x00 { domain, err := ReadUntilNull(reader) if err != nil { return nil, errors.New("failed to read domain for socks 4a").Base(err) } address = net.DomainAddress(domain) + // Check if the client sends an IP address as domain + if len(domain) > 0 && (domain[0] >= '0' && domain[0] <= '9') { + addr := net.ParseAddress(domain) + if addr.Family().IsIP() { + address = addr + } + } } switch cmd {