即使更新了 sudoers,PHP 网页也不会启动 unix 命令

发布于 2024-07-06 21:53:42 字数 2001 浏览 4 评论 0原文

基本上我正在尝试从 php 网页重新启动服务。

这是代码:

<?php
exec ('/usr/bin/sudo /etc/init.d/portmap restart');
?>

但是,在 /var/log/httpd/error_log 中,我得到

无法更改为 sudoers gid:不允许操作

,在 /var/log/messages 中,我得到

9 月 22 日 15:01:56 ri 内核:审核(1222063316.536:777):avc:拒绝 { getattr } for pid=4851 comm="sh" name="var" dev=dm-0 ino=114241 scontext=根:system_r:httpd_sys_script_t tcontext = system_u:object_r:var_t tclass = dir
9 月 22 日 15:01:56 ri 内核:审核(1222063316.549:778):avc:拒绝 { setrlimit } for pid=4851 comm="sudo" scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass=process< br> 9 月 22 日 15:01:56 ri 内核:审核(1222063316.565:779):avc:拒绝 { read } for pid=4851 comm="sudo" name="shadow" dev=dm-0 ino=379669 scontext=root:system_r :httpd_sys_script_t tcontext=system_u:object_r:shadow_t tclass=文件
9 月 22 日 15:01:56 ri 内核:审计(1222063316.568:780):avc:拒绝 { read } for pid=4851 comm="sudo" name="shadow" dev=dm-0 ino=379669 scontext=root:system_r :httpd_sys_script_t tcontext=system_u:object_r:shadow_t tclass=文件
9 月 22 日 15:01:56 ri 内核:审计(1222063316.571:781):avc:拒绝 { setgid } for pid=4851 comm="sudo"capability=6 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass =能力
9 月 22 日 15:01:56 ri 内核:审计(1222063316.574:782):avc:拒绝 { setuid } for pid=4851 comm="sudo"capability=7 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass =能力
9 月 22 日 15:01:56 ri 内核:审计(1222063316.577:783):avc:拒绝 { setgid } for pid=4851 comm="sudo"capability=6 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass =能力

在我的 visudo 中,我添加了这些行

User_Alias WWW=apache

WWW ALL=(全部)NOPASSWD:全部

你能帮我吗? 难道我做错了什么 ?

感谢您的帮助,

tiBoun

Basically I am trying to restart a service from a php web page.

Here is the code:

<?php
exec ('/usr/bin/sudo /etc/init.d/portmap restart');
?>

But, in /var/log/httpd/error_log, I get

unable to change to sudoers gid: Operation not permitted

and in /var/log/messages, I get

Sep 22 15:01:56 ri kernel: audit(1222063316.536:777): avc: denied { getattr } for pid=4851 comm="sh" name="var" dev=dm-0 ino=114241 scontext=root:system_r:httpd_sys_script_t tcontext=system_u:object_r:var_t tclass=dir
Sep 22 15:01:56 ri kernel: audit(1222063316.549:778): avc: denied { setrlimit } for pid=4851 comm="sudo" scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass=process
Sep 22 15:01:56 ri kernel: audit(1222063316.565:779): avc: denied { read } for pid=4851 comm="sudo" name="shadow" dev=dm-0 ino=379669 scontext=root:system_r:httpd_sys_script_t tcontext=system_u:object_r:shadow_t tclass=file
Sep 22 15:01:56 ri kernel: audit(1222063316.568:780): avc: denied { read } for pid=4851 comm="sudo" name="shadow" dev=dm-0 ino=379669 scontext=root:system_r:httpd_sys_script_t tcontext=system_u:object_r:shadow_t tclass=file
Sep 22 15:01:56 ri kernel: audit(1222063316.571:781): avc: denied { setgid } for pid=4851 comm="sudo" capability=6 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass=capability
Sep 22 15:01:56 ri kernel: audit(1222063316.574:782): avc: denied { setuid } for pid=4851 comm="sudo" capability=7 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass=capability
Sep 22 15:01:56 ri kernel: audit(1222063316.577:783): avc: denied { setgid } for pid=4851 comm="sudo" capability=6 scontext=root:system_r:httpd_sys_script_t tcontext=root:system_r:httpd_sys_script_t tclass=capability

In my visudo, I added those lines

User_Alias WWW=apache

WWW ALL=(ALL) NOPASSWD:ALL

Can you please help me ? Am I doing something wrong ?

Thanks for your help,

tiBoun

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

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

发布评论

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

评论(4

秋意浓 2024-07-13 21:53:42

目前问题不在于 sudo,而在于 SELinux,它(合理地)设置为拒绝 HTTPD 获取 root 权限。
您需要明确允许此操作(您可以使用 audit2allow 来实现此目的),或者将 SELinux 设置为相反,要宽容。 我建议前者。

The problem is not with sudo at the moment, but with SELinux, which is (reasonably) set to deny the HTTPD from gaining root privileges.
You will need to either explicitly allow this (you can use audit2allow for this), or set SELinux to be permissive instead. I'd suggest the former.

山有枢 2024-07-13 21:53:42

您收到的错误似乎与您的 SELinux 配置有关。 您可以尝试暂时禁用该功能。

顺便说一句,我强烈建议您调整 sudo 配置以使其更具限制性。

User_Alias WWW=apache
Cmnd_Alias WEBCMDS=/etc/init.d/portmap
WWW ALL=NOPASSWD: WEBCMDS

The error you are getting seems to be related to your SELinux configuration. You might try temporarily disabling that.

As an aside, I would strongly suggest that you adjust your sudo configuration to be more restrictive.

User_Alias WWW=apache
Cmnd_Alias WEBCMDS=/etc/init.d/portmap
WWW ALL=NOPASSWD: WEBCMDS
还不是爱你 2024-07-13 21:53:42

我最近遇到了这个问题,上面接受的答案有帮助。 但是,我想发布这个答案来详细说明相同的内容,以便下一个人不需要花费太多时间,就像我一样!

请遵循以下链接的第 7 部分:https://wiki.centos.org/HowTos/SELinux

使用 httpd_sys_script_t 执行 grep。

基本上步骤是:

# grep httpd_sys_script_t /var/log/audit/audit.log | audit2allow -M httpdallowsudo
# semodule -i httpdallowsudo.pp

I encountered the problem recently and the accepted answer above helped. However, I would like to post this answer to elaborate the same, so that the next person does not need to spend time much, like me!

Follow section 7 of the following link: https://wiki.centos.org/HowTos/SELinux.

Do grep with httpd_sys_script_t.

Basically the steps are:

# grep httpd_sys_script_t /var/log/audit/audit.log | audit2allow -M httpdallowsudo
# semodule -i httpdallowsudo.pp
说不完的你爱 2024-07-13 21:53:42

这可能是由于尝试在非交互式 shell 中执行 sudo 之类的原因。

如果您在 apache 用户邮件日志中对“sudo”执行 grep,您可能会发现类似这样的内容

sudo:抱歉,您必须有一个 tty 才能运行 sudo

This is probably down to something like trying to execute sudo in a non-interactive shell.

If you do a grep for 'sudo' in your apache users mail log you might find things like this

sudo: sorry, you must have a tty to run sudo

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