# Metasploit

## [Metasploit](https://github.com/rapid7/metasploit-framework) installation&#x20;

{% code overflow="wrap" %}
```bash
sudo apt install postgresql
sudo apt install metasploit-framework
```
{% endcode %}

## Start

<table><thead><tr><th width="205">Description</th><th>Command</th></tr></thead><tbody><tr><td>Update</td><td><code>sudo apt update &#x26;&#x26; sudo apt install metasploit-framework msfupdate</code></td></tr><tr><td>Run</td><td><code>msfconsole</code> <br><code>msfconsole -q</code> <br><code>service postgresql start &#x26;&#x26; msfconsole</code></td></tr></tbody></table>

## Database

<table><thead><tr><th width="207">Description</th><th>Command</th></tr></thead><tbody><tr><td>Initialization</td><td><code>msfdb init</code> <br><code>msfdb reinit</code></td></tr><tr><td>Check</td><td><code>db_status</code></td></tr><tr><td>Help</td><td><code>help database</code></td></tr></tbody></table>

## Workspace

<table><thead><tr><th width="208">Description</th><th>Command</th></tr></thead><tbody><tr><td>Help</td><td><code>workspace -h</code></td></tr><tr><td>Listing</td><td><code>workspace</code></td></tr><tr><td>Selecting</td><td><code>workspace &#x3C;NAME></code></td></tr><tr><td>New </td><td><code>workspace -a &#x3C;NAME></code></td></tr><tr><td>Delate workspace</td><td><code>workspace -d</code></td></tr><tr><td>Delete all workspace</td><td><code>workspace -D</code></td></tr><tr><td>Nmap</td><td><code>db_nmap &#x3C;COMMAND_NMAP></code></td></tr><tr><td>Display data<br><code>&#x3C;TYPE> -h</code></td><td><p><code>hosts</code><br><code>services</code><br><code>creds</code><br><code>loot</code><br><code>analyze</code><br><code>vulns</code><br><code>notes</code></p><p><code>route</code></p></td></tr><tr><td>Export</td><td><code>db_export -f xml</code></td></tr><tr><td>Import</td><td><code>db_import &#x3C;FILE_SCAN_NESSUS.nessus></code><br><code>db_import &#x3C;FILE_SCAN_NMAP.xml></code></td></tr></tbody></table>

## Command

<table><thead><tr><th width="180">Description</th><th>Command</th></tr></thead><tbody><tr><td>Help</td><td><code>help</code> <br><code>&#x3C;COMMAND >-h</code></td></tr><tr><td>Refresh</td><td><code>reload_all</code></td></tr><tr><td>Search modules</td><td><em><mark style="color:blue;">&#x3C;type>/&#x3C;os>/&#x3C;service>/&#x3C;name></mark></em><br><strong>Type</strong>: <em>exploits, payloads, auxiliary, post, etc.</em><br><code>search &#x3C;STRING></code> <br><code>search type:&#x3C;TYPE> name:&#x3C;STRING> [&#x3C;KEYWORD>:&#x3C;VALUE>]</code></td></tr><tr><td>Filter</td><td><code>grep &#x3C;STRING1> grep &#x3C;STRING2> &#x3C;COMMAND></code></td></tr><tr><td>Info module</td><td><code>info &#x3C;N></code></td></tr><tr><td>Select module</td><td><code>use &#x3C;N></code></td></tr><tr><td>Setting Options</td><td><code>show options</code><br><code>set &#x3C;VARIABLE> &#x3C;VALUE></code><br><code>show advanced</code></td></tr><tr><td>Setting Payload</td><td><p><code>show payloads</code></p><p><code>set payload &#x3C;N></code></p></td></tr><tr><td>Setting Target</td><td><code>show targets</code><br><code>set target &#x3C;N></code></td></tr><tr><td>Encoders</td><td><code>show encoders</code></td></tr><tr><td>Setting Global</td><td><code>setg &#x3C;VARIABLE> &#x3C;VALUE></code></td></tr><tr><td>Run</td><td><code>check</code><br><code>run</code><br><code>exploit</code><br><code>exploit -e &#x3C;shikata_ga_nai></code></td></tr></tbody></table>

## Sessions

<table><thead><tr><th width="193">Description</th><th>Command</th></tr></thead><tbody><tr><td>Help</td><td><code>sessions -h</code></td></tr><tr><td>Listing</td><td><code>sessions</code></td></tr><tr><td>Upgrade</td><td><code>sessions -u &#x3C;ID></code></td></tr><tr><td>Resume</td><td><code>sessions -i &#x3C;ID></code></td></tr><tr><td>Close</td><td><code>sessions -k &#x3C;ID></code></td></tr><tr><td>Close all</td><td><code>sessions -K</code></td></tr></tbody></table>

## Job

<table><thead><tr><th width="209">Description</th><th>Command</th></tr></thead><tbody><tr><td>Help</td><td><code>jobs -h</code></td></tr><tr><td>Start exploit in jobs</td><td><code>exploit -j</code></td></tr><tr><td>Listing</td><td><code>jobs -l</code></td></tr><tr><td>Close</td><td><code>jobs -k &#x3C;ID></code></td></tr><tr><td>Close all</td><td><code>jobs -K</code></td></tr></tbody></table>

## Meterpreter

<table><thead><tr><th width="209">Description</th><th>Command</th></tr></thead><tbody><tr><td>Help</td><td><p><code>help</code></p><p><code>&#x3C;COMMAND> -h</code></p></td></tr><tr><td>Local command</td><td><code>l&#x3C;COMMAND></code></td></tr><tr><td>Modules</td><td><code>run &#x3C;MODULES></code> <br><em><mark style="color:green;">post/multi/recon/local_exploit_suggester</mark></em></td></tr><tr><td>Migrate</td><td><p><code>ps</code>      <em>(explorer or lsas)</em></p><p><code>pgrep &#x3C;NAME></code></p><p><code>migrate &#x3C;PID></code></p></td></tr><tr><td>Background</td><td><code>background</code><br><code>CTRL+Z</code></td></tr><tr><td>Close</td><td><code>exit</code><br><code>CTRL+C</code></td></tr><tr><td>To obtain it</td><td><code>exploit/multi/script/web_delivery</code> <br><code>exploit/windows/smb/smb_delivery</code><br>or <code>Exploits</code></td></tr></tbody></table>

## Plugin

Add plugin in `/usr/share/metasploit-framework/plugins`

<table><thead><tr><th width="216">Description</th><th>Command</th></tr></thead><tbody><tr><td>Upload</td><td><code>load &#x3C;PLUGIN></code></td></tr><tr><td><a href="https://github.com/hahwul/metasploit-autopwn">Autopwn</a></td><td><code>load db_autopwn</code><br><code>db_autopwn</code></td></tr><tr><td>WMAP</td><td><p><code>load wmap</code></p><p><code>wmap_&#x3C;TAB></code> <br><code>wmap_&#x3C;X> -h</code></p></td></tr><tr><td><a href="https://github.com/darkoperator/Metasploit-Plugins">Pentest</a></td><td><code>load pentest</code></td></tr></tbody></table>

## Non-Staged & Staged

<table><thead><tr><th width="200">Type</th><th>Description</th></tr></thead><tbody><tr><td>Non-Staged</td><td>Single payload.<br><em>es. windows/<mark style="color:purple;">shell_bind_tcp</mark></em></td></tr><tr><td>Staged</td><td>Two part. <br><em>es. in windows/<mark style="color:purple;"><strong>shell</strong></mark>/<mark style="color:blue;"><strong>bind_tcp</strong></mark></em>  </td></tr></tbody></table>
