Reputation: 36418
Is there a way to send UDP packets through a SOCKS5 proxy in NodeJS?
Similarly, is it possible to bind a UDP socket to a specific localAddress?
Upvotes: 7
Views: 4005
Reputation: 2072
To send UDP packets from your client, you have to specify value 0x03 in field 2 of your client's connection request. See the fields of the client's connection request:
field 1: SOCKS version number, 1 byte (must be 0x05 for this version)
field 2: command code, 1 byte:
0x01 = establish a TCP/IP stream connection
0x02 = establish a TCP/IP port binding
0x03 = associate a UDP port
field 3: reserved, must be 0x00
field 4: address type, 1 byte:
0x01 = IPv4 address
0x03 = Domain name
0x04 = IPv6 address
field 5: destination address of
4 bytes for IPv4 address
1 byte of name length followed by the name for Domain name
16 bytes for IPv6 address
field 6: port number in a network byte order, 2 bytes
For instance, the line of code in the referenced library would need change from 0x01 to 0x03:
buffer.push(0x01); // Command code: establish a TCP/IP stream connection
I don't know how you could bind to specific local address.
Upvotes: 2
Reputation: 157
According to http://www.ietf.org/rfc/rfc1928.txt and http://en.wikipedia.org/wiki/SOCKS#SOCKS5, UDP should really be supported in Socks5.
However, if you look at some SOCKS5 implementation, you'll see that UDP is not supported in the implementation. For example: https://gist.github.com/telamon/1127459 or https://gist.github.com/robertpitt/3203203 (.
So, the short answer is NO, unless you'll find library that supports it (UDP binding).
Upvotes: 1
Reputation: 1275
The SOCKS5 protocol supports UDP connections, however most libraries for SOCKS5 only support TCP since UDP isn't very frequently used on the web (except for DNS). The protocol itself isn't very complicated, so it shouldn't be to hard to rewrite an existing library (maybe this one?) to suit your needs.
Upvotes: 3