tetherfi icon indicating copy to clipboard operation
tetherfi copied to clipboard

Future: UDP proxy

Open pyamsoft opened this issue 2 years ago • 19 comments

We may need to build a SOCKS5 proxy for UDP traffic since we can't transparent proxy UDP from an HTTP proxy

pyamsoft avatar Jan 11 '23 02:01 pyamsoft

I ran in to an issue with some UDP applications not working and would love to see it implemented.

zellchristensen avatar Jan 22 '23 16:01 zellchristensen

UDP is much trickier to proxy than TCP sadly, but this actively affects me too so its top of mind (though sadly very difficult)

pyamsoft avatar Jan 22 '23 18:01 pyamsoft

Socks with ktor https://github.com/torsm/ktor-socks/tree/master/src/main/kotlin/de/torsm/socks

Socks UDP assoc code https://github.com/bbottema/java-socks-proxy-server/blob/master/src/main/java/org/bbottema/javasocksproxyserver/Socks5Impl.java

pyamsoft avatar Feb 20 '23 06:02 pyamsoft

This will need to be an HTTP based solution since consoles and phones dont support socks natively.

Generally speaking you can't http proxy UDP, but we will see if we can implement a proxy over http via quic or something

pyamsoft avatar Feb 21 '23 05:02 pyamsoft

This will need to be an HTTP based solution since consoles and phones dont support socks natively.

Generally speaking you can't http proxy UDP, but we will see if we can implement a proxy over http via quic or something

I look forward to this as I've been struggling getting some things to work. Telegram wouldn't start a call without UDP suport. I've tried some methods to get it to work. Making it work natively would make it much easier to work with.

Perhaps a library like this could help development. https://github.com/VKCOM/KNet

Arr4y avatar Jul 11 '23 22:07 Arr4y

Hi,

I'm not sure about directly using this knet library, as it pulls in a ton of stuff and hasn't been touched code wise for a few years.

I appreciate the enthusiasm around the topic. I have 2 bare minimum requirements for a valid UDP solution in Tetherfi, it needs to run on a non rooted Android phone, and it needs to be possible without becoming the System VPN service or needing the system Mobile Hotspot.

UDP is a lot trickier since there is no method on Android to capture any UDP traffic like there is for setting a proxy up via the wifi settings for TCP currently.

Basically, the calling app needs to speak QUIC already, and assuming it does, possibly the existing TCP proxy might already work as its a simple forwarder from a client to a server.

If the app like Telegram only talks in UDP, I am not able to capture its socket connections without being a VPN app.

Tetherfi is not a VPN app, and it never will be. The google play store would never accept it.

UDP proxying will take time, this is assuming it is even technically possible in the first place in a way that doesnt require other apps to specifically change.

pyamsoft avatar Jul 11 '23 22:07 pyamsoft

Hi,

I'm not sure about directly using this knet library, as it pulls in a ton of stuff and hasn't been touched code wise for a few years.

I appreciate the enthusiasm around the topic. I have 2 bare minimum requirements for a valid UDP solution in Tetherfi, it needs to run on a non rooted Android phone, and it needs to be possible without becoming the System VPN service or needing the system Mobile Hotspot.

UDP is a lot trickier since there is no method on Android to capture any UDP traffic like there is for setting a proxy up via the wifi settings for TCP currently.

Basically, the calling app needs to speak QUIC already, and assuming it does, possibly the existing TCP proxy might already work as its a simple forwarder from a client to a server.

If the app like Telegram only talks in UDP, I am not able to capture its socket connections without being a VPN app.

Tetherfi is not a VPN app, and it never will be. The google play store would never accept it.

UDP proxying will take time, this is assuming it is even technically possible in the first place in a way that doesnt require other apps to specifically change.

I've used an app called "Android Proxy Server" and created a shadowsocks proxy with it. I've used it with Tether Fi to connect a laptop to it. That fixed the problem but I would have many instances where the app would stop working until I opened it again. The app doesn't pose as a VPN, it just creates a server. I've used others that created a socks proxy but they failed and wasn't sure why. But that was my current solution.

Arr4y avatar Jul 12 '23 04:07 Arr4y

I will look at seeing if I can implement a shadowsocks proxy in tetherfi, to avoid the current issues with running 2 apps. It could be a workable solution.

(I believe the disconnect issues are caused by both attempting to use Wifi direct to setup local hotspots. Tetherfi expects to be the exclusive Wifi direct owner, and I imagine so does the Android Proxy Server app, which is why you are probably seeing the issue.)

pyamsoft avatar Jul 12 '23 04:07 pyamsoft

I will look at seeing if I can implement a shadowsocks proxy in tetherfi, to avoid the current issues with running 2 apps. It could be a workable solution.

(I believe the disconnect issues are caused by both attempting to use Wifi direct to setup local hotspots. Tetherfi expects to be the exclusive Wifi direct owner, and I imagine so does the Android Proxy Server app, which is why you are probably seeing the issue.)

The other app does not create a wifi direct nor connection. It only hosts a server. It appears to stop working when my phone shuts off so that's most likely the app's problem.

Do we have an ETA for a shadowsocks proxy within the app?

Arr4y avatar Jul 19 '23 06:07 Arr4y

No ETA at the moment - I still need to see if a shadowsocks proxy would be the right path forward.

It looks like a shadowsocks server is a huge undertaking - and it would require connecting clients to run a shadowsocks client. If that is the case, it won't be a solution for the long-term as would not be supported by simpler devices - though it may be an interesting stop-gap solution.

Long term would probably look at something like CONNECT-UDP, which would supposedly be supported on anything that speaks HTTP, which is exactly what we would be looking for

https://datatracker.ietf.org/doc/html/rfc9298

pyamsoft avatar Jul 27 '23 03:07 pyamsoft

+1 for Socks5 proxy server.

chromer030 avatar Oct 03 '23 07:10 chromer030

Note that, as a workaround, it is possible to run an SSH service on the phone(e.g. SimpleSSHD), and use OpenSSH's application-level port forwarding feature to run a SOCKS server on the localhost that forwards the requests to the phone.

I have implemented a script to start such a service on GNU+Linux operating system: enable-ssh-socks-service.sh.gz

This may not work with all UDP use cases, though.

brlin-tw avatar May 08 '24 10:05 brlin-tw

Note that, as a workaround, it is possible to run an SSH service on the phone(e.g. SimpleSSHD), and use OpenSSH's application-level port forwarding feature to run a SOCKS server on the localhost that forwards the requests to the phone.

I have implemented a script to start such a service on GNU+Linux operating system: enable-ssh-socks-service.sh.gz

This may not work with all UDP use cases, though.

Now I manually start a socks5 proxy server(3proxy) in termux when using tetherfi, it works fine and just a bit complex.

QZLin avatar May 10 '24 07:05 QZLin

Good to hear that this works as a workaround for client devices that have access to a UNIXlike shell.

I assume, were I to incorporate something like this in-app, that TetherFi would launch a SOCKS SSH server on a port (2222) at the Wi-Fi direct IP (192.168.49.1), and the user would have to manually configure their client device (laptop, desktop) to point at it as a SOCKS proxy or use proxychains or something of the sort?

At that point, I would have to build TetherFi as a full SOCKS proxy, or a SOCKS and HTTP proxy - this may increase battery usage.

This doesn't sound like it would be a solution for things like gaming consoles, which do not support SOCKS, but it certainly is a step in the right direction!

pyamsoft avatar May 11 '24 17:05 pyamsoft

@pyamsoft yes implementing this would be really cool im trying to get steam to work with all these setups mentioned here in the comments but so far not working for me :/ definitely needs udp

moraroy avatar Jul 20 '24 04:07 moraroy

+1 for Socks5 proxy.

chromer030 avatar Jul 20 '24 19:07 chromer030

@chromer030 could this be used as a workaround too? https://github.com/jpillora/chisel

moraroy avatar Jul 21 '24 11:07 moraroy

@moraroy, internal server on same port is best solution. (Apps i know using this: nekobox, husi)

chromer030 avatar Jul 21 '24 18:07 chromer030

Any updates? I'm going on a field trip for school in like a few months and I'm in charge of being the hotspot person and some people use apps that use udp, My unlimited data plan throttles hotspot horribly (20 mbps) while I get 200+ mbps

Clyde6790pGIT avatar Sep 29 '24 07:09 Clyde6790pGIT