I would like to run a Shell Script from within one of My Perl Scripts. Say I wanted to run the shell script “go.sh” how would I execute it from within my Perl Script, or what would the syntax be to kick it off? Preferably from within the Korn Shell.
be aware that you may be opening a huge security hole. Check your inputs thoroughly, or you may get spanked.
Any time you start a second process from inside a CGI, you must be deliberate how you spawn the second process and how you pass args to it. Anyone who can do a 'view source' on a HTML form can easily figure out how to pass extra args in with your inputs from the form.
Thanks for the advice goBoating, that was an interesting point that you made. For QA purposes, and to test the security of my web form what may one of these strings look like if someone was to pass extra args into it? I'd definitely like to test this out. Also, what do you figure to be a better alternative to kicking off the shell script from within the perl script?
As far as security, if your script input includes shell metacharacters which preemptively complete the expected command, and the input further contains other commands, then the perpetrator has gained access to the system with the privileges of the CGI uid. For instance, the Perl code @ans = `grep '$user_field' some.file`; given predicted input to the $user_field variable would simply perform grep on it. Given the user input to $user_field of ; rm -fr / ; would delete everything from the owner’s home directory (
Don't check for things which may break your code... match your input to exactly what it should look like if valid using regular expressions. Don't let any potentially invalid input be passed to your script; only accept what you know to be valid.
Enabling taint mode (#!/usr/bin/perl -T) will warn you if you have any dangerous system calls using data which has not been checked.
Sincerely,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.