20. Metasploit Lab Environment
To implement these techniques in a lab environment, let's create a setup where we can safely test bypassing AV/EDR, fileless execution, persistence, and privilege escalation. Here’s a detailed plan:
Lab Environment Setup¶
1. Required Tools¶
- Attacker Machine: Kali Linux or Parrot OS with Metasploit installed.
- Target Machine: Windows 10 or Windows Server 2019.
- Disable real-time protection to simulate bypassed AV/EDR initially.
- Use a VM snapshot for safe restoration.
2. Network Configuration¶
- Use an isolated NAT or Host-Only network in your hypervisor (VirtualBox, VMware).
- Configure IPs:
- Attacker:
192.168.1.10 - Target:
192.168.1.20
- Attacker:
Bypassing AV/EDR¶
Let’s create a stealthy reverse shell payload and execute it on the target.
Steps:¶
-
Generate an Encoded Payload:
-
Obfuscate Using PEzor:
-
Install and run:
-
Output:
encoded_payload.exe_obfuscated. -
Deliver the Payload:
-
Host it via HTTP:
-
Download on the target:
-
-
Execute on the Target:
-
Set Up Listener on Attacker:
Fileless Execution¶
Run the payload directly in memory.
Steps:¶
-
Generate a PowerShell Payload:
-
Host the Script:
-
Execute with PowerShell:
Persistence¶
Use Meterpreter to maintain access.
Steps:¶
-
Meterpreter Persistence Script:
-
Registry Key:
-
Create persistence manually:
-
-
Scheduled Task:
Privilege Escalation¶
Use Metasploit or manual techniques.
Steps:¶
-
Exploit Suggestion: Run the Local Exploit Suggester:
-
Exploit Services: If a service has weak permissions:
-
Bypass UAC:
Testing Workflow¶
1. Deploy the Payload¶
Choose a method:
- Dropper (encoded EXE).
- Fileless (PowerShell loader).
2. Monitor Results¶
-
On the attacker machine:
-
Dump credentials:
-
Dump password hashes:
-
3. Validate Persistence¶
- Reboot the target and verify Meterpreter reconnects.
4. Escalate Privileges¶
Use suggested exploits or weak service permissions.