My FAQ,最新最全的IT技术FAQ
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 未整理篇 | 技术讨论
  当前位置: > 程序开发 > Shell
suid/sgid
作者:未知 时间:2005-09-13 23:27 出处:Blog.ChinaUnix.net 责编:My FAQ
              摘要:suid/sgid
suid/sgid

要了解 suid/sgid, 必需先了解 process 及 permission.
我們需知道: 每個 process 都有其 effective uid/gid , 以決定其在傳統 unix filesystem 中獲得的實際 permission .
再, process 是由 binary 產生的, 而 binary 是從 shell / shell script 載入執行.
在正常的情況下, process 的 effective uid/gid 是從 parent 繼承, 或簡單說是與 shell 的 uid/gid 一樣.
shell 的 uid/gid 則是跟據 /etc/passwd 的第 3 與 第 4 欄位決定.

當我們有了以上的概念之後, 再來看 suid 對 effective uid/gid 的影響:
若 binary file 帶有 suid/sgid 的時候,
其 effective id 就不是從 parent 那邊繼承, 而是以 binary file 本身的 user/group 為準.

舉例而言, 若一個 prog1 的 user/group 都是 root , 但沒設 suid/sgid ,
那當一個 uid(500)/gid(500) 的 parent process 執行這個 prog1 的話,
那 effective uid/gid 就是 500 ...
但若 prog1 設了 suid/sgid 後, 那其 effective uid/gid 就是 root !

一旦這個 process effective 是 root 的話, 那它對 file system 的 permission 就如脫繮野馬般任意奔騰而不受限制了.
因此我才在前面提到木馬程式與病毒的例子...
試想一下: 若病毒的 user/group 被設為 root, 然後被一般 user 執行時,
suid/sgid 的有與無將導致甚麼不同結果?

好了, 由於 suid/sgid 在系統上有其存在的必要性(舉 /usr/bin/passwd 與 /etc/shadow 為例),
但同時又有極大的殺傷力, 在應用上要異常小心!
因此, bash shell script 在先天上不支援 suid/sgid .
perl 亦如此, 除非額外再安裝 suid-perl ....



 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 myfaq.com.cn All rights reserved. www.myfaq.com.cn 版权所有