Chinaunix首页 | 论坛 | 博客
  • 博客访问: 969029
  • 博文数量: 200
  • 博客积分: 5011
  • 博客等级: 大校
  • 技术积分: 2479
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 15:07
文章分类

全部博文(200)

文章存档

2009年(12)

2008年(190)

我的朋友

分类:

2008-10-30 17:55:58

目录的set-group-id被设置的含义:该目录下建立的文件的group id为该目录的group id,而不等于建立该文件的process effective group id
文件的set-group-idset-user-id的含义是:执行这个可执行文件的时候processeffective group ideffective user id被置为该文件的group idowner id
假设我们的effective group id和目录Agroup id不同。如果A被设置了set-group-id标记,我们在其下建立一个可执行文件,那么这个可执行文件的group id就应该是其目录的group id了。如果我们给该文件设置set-group-id,那么等我们当我们运行这个文件的时候,我们processeffective group id就成了该文件的group id,即该目录的group id了,即我们获取了该group的权利。有危险。
我们是怎么能够当目录Agroup id与我们的effective group idsupplementary group id都不同的情况下在该目录下建立文件的呢?当该目录对other用户有读+执行权限时就可以了。
所以为避免这种危险:
1.     if the group ID of the new file does not equal either the effective group ID of the process or one of the process's supplementary group IDs and if the process does not have superuser privileges, then the set-group-ID bit is automatically turned off。 当group id不于当前process匹配时,你所设置的set group id被忽略。This prevents a user from creating a set-group-ID file owned by a group that the user doesn't belong to
 
2.     Linux和一些unix版本还有如下限制: If a process that does not have superuser privileges writes to a file, the set-user-ID and set-group-ID bits are automatically turned off. If malicious users find a set-group-ID or a set-user-ID file they can write to, even though they can modify the file, they lose the special privileges of the file. 如果你不具有superuser 权限,那么如果你修改了一个文件,那么这个文件的set-user-idset-group-id标记都被清除,当然你也就没办法设置了。 难道我们想把自己的文件的set-user-id设置都不可以么?注意,设置set-user-id是可以的,但是设置set-group-id就不行,你是这个文件的主人,你要给它set-user-id的权限,别人管不了。但是你不属于该文件所属的group,你就不能给其设置set-group-id,你就不能随便将该group的权限获取。我经过测试。
 

测试:

用户: root    组:root

用户: shaoting 组:users

1.           使用root建立一个目录testdir,并chmod g+s testdir即给该目录添加set-group-id标记。 chmod o+wx testdir即给其他用户在该目录下建立文件的权利。

2.           使用shaoting用户在testdir下建立file文件。结果该文件的ownshaotinggroup竟然是root组。

3.           shaoting用户chmod u+s fiile是可以的,既可以给该文件set-user-id,谁让我们是它的主人。但使用chmod g+s file是没有效果的,即我们不能随便将root组的权限给与别人。

但是如果用root帐户,什么操作都是可以的。好,我们给chmod g+s filefile 设置set-group-id。然后chmod o+w file并且给其他人修改这个文件的权利。然后我们切换用户到shaoting,修改该文件,保存,察看该文件,发现其set-group-id果然已经自动被清除了。呵呵。这样保证了:root用户在某时刻确保该程序是安全的,于是给它增加了set-group-id标记,但是依然保留了该文件被别人修改的权利。一段时间后,某人偷偷修改了该文件,那么此时危险就产生了,于是,系统为了避免这种情况,就会自动将该文件的set-group-id标记清除。

 

阅读(1260) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~