> For the complete documentation index, see [llms.txt](https://106-sam.gitbook.io/ejptv2-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://106-sam.gitbook.io/ejptv2-notes/the-metasploit-framework-msf/metasploit/metasploit-fundamentals.md).

# Metasploit Fundamentals

### Installing & Configuring The Metasploit Framework

* The MSF is distributed by Rapid7 and can be downloaded and installed as a standalone package on both Windows & Linux.
* In this course we will be utilizing the Metasploit Framework on Linux and our preferred distribution of choice is Kali Linux.
* MSF and its required dependencies come pre-packaged with Kali Linux which saves us from the tedious process of installing MSF manually.

**The MSF Database**

* The MSF database (msfdb) is an integral part of the Metasploit Framework and is used to keep track of all your assessments, host data scans etc.
* The MSF uses PostgreSQL as the primary database server, as a result, we will also need to ensure that the PostgreSQL database service is running and configured correctly.
* The MSFdb also facilitates the importation and storage of scan results from various thrid party tools like Nmap and Nessus.

**Installation Steps**

* Update our repositories and upgrade our Metasploit Framework to the Latest version.
* Start and enable the PostgreSQL database service.
* Initialize the Metasploit Framework Database (msfdb).
* Launch MSFconsole!

**Demo**

```
sudo apt update && apt get install metasploit-framework -y
```

```
sudo systemctl start postgresql
```

```
sudo msfdb
```

```
sudo msfdb init
```

* reinit deletes the data so be careful&#x20;

```
sudo msfdb reinit
```

* for status & path to configuration files

```
sudo msfdb status
```

```
msfconsole
```

***

### MSFconsole Fundamentals

* Before we can start using the Metasploit Framewrok for penetration testing, we need to get an understanding of how to use MSFconsole.
* The Metasploit Framework Console (MSFconsole) is an easy-to-use all in one interface that provides you with access to all the functionality of the Metasploit Framework.
* We will be utilizing MSFconsole as our primary MSF interface for the rest of the course.

<figure><img src="/files/fleyif715PpUquiWKWFh" alt=""><figcaption></figcaption></figure>

**MSF Module Variables**&#x20;

* MSF modules willl typically require information like the target & host IP address and port in order to initiate a remote exploit/connection.
* These options can be configured through the use of MSF variables.
* MSFconsole allows you to set both local variable values or global variable values.

<figure><img src="/files/aShZnhGnrTJ1W0aH975J" alt=""><figcaption></figcaption></figure>

**DEMO**

```
msfconsole 
> help
> version
```

* To show exploits

<pre><code><strong>> show expoits
</strong></code></pre>

* show help menu

```
> show -h
```

* searching

```
> search portscan
> use <number>/copy path
> show options
> set RHOST <targetIP>
etc...
```

* to go back or stop using present module

```
> back
```

* to search with CVE's

```
> search -h
> search cv:2017 type:exploit platform:- winodws
```

* advance options

```
> search eternalblue
> use 0
> show options
etc..
```

```
sessions
```

* &#x20;for banner grabbing

```
> connect -h 
> connect <targetIP> <port>
```

***

### Creating & Managing Workspaces

**MSF Workspaces**

* Workspaces allow you to keep track of all your hosts, scans and activities and are extremely useful when conducting penetration tests as they allow you to sort and organize your data based on the target or organization.
* MSFconsole provides you with the ability to create, manage and switch between multiple workspaces depending on your requirements.
* We will be using workspaces to organize our assessments as we progress through the course.

**DEMO**

* to check the db status

```
> dbstatus
```

```
> workspace -h
```

* by default it connect to default workspace

```
> workspace
```

* to check the hosts that we sacn or exploited&#x20;

```
> hosts
```

```
> workspace -a Test
> workspace
> hosts
```

* to move

```
> workspace default
```

* to delete workspace

```
workspace -d <workspace name>
```

* to rename workspace

```
workspace -r <workspace <oldname> <newname>
```

***
