Suppose we are looking at the following scenario:
File saymyname.c (includes omitted)
int main(int argc, char** argv){
system("whoami");
}
Build and set permission bits:
cake@lie> gcc saymyname.c -o saymyname
cake@lie> sudo chown root:root saymyname
cake@lie> sudo chmod u+s saymyname
cake@lie> ./saymyname
cake
Every resource under the sun tells me that setting the s
permission on the user-column should make the program execute with the owner's privileges, not the calling user's. Why does system("whoami");
return cake
?
Modifying the program to set the UID manually like so:
int main(int argc, char** argv){
setuid(geteuid());
system("whoami");
}
Yields the expected result
cake@lie> ./saymyname
root
Some resources claim that the SUID and GUID bits are often ignored. Is this why the observed behavior occurs? If so, is there a way to make it behave as if it was executed by root without setuid(.)
?