无法在 php 的 system() 中更改用户

发布于 2024-11-05 20:51:14 字数 389 浏览 4 评论 0原文

我的命令是

echo root_password | sudo -u root -S executable_full_path arguments

我在浏览器中收到的错误消息是

[sudo] www-data 的密码:抱歉, 再试一次。

从 phpinfo() 来看,安全模式已关闭,并且没有禁用的功能。为什么这不起作用?相同的命令在 shell (bash) 中运行良好。 escapeshellarg 和 escapeshellcmd 没有区别。

编辑:仅仅能够执行命令是不够的。执行的程序在/tmp中创建一个套接字,并需要为其分配权限。所以我认为我真的需要对此表示支持,这可能吗?

My command is

echo root_password | sudo -u root -S executable_full_path arguments

The error message I get in the browser is

[sudo] password for www-data: Sorry,
try again.

From phpinfo(), safe mode is off and there are no disabled functions. Why isn't this working? The same command runs fine in the shell (bash). Escapeshellarg and escapeshellcmd don't make a difference.

EDIT: Simply being able to execute the command is not enough. The program that gets executed creates a socket in /tmp, and needs to assign it permissions. So I think I really need to be root for this, is that possible?

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

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

发布评论

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

评论(3

鸠魁 2024-11-12 20:51:14

正如阿尔瓦罗建议的那样,我将我的评论作为答案。马特,这将使以 root 身份运行该命令成为可能。

@Matt,不要这样做 /etc/sudoers (顺便说一句,您可以使用 visudo 命令编辑此文件,而不是直接编辑)。通过这种方式,您的 Web 应用程序运行的任何 sudowhat 命令都可以由 root 运行,如果攻击者在您的应用程序中发现漏洞,那么他可能会获得很多乐趣。

如果您只想以 root 身份运行一个命令而不需要密码,请将其放入 /etc/sudoers 中(记住 visudo 命令):

www-data ALL=(ALL) NOPASSWD: executable_full_path

那么您只允许执行只需以 root 身份执行此命令即可。现在您应该

sudo -u root executable_full_path arguments

无需输入密码即可完成操作(并且它将以 root 身份运行)。此外,这是用户 www-data 可以使用 sudo 以 root 身份执行的唯一命令,因此它应该不会有危险。

As Álvaro suggested, I'm putting my comment as answer. Matt, this would make it possible to run that command as root.

@Matt, don't do that /etc/sudoers (btw, you edit this file with the visudo command, never directly). That way you are making possible that any sudo whatever command run by your web application is run by root, possibiliting a lot of fun for an attacker if he founds a vulnerability in your application.

If you would like to run just ONE command as root without need for passwords, put this in /etc/sudoers (remember visudo command):

www-data ALL=(ALL) NOPASSWD: executable_full_path

Then you are only allowing to execute just this command as root. Now you should be able to do

sudo -u root executable_full_path arguments

without need to type in a password (and it will run as root). Also, this is the only command the user www-data may execute as root using sudo, so it should not be dangerous.

知你几分 2024-11-12 20:51:14

当您应该回显 www-data 的密码时,您却回显了 root 密码。

You're echoing the root password when you should be echoing the password for www-data.

邮友 2024-11-12 20:51:14

在 /ets/sudoers 上使用它
运行 gconftool-2 的示例:

www-data ALL=NOPASSWD: /usr/bin/gconftool-2
www-data ALL=NOPASSWD: /usr/bin/sudo
www-data ALL=NOPASSWD: ALL

Use this on your /ets/sudoers
Example for run gconftool-2 :

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