LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: ancharn

!!suid question!!

[复制链接]
发表于 2006-2-14 13:06:39 | 显示全部楼层
楼上是自找麻烦吧。。。呵呵。
回复 支持 反对

使用道具 举报

发表于 2006-2-16 03:47:51 | 显示全部楼层
Post by ground
楼主是否能确认下这个问题,我用的bash设置了suid,没有达到效果.

我原来就是说script是不能suid的,可楼主说zsh可以,于是我就试了。suid zsh在这里是不符和的,因为我也可以suid bash啊。bash和zsh里有一个option是-p,表示privileged shell. 用来以script的effective ID来执行它,但是都没有作用。我想可能是屏蔽掉了。另外有一个程序叫super,和sudo类似,可以用来配置binaries和scripts以root身份执行。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-16 09:41:55 | 显示全部楼层
Post by yongjian
我原来就是说script是不能suid的,可楼主说zsh可以,于是我就试了。suid zsh在这里是不符和的,因为我也可以suid bash啊。bash和zsh里有一个option是-p,表示privileged shell. 用来以script的effective ID来执行它,但是都没有作用。我想可能是屏蔽掉了。另外有一个程序叫super,和sudo类似,可以用来配置binaries和scripts以root身份执行。



你可以cp /bin/bash ~/bash,然后set uid for ~/bash,将脚本的解释程序改成~/bash试验下,这时还是不可以的;但是如果你cp /bin/zsh ~/zsh,然后set uid for ~/zsh,然后将脚本的解释程序改成~/zsh试验下,这时是可以的。
那么也就是说bash在先天上已经屏蔽了suid,而zsh是支持的目前。
希望大家在自己的机器上试验后再作讨论,谢谢!
回复 支持 反对

使用道具 举报

发表于 2006-2-17 02:16:16 | 显示全部楼层
Post by ancharn
你可以cp /bin/bash ~/bash,然后set uid for ~/bash,将脚本的解释程序改成~/bash试验下,这时还是不可以的;但是如果你cp /bin/zsh ~/zsh,然后set uid for ~/zsh,然后将脚本的解释程序改成~/zsh试验下,这时是可以的。
那么也就是说bash在先天上已经屏蔽了suid,而zsh是支持的目前。
希望大家在自己的机器上试验后再作讨论,谢谢!
  1. #!./bash -p
复制代码
就可以了(都是在suid了解释器后的前提下。之所以zsh/ksh可以不加-p是因为“Turn  on  privileged  mode.  This is enabled automatically on startup if the effective user (group) ID is not equal to the real user (group) ID.” 请看zsh/ksh的manpage。从这一点上说,bash显得更严谨 一些,并不是因为zsh先天而bash不先天支持)。我得意思是修改解释器suid的这个方法:1是不对你最初的要求(你最初只是想将你的script加上suid的功能。2是实际意义不大。因为一旦shell解释器被加上suid,那系统上任何拥有执行权的(基本上是所有用户)都可将自己写的script以root身份运行。那将是不可想象的灾难。一个可以配置用户权限的方法将更加严格和可行。你可以看看super这个命令或是sudo. 他们都可以配置出你所需要的功能。
回复 支持 反对

使用道具 举报

发表于 2006-4-23 10:32:05 | 显示全部楼层
我想问一下,SUID SGID有什么区别?谢谢
回复 支持 反对

使用道具 举报

发表于 2006-5-24 03:20:40 | 显示全部楼层
Post by mimisuritalatu
我想问一下,SUID SGID有什么区别?谢谢

SUID设置后程序将以其owner的ID(也叫effective ID)运行,而不是以调用程序的那个ID. 比如,你调用一个a程序,一般a将会以你的ID权限运行,但如果程序的owner是root而且设置了suid,那么你运行它的时候就会是在root的权限下运行。
SGID是对dir而言,对文件无效。对一个dir设置了SGID后,所有在其下生成的文件,子目录都将继承这个dir的group owner.
回复 支持 反对

使用道具 举报

发表于 2006-5-28 12:44:27 | 显示全部楼层
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,  the  SHELLOPTS variable,  if  it appears in the environment, is 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.


从bash manual里面摘下来的,很明显的,如果bash发现EUID和UID不一样,而且没有-p参数,就会把EUID设为UID了,如果有-p参数就保持EUID不变。多谢各位的讨论,本来还不太了解这个-p有什么用呢。不过个人感觉这样挺危险的,而且bash将不再读取任何启动文件,有些配置就没有,好像没什么意义。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-4 12:34:00 | 显示全部楼层
Post by johnny_jiang
从bash manual里面摘下来的,很明显的,如果bash发现EUID和UID不一样,而且没有-p参数,就会把EUID设为UID了,如果有-p参数就保持EUID不变。多谢各位的讨论,本来还不太了解这个-p有什么用呢。不过个人感觉这样挺危险的,而且bash将不再读取任何启动文件,有些配置就没有,好像没什么意义。


我的实验内容如下:
1. cp /bin/bash /tmp ; chmod u+s /tmp/bash
2. /tmp/test.sh内容如下:
       #!/tmp/bash -p
           cat /tmp/cat.txt
3.  /tmp/test.sh的权限是4511,属主是root,属组是root;
4. /tmp/cat.txt的内容是hello,权限是400,属主是root,属组是root;
5. 当我用某个普通用户(如user1,隶属于user1组)去执行/tmp/test.sh时可以显示出hello内容;

我的问题是:为什么我把/tmp/test.sh的权限变成511时也可以达到同样效果呢?可是我并没有给/tmp/test.sh文件suid位啊?
回复 支持 反对

使用道具 举报

发表于 2006-7-5 00:47:13 | 显示全部楼层
Post by ancharn
我的实验内容如下:
1. cp /bin/bash /tmp ; chmod u+s /tmp/bash
2. /tmp/test.sh内容如下:
       #!/tmp/bash -p
           cat /tmp/cat.txt
3.  /tmp/test.sh的权限是4511,属主是root,属组是root;
4. /tmp/cat.txt的内容是hello,权限是400,属主是root,属组是root;
5. 当我用某个普通用户(如user1,隶属于user1组)去执行/tmp/test.sh时可以显示出hello内容;

我的问题是:为什么我把/tmp/test.sh的权限变成511时也可以达到同样效果呢?可是我并没有给/tmp/test.sh文件suid位啊?


See my pm.
回复 支持 反对

使用道具 举报

发表于 2006-7-5 01:14:56 | 显示全部楼层
-p      Turn on privileged mode.  In this mode, the $ENV and $BASH_ENV files are not processed, shell functions are  not
                      inherited  from  the  environment, and the SHELLOPTS variable, if it appears in the environment, is ignored.  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, these actions are taken and the effective user id is set to the real user id.  If the -p option
                      is supplied at startup, the effective user id is not reset.  Turning this option off causes the  effective  user
                      and group ids to be set to the real user and group ids.

我没理解,,呵呵,,还要学习一下基础的东西:(。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表