> For the complete documentation index, see [llms.txt](https://thamizhiniyancs.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thamizhiniyancs.gitbook.io/writeups/hackthebox/tracks/pwn-with-metasploit/optimum.md).

# Optimum

Optimum writeup by Thamizhiniyan C S

## Overview

Greetings everyone,

In this write-up, we will tackle Optimum from HackTheBox.

Machine link: [Optimum](https://app.hackthebox.com/machines/6)

Difficulty Level: Easy

Let's Begin 🙌

Firstly, connect to the HTB server using the OpenVPN configuration file generated by HTB.  [Click Here](https://help.hackthebox.com/en/articles/5185687-introduction-to-lab-access) to learn more about how to connect to VPN and access the boxes.

Once connected to the VPN service, click on "Join Machine" to access the machine's IP.

Upon joining the machine, you will be able to view the IP address of the target machine.

***

## Reconnaissance

### Nmap Aggressive Scan

`nmap -A -T4 <TARGET>`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FgeKkM8wyx63lW87WG6JB%2FUntitled.png?alt=media&amp;token=4d4375f5-9566-4fa4-ae2b-ef8e9e2a52b9" alt=""><figcaption></figcaption></figure>

### **Results**

| Ports | Services | Service Version          |
| ----- | -------- | ------------------------ |
| 80    | HTTP     | HttpFileServer httpd 2.3 |

***

## Information Gathering - Port 80

I searched google about the ‘HttpFileServer httpd 2.3’ to find more about it and found that it’s vulnerable to Remote Command Execution.

<figure><img src="https://lh7-us.googleusercontent.com/wsvMbREhRs_7WXeiw80stcRe29Kv0HYvzJNzg-iJWSCVn0KSQ2oUEnvpHMzXSY2Z_vAEW8TzMnp9SLFCQcQ6bSnbDOJyLo4UQpb6cpD_-wlNutzKvenyezouE7a3a5h84xlpE3oyuCmCfcSDAng7n-c" alt=""><figcaption></figcaption></figure>

***

## Initial Access

We found that the service ‘`HttpFileServer httpd 2.3`’ is vulnerable to Remote Command Injection on the Information Gathering phase. Let’s try to exploit that using Metasploit. Start metasploit using the command ‘msfconsole’. Search for exploits for the service ‘`httpfileserver`’ using the command ‘`search httpfileserver`’.

<figure><img src="https://lh7-us.googleusercontent.com/CpQxdFaUUqydPxikpG5xfFRgVy6hph9N5-HGn7PmmzgGP5vKLm0SGgFb4H2MGm4w_RLy7oY7Xd4uWJtPzgFrNXxTGszqfacLwp0_mGqnEoDMoCmhC3SRE3H6aVQ_f7kAujgeH4xPk7fEiBBkrFvWSzk" alt=""><figcaption></figcaption></figure>

Select the exploit using the command ‘use 0’. Next check the options for the exploit using the command ‘show options’. The required options that we need to modify are RHOSTS ( target IP ) and LHOST ( attacker IP )

<figure><img src="https://lh7-us.googleusercontent.com/brqfCYZUK3Tpnh5gHwvqsMvVmyCUhc3oMh-ip5MnSROThR1dw_GJgV-qximlSq0X9y8K_49KsEAO1c1JzdklJySZRncAef0F5uyo22XYm_wgBdPTqr8tgwq_RXDaN57ZyuEXt42Tl12SLgBAUOcgd34" alt=""><figcaption></figcaption></figure>

We can do that by using the following commands:

* `set rhosts <Target_IP>`
* `set lhost <HTB_TUN_IP>`

<figure><img src="https://lh7-us.googleusercontent.com/-STh8i0ztDdFP313C4ENDOp6Afeef0cRtMocqtAFFSdobRXiEaL0ijHTQJ0tmpeYVXT-1hJ14AppYXzRtVxj7k4cld1-3Y02RHs7x0WGSBOakcQh3SfAXhNNFO_WjEzg1WyXzf_BIF9ylMrUl9Q7Vx0" alt=""><figcaption></figcaption></figure>

Now to perform the exploit, enter the command ‘exploit’ and press enter.

<figure><img src="https://lh7-us.googleusercontent.com/0vgK-Zy_QLqgJDEpVRBoRMXvUyliTkXqqWR3F2vaHBPjXVMg9Xc1qiENPjX8JSGF0Ax076k5iqBp9Vy7nBUMMOeKRbjMwqEmVy7dlUSnbsVssjxNXZFxf5U9jS1sLRx19yjIGAXHV8rQQ5i4oDz2CgM" alt=""><figcaption></figcaption></figure>

We have successfully exploited the target and got our initial access on the target machine.

***

## Getting the User Flag

Found the user flag in the Desktop Directory.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F2zjiMPlhiV5Qqa3NfwXj%2FUntitled%208.png?alt=media&amp;token=88f8b014-46f3-49cf-8214-d93fe938fd13" alt=""><figcaption></figcaption></figure>

***

## Privilege Escalation

First I tried the ‘`getsystem`’ command which executes a ‘`meterpreter`’ script that tries to escalate privileges, but it failed.

<figure><img src="https://lh7-us.googleusercontent.com/nF7VaqmM30NBXSpK_0yVrgGETDfe-UjlnxyN0obg3lKTxTDUcF6btDA9rSVrVYzRXNrMHI90QUus6n6bZx6_iruFLICLzStkVsqlNcGL5GNqR8TgSx4qH3-xB_sxUglYOIjONUbSZPTuDrRll9lG4jA" alt=""><figcaption></figcaption></figure>

Next I decided to look out for exploits to escalate privileges. For this I used another Metasploit module ‘`local_exploit_suggester`’. To use that first we have to put the current ‘`meterpreter`’ session to background using the command ‘`background`’.

<figure><img src="https://lh7-us.googleusercontent.com/cn5VKYboxXHZdRvEkOUVZ8kceaGsxzE0zgZ2Q16mPEYEp3cP6mBB4rRfd6-4WYL-qjQEGpupePuxWVaktoN5M6fHDpmyFE43I0KVfs4E_6b2Xyu5AbFZzKW2MAq34x3fKdmHN0dIaxBPahzE5upSLOY" alt=""><figcaption></figcaption></figure>

Now select the Metasploit module by using the command ‘`use post/multi/recon/local_exploit_suggester`’. Check out the required options for the module to run. The required options are SESSION ( id of the ‘`meterpreter`’ session that we put in background ).

<figure><img src="https://lh7-us.googleusercontent.com/JBG43SQNQ1wZugSuINNwyRxWD80hQDH6CuWxZeLIHO5NasMAOCF7OwdV4J4DGktZSIM-_rJfBNYKEoTtDzDnr37Gg6gZv8lnLecPEoIeqxY7TrhAJc6jBXV82GQyuUBUo7m52EyEpskpCz4oaXR9ryI" alt=""><figcaption></figcaption></figure>

We can find the session id by using the ‘`sessions`’ command. Use the command ‘`set session 1`’ to refer to the required session.

<figure><img src="https://lh7-us.googleusercontent.com/pjHrRPtdmNANMiHj1IVc7szL6t8A6OqHsMOVPmkKO1iReLvCqCa0OsS4CGjHEbWHvM2r-HJpKMN42Ioj2c8fRxgDH6kO7Zdf4qm2Wi7FfUW7CpktPNXyU-W7Ay4V1291p-c3PdK5n3_y14bMDcVlUis" alt=""><figcaption></figcaption></figure>

We can run the module using the command ‘`exploit`’.

<figure><img src="https://lh7-us.googleusercontent.com/1POGrSisQglJV2N3-OZVodj4zjjju-SY0mTzOweWyIBofyqkV4MdOzhCRgrvmhr3yJrk7Y629h0zGLgHZokcx3xsVY9UvXWfVPn6Urn3vGkmYY22RAvUs1dcbSuhC4SyRC8pnmtvwJatqVTY-xTDkj0" alt=""><figcaption></figcaption></figure>

We can see five possible suggestions by ‘`local_exploit_suggester`’ out of which, ‘`exploit/windows/local/ms16_032_secondary_logon_handle_privesc`’ worked. We can use this exploit by using the command ‘`use exploit/windows/local/ms16_032_secondary_logon_handle_privesc`’. Check out the required options for this exploit to run. The required options are the SESSION ( id of the ‘meterpreter’ session that we put in background ) and the LHOST ( attacker IP ).

<figure><img src="https://lh7-us.googleusercontent.com/igofn4eH2UKEYv0G9Az0cSGaobu2yeR3ADcR5o8jR9VCt_8C8b8zg9RV7qhHcKnrPnIRje2dPVl0TnHoWIsdlXw0XYpbq1mNpIPtgumUFbVT-svevRXxISzbR-MkDr6HPVdf9fZ0Mdj6mWIZ2YV6BPw" alt=""><figcaption></figcaption></figure>

We can do that by using the following commands:

* `set session 1`
* `set lhost <HTB_TUN_IP>`

<figure><img src="https://lh7-us.googleusercontent.com/wNVItxsUi0pPeAzsESeVbUYxIjLeWiHwd-prBCWMwivUK5HPEiV58zDkqU_m-GxxAydnsSJUMb2139TZGAmJBsRxKzw1G8w1JMIeBKOIDmv3uij6KspDQIw7P_4d6-o62Y_Gbx-bb7mfzUaaeeuDOMQ" alt=""><figcaption></figcaption></figure>

Now execute the exploit using the command ‘`exploit`’.

<figure><img src="https://lh7-us.googleusercontent.com/d89wkoiPb2llW0RPMDFJLTDAmyN5dm7Dad9f2SnqArIxT3qH0m_9fTbxe5jJeqVaXsz7XupWNEnp_nIIG_FonWNmuhxwmXLFMHXt4hyqBGGG2v7qMmSNOwwFIzfZkHbWT3dAZx4Pipq-i51PxNw7SdM" alt=""><figcaption></figcaption></figure>

We have successfully performed privilege escalation.

***

## Getting the Root Flag

I searched for the `root.txt` using the `search` command in meterpreter.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F2JeTfwxoJrTi3ZWQeQE2%2FUntitled%2017.png?alt=media&amp;token=a4878e08-2ea8-489e-bc77-bcaa0ca98bc0" alt=""><figcaption></figcaption></figure>

Found the root flag at `C:\Users\Administrator\Desktop\root.txt`.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FxEzW4p32wPHGIrZNlx73%2FUntitled%2018.png?alt=media&amp;token=bfad4217-6964-4b6d-a87b-0362757327c7" alt=""><figcaption></figcaption></figure>

Thank You...
