Home

Awesome

<p align="center"> <img width="250px" src="https://user-images.githubusercontent.com/18649508/139117888-4f631b07-0b40-4d24-b478-fb805ceef689.png" /> </p> <hr/>

Crates.io CI Crates.io Crates.io

Ever wished you could make your stubborn programs use a proxy without them even knowing? Well, say hello to cproxy.

Key Features

[!TIP] Your proxy should be a transparent proxy port (like V2Ray's dokodemo-door inbound or shadowsocks ss-redir). But don't panic if you only have a SOCKS5 or HTTP proxy! There are tools that can transform it faster than Bill Clinton (check out transocks, ipt2socks and ip2socks-go).

Installation

You can install by downloading the binary from the release page or install with: cargo install cproxy.

Alternatively, here's a oneliner that downloads the latest release and put it in your /usr/local/bin/ (for the lazy... I mean, efficient folks):

curl -s https://api.github.com/repos/NOBLES5E/cproxy/releases/latest | grep "browser_download_url.*x86_64-unknown-linux-musl.zip" | cut -d : -f 2,3 | tr -d \" | wget -qi - -O /tmp/cproxy.zip && unzip -j /tmp/cproxy.zip cproxy -d /tmp && sudo mv /tmp/cproxy /usr/local/bin/ && sudo chmod +x /usr/local/bin/cproxy && rm /tmp/cproxy.zip

Usage

Basic Magic Trick: Just Like proxychains

You can launch a new program with cproxy with:

sudo cproxy --port <destination-local-port> -- <your-program> --arg1 --arg2 ...

All TCP connections requests will be proxied. If your local transparent proxy support DNS address overriding, you can also redirect DNS traffic with --redirect-dns:

sudo cproxy --port <destination-local-port> --redirect-dns -- <your-program> --arg1 --arg2 ...

For an example setup, see wiki.

[!NOTE] Scared of sudo in the command? Well, that's what we need to have the permission to modify cgroup. But don't worry too much, the program you run will still be run under your original user, not as root. cproxy automatically drops privileges after setting up the necessary cgroup configurations, ensuring that your program runs with the same permissions as if you had launched it directly.

The TPROXY Twist

If your system support tproxy, you can use tproxy with --mode tproxy:

sudo cproxy --port <destination-local-port> --mode tproxy -- <your-program> --arg1 --arg2 ...
# or for existing process
sudo cproxy --port <destination-local-port> --mode tproxy --pid <existing-process-pid>

With --mode tproxy, there are several differences:

An example setup can be found here.

Note that when you are using the tproxy mode, you can override the DNS server address with cproxy --mode tproxy --override-dns <your-dns-server-addr> .... This is useful when you want to use a different DNS server for a specific application.

Advanced Usage: Proxy an Existing Process

With cproxy, you can even proxy an existing process. This is very handy when you want to proxy existing system services such as docker. To do this, just run

sudo cproxy --port <destination-local-port> --pid <existing-process-pid>

The target process will be proxied as long as this cproxy command is running. You can press Ctrl-C to stop proxying.

Advanced Usage: Debug a Program's Network Activity with Iptables LOG Target

With cproxy, you can easily debug a program's traffic in netfilter. Just run the program with

sudo cproxy --mode trace <your-program>

You will be able to see log in dmesg. Note that this requires a recent enough kernel and iptables.

Advanced Usage: Proxy Specific Cgroup Paths

cproxy allows you to proxy all processes within specific cgroup paths. This is particularly useful for managing groups of related processes without specifying individual PIDs.

Suppose you have a cgroup at /sys/fs/cgroup/mygroup containing several processes you wish to proxy. You can run:

sudo cproxy --port 1080 --cgroup-path /sys/fs/cgroup/mygroup --mode tproxy

This command will proxy all TCP and UDP traffic from processes within the /sys/fs/cgroup/mygroup cgroup using TPROXY mode on port 1080.

The Secret Sauce

cproxy simply creates a unique cgroup for the proxied program, and redirect its traffic with packet rules.

Limitations

Similar Projects

There are some awesome existing work: