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?
In reply to Using exec() for executing shell scripts in CGI by stumbler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |