shell_exec()子进程应该继承euid吗?

我以 root 身份运行 php-cli 7.3.19(在 Debian 10 Buster、linux 内核 4.19.0-8-amd64 上),在使用 posix_seteuid() 更改我的 euid 后,子进程应该继承我的 euid ?


我以为答案是肯定的,但是测试了一下,


root@devdb:/srv/http/easyad_branches# whoami

root

root@devdb:/srv/http/easyad_branches# id

uid=0(root) gid=0(root) groups=0(root)

root@devdb:/srv/http/easyad_branches# php -r ' \

var_dump(posix_seteuid(posix_getpwnam("www-data")["uid"])); \

var_dump(shell_exec("whoami;id")); \ 

posix_seteuid(0); \

var_dump(posix_setuid(posix_getpwnam("www-data")["uid"])); \ 

var_dump(shell_exec("whoami;id"));'

bool(true)

string(44) "root

uid=0(root) gid=0(root) groups=0(root)

"

bool(true)

string(53) "www-data

uid=33(www-data) gid=0(root) groups=0(root)

"

看起来 whoami 继承了我的uid因为它是euid,而不是继承我的euid因为它是euid,这是预期的行为吗?


换句话说,我得到了bool(true) root bool(true) www-data,但我预料到了bool(true) www-data bool(true) www-data,是我的期望错了,还是有其他事情发生?


皈依舞
浏览 96回答 1
1回答

qq_笑_17

看起来 whoami 继承了我的 uid 因为它是 euid,而不是继承了我的 euid 因为它是 euid,这是预期的行为吗?我对 PHP 不是 100% 确定,但在直接调用 Linux 系统调用的编程语言(例如 C 或 C++)中,这种行为是正常的。这种行为的一个众所周知的副作用是,将位设置set-euid为 shell 脚本是没有意义的(只要使用“正常”shell - 例如 bash -):shell(例如/bin/sh)将在设置为不同的 UID 的情况下启动euid,但由 shell 启动的程序将同时具有euid和uid设置为uidshell 的值,即启动脚本的用户的 UID...
打开App,查看更多内容
随时随地看视频慕课网APP