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