x@iZf8zdt0lxjb33kqwiaft8Z:/bin$ ls -l su -rwsr-xr-x 1 root root 44664 Mar 14 2022 su x@iZf8zdt0lxjb33kqwiaft8Z:/bin$ ls -l /usr/bin/passwd -rwsr-xr-x 1 root root 59640 Mar 14 2022 /usr/bin/passwd
x@iZf8zdt0lxjb33kqwiaft8Z:~$ chmod u+s run x@iZf8zdt0lxjb33kqwiaft8Z:~$ ll -rwSrw-r-- 1 x x 0 Nov 19 21:35 run x@iZf8zdt0lxjb33kqwiaft8Z:~$ chmod +x run x@iZf8zdt0lxjb33kqwiaft8Z:~$ ll -rwsrwxr-x 1 x x 0 Nov 19 21:35 run*
也可以使用数字表示:SUID=4,SGID=2,SBIT=1,将原来的三位数扩展为四位数即可,把它们放在权限数字的最开头。只设置SUID可以用chmod 4664 run
x@iZf8zdt0lxjb33kqwiaft8Z:~$ cd / x@iZf8zdt0lxjb33kqwiaft8Z:/$ ll drwxrwxrwt 10 root root 4096 Nov 19 21:58 tmp/
如何设置SBIT权限
SBIT权限只能设置到目录,使用chmod o+t 目录,或者使用数字标识设置。
1 2 3 4 5 6 7
x@iZf8zdt0lxjb33kqwiaft8Z:~$ mkdir tmp x@iZf8zdt0lxjb33kqwiaft8Z:~$ ll drwxrwxr-x 2 x x 4096 Nov 19 22:34 tmp/ x@iZf8zdt0lxjb33kqwiaft8Z:~$ chmod 1777 tmp/ x@iZf8zdt0lxjb33kqwiaft8Z:~$ ll total 24 drwxrwxrwt 2 x x 4096 Nov 19 22:34 tmp/
/* * To limit bogus system(3) or popen(3) calls in setuid binaries, require * -p flag to work in this situation. */ if (!on && (uid != geteuid() || gid != getegid())) { setuid(uid); setgid(gid); /* PS1 might need to be changed accordingly. */ choose_ps1(); } }
Starting Nmap 7.60 ( https://nmap.org ) at 2022-11-20 18:29 CST WARNING: Running Nmap setuid, as you are doing, is a major security risk.
NSE: failed to initialize the script engine: /usr/bin/../share/nmap/nse_main.lua:626: file.nse is missing required field: 'action' stack traceback: [C]: infunction'error' /usr/bin/../share/nmap/nse_main.lua:626: in field 'new' /usr/bin/../share/nmap/nse_main.lua:825: inlocal'get_chosen_scripts' /usr/bin/../share/nmap/nse_main.lua:1312: in main chunk [C]: in ?
QUITTING! x@iZf8zdt0lxjb33kqwiaft8Z:~$ su root2 Password: root@iZf8zdt0lxjb33kqwiaft8Z:/home/x# id uid=0(root) gid=0(root) groups=0(root)
Linux 2.2以后增加了capabilities的概念,可以理解为水平权限的分离。以往如果需要某个程序的某个功能需要特权,我们就只能使用root来执行或者给其增加SUID权限,一旦这样,我们等于赋予了这个程序所有的特权,这是不满足权限最小化的要求的;在引入capabilities后,root的权限被分隔成很多子权限,这就避免了滥用特权的问题,我们可以在capabilities(7) - Linux manual page中看到这些特权的说明。