Local persistence
A number of techniques can be employed to maintain persistence on a Windows system, with the goal of maintaining access on the systems across restarts or other forms of interruption. For a more comprehensive list of the persistence that can be employed, refer to the entry for persistence in the MITRE ATT&CK matrices (TA0003).
Some of the techniques mentioned below can be accomplished through Cobalt Strike
's execute-assembly
(or InlineExecute-Assembly
) using the SharPersist
C# utility.
The forensics artefacts left by (some) of the persistence techniques detailed below are detailed in the [DFIR] Windows - TTPs analysis - Local persistence
note.
Local Administrator account
The following net user
commands can be used to create and add a local account to the local Administrators
group (directly or periodically through a Scheduled Task
):
Sticky Keys or Utilman backdoors
Both the Sticky Keys
(sethc.exe
) and Utilman
(utilman.exe
) utilities can be launched at the login screen before authentication as NT AUTHORITY\SYSTEM
. A graphical access to the host login prompt is needed in order to make use of this backdoor mechanism. Indeed, to remotely leverage persistence through Sticky Keys
or Utilman
:
RDP
must be enabled and theRDP
service accessible remotely over the network. Refer to theActivate RDP
andWindows Firewall
sections of the present note to activeRDP
and configure a rule allowing inboundRDP
access on the local host.The
RDP
'sNetwork Level Authentication (NLA)
security mechanism must be deactivated if no valid credentials are known.
To access a host remotely in RDP
, the user used must have the SeRemoteInteractivePrivilege
, granted by default to the members of the Remote Desktop Users
local group of the host. The following net localgroup
commands can be used to add the specified user in this group:
The sethc.exe
is launched after pushing the Maj
key five times and the utilman.exe
can be started using the Win + U
keys.
Windows startup folders
The Windows startup folders
contains shortcut links
(.lnk
) that will be executed upon any user log in (All Users
start up
folder) or when the associated user logs in (Current Users
start up
folders).
The startup folders
are located at the following paths:
A shortcut link
file can be created manually through the Windows Explorer
:
PowerShell can also be used to create and customize a shortcut link
file:
SharPersist
supports persistence techniques through the current user's startup folder
. SharPersist
presents the advantage of performing timestomping on the created shortcut link
file and setting the file icon to Internet Explorer
for increased stealth.
ASEP registry keys
A number of registry keys, known as Auto-Start Extensibility Points (ASEP)
registry keys, are run whenever the system is booted or a specific user logs in. The ASEP
keys under HKEY_LOCAL_MACHINE (HKLM)
are run every time the system is started, while the ASEP
keys under HKEY_CURRENT_USER (HKCU)
are only executed when the user associated with the keys logs on to the system.
For more information on ASEP
keys, including a more comprehensive list of ASEP
registry keys, refer to the [DFIR] Windows - TTPs analysis - Local persistence
note (ASEP registry keys
section).
RunOnce / Run / RunOnceEx
Among the most well known ASEP
keys, entries in the RunOnce
and Run
keys are executed respectively once or at every trigger (system startup or user logging depending on the keys being in HKLM
or HKCU
).
SharPersist
supports persistence techniques through a number of ASEP
keys, specified with the -k "<KEY_SPECIFIER>"
parameter:
hklmrun
:HKLM\Software\Microsoft\Windows\CurrentVersion\Run
hklmrunonce
:HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
hklmrunonceex
:HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
hkcurun
:HKCU\Software\Microsoft\Windows\CurrentVersion\Run
hkcurunonce
:HKCU\Software\Microsoft\Windows\CurrentVersion\Run
logonscript
:HKCU\Environment\
, key nameUserInitMprLogonScript
. Windows logon script executed at logon, that can be set at a domain level. May overwrite a legitimate logon script.stickynotes
:HKCU\Software\Microsoft\Windows\CurrentVersion\Run\
, key nameRESTART_STICKY_NOTES
. Does not apply to Windows 10+. TheRESTART_STICKY_NOTES
registry key is set by theSticky Notes
utility to persist across reboot. TheSticky Notes
utility re-set theRESTART_STICKY_NOTES
key after being opened.userinit
:HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
, key nameUserinit
.
Scheduled tasks
Windows services
WMI subscription
TODO
https://www.blackhat.com/docs/us-15/materials/us-15-Graeber-Abusing-Windows-Management-Instrumentation-WMI-To-Build-A-Persistent%20Asynchronous-And-Fileless-Backdoor-wp.pdf
DLL hijacking
TODO
https://www.blackarrow.net/leveraging-microsoft-teams-to-persist-and-cover-up-cobalt-strike-traffic/
References
https://github.com/mandiant/SharPersist/blob/master/Brett%20Hawkins%20SharPersist%20DerbyCon%202019.pdf
https://oddvar.moe/2018/03/21/persistence-using-runonceex-hidden-from-autoruns-exe/
https://h4wkst3r.blogspot.com/2018/05/persistence-with-sticky-notes-registry.html
https://www.ired.team/offensive-security/persistence/windows-logon-helper
Last updated