简体   繁体   English

在nginx上使用PHP-FPM执行exec(在chroot下)不返回任何内容

[英]Exec with PHP-FPM on nginx (under chroot) returns nothing

I've created a nginx server in a chroot at /srv/http with php-fpm. 我用php-fpm在/ srv / http的chroot中创建了一个nginx服务器。 Both services use the http user and it works fine. 两个服务都使用http用户,它工作正常。 The problem comes when I try to run an exec command such as 当我尝试运行诸如的exec命令时出现问题

echo shell_exec('/usr/bin/ls');

There is no output at all on the web page or in the errors. 网页或错误中根本没有输出。 I've also tried 我也试过了

error_log(shell_exec('/usr/bin/ls');

and still nothing. 但仍然没有。

Things I've Tried or Know: 我尝试或知道的事情:

  1. safe mode off 安全模式关闭
  2. exec enabled exec启用
  3. user is http (using phpinfo()) user是http(使用phpinfo())
  4. display_errors = on display_errors = on
  5. error_reporting = E_ALL error_reporting = E_ALL
  6. sudo /usr/bin/chroot --userspec=http:http /srv/http ls works fine sudo / usr / bin / chroot --userspec = http:http / srv / http ls工作正常
  7. Can create file and read from it using file_puts_content and fopen/fread 可以使用file_puts_content和fopen / fread创建文件并从中读取
  8. tried shell_exec,exec,system, and passthrough - nothing worked 尝试过shell_exec,exec,system和passthrough - 没什么用
  9. tried appending 2>&1 to the end of the command and nothing 尝试将2>&1附加到命令的末尾,什么也没有
  10. I've copied all the executables and libraries necessary over 我已经复制了所有必需的可执行文件和库
  11. all libraries, binaries, and everything under /srv/http/www (where the webpages are) have executable and read permissions 所有库,二进制文件和/ srv / http / www(网页所在的位置)下的所有内容都具有可执行和读取权限
  12. doc_root is www doc_root是www

As far as I know, everything works in the chroot, except shell commands through php-fpm. 据我所知,除了通过php-fpm的shell命令外,一切都在chroot中工作。 Anyone have any idea where I went wrong and how to fix it? 任何人都知道我哪里出错了以及如何解决它?

This may sound stupid but you must just copy /bin/sh (not /bin/bash !) to you chroot . 这可能听起来很愚蠢,但你必须将/bin/sh (不是/bin/bash !)复制到chroot

For example see this question: How do I change the shell for php's exec() 例如,看到这个问题: 如何更改php的exec()的shell

If you chroot to some directory, then this directory becomes the root for all your PHP scripts. 如果你chroot到某个目录,那么这个目录将成为所有PHP脚本的根目录。 That means, that if you execute /usr/bin/ls from within PHP, it will try to exectue /srv/http/usr/bin/ls instead. 这意味着,如果你从PHP中执行/usr/bin/ls ,它将尝试exectue /srv/http/usr/bin/ls

You can copy the executable to that directory - but be aware of the security implications. 您可以将可执行文件复制到该目录 - 但请注意安全隐患。 If you copy critical system executables into the chrooted directory you basically bypass the positive effects of chroot . 如果将关键系统可执行文件复制到chrooted目录中,则基本上可以绕过chroot的正面影响。

I get no output for 我没有输出

echo shell_exec('/usr/bin/ls');

either. 无论是。 Presumably because ls isn't a file but a built-in command. 大概是因为ls不是文件而是内置命令。 Running: 运行:

echo shell_exec('ls');

outputs: 输出:

css demos favicon.ico images js path.php robots.txt routing.php test css demos favicon.ico图片js path.php robots.txt routing.php test

which is the list of files in my root directory for the site. 这是该站点的根目录中的文件列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM