stefl has asked for the wisdom of the Perl Monks concerning the following question:
Hi wise monks, after several days of going in circles I would like some help.
I have a webform (CGI) that I am developing, and after the user fills in various parts of the form, I need to copy a file from one server to another. I have a short sample code (that isn't CGI-based but may illustrate my problem) below:
#!/usr/bin/perl -w -T use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "<IP>", user => "<username>", raw_pty => 1 ); $ssh->run_ssh() or die "SSH Process couldn't start: $!"; $ssh->exec("stty raw -echo"); my $who = $ssh->exec("whoami"); print ($who); my $scp = "scp <file> <username>\@<IP Address>:<destinationpath>; $ssh->exec($scp) or die "SCP Process error: $!";
I understand that the taint flag isn't necessary in this short example, but it is required for the main application and I believe is causing most of my problems.
Prior to this attempt, I have also tried using system() to run the scp:
system('ssh <user>\@<IP> scp $file <user2>\@<Destination IP>:<destinat +ion path>');
This involved untainting all variables before this call. This attempt resulted in a slew of errors ("Can't exec 'ssh': No such file or directory", "sh: 1: ssh: not found").
I had read (although I may be wrong) that the Net::SSH::Expect module does not have full support for taint mode.
Also, as the script is generally being run from the web, the user for the commands is www-data (I don't know exactly what relevance this has, but it seems to be important, at least in my debugging attempts).
Thank you very much for any help or advice you can give. If more information is needed, I'm happy to provide it (I just can't think of anything else to include at the moment).
Cheers!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using SSH and SCP in a perl script with taint flag
by salva (Canon) on May 28, 2015 at 16:09 UTC | |
by stefl (Acolyte) on May 29, 2015 at 10:36 UTC | |
by salva (Canon) on May 29, 2015 at 11:01 UTC | |
by stefl (Acolyte) on May 29, 2015 at 14:20 UTC | |
by stefl (Acolyte) on May 29, 2015 at 13:31 UTC | |
by salva (Canon) on May 29, 2015 at 13:54 UTC | |
Re: Using SSH and SCP in a perl script with taint flag
by herveus (Prior) on May 28, 2015 at 15:40 UTC | |
by stefl (Acolyte) on May 28, 2015 at 16:03 UTC | |
by herveus (Prior) on May 29, 2015 at 13:37 UTC |