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:

  1. Under “Active Sessions” select a session that has a “Type” of “Meterpreter”.
  1. 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

1
Core Commands
2
=============
3
4
Command Description
5
------- -----------
6
? Help menu
7
background Backgrounds the current session
8
bg Alias for background
9
bgkill Kills a background meterpreter script
10
bglist Lists running background scripts
11
bgrun Executes a meterpreter script as a background thread
12
channel Displays information or control active channels
13
close Closes a channel
14
disable_unicode_encoding Disables encoding of unicode strings
15
enable_unicode_encoding Enables encoding of unicode strings
16
exit Terminate the meterpreter session
17
get_timeouts Get the current session timeout values
18
guid Get the session GUID
19
help Help menu
20
info Displays information about a Post module
21
irb Open an interactive Ruby shell on the current session
22
load Load one or more meterpreter extensions
23
machine_id Get the MSF ID of the machine attached to the session
24
migrate Migrate the server to another process
25
pivot Manage pivot listeners
26
pry Open the Pry debugger on the current session
27
quit Terminate the meterpreter session
28
read Reads data from a channel
29
resource Run the commands stored in a file
30
run Executes a meterpreter script or Post module
31
secure (Re)Negotiate TLV packet encryption on the session
32
sessions Quickly switch to another session
33
set_timeouts Set the current session timeout values
34
sleep Force Meterpreter to go quiet, then re-establish session.
35
transport Change the current transport mechanism
36
use Deprecated alias for "load"
37
uuid Get the UUID for the current session
38
write Writes data to a channel
39
40
41
Stdapi: File system Commands
42
============================
43
44
Command Description
45
------- -----------
46
cat Read the contents of a file to the screen
47
cd Change directory
48
checksum Retrieve the checksum of a file
49
cp Copy source to destination
50
dir List files (alias for ls)
51
download Download a file or directory
52
edit Edit a file
53
getlwd Print local working directory
54
getwd Print working directory
55
lcd Change local working directory
56
lls List local files
57
lpwd Print local working directory
58
ls List files
59
mkdir Make directory
60
mv Move source to destination
61
pwd Print working directory
62
rm Delete the specified file
63
rmdir Remove directory
64
search Search for files
65
show_mount List all mount points/logical drives
66
upload Upload a file or directory
67
68
69
Stdapi: Networking Commands
70
===========================
71
72
Command Description
73
------- -----------
74
arp Display the host ARP cache
75
getproxy Display the current proxy configuration
76
ifconfig Display interfaces
77
ipconfig Display interfaces
78
netstat Display the network connections
79
portfwd Forward a local port to a remote service
80
resolve Resolve a set of host names on the target
81
route View and modify the routing table
82
83
84
Stdapi: System Commands
85
=======================
86
87
Command Description
88
------- -----------
89
clearev Clear the event log
90
drop_token Relinquishes any active impersonation token.
91
execute Execute a command
92
getenv Get one or more environment variable values
93
getpid Get the current process identifier
94
getprivs Attempt to enable all privileges available to the current process
95
getsid Get the SID of the user that the server is running as
96
getuid Get the user that the server is running as
97
kill Terminate a process
98
localtime Displays the target system's local date and time
99
pgrep Filter processes by name
100
pkill Terminate processes by name
101
ps List running processes
102
reboot Reboots the remote computer
103
reg Modify and interact with the remote registry
104
rev2self Calls RevertToSelf() on the remote machine
105
shell Drop into a system command shell
106
shutdown Shuts down the remote computer
107
steal_token Attempts to steal an impersonation token from the target process
108
suspend Suspends or resumes a list of processes
109
sysinfo Gets information about the remote system, such as OS
110
111
112
Stdapi: User interface Commands
113
===============================
114
115
Command Description
116
------- -----------
117
enumdesktops List all accessible desktops and window stations
118
getdesktop Get the current meterpreter desktop
119
idletime Returns the number of seconds the remote user has been idle
120
keyboard_send Send keystrokes
121
keyevent Send key events
122
keyscan_dump Dump the keystroke buffer
123
keyscan_start Start capturing keystrokes
124
keyscan_stop Stop capturing keystrokes
125
mouse Send mouse events
126
screenshare Watch the remote user's desktop in real time
127
screenshot Grab a screenshot of the interactive desktop
128
setdesktop Change the meterpreters current desktop
129
uictl Control some of the user interface components
130
131
132
Stdapi: Webcam Commands
133
=======================
134
135
Command Description
136
------- -----------
137
record_mic Record audio from the default microphone for X seconds
138
webcam_chat Start a video chat
139
webcam_list List webcams
140
webcam_snap Take a snapshot from the specified webcam
141
webcam_stream Play a video stream from the specified webcam
142
143
144
Stdapi: Audio Output Commands
145
=============================
146
147
Command Description
148
------- -----------
149
play play an audio file on target system, nothing written on disk
150
151
152
Priv: Elevate Commands
153
======================
154
155
Command Description
156
------- -----------
157
getsystem Attempt to elevate your privilege to that of local system.
158
159
160
Priv: Password database Commands
161
================================
162
163
Command Description
164
------- -----------
165
hashdump Dumps the contents of the SAM database
166
167
168
Priv: Timestomp Commands
169
========================
170
171
Command Description
172
------- -----------
173
timestomp 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

  1. Under “Active Session” select a session that has a “Type” of “Shell”.
  1. 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.