Manage Meterpreter and Shell Sessions
After you successfully exploit a host, either a shell or Meterpreter session is opened. By default, Metasploit attempts to deliver a Meterpreter payload. A Meterpreter payload is uploaded to a remote machine that allows you to run Metasploit modules. If Metasploit is unable to deliver a Meterpreter payload then it opens a shell.
Depending on the module used to create a session, either a Shell or both a Shell and Meterpreter session will be opened. This is because shell payloads are created by running a command on a remote machine, and they can be easier to “launch”. Some exploits are limited in functionality ,and shell commands require less manipulation by the exploit.
A Meterpreter shell gives you access to Metasploit modules and other actions not available in the command shell.
A shell session opens a standard terminal on the target host, giving you similar functions to a terminal on your OS. The functionality can differ depending on the type of exploit used. Using a shell does not provide the same actions as a Meterpreter shell.
Command Shell
“Command Shell” is listed under Shell and Meterpreter. While the name is the same, the functionality is not. Meterpreter > Command Shell will open a Meterpreter shell, while Shell > Command Shell will open a standard terminal.
Manage Your Meterpreter Session
To access the session pages in the top menu go to "Sessions".
The Meterpreter "Active Sessions" page provides you with the following information:
- Session - The number of the session. These are attached to the session in sequential order of being created.
- OS - The host operating system.
- Host - The host address and name.
- Type - The type of shell.
- Age - The time the session has been opened in minutes or seconds. Once 60 seconds is reached, time is tracked in minutes.
- Description - Any information related to how the session was opened if available. For example, bruteforce opened sessions will contain the username and password used.
- Attack Module - The exploit used to open the session.
View Available Meterpreter Actions
To see all the available actions for a Meterpreter shell during a session, do the following:
- Under “Active Sessions” select a session that has a “Type” of “Meterpreter”.
- On the session page, review the available actions. From this page, you can launch a terminal, see available modules and run post-exploitation actions.
The Meterpreter session page has the following information:
- Session - Session number and target host address. In the image above this is
Session 2 on 127.0.0.1
- Session Type - The type of payload and module used to open the session.
- Information - Any information on how the session was opened. If this was the result of a bruteforce attack it will include the authentication type and credential pair used.
- Attack Module - Exploit used to open the session.
- Available Actions - All the available actions that can be taken.
- Session History - A detailed list of all actions taken during an open session.
- Post-Exploitation Modules - Modules available to run based on the OS and payload type.
Launch the Meterpreter Command Shell
Under “Available Actions” click Command Shell. It will open a blank terminal.
At the top is the session ID and the target host address. In this example, the session ID is :
Metasploit - Mdm::Session ID # 2 (127.0.0.1)
At the bottom is the shell input. Meterpreter >
View Available Meterpreter Shell Commands
To see a list of available commands type
?
.Meterpreter > ?
It will display a list of available commands with a description of each. From here you can run a module, review the target hosts files and get networking information.To shut down a session from the shell use
quit
.
Meterpreter Shell Commands
1Core Commands2=============34Command Description5------- -----------6? Help menu7background Backgrounds the current session8bg Alias for background9bgkill Kills a background meterpreter script10bglist Lists running background scripts11bgrun Executes a meterpreter script as a background thread12channel Displays information or control active channels13close Closes a channel14disable_unicode_encoding Disables encoding of unicode strings15enable_unicode_encoding Enables encoding of unicode strings16exit Terminate the meterpreter session17get_timeouts Get the current session timeout values18guid Get the session GUID19help Help menu20info Displays information about a Post module21irb Open an interactive Ruby shell on the current session22load Load one or more meterpreter extensions23machine_id Get the MSF ID of the machine attached to the session24migrate Migrate the server to another process25pivot Manage pivot listeners26pry Open the Pry debugger on the current session27quit Terminate the meterpreter session28read Reads data from a channel29resource Run the commands stored in a file30run Executes a meterpreter script or Post module31secure (Re)Negotiate TLV packet encryption on the session32sessions Quickly switch to another session33set_timeouts Set the current session timeout values34sleep Force Meterpreter to go quiet, then re-establish session.35transport Change the current transport mechanism36use Deprecated alias for "load"37uuid Get the UUID for the current session38write Writes data to a channel394041Stdapi: File system Commands42============================4344Command Description45------- -----------46cat Read the contents of a file to the screen47cd Change directory48checksum Retrieve the checksum of a file49cp Copy source to destination50dir List files (alias for ls)51download Download a file or directory52edit Edit a file53getlwd Print local working directory54getwd Print working directory55lcd Change local working directory56lls List local files57lpwd Print local working directory58ls List files59mkdir Make directory60mv Move source to destination61pwd Print working directory62rm Delete the specified file63rmdir Remove directory64search Search for files65show_mount List all mount points/logical drives66upload Upload a file or directory676869Stdapi: Networking Commands70===========================7172Command Description73------- -----------74arp Display the host ARP cache75getproxy Display the current proxy configuration76ifconfig Display interfaces77ipconfig Display interfaces78netstat Display the network connections79portfwd Forward a local port to a remote service80resolve Resolve a set of host names on the target81route View and modify the routing table828384Stdapi: System Commands85=======================8687Command Description88------- -----------89clearev Clear the event log90drop_token Relinquishes any active impersonation token.91execute Execute a command92getenv Get one or more environment variable values93getpid Get the current process identifier94getprivs Attempt to enable all privileges available to the current process95getsid Get the SID of the user that the server is running as96getuid Get the user that the server is running as97kill Terminate a process98localtime Displays the target system's local date and time99pgrep Filter processes by name100pkill Terminate processes by name101ps List running processes102reboot Reboots the remote computer103reg Modify and interact with the remote registry104rev2self Calls RevertToSelf() on the remote machine105shell Drop into a system command shell106shutdown Shuts down the remote computer107steal_token Attempts to steal an impersonation token from the target process108suspend Suspends or resumes a list of processes109sysinfo Gets information about the remote system, such as OS110111112Stdapi: User interface Commands113===============================114115Command Description116------- -----------117enumdesktops List all accessible desktops and window stations118getdesktop Get the current meterpreter desktop119idletime Returns the number of seconds the remote user has been idle120keyboard_send Send keystrokes121keyevent Send key events122keyscan_dump Dump the keystroke buffer123keyscan_start Start capturing keystrokes124keyscan_stop Stop capturing keystrokes125mouse Send mouse events126screenshare Watch the remote user's desktop in real time127screenshot Grab a screenshot of the interactive desktop128setdesktop Change the meterpreters current desktop129uictl Control some of the user interface components130131132Stdapi: Webcam Commands133=======================134135Command Description136------- -----------137record_mic Record audio from the default microphone for X seconds138webcam_chat Start a video chat139webcam_list List webcams140webcam_snap Take a snapshot from the specified webcam141webcam_stream Play a video stream from the specified webcam142143144Stdapi: Audio Output Commands145=============================146147Command Description148------- -----------149play play an audio file on target system, nothing written on disk150151152Priv: Elevate Commands153======================154155Command Description156------- -----------157getsystem Attempt to elevate your privilege to that of local system.158159160Priv: Password database Commands161================================162163Command Description164------- -----------165hashdump Dumps the contents of the SAM database166167168Priv: Timestomp Commands169========================170171Command Description172------- -----------173timestomp Manipulate file MACE attributes
Manage your Shell Session
The Shell session page provides you with the following information:
- **Session - **Session number and target host address. In the image above this is
Session 2 on 127.0.0.1
- **Session Type - **The type of payload and module used to open the session.
- Information - Any information on how the session was opened. If this was the result of a bruteforce attack it will include the authentication type and credential pair used.
- Attack Module - Exploit used to open the session.
- **Available Actions - **All the available actions that can be taken.
- **Session History - **A detailed list of all actions taken during an open session.
- **Post-Exploitation Modules - **Modules available to run based on the OS and payload type.
View Available Shell Actions
- Under “Active Session” select a session that has a “Type” of “Shell”.
- Review the shell session page. From this page, you can launch a shell and run post-exploitation actions. Since this is a shell session, the available “Post-Exploitation Modules” will not be the same as a Meterpreter session. They will depend on the exploit used.
The Shell session page has the following information:
- **Session - **Session number and target host address. In the image above this is
Session 2 on 127.0.0.1
- **Session Type - **The type of payload and module used to open the session.
- Information - Any information on how the session was opened. If this was the result of a bruteforce attack it will include the authentication type and credential pair used.
- Attack Module - Exploit used to open the session.
- **Available Actions - **All the available actions that can be taken.
- **Session History - **A detailed list of all actions taken during an open session.
- **Post-Exploitation Modules - **Modules available to run based on the OS and payload type.
Launch a Command Shell
Under “Available Actions” click Command Shell. It will then open a blank terminal.
The session ID and the target host address are displayed at the top of the command shell. In this example, the session ID is : Metasploit - Mdm::Session ID # 1 (127.0.0.1) SSH vagrant:vagrant (127.0.0.1:22)
At the bottom is the shell input. Shell >
The commands available for the shell will depend on the target host OS.