php - 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
,我的期望是错的,还是发生了其他事情?
解决方案
似乎whoami继承了我的uid,因为它是euid,而不是继承我的euid,因为它是euid,这是预期的行为吗?
我不是 100% 确定 PHP,但是在直接调用 Linux 系统调用(例如 C 或 C++)的编程语言中,这种行为是正常的。
这种行为的一个众所周知的副作用是将该set-euid
位设置为 shell 脚本没有意义(只要使用“普通”shell - 例如 bash - ):
外壳程序(例如/bin/sh
)将启动时euid
设置为不同的 UID,但外壳程序启动的程序将同时具有euid
并uid
设置为外壳程序的uid
值,即启动脚本的用户的 UID...
推荐阅读
- php - 无法在存档循环中隐藏类别
- mongodb - 反编译 APK:更改服务器 URL
- javascript - 使用 ThemeProvider 的 Material UI Palette 自定义颜色
- hyperledger-fabric - 错误:无法读取块:&{NOT_FOUND}
- python - 在 PyJWT 库中验证 JWT 令牌签名而不对其进行解码
- javascript - 路线更改时,绘制箱线图无法正确重新布局
- python - 外键不匹配 - “app_employee”引用“app_mycustomeuser”
- c - 如何为阵列板制作保存/加载功能?在 C 中
- spring-integration - 我的集成流程和 tasklet 出了什么问题
- excel-match - 匹配部分文本并替换为excel中的另一个文本