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_NAME should be the registry key name, e.g. โrun once keyโ.
VALUE_NAME should be the name of the entry.
DATA should 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:
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.
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.