stumbler has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I want to execute some programs from a CGI script. After browsing in perlmonks and reading perlsec, I found that I can use the following approach:-
die "Can't fork: $!" unless defined $pid = open(KID, "-|"); if ($pid) { # parent while (<KID>) { # do something } close KID; } else { exec 'myprog', 'arg1', 'arg2' or die "can't exec myprog: $!"; }
I have a shell script whose arguments are the path and the executable
Shell Script: #!/bin/ksh # print the arguments for checking # $1 is the directory # $2 is the executable echo $1 echo $2 # change dir to $1 cd $1 # execute $2 $2 echo "Exit"
and I execute that using 'exec' as shown
... ... $dir = 'some path'; # untainted $exe = 'some executable'; # untainted ... ... exec 'unixscript.sh', $dir, $exe ... ...
I am wondering if it is a good idea to execute unix shell scripts with some arguments as shown? I want to use this approach in CGI scripts to run executables from the web. ( Note that the 'executable' is preset inside the CGI script and IS NOT an user input.) Are there any security issues with this approach?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using exec() for executing shell scripts in CGI
by jarich (Curate) on Dec 14, 2006 at 12:17 UTC | |
|
Re: Using exec() for executing shell scripts in CGI
by leocharre (Priest) on Dec 14, 2006 at 06:10 UTC | |
by stumbler (Acolyte) on Dec 14, 2006 at 11:32 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |