Windows
Create new user
net user mylocaladmin p@ssw0rd! /add /expires:never
net localgroup administrators mylocaladmin /addCreate user mylocaladmin with password p@ssw0rd! and add it to administrators group.
Change registry settings to allow local administrator accounts to perform administrative tasks remotely without restrictions
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /fCreate service
Make a service, with autostart. Before need prepare special payload, that is a service binary.
sc.exe create "monitexp" binPath= "C:\PathToServiceBinary" type= own start= autoThen start service
Start-Service -Name "monitexp"Background jobs
$job = Start-Job { c:/ProgramData/file.exe -args }Receive output
Scheduled task
schtasks.exe
Task create:
Task info
Force the task to start:
Delete task:
Provide RDP access
Turn on RDP
Bypass Restricted Admin Mode
Connect
Go based binary to create local admin
Registry
What are Run keys?
There are two different types of run keys: Those that get run once and those that get run every time the user logs in.
The following key get run everytime a specific user logs in. You will have to specify the SID of the user:
The following registry key runs every time any user logs into the machine:
The run once keys are only executed once. If your malware uses these keys to persist, then it should contain a function to add this key every time it gets executed.
Command Prompt / CMD
With reg add KEY_NAME /V VALUE_NAME /d DATA /f you can add a new key.
KEY_NAMEshould be the registry key name, e.g. “run once key”.VALUE_NAMEshould be the name of the entry.DATAshould be the data of the entry, for example the path to your malicious executable.
Code
Of course you can also implement the creation of a registry key in your code. In C# you can do that with the following code:
Registry run keys
HKCU
HKLM
HKCU\Software\Microsoft\Windows\CurrentVersion\RunHKLM\Software\Microsoft\Windows\CurrentVersion\Run
DIfference: HKCU → for current user only, HKLM → for all
there are two more registry locations that could allow red teams to achieve persistence by executing either an arbitrary payload or a DLL. These will be executed during logon and require admin level privileges.
Image File Execution Options (IFEO)
The hexadecimal value 0x200 in the “GlobalFlag” registry key enables the silent exit monitoring for the notepad process.
The ReportingMode registry key enables the Windows Error Reporting process (WerFault.exe) which will be the parent process of the “MonitorProcess” pentestlab.exe.
When the notepad process is killed (user has closed the notepad application) the payload will be executed and the communication will establish with the command and control.
Last updated
