suPHP 以 root 身份执行 PHP 脚本

发布于 2024-11-01 03:30:14 字数 1293 浏览 4 评论 0 原文

我创建了几个网站。现在我需要执行 root 任务。我创建了一个网络平台并安装了。 root 拥有 /var/private-www/ 中的所有脚本,并且它们已被 chmodded (0777)。在 /var/private-www/test.php 中: 。我的 suPHP 配置是这样的:

 [global]
;Path to logfile
logfile=/var/log/suphp/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=root

;Path all scripts have to be in
docroot=/var/private-www

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=false

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
umask=0077

; Minimum UID
min_uid=0

; Minimum GID
min_gid=0


[handlers]
;Handler for php-scripts
application/x-httpd-suphp="php:/usr/bin/php-cgi"

;Handler for CGI-scripts
x-suphp-cgi="execute:!self"

当我在浏览器中执行 test.php 时,它显示:www-data :(。不是 root...即使当我在命令行中执行它时,我也做了a2enmod suphpapachectl restart,所以我认为它会起作用。我该如何解决这个问题?

I have created several websites. Now I need to perform root tasks. I created a webplatform and installed. root owns all scripts in /var/private-www/ and they are chmodded (0777). In /var/private-www/test.php stands: <?php echo exec('whoami'); ?>. My suPHP config is this:

 [global]
;Path to logfile
logfile=/var/log/suphp/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=root

;Path all scripts have to be in
docroot=/var/private-www

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=false

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
umask=0077

; Minimum UID
min_uid=0

; Minimum GID
min_gid=0


[handlers]
;Handler for php-scripts
application/x-httpd-suphp="php:/usr/bin/php-cgi"

;Handler for CGI-scripts
x-suphp-cgi="execute:!self"

When I execute test.php in my webbrowser, it says: www-data :(. Not root... Even when I execute it in the command line. Besides, I did a2enmod suphp and apachectl restart, so I was thinking it would work. How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫烠⑼条掵仅有一顆心 2024-11-08 03:30:14

查看这些已知的 Web 应用程序攻击:OWASP。以 root 身份运行和 0777 权限都是您应该尽量避免的事情。

Take a look at these known web app attacks: OWASP. Running as root and 0777 permissions are both things you should try to avoid.

故事与诗 2024-11-08 03:30:14

简短的回答:不要这样做。

任何需要以 root 身份运行的任务都应该通过 cron 作业来完成。

无论如何,你为什么要这样做呢?

Short answer: Don't do this.

Any tasks that needs to be run a root, should be done via a cron job.

Why are you trying to it this way, anyway?

棒棒糖 2024-11-08 03:30:14

我会后悔这么说,而且我不想成为推动者,但是:

您可能需要 重新编译。最小 UID 和 GID 不仅仅是可配置项,在编译时也会进行最少的检查。也不能保证不存在针对以 root 身份运行的硬编码检查。

您确实应该考虑一种执行所需任务的替代方法,该方法不涉及公开以 root 身份运行的 Web 应用程序。定期运行的 cron 作业(检查未完成的任务)或工作队列服务可以轻松实现这些目标。然后,Web 公开的前端不需要以 root 身份运行。

I'm gonna regret saying this, and I don't want to be an enabler, but:

You're probably going to need to recompile. The minimum UID and GID aren't (just) configurable items, there are minimum checks made at compile time as well. There's also no guarantee that there aren't hard-coded checks against running as root.

You really should consider an alternative method of performing your desired tasks that does not involve exposing a web application running as root. A regularly running cron job that checks for uncompleted tasks or a work queue service can easily accomplish these goals. The web-exposed front-end then does not need to run as root.

被翻牌 2024-11-08 03:30:14

这不是您正在寻找的答案,但您应该考虑一下:

虽然在某些情况下您希望这样做,但以 root 身份运行所有 php 脚本通常是不好的做法,您可能会面临许多障碍。

避免这种情况的一种简单方法是使用 sudo。将您的命令添加到 www-data 的 sudoers 中,并让您的脚本使用 sudo 执行外部命令。

甚至外部 php 脚本也可以通过 sudo 以 root 身份运行。这样你就可以实现权限分离。

否则你将不得不以 root 身份运行 apache+modphp 或修改 suphp 的代码。

This is not the answer you are looking for, but you should consider this a bit:

Although there are cases where you would like to do so, running all your php scripts as root in general is bad practice and you may face a number of obstacles.

One easy way to avoid this is to use sudo. Add your commands to sudoers for www-data and let your scripts execute an external command with sudo.

Even external php scripts can be ran as root via sudo. This way you will achieve privilege separation.

Otherwise you will have to run apache+modphp as root or hack the code of suphp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文