sorz / moproxy

A transparent TCP to SOCKSv5/HTTP proxy on Linux written in Rust.
MIT License
223 stars 35 forks source link

[Feature suggestion] UDP transparent proxy for SOCKS5 (TPROXY) #14

Closed phantomcraft closed 1 year ago

phantomcraft commented 1 year ago

Here I use another program for UDP transparent proxying, but it doesn't work with LD_PRELOAD, so a Rust program for doing that is what I'm looking for.

It would be a good idea to implement support for UDP transparent proxy because many censorship solutions such as Shadowsocks, VMess, Vless and so on support UDP.

This project could serve as a basis for this implementation: https://github.com/MengJiangProject/redproxy-rs/search?q=tproxy

/\ Another thing that must be done is using the SOCKS5 command 03, for UDP ASSOCIATE.

It's my suggestion.

sorz commented 1 year ago

I'm experimenting UDP proxying on another project quproxy.

I was trying to add UDP capability directly onto moproxy but found out that it's better to treat two protocols of a single upstream proxy as two distant proxies: doing alive/latency test separately and maintain two independent list of proxies. And the UDP session management is differ from TCP's. So I decided start a fresh project rather than integrate it onto moproxy (at least for now). It's also easier to experiment some fancy features that only possible with UDP (like QUIC connection migration) on a fresh project.

phantomcraft commented 1 year ago

Ok, I understand, I didn't know about quproxy, thanks.

phantomcraft commented 1 year ago

I tried to compile quproxy:

user@localhost:~/Desktop/quproxy-main$ cargo build
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.43
[...]
   Compiling toml v0.5.9
   Compiling quproxy v0.1.0 (/home/user/Desktop/quproxy-main)
error[E0658]: deriving `Default` on enums is experimental
  --> src/app/socks5/server.rs:28:17
   |
28 | #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize)]
   |                 ^^^^^^^
   |
   = note: see issue #86985 <https://github.com/rust-lang/rust/issues/86985> for more information
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: deriving `Default` on enums is experimental
  --> src/cli.rs:94:23
   |
94 | #[derive(Deserialize, Default, PartialEq, Eq, Clone, Copy)]
   |                       ^^^^^^^
   |
   = note: see issue #86985 <https://github.com/rust-lang/rust/issues/86985> for more information
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0658`.
error: could not compile `quproxy` due to 2 previous errors

I know that that project is still under development, but I'm looking forward for compiling it.

You could put authentication on TODO list of quproxy.

sorz commented 1 year ago

Try update Rust to 1.62 or newer. derive_default_enum was stabilized on 1.62.

phantomcraft commented 1 year ago

Here I use Debian testing and Rust is 1.61, I had to compile the beta version.

I tested quproxy here and it doesn't work:

# /opt/quproxy/quproxy --host 127.0.0.1 --port 12345 --socks5-tcp 127.0.0.1:1081 --socks5-udp 127.0.0.1:1081
2022-10-19T11:20:13.966868Z  INFO quproxy::app::context: Configured SOCKSv5 servers: 2
2022-10-19T11:20:13.968467Z  INFO check_all: quproxy::app::socks5::refer: Connected with 127.0.0.1:1081, UDP endpoint 127.0.0.1:57507
2022-10-19T11:20:14.168934Z  INFO launch:ping_all: quproxy::app::checking::service: Failed to ping upstream [127.0.0.1:1081]: Connection refused (os error 111)
2022-10-19T11:20:14.168951Z  INFO launch:ping_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes trouble
2022-10-19T11:20:44.168715Z  INFO launch:ping_all: quproxy::app::checking::service: Failed to ping upstream [127.0.0.1:1081]: Connection refused (os error 111)
2022-10-19T11:20:47.369359Z  INFO launch:ping_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes trouble
2022-10-19T11:20:47.968096Z  INFO launch:meter_sampling_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes out of trouble
2022-10-19T11:21:14.169621Z  INFO launch:ping_all: quproxy::app::checking::service: Failed to ping upstream [127.0.0.1:1081]: Connection refused (os error 111)
2022-10-19T11:21:17.369465Z  INFO launch:ping_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes trouble
2022-10-19T11:21:17.967755Z  INFO launch:meter_sampling_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes out of trouble
2022-10-19T11:21:44.169658Z  INFO launch:ping_all: quproxy::app::checking::service: Failed to ping upstream [127.0.0.1:1081]: Connection refused (os error 111)
2022-10-19T11:21:44.169709Z  INFO launch:ping_all: quproxy::app::checking::service: Failed to ping upstream [127.0.0.1:1081]: Connection refused (os error 111)
2022-10-19T11:21:44.169721Z  INFO launch:ping_all: quproxy::app::checking::health: Upstream [127.0.0.1:1081] goes trouble

I know that is under development, so I marked its page on my bookmarks for latter usage.