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

Dropping privileges prevents arping from working on Android #24

Closed
zb3 opened this issue Jun 19, 2017 · 10 comments
Closed

Dropping privileges prevents arping from working on Android #24

zb3 opened this issue Jun 19, 2017 · 10 comments

Comments

@zb3
Copy link

zb3 commented Jun 19, 2017

arping drops all privileges, but since Android uses predefined group ids to allow access to various things (enforced by the kernel), dropping all group ids causes arping to fail even though the user has access to raw sockets (inet(3003)).

Fail message:

arping: libnet_get_hwaddr(): socket: Permission denied

Note that it's not about opening raw sockets, that works fine before dropping privileges. Here's the offending syscall:

setgroups32(0, [])                      = 0
setgid32(65534)                         = 0
setuid32(65534)                         = 0
...
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = -1 EACCES (Permission denied)

Maybe it could be solved by making privilege drop optional?

@zb3 zb3 changed the title Droping privileges prevents arping from working on Android Dropping privileges prevents arping from working on Android Jun 19, 2017
@ThomasHabets
Copy link
Owner

You're saying you need to be in a particular set of groups to allow any network access?

Hmm, yes that does sound like it calls for a flag to not drop privileges. Unless: is there a well-known group or user that can be changed to (65534 is "nobody") that still has network access?

@zb3
Copy link
Author

zb3 commented Jun 19, 2017

Yes, after calling setuid, group 3003(inet) is required to open sockets, while group 3004(net_raw) is required to open raw sockets. I've tested this on Marshmallow, maybe this isn't universal.

@ThomasHabets
Copy link
Owner

OK, that's what you meant.

Could you confirm that if you change https://github.com/ThomasHabets/arping/blob/arping-2.x/src/arping.c#L330 to day drop_uid(uid, 3003) that it works?

In that case can add a flag that allows setting group by name.

@zb3
Copy link
Author

zb3 commented Jun 19, 2017

Yes, drop_uid(uid, 3003) works in my case (setgid to 3004 works too)

@ThomasHabets
Copy link
Owner

Could you try building current state and running with -g inet?

Actually, maybe arping should detect that it's running in Android and do this automatically, since extra arg every command would be annoying.

@ThomasHabets ThomasHabets reopened this Jun 20, 2017
@zb3
Copy link
Author

zb3 commented Jun 20, 2017

This works for me, but keep in mind that I am building this in a chrooted Debian environment, where there's no group named inet by default (one has to add it manually, for instance by installing the android-permissions package).

@ThomasHabets
Copy link
Owner

I know very little of Android development. Do you mean android-permissions needs to be installed on the Android phone, or in the development environment?

Do you think arping -g should accept numeric group as well?

And do you know of a way to find out that the system is an Android one, or would it even be possible at compile time? (I don't know the dev environment either)

@zb3
Copy link
Author

zb3 commented Jun 20, 2017

I'm not an expert here either :) But let's make one thing clear - by Android here I mean the kernel, not the OS.
android-permissions is a Debian package which simply adds groups with proper ids to the /etc/group file so we can refer to them by name. So in that case, we'd need it installed in the OS. It's Debian specific, but we can always use groupadd or simply edit the file.

If arping -g accepted numeric groups, it could make those things easier.

@zb3
Copy link
Author

zb3 commented Jun 20, 2017

As for detecting Android kernels, presence of a /dev/binder file seems Android specific, but maybe there's a better way.

@ThomasHabets
Copy link
Owner

Filed separate feature request for detecting android: #25

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

No branches or pull requests

2 participants