Question: Task 8 : Invoking External Programs Using system ( ) versus execve ( ) Although system ( ) and execve ( ) can both be
Task : Invoking External Programs Using system versus execve
Although system and execve can both be used to run new programs, system is quite danger
ous if used in a privileged program, such as SetUID programs. We have seen how the PATH environment
variable affect the behavior of system because the variable affects how the shell works. execve
does not have the problem, because it does not invoke shell. Invoking shell has another dangerous conse
quence, and this time, it has nothing to do with environment variables. Let us look at the following scenario.
Bob works for an auditing agency, and he needs to investigate a company for a suspected fraud. For
the investigation purpose, Bob needs to be able to read all the files in the companys Unix system; on the
other hand, to protect the integrity of the system, Bob should not be able to modify any file. To achieve this
goal, Vince, the superuser of the system, wrote a special setrootuid program see below and then gave the
executable permission to Bob. This program requires Bob to type a file name at the command line, and then
it will run bincat to display the specified file. Since the program is running as a root, it can display any
f
ile Bob specifies. However, since the program has no write operations, Vince is very sure that Bob cannot
use this special program to modify any file.
Listing : catall.c
int mainint argc, char argv
char v;
char command;
ifargc
printfPlease type a file name.
;
return ;
vbincat; v argv; v NULL;
command mallocstrlenv strlenv;
sprintfcommands s v v;
Use only one of the followings.
systemcommand;
execvev v NULL;
Environment Variable and SetUID Program Lab
CIS
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
