I've written and compiled a short program to allow any user to change the contents of my /sys/class/backlight/intel_backlight/brightness
file, but I fail to escalate their permissions. What could I be missing.
#include <stdio.h>
#include <stdlib.h>
#define FILENAME "/sys/class/backlight/intel_backlight/brightness"
int main (int argc, char * argv[])
{
int res;
setuid(0); // I didn't intend to keep this, but I included it just in case
printf("euid %d\n", geteuid());
system("whoami");
// Attempt to open FILENAME; print "Can't open..." on failure
}
Yet, whoami
consistently returns exampleuser
instead of root
, and the program consistently fails to open the output file.
I compile it and set the uid bit then run the program:
$ gcc -o example.bin example.c # compile
$ sudo chown root:root example.bin # set owner & group
$ sudo chmod 4770 example.bin # set uid bit
$ ./example.bin 75 # execute
euid 1000
exampleuser
Can't open output file /sys/class/backlight/intel_backlight/brightness
The target output file does exist:
$ ls -l /sys/class/backlight/intel_backlight/brightness
-rw-r--r-- 1 root root 4096 May 2 07:57 /sys/class/backlight/intel_backlight/brightness
I'm running Ubuntu 14.04 LTS
example.bin
is located mounted withnosuid
? Also, I suggestid -a
as a more comprehensive test command instead ofwhoami
. I am not sure but I thinkwho
and/orwhoami
obtain information fromutmp
which could cloud the facts.