When learning the system security in the ubuntu 20.04 on the VMware, I tried the set-uid operation and found the fllowing question:
With the excutable file catcall
compiled by the source code caltcall.c
:
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char* argv[]){
char *cat = "/bin/cat";
if(argc < 2){
printf("please type a file name.\n");
return 1;
}
char *command = malloc(strlen(cat) + strlen(argv[1] + 2));
sprintf(command, "%s %s",cat, argv[1]);
system(command);
return 0;
}
I complete the set-uid operation through the following codes:
$ sudo chown root catcall
$ sudo chmod 4755 catcall
When excuting the excutable file catcall
, I thought I can see the content of the file /etc/shadow
, for the 'catcall' has been set to the Set-Uid programme.
But the operation is denied when trying to access the etc/shadow
:
/bin/cat: /etc/shadow: Permission denied
Why did the set-uid operation failed?