# TryHack3M Subscribe

***

## INTRO

TryHack3M Subscribe is a wonderful room prepared by the following creators: [tryhackme](https://tryhackme.com/p/tryhackme), [ar33zy](https://tryhackme.com/p/ar33zy), [Dex01](https://tryhackme.com/p/Dex01), and [1337rce](https://tryhackme.com/p/1337rce) on [TryHackMe](https://tryhackme.com/r/room/subscribe) site. It's a room that incorporates both "Red teaming" and "Blue teaming" aspects.

## Enumeration

#### NMAP

We'll start with an Nmap scan of all ports using the command:

```coffeescript
sudo nmap -p- -sS 10.10.213.37 -vv 
```

Next, we'll scan the found ports, which are 22, 80, 8089, and 8000.

```coffeescript
nmap -sV -sC -O -A -p22,80,8089,8000 10.10.213.37 -vv
```

On ports 8000 and 8089, there is Splunk, which will be needed only in the second part of the room.

#### GOBUSTER

We'll start enumeration using Gobuster, as shown, the program found several interesting entries that we can check. An important aspect is to examine active js files on the server.

```coffeescript
gobuster dir -u http://admin1337special.hackme.thm -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt 
```

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2Fa95WKQVE9zWr5hEyLTmX%2FUntitled.png?alt=media&#x26;token=fb3fccb9-8093-4955-8bb7-0447489178bd" alt=""><figcaption></figcaption></figure>

## Invite code

And there, we find detailed instructions under one of them on the condition under which an invite code will be returned to us.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FX3dUuQsdNkcYlWjWlaDX%2FUntitled%201.png?alt=media&#x26;token=f221d4bd-4f66-4993-a9cf-96c4ecdb9718" alt=""><figcaption></figcaption></figure>

As we can see, it uses the function `window.location.hostname`

to check where the package is heading. To receive the file `inviteCode1337HM.php`, we will need to add a new record to the `/etc/hosts`file on our system. However, first, we will modify the code on the page to point to the file we need.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FBKTuNpeljddrnmcLkKdI%2FUntitled%202.png?alt=media&#x26;token=1d74b7c3-d0f2-44a0-bb25-87e94dccfb8b" alt=""><figcaption></figcaption></figure>

Here we add a new file location that is downloaded from the server. We'll change it to **`inviteCode1337HM.php`**.

Then, in the **`/etc/hosts`** file, we'll add a new record pointing to the server's IP address.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FwjLOKjxwA9c6l6tRyKAi%2FUntitled%203.png?alt=media&#x26;token=64bb2554-3bff-4ede-8ae1-e7528b180ec7" alt=""><figcaption></figcaption></figure>

Then we'll try entering any code. It doesn't really matter because, with our host set up correctly, the server will return us an invite code.

In exchange for writing code on the website, we'll receive guest account credentials.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FreKlCYAwGYbTyqPMENO7%2FUntitled%204.png?alt=media&#x26;token=91039014-1150-424e-8d6d-2cf3c554045b" alt=""><figcaption></figcaption></figure>

***

## Administrator Panel

After entering the correct code, a page suspiciously resembling another well-known site will appear.

We have two options to choose from: either the free one or the VIP one. Of course, since we're not VIPs, we only have access to the free one.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FRoT5kkyw3nxnci9WuWUP%2FUntitled%205.png?alt=media&#x26;token=7a5139a1-0c3a-4fc0-827d-6543274b507d" alt=""><figcaption></figcaption></figure>

As it turns out, we can obtain VIP status by changing "true" to "false" in Burp Suite.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FWpbHdybUTHWGbpJvBlKj%2FUntitled%206.png?alt=media&#x26;token=cc1f2ebb-311f-44c4-b623-5e4b1307956b" alt=""><figcaption></figcaption></figure>

Now we have access to the VIP subpage; however, there isn't much to see here. The buttons redirect us back to the initial page.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FXrS8eJPbfV17mSCfh1Cr%2FUntitled%207.png?alt=media&#x26;token=280c2390-748e-4ee6-9f70-11960d35c1d8" alt=""><figcaption></figcaption></figure>

The real gem lies in the code of the page, specifically in one of the links. By entering this link, we gain access to the "AttackBox" simulation on tryhackme.com.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FZ72kXhLznPr03iPLMjci%2FUntitled%208.png?alt=media&#x26;token=aff7ad32-e56e-4255-af26-6ca8f07660a4" alt=""><figcaption></figcaption></figure>

Now we can execute commands on the server B).

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FFLZxBRDQEePN1IRQ9PWV%2FUntitled%209.png?alt=media&#x26;token=687ad76a-fe90-4baf-8397-c8c646c94782" alt=""><figcaption></figcaption></figure>

By intercepting packets with Burp Suite, we can easily use commands. It's important to note that to execute a command each time, we need VIP status, which is why Burp Suite is a convenient and practical solution.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FHm0FY9hECebDwxTAl2np%2FUntitled%2010.png?alt=media&#x26;token=220bf82a-4ed0-4bdc-a1f3-c4aec2df47ea" alt=""><figcaption></figcaption></figure>

We got RCE B)

Well, not exactly. There's a filter on the system that prevents us from executing most commands. The available commands are found in the code of the page.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FJM5KpRehNIiCL0YCGy5x%2FUntitled%2011.png?alt=media&#x26;token=0bc14321-0b12-47bf-947f-1faa61c2ba5a" alt=""><figcaption></figcaption></figure>

We see that the machine allows the execution of the `cat`

command, which allows displaying the contents of the `config.php`

file.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2Ft2VvHGem2HT83W4ObxzQ%2FUntitled%2012.png?alt=media&#x26;token=44d97319-ebaf-4bc3-8199-9265b2a7c9c6" alt=""><figcaption></figcaption></figure>

***

## Fixing what broken - admin panel

During the attempt to open the page located in the found file, we received a 403 error, and in fact, we can't do anything else. At this stage, I had a really big problem - I had a secure admin token but no place to use it. I decided to start over - from enumeration. So, I ran Gobuster with the command below:

```coffeescript
gobuster dir -u http://admin1337special.hackme.thm:40009/public/html/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
```

Fortunately, Gobuster didn't let me down and detected an interesting location: `/login`

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2Fq6KeIyL30rlUPrOeM0tJ%2FUntitled%2013.png?alt=media&#x26;token=7acc2e30-118e-4665-9c46-c0619f5cb1df" alt=""><figcaption></figcaption></figure>

That's it! That's what I was looking for! Now we have the opportunity to use our token.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FTs4tIuXdveqINkV0knwL%2FUntitled%2014.png?alt=media&#x26;token=521996d9-3fd7-46de-b269-ab2d849e34d6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FhrkodJP9MpSpayIXFsDg%2FUntitled%2015.png?alt=media&#x26;token=6d38a87f-01b4-4e37-a790-6f8d5248cd88" alt=""><figcaption></figcaption></figure>

But now another problem has appeared: we got a login panel with no hints in the form of a username or password. I tried popular combinations like admin: admin, but it didn't work. I decided to check if there was room for SQLi here, and sure enough, an error popped up after entering the well-known and beloved `'` character.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2F0proqAJerpVivQ7OMJR2%2FUntitled%2016.png?alt=media&#x26;token=237022d9-0a83-4f6d-99bc-241d601370b8" alt=""><figcaption></figcaption></figure>

***

### SQLMAP

First, we need to copy the packet intercepted by Burp Suite to a file. This can be done by right-clicking and then selecting `save to file`. This way, SQLmap will bypass the secure\_token, which would need to be provided in the first place. The command is:

```coffeescript
sqlmap -r request.txt --dump --batch
```

And now we leave SQLmap to do its thing. The option "--batch" allows bypassing all prompts displayed by SQLmap.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FUEIUjToub6TgKJIbAUw3%2FUntitled%2017.png?alt=media&#x26;token=17984e8c-1570-4885-a983-def4f1908617" alt=""><figcaption></figcaption></figure>

And voila, SQLmap dumped the database, giving us access to the admin panel.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FhtOfVUQ4IqUSjh81KqTq%2FUntitled%2018.png?alt=media&#x26;token=893a8d1a-eb11-4427-876e-5687d30d78d5" alt=""><figcaption></figcaption></figure>

Returning to the main page, we'll receive a message and a flag.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FxnZaMSogtcBXXUSxTIdd%2FUntitled%2019.png?alt=media&#x26;token=f7b55f22-8691-4ad5-bc5c-21640e4c2684" alt=""><figcaption></figcaption></figure>

***

## SPLUNK

We'll start by logging in using the provided credentials on port 8000.

Username: admin Password: splunklab

Once logged in, select the option `Search your data` which will present us with a search field to filter our logs. To display all logs, change the time range  `All time` from the dropdown menu on the left side of the search bar. Then, enter the command `index=*` to display all entries. As you can see, there are 10,530 of them.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FI8MMwF4oWtkh0I12qhEB%2FUntitled%2020.png?alt=media&#x26;token=0a14db71-9e31-4aac-9b8b-32026b47deeb" alt=""><figcaption></figcaption></figure>

We can only answer the next question once we gather sufficient information about the attack itself. On the left side, we can see predefined filters. By searching through them one by one, we will find the `user agent` tab, within which there is an entry containing `sqlmap`. Additionally, we also have the count of entries corresponding to this filter, which is the answer to the next question.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FfY2phKAq7gFnKOWbUiVd%2FUntitled%2021.png?alt=media&#x26;token=b6c6f518-92f0-4081-9ef6-9322b979f300" alt=""><figcaption></figcaption></figure>

Clicking on the filter with `sqlmap` will present us with individual entries, clearly showing the source IP of the attacker.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FmOO8u8Wt5Gc7ro1haznl%2FUntitled%2022.png?alt=media&#x26;token=124586c1-e649-4f26-99eb-6138c5eb4ede" alt=""><figcaption></figcaption></figure>

To check the number of entries with this IP address, we will enter the query: `index=* source_ip="83.45.212.17”`

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2FnsrzYcSjotfolnxLqgAO%2FUntitled%2023.png?alt=media&#x26;token=94ba8920-3f08-4275-9e66-8e0bc0125dd2" alt=""><figcaption></figcaption></figure>

We can answer this question by clicking on the first entry, and then clicking the arrow next to the URL. This will show us all the URIs to which the attacker sent requests. As we can see, one very suspicious entry was sent only once and contains the entire SQL injection query used by the hacker. After the 'from' clause, there is the table name.

<figure><img src="https://1974736290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0LCDHJIQfEjfL8GlTIKz%2Fuploads%2F9K5BxfG4YGQKcV5hmW9S%2FUntitled%2024.png?alt=media&#x26;token=373c9431-57c3-4bf9-90b7-cfb9d87efba9" alt=""><figcaption></figcaption></figure>

***

## Conclusion

A really pleasant room that emphasized various aspects of web exploiting. The additional module with Splunk was also an interesting addition.

Thanks for reading and see you soon!
