Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executing a shell script from within a cgi script 2

Status
Not open for further replies.

richy00

MIS
Nov 13, 2000
21
US
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.
 
you can use `` to execute commands or system();

there is a difference between them, i just don't remember what it is right now.
 
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.






keep the rudder amid ship and beware the odd typo
 
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?
 
Try: do "go.sh"; That may work as well.

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,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top