Set User Id - ggubuk97/apue GitHub Wiki
๊ฐ ์ฌ์ฉ์๊ฐ ์ด๋ป๊ฒ passwd๋ฅผ ์คํํด์ superuser ๊ถํ์ผ๋ก ์๊ธฐ์ password๋ฅผ ๋ฐ๊พธ๋๊ฐ ์ฌ๋ฏธ์๋ ๋ด์ฉ์ธ๋ฐ
bart@bear:/usr/bin$ cd /usr/bin/
bart@bear:/usr/bin$ ls -al passwd
-rwsr-xr-x 1 root root 42824 Sep 13 2012 passwd
user ๊ถํ์ด rws๋ก ๋์ด ์๋ ๊ฒ์ ์ ์ ์๊ณ rws๋ ์คํ๋ process๊ฐ superuser ๊ถํ์ ๊ฐ์ง๊ฒ ๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ์ด๊ฒ์ chomod u+s ๋ก shell์์ ๋ฐ๊ฟ์๋ ์๊ณ ๋ค์๊ณผ ๊ฐ์ด ์ํ ํ๋ก๊ทธ๋จ์ ์ง๋ด๋ ๋ฉ๋๋ค.
bart@bear:~/ws/bart$ ll
total 24
drwxrwxr-x 2 bart bart 4096 Oct 8 09:08 ./
drwxrwxr-x 8 bart bart 4096 Oct 7 21:12 ../
-rwxrwxr-x 1 bart bart 8542 Oct 7 22:04 a.out*
-rw-rw-rw- 1 bart bart 245 Oct 8 09:08 passwd.c
bart@bear:~/ws/bart$
bart@bear:~/ws/bart$ cat passwd.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
struct stat buf;
if (stat("passwd.c", &buf) < 0) {
printf("error\n");
}
chmod("passwd.c", buf.st_mode | S_ISUID);
}
์คํํ๊ณ ๋๋ฉด
bart@bear:~/ws/bart$ ./a.out
bart@bear:~/ws/bart$ ll
total 24
drwxrwxr-x 2 bart bart 4096 Oct 8 09:08 ./
drwxrwxr-x 8 bart bart 4096 Oct 7 21:12 ../
-rwxrwxr-x 1 bart bart 8542 Oct 7 22:04 a.out*
-rwSrw-rw- 1 bart bart 245 Oct 8 09:08 passwd.c
rwS๊ฐ ๋์ด ์๋ค์ rwx์ s๋ฅผ ๋ํ๋ฉด rws๊ฐ ๋๊ณ rw-์ s๋ฅผ ๋ํ๋ฉด rwS๊ฐ ๋ฉ๋๋ค.