I have two users first being ace and the second being ej
ace has a file in its home directory, which is a shell script, with the following permission set ( setuid i have used )
-rwsr--r-x 1 ace ace 15 Jan 20 05:18 /home/ace/myshellscript
the content of script is very simple, listed following
echo "`whoami`"
cat ./testPrevEsc
but if I try to read another file owned by the the ace (testPrevEsc) which I think i can do by just passing cat filename in the $1, i think i should be able to do it, irrespective of permission that is set for others, as long as the owner can read it, but I can't why ?
My understanding of setuid says, that the program or shell executes as its being executed by owner, instead of executing user ( ej in my case), so why cant I read the file and still getting whomai as ej instead of ace ? on the other hand doing sudo whoami works fine it give you root, not the user you are running, I think I'm missing something here.
echo "\whoami`"is silly, you could just runwhoami` directly. – ilkkachu Jan 20 '24 at 09:33