简体   繁体   English

使用C包装程序在脚本上设置Setuid

[英]Setuid on scripts with C wrapper

i've just want to use a php script with root permission with a C wrapper like this tutorial . 我只想使用带有root权限的php脚本,并像本教程一样使用C包装程序。

ls -l : ls -l:

-rwsr-xr-x. 1 root root 6466 Aug 15 03:07 createConfig
-rwxrwxrwx. 1 root root  102 Aug 15 04:23 test.php
-rw-r--r--. 1 root root  822 Aug 14 21:35 index.php

createConfig.c : createConfig.c:

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main(void) {
    system("/usr/bin/php /var/www/html/test.php");
    return 0;
}

test.php : test.php:

<?php
mkdir("/root/ourDir");
?>

index.php : index.php:

<?php
exec("/var/www/html/createConfig");
?>

but when run index.php on browser i got this error : 但是在浏览器上运行index.php时出现此错误:

sh: /var/www/html/createConfig: Permission denied

Thanks 谢谢

You should put setgid(getegid()); setuid(geteuid()) 你应该把setgid(getegid()); setuid(geteuid()) setgid(getegid()); setuid(geteuid()) before calling system() . setgid(getegid()); setuid(geteuid())在调用system()之前。

As a side-note, the way the file permissions are set up in your example, your "solution" is totally unsecure. 附带说明一下,在示例中设置文件权限的方式,您的“解决方案”是完全不安全的。 Any user can change the contents of the .php script to be run by that setuid C program, and then use the C program to execute the changed contents as root . 任何用户都可以更改该setuid C程序要运行的.php脚本的内容,然后使用C程序以root身份执行更改的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM