Suppose I have a vulnerable SUID program belonging to the user Bob, which is executable by all users.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
const char* s = getenv("USER"); // for debugging
printf("%s\n", s); // for debugging
char cmd[256] = "/home/bob/hello.sh $USER"; //hello.sh prints "Hello world"
execl("/bin/bash", "bash", "-p", "-c", cmd, NULL);
return 0;
}
I want to use the fact that the command it runs has the USER environment variable appended to it, to read a file that only Bob can see. For example, if I set USER to ";cat /home/bob/secret-file"
env USER=";cat /home/bob/secret-file" ./program
This does not run and only returns:
;cat /home/bob/secret-file
Hello world
The second command never runs, despite the USER environment variable changing.
Without editing the C code, how can I run a command such as 'cat' using the USER environment variable to run it with bob's permissions (because the program is SUID) and view files only bob can see.