Msfvenom
Introduction
Msfvenom is the standalone command-line utility within the Metasploit Framework used to generate and encode custom payloads.
Basic usage syntax
Commands
List all the msfvenom payloads
List all the supported output formats
Generate a Reverse TCP Meterpreter payload for Windows
(This command generates a Windows executable file (payload.exe
) containing a reverse TCP Meterpreter payload that connects back to the attacker's machine at 192.168.1.100
on port 4444
)
Generate and encoded payload
(This command generates a Linux ELF executable (payload.elf
) containing a reverse TCP Meterpreter payload, encoded five times using the x86/shikata_ga_nai
encoder)
Generate a python script for reverse shell
Generate a PHP code for reverse shell
(Note: You need to edit the reverse_shell.php file to convert it into a working PHP file by removing comments and adding closing tag)
Multi Handler
It is a msf module required to recieve and listen to the incoming connections.
For using it, open up the msfconsole prompt using msfconsole
command, then follow the given workflow:
(The payload should be same as that used before to generate the msfvenom payload)
(The lhost value should be the IP address for your local machine)
(Set the unused port, which is the same as the one used in the msfvenom payload)
Some payloads
php/meterpreter/reverse_php
raw
.php
python/meterpreter/reverse_php
raw
.py
linux/x86/meterpreter/reverse_php
elf (linux executable and linkable format)
.elf
windows/meterpreter/reverse_php
exe
.exe
cmd/unix/reverse_python
raw
.py
windows/meterpreter/reverse_php
asp
.asp
php/meterpreter_reverse_php
raw
.php
Note: You can view the required payload by using grep
command along with the command to list the msfvenom payloads (msfvenom -l paylaods
)
Example
Here is an example showcasing the basic workflow (We have access to the target machine and we want to create a reverse shell):
First connect to the target machine via
ssh
Create a payload for reverse shell after connecting to the target machine (on local machine)
Then host it using python's http.server module (on local machine)
(Alternatively, you can use Apache server in your local machine to host it)
Download the created reverse shell file in the accessed target machine (file was hosted in the given port on your local machine)
Listen to the connection in your local machine using Multi Handler
Finally run the .elf file for creating meterpreter session in the target machine connection
(You may need to give executable permission to the rev_shell.elf file as: sudo chmod 777 rev_shell.elf
)
Hence, you will have the meterpreter session in your local machie which was listening to connections using Multi Handler.
Last updated