7

Is it possible to send UDP datagrams over SOCKS5 proxy in Python using any SOCKS client lib? SocksiPy does not seem to work or maybe I am just using it wrong. The following code does not work, it tries to connect to the destination directly:

s = socks.socksocket ( socket.AF_INET, socket.SOCK_DGRAM )
s.setproxy(socks.PROXY_TYPE_SOCKS5,"socks.proxy.lan")
s.sendto ( payload, ( ip, port ) )

If I change SOCK_DGRAM to SOCK_STREAM the code does not work either, it does not try to connect anywhere then.

Alex
  • 907
  • 2
  • 8
  • 22
  • did you find any solution to this? – ykhrustalev Apr 20 '16 at 11:41
  • 1
    @ykhrustalev Yes, but I can't recall exact details. Most probably I just set up a transparent SOCKS proxy using a tool called RedSocks (w/my patches, it's available on my github account freely. – Alex Apr 20 '16 at 16:04

2 Answers2

2

Have you tried to use connect() and send() instead of sendto()? Judging from the SocksiPy source code, connectionless mode isn't implemented.

Edit:

req = struct.pack('BBB', 0x05, 0x01, 0x00)

TCP stream connection (0x01) seems to be hardcoded here. SocksiPy as it is won't work.

WGH
  • 3,222
  • 2
  • 29
  • 42
0

Have you tried this:

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "socks.proxy.lan", 8080, True)

replace 8080 with the port and "True" is True if you want rdns enabled.

If you are using Python version 3 and above i suggest you use PySocks and it would be

socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, "socks.proxy.lan", 8080, True)
FlameBlazer
  • 1,592
  • 2
  • 10
  • 9