TryHackMe | h4cked Walkthrough

Enes Cayvarlı
9 min readMar 3, 2023

--

Hi there, I’m glad to see you here. In this article, we’ll solve together the “h4cked” room in TryHackMe. In some sections, I’ll share brief about the subject. Don’t forget! You must always research to learn more. I hope it will be helpful for you. Let’s start!

h4cked

Contents:

-Traffic Analysis using Wireshark

-Reconnaissance using Nmap

-Brute Force Attack using Hydra

-Reverse Shell

-Privilege Escalation

Task 1

Subject : Oh no! We’ve been hacked!

It seems like our machine got hacked by an anonymous threat actor. However, we are lucky to have a .pcap file from the attack. Can you determine what happened? Download the .pcap file and use Wireshark to view it.

Before we begin, I think it’s important that we understand what wireshark is.

Wireshark is a free and open-source packet analyzer. It is used for network troubleshooting, analysis, software and communications protocol development, and education.

First of all, if we apply some configurations on Wireshark, the analysis process will be easier for us.

To open the relevant file, select the “Open” option from the “File” menu.

File → Open
Capture.pcapng

To add columns in Wireshark, use the Column Preferences menu. Right-click on any of the column headers, then select “Column Preferences…”.

Column Preferences

And then click the “+” button to add a column.

Columns

Set the “Title” and “Type” values as shown in the image below to display the Source Port and Destination Port information in columns.

Add a column

Answer the questions below

Q1: The attacker is trying to log into a specific service. What service is this?

A1: FTP

When we look at the traffic in general, we can see that there is traffic to port 21. Port 21 is commonly associated with FTP.

FTP (File Transfer Protocol) is a network protocol for transmitting files between computers over Transmission Control Protocol/Internet Protocol (TCP/IP) connections. Within the TCP/IP suite, FTP is considered an application layer protocol.

Port 21 / FTP

Q2: There is a very popular tool by Van Hauser which can be used to brute force a series of services. What is the name of this tool?

A2: hydra

https://github.com/vanhauser-thc/thc-hydra

Hydra is a parallelized login cracker which supports numerous protocols to attack.

HYDRA

Q3: The attacker is trying to log on with a specific username. What is the username?

A3: jenny

When we examine the requests in the Info column, we can see that there is brute-force traffic for the user “jenny”.

Username

Q4: What is the user’s password?

A4: password123

When we look at the responses to the related requests, there is a response called “Login successful”.

Line : 305

To filter to a particular stream, select a TCP, UDP, DCCP, TLS, HTTP, HTTP/2, QUIC or SIP packet in the packet list of the stream/connection you are interested in and then select the menu item Analyze → Follow → TCP Stream. Wireshark will set an appropriate display filter and display a dialog box with the data from the stream laid out.

TCP Stream

Unfortunately, Jenny has a very simple password…

Password

Q5: What is the current FTP working directory after the attacker logged in?

A5: /var/www/html

We can search for the “pwd” command to detect the working directory.

Line : 401

The pwd (print working directory) command writes to standard output the full path name of your current directory (from the root directory).

Current Directory

Q6: The attacker uploaded a backdoor. What is the backdoor’s filename?

A6: shell.php

Mastering important details like a filename, a file extension, or a command speeds up the analysis process.

We can see that the attacker is using a backdoor named “shell.php” in this stage.

Line : 425

A client issues the STOR command after successfully establishing a data connection when it wishes to upload a copy of a local file to the server.

Backdoor

Q7: The backdoor can be downloaded from a specific URL, as it is located inside the uploaded file. What is the full URL?

A7: http://pentestmonkey.net/tools/php-reverse-shell

We can see that the transfer process was successful after we discovered the backdoor.

Line : 431

Correct choice my friend! PentestMonkey is really good.

Full URL

Q8: Which command did the attacker manually execute after getting a reverse shell?

A8: whoami

As shown in the images below, we can examine what the attacker did after gaining access to the device.

whoami

As its name suggests, the whoami command prints the user name of the effective user ID. In other words, it displays the name of the currently logged-in user.

Q9: What is the computer’s hostname?

A9: wir3

Hostname

Q10: Which command did the attacker execute to spawn a new TTY shell?

A10: python3 -c ‘import pty; pty.spawn(“/bin/bash”)’

For more information on the TTY Shell:

https://steflan-security.com/linux-tty-shell-cheat-sheet

https://book.hacktricks.xyz/generic-methodologies-and-resources/shells/full-ttys

TTY Shell

Q11: Which command was executed to gain a root shell?

A11: sudo su

Things will only get worse from there, because the attacker will perform the operations with the privileges of the root user.

sudo su

Q12: The attacker downloaded something from GitHub. What is the name of the GitHub project?

A12: Reptile

Reptile is a Linux kernel mode rootkit with detection evasion, persistence, and a backdoor.

https://github.com/f0rb1dd3n/Reptile

Reptile

Q13: The project can be used to install a stealthy backdoor on the system. It can be very hard to detect. What is this type of backdoor called?

A13: Rootkit

Rootkit malware is a collection of software designed to give malicious actors control of a computer network or application.

Rootkit

Congratulations! From the beginning to the end, we worked together to determine what actions the attacker took. I’m looking forward to the next stage because we will apply the same operations by imitating the attacker’s method. Now it’s our turn! 👊🏻

Task 2

Subject : Hack your way back into the machine

The attacker has changed the user’s password! Can you replicate the attacker’s steps and read the flag.txt? The flag is located in the /root/Reptile directory. Remember, you can always look back at the .pcap file if necessary. Good luck!

Deploy the machine

Step 1: You need openvpn configuration file to connect with VPN to machines in TryHackMe.

https://tryhackme.com/access?o=vpn

Configuration File

Step 2: Use openvpn command and start your VPN connection.

openvpn

Step 3: Can you see the IP address of the machine?

Active Machine Information

Step 4: You can check your connection.

ping
OpenVPN Access Details

Answer the questions below

Q1: Read the flag.txt file inside the Reptile directory

A1: ********************************

Firstly, we need to run a nmap scan to find out which ports are open and which services are running on these ports.

Nmap (Network Mapper) is a free and open source utility for network discovery and security auditing.

nmap -A -T4 -Pn -p- 10.10.177.32

-A : Enable OS detection, version detection, script scanning and traceroute.

-T4 : Set timing template (higher is faster).

-Pn : Treat all hosts as online — skip host discovery.

-p- : You can specify “-p-” to scan ports from 1 through 65535.

Nmap Scan Result

I’m sorry, Jenny. We have to do this…

hydra -l jenny -P /usr/share/wordlists/rockyou.txt 10.10.177.32 ftp

-l : Login with LOGIN name.

-P : Load several passwords from FILE.

[machine IP] : The IP address of the target machine.

ftp / protocol : Sets the protocol.

hydra

Yes, we are inside!

FTP Login

Let’s use the get command to transfer the file we’ll use for the backdoor to our own device.

get

We need to change the IP address and port information.

If you have connected via VPN, you have to use the IP address in the tun0 (VPN Interface) section. You can use the ifconfig command to find out.

shell.php

We can use the put command to transfer the backdoor we created from our device to the target system.

put : To copy a single file, use the put command.

mput : To copy multiple files at once, use the mput command. (A little additional information… 😉)

put

Don’t forget to run netcat in the background before transfer!

Netcat or nc is a utility tool that uses TCP and UDP connections to read and write in a network.

nc -lvnp 4444

-l is used to tell netcat that this will be a listener.

-v is used to request a verbose output.

-n tells netcat not to resolve host names or use DNS.

-p indicates that the port specification will follow.

TTY Shell : python3 -c 'import pty; pty.spawn("/bin/bash")'
netcat

Let’s check if we have any permissions to execute specific commands as sudo.

sudo -l : The -l (list) option will print out the commands allowed (and forbidden) the user on the current host.

sudo

It appears that we have all of the necessary permissions. Let’s get this done!

flag.txt

Congratulations! You found the flag, and my friend, you were exactly like an attacker! 👌🏻

--

--

No responses yet