即使更新了sudoers,PHP网页也不会启动Unix命令
时间:2020-03-06 14:31:43 来源:igfitidea点击:
基本上,我试图从php网页重新启动服务。
这是代码:
<?php exec ('/usr/bin/sudo /etc/init.d/portmap restart'); ?>
但是,在/ var / log / httpd / error_log
中,我得到了
unable to change to sudoers gid: Operation not permitted
在/ var / log / messages中,我得到了
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
在我的visudo中,我添加了这些行
User_Alias WWW=apache WWW ALL=(ALL) NOPASSWD:ALL
你能帮我么 ?难道我做错了什么 ?
谢谢你的帮助,
tiBoun
解决方案
我们收到的错误似乎与SELinux配置有关。我们可以尝试暂时禁用它。
顺便说一句,我强烈建议我们调整sudo配置,使其更具限制性。
User_Alias WWW=apache Cmnd_Alias WEBCMDS=/etc/init.d/portmap WWW ALL=NOPASSWD: WEBCMDS
这可能归结为试图在非交互式shell中执行sudo之类的事情。
如果我们在apache用户邮件日志中为'sudo'做grep,我们可能会发现类似这样的内容
sudo: sorry, you must have a tty to run sudo
现在的问题不在于sudo,而在于SELinux,它被(合理地)设置为拒绝HTTPD获得root特权。
我们将需要明确允许这样做(可以为此使用audit2allow),或者将SELinux设置为允许。我建议前者。