# Lab - Hard

## Now Let’s Begin 🚀 <a href="#df44" id="df44"></a>

## Lab -Hard <a href="#lab-easy" id="lab-easy"></a>

Initially, we'll conduct reconnaissance to detect open ports. This involves performing TCP and UDP port scans to identify all available open ports.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fob6ac7OlaFxvfaCrzWa1%2FScreenshot.png?alt=media&#x26;token=732d1336-fdde-47d7-8fcb-34a2c4929c41" alt=""><figcaption><p>TCP Port Scan</p></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FlGKPoatjA4dJassNCJ2Q%2FScreenshot(1).png?alt=media&#x26;token=69fa6bcd-679d-463a-a531-a0b8531dc653" alt=""><figcaption><p>UDP Port Scan</p></figcaption></figure>

Here are the open ports detected following a scan of TCP and UDP ports.

I attempted to experiment with the IMAP and POP3 services, but unfortunately encountered no success. Let's now investigate the UDP services to determine potential findings. UDP Port 161 is accessible, indicating the presence of an SNMP service.

**SNMP - Simple Network Management Protocol** is a protocol used to monitor different devices in the network (like routers, switches, printers, IoTs...).

For footprinting SNMP, we can use tools like `snmpwalk`, `onesixtyone`, and `braa`. `Snmpwalk` is used to query the OIDs with their information. `Onesixtyone` can be used to brute-force the names of the community strings since they can be named arbitrarily by the administrator. Since these community strings can be bound to any source, identifying the existing community strings can take quite some time.

I attempted to utilize snmpwalk, but encountered no response.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FjU7PiC8XwXJ23lYlyUM4%2FScreenshot(2).png?alt=media&#x26;token=91c99f78-a30a-4258-8cf8-4396116ab789" alt=""><figcaption></figcaption></figure>

Now I don't know the community string, so I used **`onesixtyone`**&#x74;ool and **`Seclists`**&#x77;ordlists to identify these community strings.

In order to access the information saved on the **MIB** you need to know the community string on versions 1 and 2/2c and the credentials on version 3.

The are 2 types of community strings:

* **`public`** mainly **read only** functions
* **`private`** **Read/Write** in general

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FtMkr7OThxBa9QTwtuX1s%2FScreenshot(3).png?alt=media&#x26;token=8938c076-dfa1-47bc-a72b-606708b512d3" alt=""><figcaption></figcaption></figure>

I discovered a community string, which is enclosed within the brackets \[]. Let's utilize this community string with the braa tool to explore the available information.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fz8HTJqceRqTgXkNG0jOc%2FScreenshot(4).png?alt=media&#x26;token=e89e1f8c-e834-4a37-ada5-0c8d0970d81f" alt=""><figcaption></figcaption></figure>

After employing Braa with the discovered community string, I obtained credentials for a user named 'Tom'. Let's attempt to utilize these credentials with IMAP to ascertain the available data.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FM3nqvIZvM6D53IhFdtwQ%2FScreenshot(5).png?alt=media&#x26;token=ec55c572-1a0f-49dc-9ae9-cddfa7a36b48" alt=""><figcaption></figcaption></figure>

Here's what I've accomplished:

1. Logged in with the comman&#x64;**`LOGIN username password`**
2. Listed all directories usin&#x67;**`LIST "" *`**
3. Selected the 'INBOX' mailbox with **`SELECT "INBOX"`**
4. Checked for available messages with **`1 STATUS INBOX (MESSAGES)`**  and found one
5. Retrieved the entire message with **`1 FETCH 1 all`**
6. Obtained the message content using **`1 FETCH 1 BODY[]`**

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F2EawNKkgIMAfrutoD5XX%2FScreenshot(7).png?alt=media&#x26;token=f1dfd5c1-83e3-496e-aff3-19e411a09e99" alt=""><figcaption></figcaption></figure>

I discovered a private key associated with the user 'Tom' in the message. Let's attempt to SSH using this key.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FoEbJp7sab74th8Ix15ox%2FScreenshot(8).png?alt=media&#x26;token=18a8d80c-82e9-42c0-ba88-12e73aa9b843" alt=""><figcaption></figcaption></figure>

I saved the private key as `id_rsa` and adjusted its permissions before using SSH to gain access to the target.

After conducting enumeration, I compiled a list of all files within the current directory belonging to the user 'tom.' Subsequently, I examined the`.bash_history` file and discovered the presence of a MySQL command within it.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F9dN0f3kIj1LBx8Dr51h0%2FScreenshot(9).png?alt=media&#x26;token=00cb93a5-417b-4438-9859-ef672490143c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FkI4h9VuoI8pEv2Tz7kK1%2FScreenshot(10).png?alt=media&#x26;token=651ca57c-7359-47ec-8df9-e16271cfbe8e" alt=""><figcaption></figcaption></figure>

Let's attempt to access MySQL by entering the command **`mysql -u tom -p`**, utilizing the previously discovered password for the user 'Tom'.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FHDtf45m5CNBQBTHn92Wj%2FScreenshot(11).png?alt=media&#x26;token=c04be76f-ede2-4288-99c7-728a75c432e8" alt=""><figcaption></figcaption></figure>

Upon logging in, I discovered a database named **`users`**&#x63;ontaining a table labeled as such. I proceeded to extract a comprehensive list of all columns within the **`users`** table, ultimately obtaining the password associated with the **`HTB`** user.

We have successfully completed the lab. Thank you for taking the time to read this write-up; your attention is greatly appreciated.
