http://theurbanpenguin.com/wp/index.php/using-a-simple-c-program-to-explain-the-suid-permission/ 의 소스를 참조했다.



$ cat > test.c

#include <stdio.h>

#include <unistd.h>

int main () {

  int real = getuid();

  int euid = geteuid();

  printf("The REAL UID =: %d\n", real);

  printf("The EFFECTIVE UID =: %d\n", euid);

  sleep(100);

}



$ cc test.c

$ ./a.out

The REAL UID =: 1000

The EFFECTIVE UID =: 1000



$ sudo chown root a.out

$ sudo chmod 4755 a.out



결과

$ ./a.out

The REAL UID =: 1000

The EFFECTIVE UID =: 0

(대기)



다른 터미널에서 ps 명령어로 확인한다.

$ ps -eo pid,euser,ruser,comm | grep a.out
PID EUSER    RUSER    COMMAND

 4481 root     deploy   a.out



리눅스에서 프로세스의 유효한(effective) 사용자 ID(euid)와 리얼(real) 사용자 ID(ruid)를 볼 수 있다.

setuid를 실행하는 시점에서는 다른 리얼 사용자 ID를 볼 수 있도록 아래 명령어를 실행한다. 일반적인 경우 한 프로세스의 euid와 ruid는 동일하다.


a.out 은 setuid로 실행되기 때문에 결과가 euser와 ruser가 다른 값이 나온다.

Posted by '김용환'
,