【问题标题】:Setuid on scripts with C wrapper带有 C 包装器的脚本上的 Setuid
【发布时间】:2013-11-03 23:37:47
【问题描述】:

我只想使用具有 root 权限的 php 脚本和像 tutorial 这样的 C 包装器。

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:

#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:

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

index.php:

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

但是当在浏览器上运行 index.php 时我得到了这个错误:

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

谢谢

【问题讨论】:

标签: php c linux centos suid


【解决方案1】:

你应该在调用system()之前输入setgid(getegid()); setuid(geteuid())

作为旁注,在您的示例中设置文件权限的方式,您的“解决方案”是完全不安全的。任何用户都可以更改该setuid C 程序运行的.php 脚本的内容,然后使用C 程序以root 执行更改后的内容。

【讨论】:

    猜你喜欢
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2011-09-11
    相关资源
    最近更新 更多