๐Ÿ–ฅ๏ธ Computer Science/OS

[OS/Linux] ํ”„๋กœ์„ธ์Šค ๊ถŒํ•œ, ID, ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ ์ •๋ณด ๊ด€๋ จ ํ•จ์ˆ˜

Rosieblue 2023. 9. 15. 12:46
728x90

ํ”„๋กœ์„ธ์Šค์—์„œ์˜ UID

User ID(UID)๋Š” 32bit์˜ ์ •์ˆ˜๊ฐ’! ์ด๊ฑธ๋กœ user๋ฅผ ์‹๋ณ„!

  • ruid : Real User ID!! ์ฆ‰ ์ด ํ”„๋กœ์„ธ์Šค๋ฅผ '์‹œ์ž‘'ํ•œ ์œ ์ €์˜ ์•„์ด๋””
  • euid : '๊ถŒํ•œ ๊ฒ€์‚ฌ'ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” id. ๋ณดํ†ต์€ ruid์™€ ๊ฐ™๊ฒ ์ง€๋งŒ SetUID๋น„ํŠธ ๋“ฑ์ด ์„ค์ •๋œ ๊ฒฝ์šฐ, ํŒŒ์ผ ์†Œ์œ ์ž์˜ ์•„์ด๋””๋กœ ๋ฐ”๋€œ. ๋”ฐ๋ผ์„œ ์–˜๋ฅผ root๋กœ ๋ฐ”๊พผ๋‹ค๋ฉด root๊ถŒํ•œ์œผ๋กœ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€
  • suid : Saved User ID!! Privileged Process(๋ณดํ†ต root๊ฐ€ ์‹คํ–‰ํ•œ ํ”„๋กœ์„ธ์Šค)๊ฐ€ ๋ชจ์ข…์˜ ์ด์œ ๋กœ ๊ถŒํ•œ์„ ๋‚ฎ์ถฐ์•ผํ•˜์ง€๋งŒ ๋‹ค์‹œ ๋Œ์•„์˜ฌ๋•Œ ํ•„์š”ํ•œ ์•„์ด๋””
Non-root process๊ฐ€ ์ž์‹ ์˜ euid๋ฅผ ๋ฐ”๊พธ๋ ค๊ณ  ํ•  ๋•Œ, euid๋Š” ํ˜„์žฌ์˜ ruid, euid, suid๋กœ ๋ฐ–์— ์„ค์ •ํ•  ์ˆ˜ ์—†์Œ

 

euid, ruid, suid - HackTricks

 

euid, ruid, suid - HackTricks

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, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the environment, are ignored. If

book.hacktricks.xyz

 

์•„๋ž˜์ฒ˜๋Ÿผ uid๋“ค๊ณผ ๊ฐ๊ฐ์˜ ๊ถŒํ•œ์ด ๊ตฌ๋ถ„๋˜์–ด์žˆ๋Š”๋ฐ, ์ปค๋„ ๊ถŒํ•œ์€ ๋˜ ๋”ฐ๋กœ ๋ถ„๋ฅ˜๋˜์–ด์žˆ๋‹ค!

root ๊ถŒํ•œ์˜ ํ”„๋กœ์„ธ์Šค๋„ kernel ๋ฉ”๋ชจ๋ฆฌ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์€ ๊ธˆ์ง€๋˜์–ด์žˆ๋‹ค!

 

๋ฆฌ๋ˆ…์Šค ๊ถŒํ•œ

 

ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ ์ •๋ณด ์–ป๊ธฐ

์•„๋ž˜ ํ•จ์ˆ˜๋“ค์€ 'ํ˜„์žฌ' ํ”„๋กœ์„ธ์Šค์˜ id๋“ค์„ ์–ป๋Š” ํ•จ์ˆ˜๋“ค์ด๋‹ค.

pid_t getpid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ pid ์–ป๊ธฐ
pid_t getppid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค id ์–ป๊ธฐ
pid_t getuid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ uid ์–ป๊ธฐ
pid_t getgid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ gid ์–ป๊ธฐ
pid_t geteuid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํšจ ์‚ฌ์šฉ์ž id (euid) ์–ป๊ธฐ
pid_t getegid(void); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํšจ ๊ทธ๋ฃน id(egid) ์–ป๊ธฐ

error๋Š” ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ฐธ๊ณ ๋กœ ํ”„๋กœ์„ธ์Šค์˜ uid๋ผ๋Š”๊ฑด ํŒŒ์ผ์˜ ์†Œ์œ ์ž id๊ฐ€ ์•„๋‹ˆ๋ผ ํ˜„์žฌ ํŒŒ์ผ์„ ์‹คํ–‰ํ•œ id๋ฅผ ์˜๋ฏธํ•œ๋‹ค!

 

ํ”„๋กœ์„ธ์Šค ๊ด€๋ฆฌ ์ •๋ณด ์„ค์ •

int setuid(uid_t uid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ uid ์„ค์ •
int setgid(gid_t gid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ gid ์„ค์ •
int seteuid(uid_t euid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํšจ ์‚ฌ์šฉ์ž id ์„ค์ •
int setegid(gid_t egid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํšจ ๊ทธ๋ฃน id ์„ค์ •
int setreuid(uid_t ruid, uid_t euid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ ruid, euid ์„ค์ •
int setrguid(gid_t rgid, gid_t egid); //ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค์˜ rgid, egid ์„ค์ •

์–˜๋„ ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค ๊ธฐ์ค€!

์„ฑ๊ณตํ•˜๋ฉด 0, ์‹คํŒจํ•˜๋ฉด -1 ๋ฐ˜ํ™˜