简体   繁体   中英

How to execute program in chrooted PHP-FPM?

I am now writing a small script to execute gpg from PHP (FPM) but somehow PHP does not allow me to execute any binary/shell script and return exit code 127 . But if I execute those in php-cli it works just fine.

PHP Configuration:

PHP: php-fpm

Webserver: nginx

chroot /user/home/php-root

chdir /

Safemode Off

Disable exec* ?: No

I tried the ff:

  1. I have tried execute exec('whoami') or ls all return NULL and gives exitcode 127
  2. shell_exec() all commands return NULL
  3. system() also return NULL
  4. Use full path
  5. Use 2>&1 return NULL
  6. Copy gpg , whoami in chrooted-root/bin
  7. Execute binary from chrooted-root/bin

As far as I tried, nothing works.

Are there anyone able to make PHP-FPM execute shell/binary in chrooted environment?

Thank you very much!

I found that copying /bin/sh to chrooted-root/bin worked. Also needed dependencies:

$ ldd /bin/sh
    linux-vdso.so.1 (0x00007ffc098c6000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2e92d52000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f2e9331e000)

So I had to copy /lib/x86_64-linux-gnu/libc.so.6 and /lib64/ld-linux-x86-64.so.2 under my chrooted directory.

I'm not sure if it's /bin/sh under all distros, might be /bin/bash or something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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