admin管理员组文章数量:1302328
When using exec() or proc_open() after posix_seteuid() or posix_setuid() I expected the resulting process to run as the UID I set inside the running script. This does not happen.
is this how it's supposed to work? I've worked around this by changing the user on the executed commandline, but it just seems like a security hole to change the UID and have exec() and proc_open() run things as root anyway.
Google searching has turned up nothing on this subject.
<?php
if (false === posix_setgid(1000)) echo "Could not setgid\n";
if (false === posix_setuid(1000)) echo "Could not setuid\n";
echo posix_getpwuid(posix_getuid())['name']."\n";
echo exec('echo $USER')."\n";
Was expecting:
# php test
ron
ron
Got instead:
# php test
ron
root
When using exec() or proc_open() after posix_seteuid() or posix_setuid() I expected the resulting process to run as the UID I set inside the running script. This does not happen.
is this how it's supposed to work? I've worked around this by changing the user on the executed commandline, but it just seems like a security hole to change the UID and have exec() and proc_open() run things as root anyway.
Google searching has turned up nothing on this subject.
<?php
if (false === posix_setgid(1000)) echo "Could not setgid\n";
if (false === posix_setuid(1000)) echo "Could not setuid\n";
echo posix_getpwuid(posix_getuid())['name']."\n";
echo exec('echo $USER')."\n";
Was expecting:
# php test
ron
ron
Got instead:
# php test
ron
root
2 Answers
Reset to default 2You should execute id -u
or whoami
command to inspect the current user. $USER
is an environment variable which is initialized by the login
command (see Who sets $USER and $USERNAME environment variables?). setuid
or seteuid
only changes the uid of the process.
It's because the exec()
and proc_open()
functions don't respect the changes made to the user ID (UID
) or group ID (GID
) with posix_setuid()
and posix_setgid()
within the PHP script.
You'll need to run the PHP script with the desired user privileges from the start, or explicitly specify the user in the command line
OR
You can use another methods like sudo
to control the user under which the command runs.
本文标签: posixPHP posixseteuid() and posixsetuid() not reflected in exec() or procopen()Stack Overflow
版权声明:本文标题:posix - PHP: posix_seteuid() and posix_setuid() not reflected in exec() or proc_open()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741680551a2392142.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论