相关疑难解决方法(0)

允许在 shell 脚本上使用 setuid

setuid权限位告诉Linux与业主,而不是执行者的有效用户ID运行程序:

> cat setuid-test.c

#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv) {
    printf("%d", geteuid());
    return 0;
}

> gcc -o setuid-test setuid-test.c
> ./setuid-test

1000

> sudo chown nobody ./setuid-test; sudo chmod +s ./setuid-test
> ./setuid-test

65534
Run Code Online (Sandbox Code Playgroud)

但是,这仅适用于可执行文件;shell 脚本忽略 setuid 位:

> cat setuid-test2

#!/bin/bash
id -u

> ./setuid-test2

1000

> sudo chown nobody ./setuid-test2; sudo chmod +s ./setuid-test2
> ./setuid-test2

1000
Run Code Online (Sandbox Code Playgroud)

维基百科

由于安全漏洞的可能性增加,许多操作系统在应用于可执行 shell 脚本时会忽略 setuid 属性。

假设我愿意接受这些风险,有没有办法告诉 Linux 将 shell 脚本上的 setuid …

shell security scripting setuid

223
推荐指数
7
解决办法
18万
查看次数

setuid 位好像对 bash 没有影响

我进行了一些试验并注意到一些奇怪的事情:在位于 bash 的副本上设置 setuid 位/usr/bin/bash-test似乎没有效果。当我运行一个实例时bash-test,我的主目录没有设置为/root,当我whoami从运行命令时bash-test,我的用户名没有被报告为是root,这表明它bash-test没有以 root 身份运行。但是,如果我将 setuid 位设置为 on whoami,则正如预期的那样,我被报告为任何 shell 中的 root 用户。

我也尝试设置 setuid 位/usr/bin/bash并观察到相同的行为。

当我在其上设置 setuid 位时,为什么 bash 没有以 root 身份运行?selinux 可能与此有关吗?

linux bash setuid

15
推荐指数
1
解决办法
2万
查看次数

setuid root 不起作用

目标:以 root 身份运行程序(C++ 二进制文件)。同:SetUID 位在 Ubuntu 中不起作用?

并且:为什么 setuid 对可执行文件不起作用?

./a.out 输出:

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? psurana //output for "whoami" Look below for the code.

ls -l 输出:

-rwsrwxr-x 1 root root 46136 Jun 7 20:13 a.out

编码 :

#include <string>
#include <stdlib.h>
int main(int argc, char *argv[]){
        std::string input = "apt-get install " + std::string(argv[1]);
        system(input.c_str());
        system("whoami"); …
Run Code Online (Sandbox Code Playgroud)

linux setuid privileges

3
推荐指数
1
解决办法
2979
查看次数

标签 统计

setuid ×3

linux ×2

bash ×1

privileges ×1

scripting ×1

security ×1

shell ×1