maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   MeeGo / Harmattan (https://talk.maemo.org/forumdisplay.php?f=45)
-   -   suid bit / setuid() does not work? (https://talk.maemo.org/showthread.php?t=99203)

meego_leenooks1 2017-03-27 12:56

suid bit / setuid() does not work?
 
Take the simplest program which executes command as root:
Code:

/dev/shm/suid # cat setuid.c
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[]) {
  setuid(0);
  system(argv[1]);
}

Compile it and set setuid bit:
Code:

/dev/shm/suid # gcc setuid.c -o /usr/bin/setuid
/dev/shm/suid # chown root:root /usr/bin/setuid
/dev/shm/suid # chmod 4755 /usr/bin/setuid
/dev/shm/suid # ls -l /usr/bin|grep rws
-rwsr-xr-x    1 root    root          5480 Mar 27 19:51 setuid
-rwsr-xr-x    2 root    root        94144 Mar 12  2012 sudo
-rwsr-xr-x    2 root    root        94144 Mar 12  2012 sudoedit

See that it does not work:
Code:

/dev/shm/suid # whoami
root
/dev/shm/suid # setuid whoami
root
/dev/shm/suid # su user

BusyBox v1.20.0.git (MeeGo 3:1.20-0.2+0m8) built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ $ whoami
user
~ $ setuid whoami
user

There is no "nosuid" option for /usr/bin mount point and "sudo" suid binary works:
Code:

~ $ mount|grep nosuid | grep usr
~ $ sudo whoami
Password:
root

What am I doing wrong? How to create a suid binary?

rainisto 2017-03-27 17:54

Re: suid bit / setuid() does not work?
 
You need to give right capas to the binary, for example with refhashlist or putting binary inside installable deb package with the capas.

meego_leenooks1 2017-03-27 20:22

Re: suid bit / setuid() does not work?
 
Please give the link to manual about refhashlist or how to build deb package with setuid capability.

rainisto 2017-03-28 15:42

Re: suid bit / setuid() does not work?
 
Quote:

Originally Posted by meego_leenooks1 (Post 1526060)
Please give the link to manual about refhashlist or how to build deb package with setuid capability.

Here is small example of diff how to turn develsh to opensh
http://maemo.cloud-7.de/HARM/N9/open...h/develsh.diff

main() basicly just calls setuid and setgid before opening shell. You only need the right .aegis file to gain the capas.

With opensh you can test your selfbuild binary with:
opensh -c 'aegis-exec -c -a CAP::setuid /usr/bin/setuid'

For refhashlist you just use google :)

nieldk 2017-03-28 16:26

Re: suid bit / setuid() does not work?
 
Excellent example on the Power of aegis (I hate it lol)

rainisto 2017-03-28 17:18

Re: suid bit / setuid() does not work?
 
For longer manual http://mirror.thecust.net/meego_1.2_..._security.html


All times are GMT. The time now is 03:07.

vBulletin® Version 3.8.8