Note that there are some explanatory texts on larger screens.

plurals
  1. PORun executable from php without spawning a shell
    primarykey
    data
    text
    <p>I need to call an executable from an imposed context of a PHP script. Both performance and security wise it's better not to call a shell at all between web server process and executable.</p> <p>Of course I searched the web, without success (in such a PHP context). Many other languages allow that and document it clearly.</p> <p>Alas, backticks, <code>exec()</code>, <code>shell_exec()</code>, <code>passthru()</code>, <code>system()</code>, <code>proc_open()</code>, <code>popen()</code> call a shell. And <code>pcntl_fork()</code> seems unavailable.</p> <h1>How to test if a function calls a shell or not.</h1> <p>This was tested on a Debian 6 64bit with PHP 5.3.3-7+squeeze15 . Test code on <a href="http://pastebin.com/y4C7MeJz" rel="noreferrer">http://pastebin.com/y4C7MeJz</a></p> <p>To get a meaningful test I used a trick which is to ask to execute a shell command not also available as an executable. A good example is <code>umask</code> . Any function returning something like 0022 definitely called a shell. <code>exec()</code>, <code>shell_exec()</code>, <code>passthru()</code>, <code>system()</code>, <code>proc_open()</code> all did. See detailed results on <a href="http://pastebin.com/RBcBz02F" rel="noreferrer">http://pastebin.com/RBcBz02F</a> .</p> <h1>pcntl_fork fails</h1> <p>Now, back the the goal : how to execute arbitrary program without launching a shell ?</p> <p>Php's exec takes as expected an array of string args instead of a unique string. But pcntl_fork just stops the requests without even a log.</p> <p>Edit: pcntl_fork failure is because the server uses Apache's mod_php, see <a href="http://www.php.net/manual/en/function.pcntl-fork.php#49949" rel="noreferrer">http://www.php.net/manual/en/function.pcntl-fork.php#49949</a> .</p> <p>Edit: added <code>popen()</code> to the tests, following @hakre suggestion.</p> <p>Any hint appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload