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

# Metasploit

## Basic navigation

<table><thead><tr><th width="194">Command or Key(s)</th><th>Description</th></tr></thead><tbody><tr><td>&#x3C;Tab></td><td>Auto-completion</td></tr><tr><td>&#x3C;Tab>&#x3C;Tab></td><td>Show list of matches so far</td></tr><tr><td>clear</td><td>Clear the screen</td></tr><tr><td>CTRL + L</td><td>Clear the screen</td></tr><tr><td>&#x3C;Up> | &#x3C;Down></td><td>Scroll through history</td></tr></tbody></table>

## Metasploit commands

### Help commands

<table><thead><tr><th width="230">Command</th><th>Description</th></tr></thead><tbody><tr><td>?</td><td>Show help menu</td></tr><tr><td>help</td><td>Show help menu</td></tr><tr><td>help &#x3C;cmd></td><td>Show help on command &#x3C;cmd></td></tr><tr><td>&#x3C;cmd> -h</td><td>Show help on command &#x3C;cmd></td></tr><tr><td>info &#x3C;module></td><td>Provide detailed information about a particular module</td></tr><tr><td>search &#x3C;string></td><td>Regular-expression based search functionality.</td></tr><tr><td>search &#x3C;keyword>:&#x3C;string></td><td>Regular-expression based search functionality, <br>Keywords = type, platform, path, name</td></tr></tbody></table>

#### Search examples

To search for an auxiliary module matching the `postgres` search term

```
search type:auxiliary postgres
```

To search for an exploit module on the Linux platform matching the search term `dirty`

```
search type:exploit platform:linux dirty
```

The following are search operators that are available:

* name
* path
* platform
* type
* app
* author
* cve
* bid
* osdvb

### Global commands

<table><thead><tr><th width="209">Command</th><th>Description</th></tr></thead><tbody><tr><td>back</td><td>Move out of the current context (also removes local variables)</td></tr><tr><td>exit</td><td>Exif MsfConsole</td></tr><tr><td>load &#x3C;plugin></td><td>Loads a plugin from Metasploit’s ‘plugin’ directory</td></tr><tr><td>resourse &#x3C;file></td><td>Run commands from resource file</td></tr><tr><td>use &#x3C;module></td><td>Select this module</td></tr></tbody></table>

### Module commands

<table><thead><tr><th width="213">Command</th><th>Description</th></tr></thead><tbody><tr><td>advanced</td><td>Show advanced options</td></tr><tr><td>check</td><td>Check to see if a target is vulnerable (not supported on all exploit modules)</td></tr><tr><td>exploit</td><td>Execute exploit module</td></tr><tr><td>exploit -j</td><td>Run exploit in the background (“jobify”)</td></tr><tr><td>exploit -z</td><td>Exploit and put sessions in the background</td></tr><tr><td>generate</td><td>Execute payload module</td></tr><tr><td>info</td><td>View full module info</td></tr><tr><td>options</td><td>Display which settings are available and/or required</td></tr><tr><td>run</td><td>Run auxiliary module</td></tr><tr><td>set</td><td>Display currently set variables</td></tr><tr><td>set &#x3C;var> &#x3C;value></td><td>Configure module options and parameters</td></tr><tr><td>setg</td><td>Display currently set global variables</td></tr><tr><td>setg &#x3C;var> &#x3C;value></td><td>Set global variables within msfconsole</td></tr><tr><td>show advanced</td><td>Show advanced options (use just advanced instead)</td></tr><tr><td>show missing</td><td>Display all required, but not yet set, options</td></tr><tr><td>show options</td><td>Display which settings are available and/or required (use just options instead)</td></tr><tr><td>show targets</td><td>Display which target types are supported</td></tr><tr><td>unset &#x3C;var></td><td>Unset options or parameters</td></tr><tr><td>unset all</td><td>Unset all options or parameters (including global variables)</td></tr></tbody></table>

### Session commands

<table><thead><tr><th width="254">Command or Keys</th><th>Description</th></tr></thead><tbody><tr><td>background</td><td>Put current session in the background</td></tr><tr><td>CTRL + Z</td><td>Put current session in the background</td></tr><tr><td>sessions –i &#x3C;session_no></td><td>Interact with session &#x3C;session_no></td></tr><tr><td>session -k &#x3C;session_no></td><td>Kill specific session</td></tr><tr><td>sessions -K</td><td>Kill all sessions</td></tr><tr><td>sessions -l</td><td>List current sessions (same as ‘show sessions’)</td></tr><tr><td>sessions –u &#x3C;session_no></td><td>Upgrade shell session to Meterpreter shell</td></tr></tbody></table>

### Database backend commands

<table><thead><tr><th width="254">Command or Keys</th><th>Description</th></tr></thead><tbody><tr><td>db_connect</td><td>Connect to an existing database</td></tr><tr><td>db_disconnect</td><td>Disconnect from the current database instance</td></tr><tr><td>db_export</td><td>Export a file containing the contents of the database</td></tr><tr><td>db_import</td><td>Import a scan result file (filetype will be auto-detected)</td></tr><tr><td>db_nmap</td><td>Executes nmap and records the output automatically</td></tr><tr><td>db_rebuild_cache</td><td>Rebuilds the database-stored module cache</td></tr><tr><td>db_status</td><td>Show the current database status</td></tr><tr><td>hosts</td><td>List all hosts in the database</td></tr><tr><td>loot</td><td>List all loot in the database</td></tr><tr><td>notes</td><td>List all notes in the database</td></tr><tr><td>services</td><td>List all services in the database</td></tr><tr><td>vulns</td><td>List all vulnerabilities in the database</td></tr><tr><td>workspace</td><td>Switch between database workspaces</td></tr></tbody></table>

## Resources

Metasploit - Documentation: <https://docs.metasploit.com/>

Metasploit - Homepage: <https://www.metasploit.com/>

Metasploit - Wikipedia: <https://en.wikipedia.org/wiki/Metasploit>

Metasploit-Framework - Kali Tools: <https://www.kali.org/tools/metasploit-framework/>

Msfconsole Commands - Metasploit Unleashed - OffSec: <https://www.offsec.com/metasploit-unleashed/msfconsole-commands/>

Using the Database - Metasploit Unleashed - OffSec: <https://www.offsec.com/metasploit-unleashed/using-databases/>
