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

iptables cannot be used with setuid #80

Open
cjc7373 opened this issue May 31, 2022 · 3 comments
Open

iptables cannot be used with setuid #80

cjc7373 opened this issue May 31, 2022 · 3 comments

Comments

@cjc7373
Copy link

cjc7373 commented May 31, 2022

I've encountered iptables errors recently:

$ cproxy mpv xxxx
Error: Running ["iptables", "-t", "nat", "-N", "nozomi_redirect_out_23962"] exited with error; status code: 111

It may be related to a change introduced in iptables 1.8.8, that iptables cannot be called by a setuid executable. See https://git.netfilter.org/iptables/commit/?id=ef7781eb1437a2d6fd37eb3567c599e3ea682b96

I'm not sure how to deal with it, but I think Linux capabilities is an option.

@kauruus
Copy link

kauruus commented Dec 31, 2022

setting capabilities works for me:

sudo setcap cap_sys_admin+ep `which cproxy`

oops, sorry, i test with sudo. setting capabilities doesn't work.

@kauruus
Copy link

kauruus commented Dec 31, 2022

my temporary workaround:

  1. disable seteuid check in cproxy https://github.com/NOBLES5E/cproxy/blob/master/src/main.rs#L155-L160
  2. add all capabilities (no time to figure out the exact one) to both cproxy and iptables, setcap all+ep ...

it mostly works, except failing to clean up iptable rules. i have to remove it manually.

$ ./target/debug/cproxy --port 1081 -- curl https://www.ipconfig.io
xxx.xxx.xxx.xxx
thread 'main' panicked at 'drop iptables and cgroup failed: Custom { kind: Other, error: "Running [\"iptables\", \"-t\", \"nat\", \
"-D\", \"OUTPUT\", \"-j\", \"nozomi_redirect_out_11570\"] exited with error; status code: 111" }', src/guards.rs:108:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@kauruus
Copy link

kauruus commented Dec 31, 2022

instead of setuid and capabilities, maybe it's easier to run cproxy with sudo, after setting up iptables, cproxy start the program as the original user and add it to the cgroup.

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