Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use TCP to communicate. Now most SOCKS use TCP instead of UDP. #21

Open
etan96 opened this issue Mar 15, 2021 · 3 comments
Open

Comments

@etan96
Copy link

etan96 commented Mar 15, 2021

How to use TCP to communicate. Now most SOCKS use TCP instead of UDP.

@iMrDJAi
Copy link

iMrDJAi commented Mar 27, 2021

Same question ^^^
I use a socks proxy node.js library that doesn't seem to support UDP, unfortunately I couldn't find a solution for this.

IMG20210326224910

@iMrDJAi
Copy link

iMrDJAi commented Mar 31, 2021

Well, I was wrong... Actually we're all wrong, and your question @77193404 is also incorrect. The device traffic itself goes over TCP as normal, the DNS queries are what go over UDP! as mentioned here #18 (comment).
Since the DNS queries go through UDP and not TCP, you won't get a working internet unless your server can resolve them separately, and it likely cannot.
In this case, you may only connect to servers using IPs, that's why the internet worked in some apps on my device like Facebook lite, Instagram lite, Telegram.. All of these apps connect directly to their servers using IP addresses instead of domain names.
By the way, what I'm trying to build is an SSH client, I'm using TUN2SOCKS to forward the device traffic through a SOCKS5 proxy running on localhost and connected to a remote SSH server, I'm using nodejs-mobile-cordova to run a good SOCKS5 library (@sansamour/node-sock) that actually supports UDP associate (see page 7).
But, when @alalamav mentioned that the SOCKS proxy server has to support UDP, he didn't mean UDP associate, he meant Shadowsocks UDP relay (Also called UdpGw relay, which means "UDP Gateway". See this comment 5fe4a0c#r109713257 by @trevj), which is a way to resolve DNS queries!
It won't be a part of your SOCKS5 proxy, it will be a separate UDP server running on the same port as your proxy (I didn't know that I may run 2 server on the same port before, I was surprised when I discovered that), and that also explains why they didn't gave us a way to specify a different port for it.
So I've created a simple UDP server in javascript to listen to DNS packets:

var udp = require('dgram')
var server = udp.createSocket('udp6')

server.on('error', err => {
  error('Error: ' + err)
  server.close()
})
server.on('message', (msg, info) => {
  log('UDP: ' + msg.toString('hex') + '\n(' + msg.toString() + ')')
})
server.bind(1080, () => {
  log(`UDP server started on port 1080!`)
})

/** output:
UDP: 0000000108080808003517b8010000010000000000000377777706676f6f676c6503636f6d0000010001
(�����5�����www�google�com��)
**/

What I'm not sure about is how to handle these packets, I didn't find any resources that may help, hopefully the collaborators may provide me some info in order to parse the buffer and structuring the response to send it back to the client.

@iMrDJAi
Copy link

iMrDJAi commented Jun 9, 2021

I ended up using the actual UDP associate feature of SOCKS v5, someone made a pull request (#20) to add support for it.
I have published a working version here:
https://github.com/iMrDJAi/cordova-plugin-tun2socks-udp-associate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants