文件特殊权限SUID测试

文件特殊权限SUID测试,第1张

概述思路:使用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 [[emai

思路:使用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测试

@H_724_404@ 总结

以上是内存溢出为你收集整理的文件特殊权限SUID测试全部内容,希望文章能够帮你解决文件特殊权限SUID测试所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/1023108.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存