#readwise
# Using the Metasploit Framework - Sessions

## Metadata
- Author: [[Hack The Box]]
- Full Title: Using the Metasploit Framework - Sessions
- URL: https://academy.hackthebox.com/module/39/section/415
## Summary
MSFconsole allows users to manage multiple sessions for running exploits simultaneously. Users can background a session to keep it running while launching other modules. To view active sessions, the command `sessions` can be used, and specific sessions can be interacted with using `sessions -i [no.]`. Jobs can also be created to run tasks in the background, and users can list or terminate these jobs with specific commands.
## Highlights
MSFconsole can manage multiple modules at the same time. This is one of the many reasons it provides the user with so much flexibility. This is done with the use of `Sessions`, which creates dedicated control interfaces for all of your deployed modules. Once several sessions are created, we can switch between them and link a different module to one of the backgrounded sessions to run on it or turn them into jobs. Note that once a session is placed in the background, it will continue to run, and our connection to the target host will persist. Sessions can, however, die if something goes wrong during the payload runtime, causing the communication channel to tear down. ([View Highlight](https://read.readwise.io/read/01jrxd3qtf7febkm34q58s3ppg))
---
While running any available exploits or auxiliary modules in `msfconsole`, we can background the session as long as they form a channel of communication with the target host. This can be done either by pressing the `[CTRL] + [Z]` key combination or by typing the `background` command in the case of Meterpreter stages. ([View Highlight](https://read.readwise.io/read/01jrxd4qeqm8dbsqp8mevghd0n))
---
We can use the `sessions` command to view our currently active sessions. ([View Highlight](https://read.readwise.io/read/01jrxd4y2tj9zcmgwwzpvk2tr0))
---
You can use the `sessions -i [no.]` command to open up a specific session. ([View Highlight](https://read.readwise.io/read/01jrxd58bnqnfbhy83qh334c29))
---
This is specifically useful when we want to run an additional module on an already exploited system with a formed, stable communication channel. This can be done by backgrounding our current session, which is formed due to the success of the first exploit, searching for the second module we wish to run, and, if made possible by the type of module selected, selecting the session number on which the module should be run. This can be done from the second module's `show options` menu. Usually, these modules can be found in the `post` category, referring to Post-Exploitation modules. The main archetypes of modules in this category consist of credential gatherers, local exploit suggesters, and internal network scanners. ([View Highlight](https://read.readwise.io/read/01jrxd7brn548xjvstx29h2mx8))
---
If, for example, we are running an active exploit under a specific port and need this port for a different module, we cannot simply terminate the session using `[CTRL] + [C]`. If we did that, we would see that the port would still be in use, affecting our use of the new module. So instead, we would need to use the `jobs` command to look at the currently active tasks running in the background and terminate the old ones to free up the port. ([View Highlight](https://read.readwise.io/read/01jrxd8v62d8mwj59574yzgdkh))
---
When we run an exploit, we can run it as a job by typing `exploit -j`. Per the help menu for the `exploit` command, adding `-j` to our command. Instead of just `exploit` or `run`, will "run it in the context of a job." ([View Highlight](https://read.readwise.io/read/01jrxdan7b868mch4qxxa76wge))
---
To list all running jobs, we can use the `jobs -l` command. To kill a specific job, look at the index no. of the job and use the `kill [index no.]` command. Use the `jobs -K` command to kill all running jobs. ([View Highlight](https://read.readwise.io/read/01jrxdad2fyrbcbzc2fxsgkf5w))
---