SUID权限

SUID 权限特色

  • SUID 权限仅对二进制程序有效
  • 执行者对于该程序需要有可执行权限(x权限)
  • SUID 权限仅仅在程序执行过程中有效
  • 执行该程序时,执行者将具有该程序拥有者的权限

SUID权限举例

当 s 标志出现在文件所有者的 x 权限上时,则此程序被设置了SUID特殊权限。

root@ylhao-virtual-machine:/home/ylhao# ll /usr/bin/passwd 
-rwsr-xr-x 1 root root 54256 3月  29  2016 /usr/bin/passwd*

查找所有设置了 setuid 位的程序

下面的命令查找/bin, /sbin ,/usr/bin, /usr/sbin目录下的所有具有SUID权限的程序,并将结果写到/home/ylhao/suid_program文件中

root@ylhao-virtual-machine:/home/ylhao# find /bin /sbin /usr/bin /usr/sbin -perm -4000 -exec ls -l > /home/ylhao/suid_program {} \;
root@ylhao-virtual-machine:/home/ylhao# cat suid_program 
-rwsr-xr-x 1 root root 30800 3月  11  2016 /bin/fusermount
-rwsr-xr-x 1 root root 27608 5月  27  2016 /bin/umount
-rwsr-xr-x 1 root root 44680 5月   8  2014 /bin/ping6
-rwsr-xr-x 1 root root 142032 2月  18  2016 /bin/ntfs-3g
-rwsr-xr-x 1 root root 40128 3月  29  2016 /bin/su
-rwsr-xr-x 1 root root 40152 5月  27  2016 /bin/mount
-rwsr-xr-x 1 root root 136808 5月   5  2016 /usr/bin/sudo
-rwsr-xr-x 1 root root 39904 3月  29  2016 /usr/bin/newgrp
-rwsr-xr-x 1 root root 54256 3月  29  2016 /usr/bin/passwd
-rwsr-xr-x 1 root root 23376 1月  18  2016 /usr/bin/pkexec
-rwsr-xr-x 1 root root 49584 3月  29  2016 /usr/bin/chfn
-rwsr-xr-x 1 root root 23288 4月  30  2016 /usr/bin/ubuntu-core-launcher
-rwsr-xr-x 1 root root 75304 3月  29  2016 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 40432 3月  29  2016 /usr/bin/chsh
-rwsr-xr-- 1 root dip 390888 1月  29  2016 /usr/sbin/pppd

修改 /bin/ping 程序的权限

  1. 使用chmod将ping程序设定为non-Set-UID。然后以普通用户权限运行,解释现象
  2. 之后给ping设置相应的权能,使普通用户能够运行。

还没有使用 chmod 将 ping 程序设定为 non-Set-UID

普通用户权限运行

yilonghao@yilonghao-Inspiron-5520:~$ ping -c 4 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.056 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.052 ms

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2998ms
rtt min/avg/max/mdev = 0.041/0.049/0.056/0.007 ms

root 用户权限运行

root@yilonghao-Inspiron-5520:/home/yilonghao# ping -c 4 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.030 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.059 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.039 ms

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.030/0.041/0.059/0.013 ms

使用 chmod 将 ping 程序设定为 non-Set-UID

root@yilonghao-Inspiron-5520:/home/yilonghao# chmod 755 /bin/ping
root@yilonghao-Inspiron-5520:/home/yilonghao# ll /bin/ping
-rwxr-xr-x 1 root root 44168 May  8  2014 /bin/ping*

普通用户权限运行

yilonghao@yilonghao-Inspiron-5520:~$ ping -c 4 127.0.0.1
ping: icmp open socket: Operation not permitted
yilonghao@yilonghao-Inspiron-5520:~$ 

root用户权限运行

yilonghao@yilonghao-Inspiron-5520:~$ sudo su
sudo: unable to resolve host yilonghao-Inspiron-5520
root@yilonghao-Inspiron-5520:/home/yilonghao# ping -c 4 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.052 ms

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.038/0.042/0.052/0.007 ms

其他特殊权限

  1. SGID
  2. SBIT
    共有12个权限位,其中最开始的三位对应特殊权限位,SUID=4,SGID=2,SBIT=1。

你可能感兴趣的:(SUID权限)