linux - 无法使用 suid 二进制文件删除特权?

标签 linux suid

我想知道是否有一种方法可以使用 suid 二进制文件(使用 Ubuntu 18.04)来删除特权。看:

# cp /bin/bash .
# chown www-data bash
# chmod 4700 bash
# ls -lh
-rws------ 1 www-data root 1,1M abr  4  2018 bash
# ./bash
# id
uid=0(root) gid=0(root) groups=0(root)

是否有关于为什么可以使用 suid 二进制文件获得特权但不能放弃特权的解释?

您可能想知道我要完成什么,但这只是为了学习。

谢谢!

最佳答案

这在一般情况下有效:

# cp /usr/bin/id .
# chown www-data id
# chmod 4700 id
# ./id
uid=0(root) gid=0(root) euid=33(www-data) groups=0(root)

bash 是一个特例。来自 bash 手册的“INVOCATION”部分,并强调了相关部分:

If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.

传递 -p(特权)标志确实会抑制这种行为:

# cp /bin/bash .
# chown www-data bash
# chmod 4700 bash
# ./bash -p
bash-4.4$ id
uid=0(root) gid=0(root) euid=33(www-data) groups=0(root)

关于linux - 无法使用 suid 二进制文件删除特权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53179739/

相关文章:

c - 如何将 fork() 移植到 Vxwork

linux - 用适当数量的 "*"替换偶数词

c - 在 Apache 下运行 SUID C 脚本

c - 为什么我自己的 suid-ed 程序仍然保留原来的 uid?

linux - 在 linux 中只获取文件名(不包括路径名)和记录数

c - 内核空间的Linux UDP获取sockaddr_in

linux - 从 CUPS 打印 Windows (samba) 打印队列的作业状态

linux - 为什么许多 Linux 发行版使用 setuid 而不是功能?

linux - suid和其他权限(世界权限)有什么区别?

c++ - 如何从 C++ 程序内部重新启动 Linux?