【问题标题】:Httpd + /bin/false == system() ?httpd + /bin/false == system() ?
【发布时间】:2011-12-02 13:17:47
【问题描述】:

我有两个网络服务器,都在 Lighttpd + php 上(通过 fastCGI)。

[user@box ~]$ lighttpd -v
lighttpd/1.4.29 (ssl) - a light and fast webserver
Build-Date: Aug  7 2011 10:52:01
[user@box ~]$ php -v
PHP 5.3.8 with Suhosin-Patch (cli) (built: Sep 30 2011 05:34:36) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
[user@box ~]$ php-cgi -v
PHP 5.3.8 with Suhosin-Patch (cgi-fcgi) (built: Sep 30 2011 05:35:14)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

Lighttpd 和 php-cgi 在用户 'http' 下使用 /bin/false(伪造的)shell 运行:

[user@box ~]$ cat /etc/passwd | grep http
http:x:33:33:http:/srv/http:/bin/false
[user@box ~]$ ps aux | grep "lighttpd\_php-cgi"
http      1291  0.0  1.1   5152  2816 tty1     S    Oct06   0:00 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
http      1292  0.0  1.5  14476  3904 ?        Ss   Oct06   0:00 /usr/bin/php-cgi

但是我仍然可以通过php的system()函数执行shell命令(例如)!

我的 php.ini 中没有 disable_functions。 如果我通过 php 执行 system("whoami")system("id") ,我会得到以下信息:

http
uid=33(http) gid=33(http) groups=33(http)

(必须如此)。

为什么我可以使用 /bin/false 作为 shell 执行用户的命令?

【问题讨论】:

    标签: php security lighttpd


    【解决方案1】:

    正如documentation 中明确指出的那样,php 的system 只是C 中系统的绑定。来自系统的manpage

    system()通过调用/bin/sh -c command来执行command中指定的命令...

    /bin/false 只是登录 shell(与login、telnet、ssh 等结合使用)。

    【讨论】:

      【解决方案2】:

      /bin/false 与这里无关。您无法通过更改用户的 shell 来控制对系统命令的访问,因为它们根本不是通过 shell 执行的。阅读更多here

      【讨论】:

      • 哦,不知道。谢谢,我会记住的!
      猜你喜欢
      • 2014-05-04
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 1970-01-01
      相关资源
      最近更新 更多