I am learning linux suid,so I have written a small c program with the following content to test it
#include<stdio.h>
int main(){
system("echo 100 >> test.txt");
return 0;
}
-rwsr-xr-x 1 root root 8004 Sep 10 16:19 test
test.txt
is a file which can only be modified by root
-rw-r----- 1 root root
If I run the test program with a user account, it should add 100
to the empty file.
But, it comes out:
sh:test.txt:Permission denied
Why?
echo 100 >> test.txt
toid -u
, what does that print?/bin/sh --version
?