gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:05:00 25 4
gpt4 key购买 nike

我想知道是否有一种方法可以使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com