慕村225694
在尝试之前,请阅读整个文章,然后进行选择。使用二进制包装器(带有suid位)的解决方案1)创建一个脚本(最好是.sh),其中包含要作为root用户运行的脚本。# cat > php_shell.sh < wrapper.c < #include #include int main (int argc, char *argv[]) { setuid (0); /* WARNING: Only use an absolute path to the script to execute, * a malicious user might fool the binary and execute * arbitary commands if not. * */ system ("/bin/sh /path/to/php_shell.sh"); return 0; }CONTENT4)编译并设置适当的权限,包括suid位(假设它应以root特权运行):# gcc wrapper.c -o php_root# chown root php_root# chmod u=rwx,go=xr,+s php_rootphp_root现在将以root权限运行,并执行中指定的命令php_shell.sh。如果您不需要轻松更改将要执行的命令的选项,建议您直接在wrapper.c步骤4下编写这些命令。然后,您无需让二进制文件执行外部脚本来执行所讨论的命令。在中wrapper.c,用于system ("your shell command here");指定您要执行的命令。