shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

mansoor
Hi,
I am using OpenBSD 6.4 and php version 5.6, I am trying to execute shell
commands through php file using exec, shell_exec or system (tried all of
them) but none is working.

Here is a sample code in my index.php file.

<?php
$output = shell_exec('ls -l');
echo "<pre>$output</pre>";
?>

Here is  link
<https://stackoverflow.com/questions/56933389/run-exec-system-etc-command-using-php-openbsd>
to my stackoverflow question.

I am stuck in this problem for about a week now.
Please help me if anyone know about this.
Thanks



--
Sent from: http://openbsd-archive.7691.n7.nabble.com/openbsd-user-misc-f3.html

Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

Edgar Pettijohn III-2

On Jul 9, 2019 4:40 AM, mansoor <[hidden email]> wrote:

>
> Hi,
> I am using OpenBSD 6.4 and php version 5.6, I am trying to execute shell
> commands through php file using exec, shell_exec or system (tried all of
> them) but none is working.
>
> Here is a sample code in my index.php file.
>
> <?php
> $output = shell_exec('ls -l');
> echo "<pre>$output</pre>";
> ?>
>
> Here isĀ  link
> <https://stackoverflow.com/questions/56933389/run-exec-system-etc-command-using-php-openbsd>
> to my stackoverflow question.
>
> I am stuck in this problem for about a week now.
> Please help me if anyone know about this.
> Thanks
>
>
>
> --
> Sent from: http://openbsd-archive.7691.n7.nabble.com/openbsd-user-misc-f3.html
>

Is it possibly a chroot issue? Not sure what http server you are using.

Edgar

Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

Martijn van Duren-6
In reply to this post by mansoor
On 7/9/19 11:40 AM, mansoor wrote:

> Hi,
> I am using OpenBSD 6.4 and php version 5.6, I am trying to execute shell
> commands through php file using exec, shell_exec or system (tried all of
> them) but none is working.
>
> Here is a sample code in my index.php file.
>
> <?php
> $output = shell_exec('ls -l');
> echo "<pre>$output</pre>";
> ?>

It's almost never a good idea to use shell_exec or system.
In this case I'd advise to use opendir+readdir and stat if you need the
file metadata.
>
> Here is  link
> <https://stackoverflow.com/questions/56933389/run-exec-system-etc-command-using-php-openbsd>
> to my stackoverflow question.
>
> I am stuck in this problem for about a week now.
> Please help me if anyone know about this.
> Thanks

You haven't given enough information for a definitive answer, but my
guess is that you run php through php-fpm, which is by default chrooted
to /var/www. Since shell_exec and system first call /bin/sh and you
most likely didn't copy it to /var/www/bin/sh it can't find your shell.
After that you'd also need to copy the binaries (in this case ls) to
your chroot and possible library dependencies (not needed for files
under /bin).

Hope this helps for illustrative purposes, but please don't use it in
production.

martijn@
>
>
>
> --
> Sent from: http://openbsd-archive.7691.n7.nabble.com/openbsd-user-misc-f3.html
>

Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

Allan Streib-2
Martijn van Duren <[hidden email]> writes:

> You haven't given enough information for a definitive answer, but my
> guess is that you run php through php-fpm, which is by default chrooted
> to /var/www. Since shell_exec and system first call /bin/sh and you
> most likely didn't copy it to /var/www/bin/sh it can't find your shell.
> After that you'd also need to copy the binaries (in this case ls) to
> your chroot and possible library dependencies (not needed for files
> under /bin).
>
> Hope this helps for illustrative purposes, but please don't use it in
> production.

Agree this is likely the problem, unfortunately in PHP-land sometimes
you can't avoid it. For platforms such as Drupal (just to pick an
example I am familiar with) some of the modules will run shell commands
to do things such as send email.

Allan

Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

Kevin Chadwick-4

>Agree this is likely the problem, unfortunately in PHP-land sometimes
>you can't avoid it. For platforms such as Drupal (just to pick an
>example I am familiar with) some of the modules will run shell commands
>to do things such as send email.
>
>Allan

The php mail() function runs /bin/sh sendmail. I used to replace /bin/sh in the chroot but I've moved to golang now :)


Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

Tom Smyth
Roman has, a nice mail setup on his blog that
describes sending mails without exec IIRC
https://www.romanzolotarev.com/

another alternative is to use postifx and maildrop folders or postdrop
folder ...  I hope this helps

Tom Smyth

On Wed, 10 Jul 2019 at 00:31, Kevin Chadwick <[hidden email]> wrote:

>
> >Agree this is likely the problem, unfortunately in PHP-land sometimes
> >you can't avoid it. For platforms such as Drupal (just to pick an
> >example I am familiar with) some of the modules will run shell commands
> >to do things such as send email.
> >
> >Allan
>
> The php mail() function runs /bin/sh sendmail. I used to replace /bin/sh
> in the chroot but I've moved to golang now :)
>
>
>

--
Kindest regards,
Tom Smyth.
Reply | Threaded
Open this post in threaded view
|

Re: shell_exec() exec() and system() not working in php 5.6 openbsd 6.4

mansoor
In reply to this post by Martijn van Duren-6
Thanks a lot this was the problem.



--
Sent from: http://openbsd-archive.7691.n7.nabble.com/openbsd-user-misc-f3.html