Skip to content

Commit

Permalink
SOCKS4a: Check if the client sends an IP address as domain
Browse files Browse the repository at this point in the history
Fix #3622
  • Loading branch information
Fangliding authored Aug 2, 2024
1 parent 7e24239 commit b11fcf0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions proxy/socks/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

1 comment on commit b11fcf0

@xqzr
Copy link
Contributor

@xqzr xqzr commented on b11fcf0 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.