Table of Contents
Mercury is an easy Box though you will likely Capture the Flag (CTF) and be on the harder side of easy, depending on your experience.
You can easily set up the server to VirtualBox, simply click on import, and then import the file. It will automatically initiate an instance. Once you are done with these, click on setting and change the network adapter to the host-only adapter.
Enumeration
We have discovered an IP address, so let's Perform a network scan to detect what ports are open is already known as an essential part of the enumeration process. This offers us the opportunity to better understand the attacking surface and design targeted attacks.
As in most cases, we are going to use the famous Nmap tool.
Conducting Network Scans with Nmap
- -sV: Enables version detection, which will detect what versions are running on what port.
From the network scan(Nmap), we have spotted 2 open ports.
- Port 22/TCP runs an ssh service, which means, that if you have a valid credential then it will be easy to gain login access to the server.
- Port 8080/TCP runs an HTTP-proxy service, which indicates that there is a website running state.
To look at the contents ourselves, we can open a web browser of our choice and navigate to the target's IP address along with port 8080 in the URL bar at the top of the window:
This might be in the developing stage and there is nothing to enumerate on the webpage. There might be any hidden or hardly accessible directories and pages, and that can be done through directory busting.
Performing Directory Enumeration with Gobuster
- dir : Uses directory/file enumeration mode.
- -u : The target URL.
- -w : Path to the wordlist.
As a result of Directory busting, we obtained an important file i.e., robots.txt. Let’s dig into this directory and find out if there is any sensitive information that might help us in foothold.
Foothold
After analyzing the robots.txt file, we have finalized that there is an error page, which can be accessed through an asterisk(*).
This error page may be indicated in another directory. So, let’s access the identified folder “mercuryfacts/” on the browser.
On accessing the mercury facts directory, we found a hyperlink consisting of a fact (Load a fact). So, now, click on load a fact. It will redirect to another page.
By checking the URL, we conclude that there may be a variable ID that is responsible for all these. We could test it to see if it's SQL injectable, but instead of doing it manually, we will use a tool called sqlmap.
Database Enumeration with SQLMap
Sqlmap comes pre-installed with Kali Linux and ParrotSec OS.
Now open your terminal and type the following command.
- There will be some questions that the tool will ask you, you can respond with 'Yes ' or 'No', or just by pressing ENTER for the default answer.
After analyzing the output, we confirm that this server is vulnerable to SQL injection flaws and is in a critical situation, but the id parameter seems not to be injectable.
Let's list information about the existing databases. So firstly, we have to enter the web URL that we want to check along with the -u parameter.
Now typically, we would want to test whether it is possible to gain access to a database. So we use the --dbs option to do so.
- --dbs, lists all the available databases.
- --batch is used to never ask for user input, use the default behavior.
The output shows us that there are two available databases. We observe that there are two databases, information_schema, and mercury.
Now, List information about Tables present in a particular Database
To try and access any of the databases, we have to slightly modify our command. We now use -D to specify the name of the database that we wish to access, and once we have access to the database, we want to see whether we can dump all DBMS database table entries. For this, we use the --dump-all query.
From the output, We have got a few usernames and passwords. As we already know, there is an SSH service running on port 21.
Establishing Secure Remote Connections with SSH
Let's perform a Secure shell connection to enable secure remote connections using these usernames and their relevant passwords.
Next, use the ls command to list the files and the directories' contents. As a result, we found user_flag.txt, opened this using the cat command.
Privilege Escalation
Let's identify the rights and privileges of the current user by executing the sudo -l command.
We got an output, which is the user Mercury doesn't have permission to run the sudo command.
After analyzing, we have discovered a directory that may contain some sensitive information. Let's change the directory to the mercury project directory.
Now run the ls command to list the files and directories. There is a text file, let's see what is there in this file.
Open this file with the cat command.
- This file contained some login strings, that seem to be base-64 encoded strings.
- We used the echo command to decode the base-64 string.
After successfully decoding these strings, we found a clear-text password for the user linuxmaster.
Now, again run sudo -l to identify the rights and privileges of the current user linuxmaster.
There is a file that contains the root permission to the /usr/bin/check_syslog.sh.
- This means the current user owns sudo rights for the “check_syslog.sh” bash script. This is a part of the local privilege escalation.
Path Manipulation(Path Traversal) Privilege Escalation
Let’s use this file to escalate the current user privilege to root.
Firstly read the contents of the bash script, the script was written to execute the tail program for reading the last 10 Syslog entries.
So, we tried to create a hard link or a symbolic link to an existing file or directory to the specified TARGET using the VI text editor. This could be done using the following commands.
Once, you will execute the above command, further, you need to execute the following command that will execute "check_syslog.sh" in a preserve the environment which will link the VI editor to the tail program and open the " Syslog.sh " script in vi editor mode.
On execution of this command, I got a prompt from the VI text editor. Now execute the :!/bin/bash and hit enter to get a root shell.
You can find out the root flag by changing the directory to /root. Read this root flag using the cat command.
Congratulations! We have successfully captured the flag.