星期一, 四月 02, 2007

python script suid

在较新的内核中,已经禁止了对 script 的 suid,只有二进制程序拥有 suid 权限:
#!/usr/bin/python
import os
print os.geteuid(), os.getegid()

-bash-3.00$ ls /usr/bin/passwd -l
-r-s--x--x 1 root root 21200 2005-06-17 /usr/bin/passwd

-bash-3.00$ ls test.py -l
-r-sr-xr-x 1 root root 62 Mar 26 17:43 test.py
-bash-3.00$ ./test.py
10001 10001
-rwsr--r-- 1 root root 66 Mar 30 17:59 test.py
-bash-3.00$ ./test.py
-bash: ./test.py: Permission denied
可以看到,起作用的并不是 s 位,而仅仅是 x 位。其他 script 如 perl/php 亦同。

因此在编写 cgi 脚本时需要考虑这一点,mailman 的 cgi 程序就都是二进制的程序(C 编译)。

没有评论: