# Dog Machine

***

### Machine Information

* **Machine Name:** Dog
* **Machine IP:** 10.10.11.58
* **Machine Difficulty:** Easy
* **Machine OS:** Linux

***

### Reconnaissance - gathering information

Information gathering is a very crucial step in any kind of hack, and it is performed by all kinds of hackers regardless of what hat they are wearing. In this, we try to collect as much information as possible about the target, so later on we can find a vulnerability to exploit.

#### Ports and Services scan

You are given a task to rob a royal palace, but the only information you have is the **address** of the royal palace, what will be your next step? For me it would be walking around the palace to find **open doors & ports**, cause their availability is the greatest reason for their vulnerability. This is what happens in most of the attacks, a computer has a vulnerable or unwanted port open which becomes a perfect gateway for hackers to gain access to the system.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-2e83f2ac19894def4ad8d5bc9c6bc62dd87822cc%2F1.png?alt=media)

**Command I performed:**

* `sudo nmap -sVC -p- -O 10.10.11.58 | tee nmapDog.txt`

**Understanding the command:**

* **-sVC** - It check for Service version and execute all default NSE scripts corresponding to the services for more information.
* **-p-** - It scan all ports.
* **-O** - It detects possible OS running on the target machine.

I use nmap tool to scan for all TCP open ports with OS detection, and in the result we get 2 ports that are open, which are as follow:

1. 22/tcp - OpenSSH 8.2p1
2. 80/tcp - Apache httpd 2.4.41 (likely vulnerable)\
   With the Apache service, we found 2 interesting things, which are a robots.txt and a git repository. These two things can be utilized for further investigation and staging our initial exploit.

#### Website Recon

In this phase, we will go through target's website and try to gather information that can help us to identify potential vulnerabilities or chances for any exploitation.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-3616089c92efc438f3f8d2023a3b092630c1ce00%2F2.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-d5b174e0ead4c2227c4c433ffd7297de38174f8e%2F3.png?alt=media)

As we open the website, we see it is related to Dogs, such as causes of obesity in dogs, dog's diet, lack of exercise, etc. I manually checked all links in the website and they all end up to different webpages with information related to Dogs.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-157b1d5319a109f3ee96b61cfeca262cccc813cd%2F4.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-8b11dd0eba2b7d9e8eec043937c2c215b4798179%2F5.png?alt=media)

As I was searching through the website, I found a **Powered by Backdrop CMS** line at the bottom of the website, which clarifies that the website is based on Backdrop CMS. I also visited the About page and found a support email, I noted it down thinking it might become useful in future.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-d6af93bd360c55505e28e57f8bef73f3c69a7fd1%2F6.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-095f52f98fa42a22b1086afa99778894d264d520%2F7.png?alt=media)

Next, I visit the login page and we also see reset portal here. Another interesting thing to explore here is the git repository by appending `/.git/` at the end of your url as shown in the image. I explored it manually and you can also do to get an idea of the structure, but it is not directly related to our Hack The Box task so I would not be adding all those process or findings here.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-0da3034ce98d06f871a80131ced760573c9705a7%2F9.png?alt=media)

For investigating publicly accessible git repositories there is a great tool on github, and I would be using it to locally download the git repo and unpacking it for analysis.

**Commands I performed:**

* `git clone https://github.com/internetwache/GitTools.git`
* `cd GitTools/Dumper`
* `./gitdumper.sh http://10.10.11.58/.git/ ./dog-git`
* `cd ..`
* `cd Extractor`
* `./extractor.sh ../Dumper/dog-git/ dog-ext-git/`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-fa25914fc7936cd8738c9b356eb4bb9ca1062077%2F10.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-7cf06ae5d41491ae016efa164bc0018c99ca5d10%2F11.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-47daea20c9318b5ca41225e5807aa47d673d5aa0%2F12.png?alt=media)

In the GitTools, there is a `gitdumper` command that will create a local directory which will dump all the content of git repo according to the target URL. After that, you will have to use `extractor` command to create another local directory which will take all the dumped data previously created with `gitdumper` and it will extract everything in it. This will allow you to view the content of git repository on your local system.

Next step is to go into the extracted directory and look for valuable information.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-a13a0a297227f62affc30e6a48b20eacbd6f5186%2F13.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-b9e7cd969975f3cece60548b6fa18c15c380a1b5%2F14.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-8299e8aaf3cbc51c032d8d592999f7aa4a606479%2F15.png?alt=media)

I explored almost all files and folders and found many interesting things, which included the following:

1. **hash salt:** There is a variable named hash\_salt with a hashed value, it is probably the salt used for passwords.
2. **mysql database path:** We see a mysql database path, which includes a username root and a password BackDropJ2024DS2024.
3. **config dir:** We also found the URL path for the config files (active and staging).\
   These information can further help us to find more valuable things or maybe even give us access to the admin dashboard.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-6e2f4b8d50b2c050ebbfe0e193a9e86a927d3180%2F16.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-a3a74d2fc6990f0e2dd31ce8b3830aa828020b0d%2F16_1.png?alt=media)

Lastly, I search for meaningful information in the config/active file and found an email address. Considering the fact that we already have found a password, we can try using it with this email to login into the admin portal. There was also core/modules/system directory where we found the exact version of **backdrop** in system.info file.

***

### Exploitation: Gaining Access

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-4a3f43dfd259d96d27e6485932e4059b8bb6ae40%2F17.png?alt=media)

We were successfully able to login into the admin portal using the leaked email and password we found during our analysis, and it is an Admin dashboard which can be further used to exploit the system. The password is comparatively complex than other challenges

> *"A strong password does not always define a secure environment, there are other ways to get in"*

#### Searching for available exploits & vulnerabilities

We already have version information which we previously found during our investigation, now we can use it to search for available vulnerabilities and their exploits. I would use a well-known tool `searchsploit` for this job.

**Commands I performed:**

* `searchsploit backdrop 1.27.1`
* `searchsploit -m php/webapps/52021.py`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-3d18008cf6735b274793e06ac866d779daab944e%2F18.png?alt=media)

I searched for available exploits for backdrop 1.27.1, and there was only one exploit available in their database, and it is a Authenticated RCE which means that to execute it the attacker will need to be authenticated. This would work for us because we already are authenticated and RCE seems a good way in. So, I immediately install the exploit in my local system. For now, we will see how the exploit works, a detailed explaination might be launched soon or will be available on my discord server.

#### Exploiting the system

**Commands I performed:**

* `python3 52021.py http://10.10.11.58/`
* `tar -czf shell.tar.gz shell`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-4012e785b25655f54f879211b45774ee32f3a912%2F19.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-254e662c451cb88e55b0ada90350e25eff218523%2F19_1.png?alt=media)

Going through the exploit, it is pretty clear that it generates a evil zip file which can be uploaded on the website to get a reverse shell. The problem with us is that our site only accepts files with **tar.gz** compression, so after generating the evil file we will have to recompress it with tar.gz.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-9f5c484c6736c3e5b4f27a2e3015eb3bc66a47e6%2F20.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-c0c885f7cca15d277b31fc3e63b94dee200bdbd1%2F21.png?alt=media)

Lastly, we go to the `installer/manual` subdirectory for uploading our malicious file and we were successfully able to upload it. Now it is time to access it, but during this period I realized there was some firewall that immediately deleted our uploaded shell after we executed certain commands, so definitely we cannot use it as a persistent reverse shell.

**Command I performed (on the shell uploaded):**

* `cat /etc/passwd`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-271b8dafe5e957c9e37014af06903d5b6dfbf887%2F23.png?alt=media)

After spending some time I found a way to get inside the system without any trouble. We can expose the `/etc/passwd` file and use the user information of johncusack to get a connection from SSH. We would be using the following credential to login SSH:

* **Username:** johncusack
* **Password:** BackDropJ2024DS2024

**Command I performed:**

* `ssh johncusack@10.10.11.58`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-4f4d65bbe6a8a339c118d4ef743a07e851813ad1%2F24.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-6019a27cfe06b0ac847aa08d6cf9dd3f784b4d34%2Fuser_flag.png?alt=media)

Nice achievement! We were able to successfully login into the user through SSH and a reused password. We also got our first flag, now we will find ways to escalate our privileges.

***

### Privilege Escalation - root Me Please

Privilege Escalation is a process of elevating your privileges from a normal user to a admin-level or root user. It is used in many challenges, and it is one of the most complex things but also simpler to achieve. The exploits or path way used in privilege escalation can sometimes be difficult to understand, but it is worth giving a shot.

#### Searching for loopholes

The first step is to search for gateways that will possibly help you to elevate privileges, it is similar to scanning for available vulnerabilities.

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-77c3abb43722e39dcd413d6e5f7ddd0d72856507%2F25.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-eea8315394159f915146c9566d5cdb5f2dfde3f0%2F26.png?alt=media)

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-c9fcbbbbf2c7dfe00d9272ca18d86e10357b9b6a%2F27.png?alt=media)

Great! We found a binary that we can execute as johncusack user as root, and we will require password for this (which we already have). On further analysis, I found that there is a way to execute commands using this binary, by using the `--root` and `eval` options.

**Command I performed:**

* `sudo /usr/local/bin/bee --root=/var/www/html/ eval 'system("/bin/bash")'`

![](https://347332819-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F02pUMNuypUM36V79J5Yr%2Fuploads%2Fgit-blob-b2e4551101b6bf556e49557fd2cf1f0554d647d4%2Froot_flag.png?alt=media)

Finally we were successfully able to escalate our privileges as root and got the root flag. The detailed explaination for exploits used might be released soon on my discord server, so don't forget to join it.

***

### Conclusion - lesson learned

Time for concluding everything that we can learn from this vulnerable machine, such as detail on vulnerability or fixes available. For me, the initial foothold was quite difficult as compared to privilege escalation. If there are any other possible ways to exploit the machine then do not hesitate to ping the methodology on my discord server's `HTB` channel by mentioning me.

#### Vulnerabilities - what was hacked?

This section will discussion the vulnerabilities that were exploited and used for our benefit to gain access to the system, and it will also include available fixes for those vulnerabilities.

**Git Repo - exposed to the web**

Initially while performing our ports and services scan, we were able to find `.git` repository being exposed to the Internet, it means anyone can use it to extract sensitive information. In most cases, people do not openly share their git repo if it contains some sensitive information, but here it was accessible and it also had sensitive information that helped us to gain our foothold on the system.

**Fix - what should be done**

The best recommended fix is to private the git repository from the github account if it contains any sensitive information, cause github is a place where open-source software are published, and it is by-default publicly accessible. It is better to private it from the setting of the git repository which will avoid any access to it.

#### backdrop 1.27.1 - outdated software

After getting the access to the admin's account using the information that was gathered from git repository, we were able to find available exploit for LFI vulnerability in the backdrop 1.27.1 CMS. This vulnerability allow an authenticated user to upload a malicious file which he can execute to get a reverse shell.

**Fix - what should be done**

The best recommended advice is to update backdrop < 1.27.1 or to its latest version. This will get rid of the LFI vulnerability because it is been already patched in the later versions by backdrop.

This is the end, for my discord server join the following link: [Discord - Cyber X army](https://discord.gg/wyfwSxn3YB)
