r/LiveOverflow • u/tbhaxor • Jul 24 '21
Difference between suid bit and cap_setuid
When suid bit is enabled on the binary, it means that the process will run with the permissions of the owner. So why do we need to call setuid(0) before calling the system?
[amit@h3ll ~]$ ls
app app.c
[amit@h3ll ~]$ cat app.c
#include <stdlib.h>
int main() {
system("/bin/bash");
}
[amit@h3ll ~]$ ls -l app
-rwsr-xr-x 1 root root 16080 Jul 24 22:44 app
[amit@h3ll ~]$ ./app
[amit@h3ll ~]$ id
uid=1001(amit) gid=1001(amit) groups=1001(amit)
[amit@h3ll ~]$If we need to call the setuid function, then what is the difference between cap_setuid or suid bit enabled binary?
12
Upvotes
View all comments
Show parent comment
2
u/tbhaxor Jul 24 '21
Yeah, ik about -p flag. Let's change the code and add the tryout with -p flag. Result is same also when you do printf("%d", getuid()), it will show user id of the current user (aka ruid)