| name | performing-container-escape-detection |
| description | 通过分析命名空间配置、特权容器检查、危险能力分配和宿主机路径挂载,使用 kubernetes Python 客户端检测容器逃逸尝试。识别通过 cgroup 滥用的 CVE-2022-0492 类型逃逸。 适用于审计容器安全态势或调查逃逸尝试。
|
| domain | cybersecurity |
| subdomain | container-security |
| tags | ["performing","container","escape","detection"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
执行容器逃逸检测
说明
审计 Kubernetes Pod 的容器逃逸向量,包括特权模式(Privileged Mode)、危险能力(Dangerous Capabilities)、宿主机命名空间共享和可写的 hostPath 挂载。
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
pods = v1.list_pod_for_all_namespaces()
for pod in pods.items:
for container in pod.spec.containers:
sc = container.security_context
if sc and sc.privileged:
print(f"特权容器: {pod.metadata.namespace}/{pod.metadata.name}")
主要逃逸向量:
- 特权容器(完整宿主机访问权限)
- CAP_SYS_ADMIN 能力
- 宿主机 PID/网络/IPC 命名空间共享
- 对 / 或 /etc 的可写 hostPath 挂载
- Docker socket 挂载(/var/run/docker.sock)
示例
for vol in pod.spec.volumes or []:
if vol.host_path and "docker.sock" in (vol.host_path.path or ""):
print(f"暴露的 Docker socket:{pod.metadata.name}")