加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

文件特殊权限SUID测试

发布时间:2020-12-14 00:22:30 所属栏目:Linux 来源:网络整理
导读:思路:使用shell脚本,然后把脚本编译为二进制,赋予 suid 权限,用不同的用户执行这样就能比较是否执行的时候用户是文件的所属用户 安装shc编译shell脚本 1 2 3 4 5 6 7 8 [[email?protected] shc] [[email?protected] tmp] # git clone https://github.com/

思路:使用shell脚本,然后把脚本编译为二进制,赋予 suid
权限,用不同的用户执行这样就能比较是否执行的时候用户是文件的所属用户

安装shc编译shell脚本

1
2
3
4
5
6
7
8
[[email?protected] shc]
[[email?protected] tmp]# git clone https://github.com/neurobin/shc.git
[[email?protected] shc]# cd shc
[[email?protected] shc]# mkdir m4
[[email?protected] shc]# ./autogen.sh
[[email?protected] shc]# ./configure
[[email?protected] shc]# make
[[email?protected] shc]# make install

测试环境配置

1
2
3
4
5
6
7
8
9
10
11
12
[[email?protected] tmp]$ vim rmfile.sh
# rmfile.sh
# #!/bin/bash
# rm -i /home/aoenian/file.txt

[[email?protected] tmp]$ shc -f rmfile.sh -o rmfile
[[email?protected] tmp]$ su test
[test@centos-rpi3 tmp]$ ./rmfile
[test@centos-rpi3 tmp]$ exit
[[email?protected] tmp]$ chmod 4755 rmfile
[[email?protected] tmp]$ su test
[test@centos-rpi3 tmp]$ ./rmfile

结果都是失败,都会显示没有权限,这个和设想的就不一样了,然后查看了命令运行时候进程的用户,发现依然是
test 用户在运行 rm 命令

个人理解:可能执行rmfile程序的时候是aoenian用户,但是rmfile程序调用rm命令的时候就变回来了

测试方法2(成功)

思路:不使用系统命令,使用C语言编写二进制文件

rmfile.c文件的内容如下:

会出现警告,不影响使用

1
2
3
4
5
6
7
8
9
10
11

int (){
char filename[80];
printf("The file to delete: ");
gets(filename);
if( remove(filename) == 0 )
printf("Removed %s.",filename);
else
perror("remove");
return 0;
}
1
2
3
4
5
6
7
[[email?protected] tmp]$ gcc -Wall rmfile.c -o rmfile
[[email?protected] tmp]$ touch test.txt
[[email?protected] tmp]$ chmod 4755 rmfile
[[email?protected] tmp]$ su test
[test@centos-rpi3 tmp]$ ./rmfile
The file to delete: test.txt
Removed test.txt.

测试成功,还是挺有意思的。

原文:大专栏 ?文件特殊权限SUID测试

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读