Chinaunix首页 | 论坛 | 博客
  • 博客访问: 164715
  • 博文数量: 26
  • 博客积分: 17
  • 博客等级: 民兵
  • 技术积分: 145
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-10 13:14
文章分类
文章存档

2014年(1)

2013年(1)

2012年(22)

2011年(2)

分类:

2012-02-24 17:01:16

当执行一个程序文件时,进程的有效用户ID通常就是实际用户ID,有效组ID通常是实际组ID。

文件的“设置用户id”位的作用是:若为程序文件设置了“设置用户id”位,那么当执行此文件时,将进程的有效用户id设置为文件所有者的用户ID;
文件的“设置组id”位的作用是:若为程序文件设置了“设置组id”位,那么当执行该文件时,将进程的有效组id设置为文件所有者的组id

/usr/bin/passwd就是一个设置了"设置用户id"的程序文件,测试如下:
1test.c
  1. #include <stdio.h>
  2. #include <sys/stat.h>
  3. int main(int argc, char *argv[])
  4. {
  5.     int i;
  6.     struct stat buf;
  7.     if(argc != 2){
  8.         printf("%s filename\n", argv[0]);
  9.         return 1;
  10.     }
  11.     if(stat(argv[1], &buf) < 0){
  12.         perror("stat error\n");
  13.         return 2;
  14.     }
  15.     printf("st_mode: %x\n", buf.st_mode);
  16.     if(S_ISUID & buf.st_mode){
  17.         printf("set user id\n");
  18.     }
  19.     if(S_ISGID & buf.st_mode){
  20.         printf("set group id\n");
  21.     }
  22.     return 0;
  23. }
gcc -o 1test 1test.c
执行:
  1. [root@localhost uid]# ./1test /usr/bin/passwd
  2. st_mode: 89ed
  3. set user id
  4. [root@localhost uid]#

  1. [root@localhost uid]# ./1test /usr/bin/ssh
  2. st_mode: 81ed
  3. [root@localhost uid]#

/usr/bin/passwd的所有者是root,而且设置了该文件的设置用户ID位,所以当该程序(passwd)由一个进程A执行时,进程A具有超级用户特权。但是,由于进程A一般只能用exec的方式执行/usr/bin/passwd,所以,我们貌似也没有多少搞破坏的空间噢
阅读(1397) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~