Perl $ENV{PATH} Issue

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

Perl $ENV{PATH} Issue

Postby arijit » Fri Aug 23, 2013 8:47 am

Greetings!

We've run into this interesting scenario while working with SSH2 to execute commands inside a chrooted environment.

Step 1:

Do an ssh into the user's account from the shell, e.g.
Code: Select all
~$ ssh jailuser@localhost


Then execute a perl script, which basically prints out the $ENV variables.

Code: Select all
#!/usr/bin/env perl

foreach my $key (sort keys %ENV) {
  print "\$ENV{$key} = $ENV{$key}\n";
}


The script outputs:
Code: Select all

$ENV{LS_COLORS} =
$ENV{PATH} = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ENV{PWD} = /home/jailuser
$ENV{SHELL} = /bin/bash
$ENV{SHLVL} = 1
$ENV{USER} = jailuser
$ENV{USERNAME} = jailuser
$ENV{_} = ./test.pl



So far so good.

Step 2:

We attempt to do the same, but this time through the PHP SSH2 Library. E.g.

Code: Select all
$con->exec('./test.pl');


The login works perfectly. However, the output is as below:

Code: Select all
$ENV{HOME} = /home/jailuser
$ENV{PWD} = /home/proggui/jailuser
$ENV{SHELL} = /bin/bash
$ENV{SHLVL} = 1
$ENV{USER} = jailuser
$ENV{USERNAME} = jailuser
$ENV{_} = ./test.pl


Note the missing $ENV{PATH} variable. Any idea as to what makes this happen?

Thanking you for your consideration in advance.
arijit
Traveler
 
Posts: 4
Joined: Tue Aug 20, 2013 10:44 am

Re: Perl $ENV{PATH} Issue

Postby TerraFrost » Fri Aug 23, 2013 2:19 pm

Could be that it needs a PTY or could be that it needs a full blown interactive shell for that variable to populate.

You can do PTY with exec() but it does work a little differently. exec() without PTY closes immediately so all the output is available in one go. With a PTY it may block until more input is provided. Examples can be found here:

http://phpseclib.sourceforge.net/ssh/pty.html

Here's an example of how to use an interactive shell:

http://phpseclib.sourceforge.net/ssh/ex ... nteractive
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Perl $ENV{PATH} Issue

Postby arijit » Sat Aug 24, 2013 6:52 am

Thank you, once again, for your prompt response. I shall surely check out the examples.

However, we did successfully implement the same exec() implementation on CentOS earlier and did not need to use interactive shells. This time we've run into issues while working on Ubuntu. Could it be an issue with system-level PATH definitions, as opposed to the absence of an interactive shell?
arijit
Traveler
 
Posts: 4
Joined: Tue Aug 20, 2013 10:44 am

Re: Perl $ENV{PATH} Issue

Postby TerraFrost » Sun Aug 25, 2013 7:27 am

arijit wrote:However, we did successfully implement the same exec() implementation on CentOS earlier and did not need to use interactive shells. This time we've run into issues while working on Ubuntu. Could it be an issue with system-level PATH definitions, as opposed to the absence of an interactive shell?

Could be.. that's more of a Linux issue I'd say.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 1 guest

cron