I was wondering if there is a way to drop privileges using a suid binary (using Ubuntu 18.04). Look:
# 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)
Is there an explanation of why one can gain privileges but not drop them with suid binaries?
You may be wondering what I'm trying to accomplish, but it's only to learn.
Thanks!
This works in the general case:
bash
is a special case. From the "INVOCATION" section ofbash
manual, with added emphasis on the relevant portion:Passing the
-p
(privileged) flag will indeed suppress this behavior: