In: Computer Science
int main()
{
system("ls");
return 0;
}
Please compile the above program, and change its owner to root, and make it a Set-UID program. Can you let this Set-UID program run your code instead of /bin/ls? If you can, is your code running with the root privilege? Describe and explain your observations.
To change the file permission use chmod command to give the permission to the file.
in the command prompt enter the chmod u+s "File_Name.c". It will set the UID of the file
The code is not running with root privilege. But the file is running with the root privilege.
//include the header file
#include<stdio.h>
#include <stdlib.h>
int main()
{
system("ls"); //it will execute the command
return 0;
}
USER$ ls -l systemLSS.c
---------- 1 USER staff 134 Sep 15 19:08 systemLSS.c
USER$ chmod u+s systemLSS.c
USER$ ls -l systemLSS.c
---S------ 1 USER staff 134 Sep 15 19:08 systemLSS.c
USER$ gcc systemLSS.c -o systemLSS
error: error reading 'systemLSS.c'
1 error generated.
Enter the command with sudo to run the program and enter
the root password
USER$ sudo gcc systemLSS.c -o systemLSS
Password:
Run the program to list the file in the directory which
the user has the file
USER$ ./systemLSS
Animal
filreadwrite.c
AnimalBirdChoose.cpp
filreadwrite.layout
ArraySum.cpp
filreadwrite.o