作者hth9494 (掰掰惹 仙度瑞拉)
看板Linux
标题[问题] setuid bit疑问
时间Tue Feb 5 20:37:16 2019
我有两个用户tenghaooo和user1
首先用户tenghaooo在自家目录新创一个文字档file
并将其权限改为640
-rw-r----- 1 tenghaooo tenghaooo 9 Feb 5 19:45 file
然後再编译一个C档 test.c,源码如下
#include <stdlib.h>
int main(void) {
system("/bin/cat file");
return 0;
}
编译後的a.out改其权限为4755
-rwsr-xr-x 1 tenghaooo tenghaooo 8304 Feb 5 20:04 a.out
最後切换用户成user1,到tenghaooo家目录里执行a.out
结果无法成功看见file内容
/bin/cat: file: Permission denied
我以为由於a.out setuid bit的缘故,当user1执行a.out时,权限会变成tenghaooo
进而能够看见file内容
但似乎不是如此
希望各位大大解说一下setuid bit的运作方式
谢谢,新年快乐
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.164.30.88
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1549370242.A.024.html
1F:推 lantw44: 有些 shell 在启动时会主动把 setuid bit 拿掉以免意外 02/05 23:20
2F:→ lantw44: 可以试试看不要用 system 以避开 shell 02/05 23:21
3F:→ kenduest: 若是还要用 system(), 一般土炮方式 setuid(0) 补上 02/08 23:09
4F:推 Ryu3y3s: setreuid() 02/09 10:31
5F:推 bamchisu: 三楼方法也许可以硬解,但是不太安全会变成root... 02/13 00:13
6F:→ kenduest: 抱歉因为我测试是 chown root 方式达成,所以要改改 02/13 01:54
7F:→ kenduest: 不用 system() 是比较单纯的 02/13 01:55