Sessions and Jobs
Overview
Sessions and jobs in Metasploit enable penetration testers to manage multiple ongoing tasks, maintain access to exploited systems, and organize their workflows. This chapter focuses on understanding, creating, and managing sessions and jobs effectively.
Sessions in Metasploit
A session is an active connection between the attacker and the target system, established after a successful exploit. Sessions allow interaction with compromised systems through Meterpreter shells, command-line interfaces, or other payload connections.
Working with Sessions
List Active Sessions:
View all open sessions:
Interact with a Session:
Switch to a specific session:
Background a Session:
Send an active session to the background:
Alternatively, use
Ctrl+Z
to background a session.
Terminate a Session:
End a specific session:
Kill all active sessions:
View Session Information:
Display details about a specific session:
Jobs in Metasploit
A job is a background task running in Metasploit. Jobs are often used for long-running tasks, such as exploit handlers or auxiliary modules like scanners.
Working with Jobs
List Active Jobs:
Display all running jobs:
Stop a Job:
Terminate a specific job:
Kill all active jobs:
Run a Module as a Job:
Execute an exploit or auxiliary module in the background:
View Job Information:
Display detailed information about a job:
Using Sessions and Jobs Together
Exploit and Maintain Access:
Run an exploit in the background while monitoring active sessions:
Link Modules to a Session:
Use post-exploitation modules on an existing session:
Switch Between Sessions:
Interact with multiple compromised systems by switching between sessions:
Convert a Session to a Job:
Background a session to free up the console for other tasks:
Practical Example: Meterpreter Session
Create a Session:
Use an exploit to gain access:
Interact with the Session:
Check active sessions:
Interact with the session:
Background the Session:
Run a Post-Exploitation Module:
Gather system information from the target:
Best Practices
Organize Sessions and Jobs:
Regularly list and terminate unused sessions and jobs to avoid conflicts.
Track Active Sessions:
Use meaningful notes or labels to identify each session (e.g., IP or hostname).
Monitor Resource Usage:
Avoid running too many concurrent jobs or sessions to prevent performance issues.
Background Long-Running Tasks:
Always background tasks like handlers or scanners to free up the console.
Command Cheatsheet
sessions
List all active sessions.
sessions -i <id>
Interact with a specific session.
sessions -k <id>
Terminate a specific session.
sessions -K
Kill all active sessions.
jobs
List all running jobs.
jobs -k <id>
Terminate a specific job.
jobs -K
Kill all active jobs.
exploit -j
Run an exploit as a background job.
background
Background the current session.