Now let's turn our attention to sessions in the Metasploit Framework.
Sessions are connections to compromised systems in our testing.
Sessions are a great tool when you're working on projects
where there are multiple targets or there are multiple
vulnerabilities that have been exploited.
Metasploit allows you to have multiple sessions to
compromised systems open at the same time.
The sessions management system allows you to switch between them easily.
You can manage those open sessions to switch back to interacting
with the target system or terminate open sessions.
Sessions also facilitate post‑exploitation since you can load
post‑modules and specify which open session to utilize.
You need to begin managing sessions once you have a compromised target
with a remote command shell or Meterpreter open.
Once you're in an open session,
you may need to get back to the Metasploit console.
To do that, hit Ctrl+Z.
This will prompt you to background the current session.
Answer Yes to return to the Metasploit console.
Once back at the console, you can list your current sessions.
You can also terminate any open sessions.
There are several options for managing sessions using the sessions command,
which we'll describe next.
To see all of the sessions, use the sessions command with one of these options.
You can see the current session with ‑l or more
details with the ‑v and ‑x options.
The ‑d option lists inactive sessions.
To keep things clear,
you can apply a name to a session with the ‑n option and a name.
You can also attempt to upgrade command shell‑based
sessions to Meterpreter with ‑u.
Eventually, your work in the sessions will be complete.
When you escape back to the Metasploit console,
you can end those sessions as needed.
You can either terminate a specific session with a
‑k option and the session number,
or you can terminate all sessions with a ‑K. Now I would like to demonstrate
how to manage sessions in the Metasploit Framework console.
We'll start with a listing of the existing sessions.
Then we'll interact with an open session. We'll execute a
post‑module through an existing session. And, finally, we'll
terminate some of those sessions.
Let's get started. Here we are back in the Metasploit console.
The sessions command is used to manage the sessions.
Here's the help documentation.
Let's see what sessions we have open currently.
Here's the same session information with some more details.
We will select session number 1 and connect to it.
This one still works.
Let's escape from this one with a Ctrl+Z. When you do that,
it will ask if you want to background the session. We will say Yes.
Now let's run a post‑module on session 1.
This particular module checks to see if the target is running as a virtual
machine and what kind. We can see that this machine is running as a VM in
Virtualbox. Again, here's our list of sessions.
Let's terminate session 2.
And now let's just terminate all of them.
So that's a quick demo of managing sessions in the Metasploit Framework console.