socks5
socks5 copied to clipboard
connection.py enforces incorrect logic on replies
https://github.com/mike820324/socks5/blob/master/socks5/connection.py#L207 enforces response host and port matching requested CONNECT host and port.
However, the RFC states:
In the reply to a CONNECT, BND.PORT contains the port number that the
server assigned to connect to the target host, while BND.ADDR
contains the associated IP address. The supplied BND.ADDR is often
different from the IP address that the client uses to reach the SOCKS
server, since such servers are often multi-homed. It is expected
that the SOCKS server will use DST.ADDR and DST.PORT, and the
client-side source address and port in evaluating the CONNECT
request.
I.e. the bind host/port, which are the server-side host/port, not the destination - socket.getsockname() vs socket.getpeername(). These are always IPs too, so even if connection was requested to domain name the response needs to be an IP.
This issue affects connecting to tor, which just puts zero for both address and port:
Simply removing https://github.com/mike820324/socks5/blob/master/socks5/connection.py#L73-L75 fixes the problem.