RH413企业安全加固 第6章 管理特殊权限

第6章管理特殊权限

 

1、suidsgid

2、显示特殊权限(注意:红字)

1) suid

[root@student ~]# which passwd

/usr/bin/passwd

[root@student ~]# ls -l /usr/bin/passwd 

-rwsr-xr-x. 1 root root 30768 Feb 17  2012 /usr/bin/passwd

[root@student ~]# ls -l /etc/shadow

----------. 1 root root 908 Jan 16 07:18 /etc/shadow

以上的演示说明 shadow本身是没有权限来写用户密码的,但在/usr/bin/passwd,在用户

下给了个s的权限,这里相当于普通用户借用了root用户的权限来修改shadow密码。

使用用户所属的权限来执行,而不是命令执行者的权限,不能用于shell脚本用户的执行,

只针对系统二进制文件,不针对其他文件。

在举个ping文件的例子:

[root@student ~]# ls -l /bin/ping

-rwsr-xr-x. 1 root root 40760 Mar 22  2011 /bin/ping

[root@student ~]# chmod u-s /bin/ping

[root@student ~]# ls -l /bin/ping

-rwxr-xr-x. 1 root root 40760 Mar 22  2011 /bin/ping

[root@student ~]# su - student

[student@student ~]$ ping 127.0.0.1

ping: icmp open socket: Operation not permitted

 

[root@student ~]# chmod u+s /bin/ping 

[root@student ~]# ls -l /bin/ping

-rwsr-xr-x. 1 root root 40760 Mar 22  2011 /bin/ping

[root@student ~]# su - student

[student@student ~]$ ping 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.029 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.066 ms

说白了就是针对用户位上的权限。

 

2) sgid

sgid是针对目录来进行生效的。

[root@student ~]# mkdir ./test/

[root@student ~]# chgrp student ./test/

[root@student ~]# cd ./test/

[root@student test]# touch file.log

[root@student test]# ls -l

total 0

-rw-r--r--. 1 root root 0 Jan 18 08:42 file.log

[root@student test]# cd ..

[root@student ~]# chmod g+s ./test/

[root@student ~]# cd ./test/

[root@student test]# touch file2.log

[root@student test]# ls -l

total 0

-rw-r--r--. 1 root student 0 Jan 18 08:43 file2.log

-rw-r--r--. 1 root root    0 Jan 18 08:42 file.log

 

以上是说明了不管用户是谁,只要赋予gid的权限,目录下的所有权限都赋予这个用户组的权限。

3) 粘滞位

[root@student /]# mkdir /test/

[root@student /]# chmod 777 /test/

[root@student /]# chmod o+t /test/

[root@student /]# ls -l /test/

total 0

[root@student /]# ls -ld /test

drwxrwxrwt.   2 root root  4096 Jan 18 08:49 test

[root@student /]# cd /test/

[root@student test]# touch file.log

[root@student test]# su - student

[student@student ~]$ cd /test/

[student@student test]$ ls

file.log

[student@student test]$ rm -rf file.log 

rm: cannot remove `file.log': Operation not permitted

粘滞位作用是只要在这个粘滞位上的目录只有root的用户或所属的用户才能删除文件。

 

4) 用 4代表suid2代表sgid 1代表sticky

[root@student test]# chmod 4664 file.log 

[root@student test]# ls -l

total 0

-rwSrw-r--. 1 root root 0 Jan 18 08:50 file.log

[root@student test]# chmod 2664 file.log 

[root@student test]# ls -l

total 0

-rw-rwSr--. 1 root root 0 Jan 18 08:50 file.log

[root@student test]# chmod 1664 file.log 

[root@student test]# ls -l

total 0

-rw-rw-r-T. 1 root root 0 Jan 18 08:50 file.log

 

这些特殊权限必须配上执行权限才能作用。

 

3、查找特殊权限

[root@student test]# find / -perm -4000

/bin/su

/bin/ping6

/bin/ping

只要满足带有suid(4000)权限都给列出来。

 

[root@student test]# find / -perm /4000

/bin/su

/bin/ping6

/bin/ping

只要其中一个带有suid(4000)权限都给列出来。

 

4、练习

1)创建目录为 /data/etc

[root@student /]# mkdir /data

[root@student /]# cd /data/

[root@student data]# mkdir etc

[root@student data]# cd ..

[root@student /]# ls -ld /data/etc/

drwxr-xr-x. 2 root root 4096 Jan 18 09:17 /data/etc/

 

2)给/data/etc 赋予权限

[root@student /]# chown -R student:student /data/etc/

[root@student /]# ls -ld /data/etc

drwxr-xr-x. 2 student student 4096 Jan 18 09:17 /data/etc

 

3)使用cp命令复制/bin/touch文件到/data/etc目录下

[root@student /]# cp /bin/touch /data/etc/createfile

 

4)更改createfile文件权限

[root@student /]# cd /data/etc/

[root@student etc]# chown student:student createfile 

[root@student etc]# ls -l

total 52

-rwxr-xr-x. 1 student student 52656 Jan 18 09:21 createfile

 

5)在/data/etc 下创建的文件属于student用户和组的权限(注意:红字)

[root@student etc]# su - student

[student@student ~]$ cd /data/etc/

[student@student etc]$ ./createfile file.log

[student@student etc]$ ls -l

total 52

-rwxr-xr-x. 1 student student 52656 Jan 18 09:21 createfile

-rw-rw-r--. 1 student student     0 Jan 18 09:25 file.log

6)使用root的用户创建出文件属于student用户和组

[root@student etc]# chmod u+s createfile 

[root@student etc]# ls -l createfile 

-rwsr-xr-x. 1 student student 52656 Jan 18 09:21 createfile

[root@student etc]# chmod g+s /data/etc/

[root@student etc]# ls -ld /data/etc/

drwxr-sr-x. 2 student student 4096 Jan 18 09:25 /data/etc/

[root@student etc]# ./createfile file2.log

[root@student etc]# ls -l

total 52

-rwsr-xr-x. 1 student student 52656 Jan 18 09:21 createfile

-rw-r--r--. 1 student student     0 Jan 18 10:43 file2.log

-rw-rw-r--. 1 student student     0 Jan 18 09:25 file.log

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随行之旅

python国产化自动化

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值