githubEdit

Persistence with CS

RUN Key

cd C:\Users\pchilds\AppData\Local\Microsoft\WindowsApps
cp C:\Payloads\http_x64.exe C:\Scratch\<BLENDY NAME>
upload C:\Payloads\<BLENDY NAME>

reg_set HKCU Software\Microsoft\Windows\CurrentVersion\Run <KEY NAME> REG_EXPAND_SZ %LOCALAPPDATA%\Microsoft\WindowsApps\<BLENDY NAME>

reg_query HKCU Software\Microsoft\Windows\CurrentVersion\Run <KEY NAME>

Logon Script

ONLY WHEN USER LOGS IN

The HKCU\Environment registry key contains the user's environment variables, such as %Path% and %TEMP%.

An adversary can add another value to this key called UserInitMprLogonScript [T1037.001arrow-up-right].

reg_set HKCU Environment UserInitMprLogonScript REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\<BLENDY NAME>

reg_query HKCU Environment UserInitMprLogonScript

PowerShell Profile

ONLY WHEN USER OPENS POWERSHELL The PowerShell console supports the following basic profile files. These file paths are the default locations.

  • All Users, All Hosts - $PSHOME\Profile.ps1

  • All Users, Current Host - $PSHOME\Microsoft.PowerShell_profile.ps1

  • Current User, All Hosts - $HOME\Documents\WindowsPowerShell\Profile.ps1

  • Current user, Current Host - $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 If the profile and/or directory doesn't exist, just create it.

LOCAL It's important not to put any code into the profile that will block because the user will not be presented with an input prompt until the profile script has finished executing. Some workarounds include executing the payload via the Start-Jobarrow-up-right cmdlet.

Then upload the profile to the user's WindowsPowerShell directory.

Scheduled Tasks

AT BOOT RUN BINARY SYSTEM

AT BOOT RUN BINARY USER BACKGROUNDED NO UI

AT USER LOGON RUN BINARY

Create the task, UI will open, select your XML task definition

Service Persistence

Startup Folder

Programs in the user's startup folder will also run automatically on login. Look in %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup.

COM Hijacking

COM provides an interoperability standard so that applications written in different languages can reuse the same software libraries.

Every COM object is tracked in the registry by a unique identifier called a CLSID (which are just GUIDs), and can be found in HKEY_CLASSES_ROOT\CLSID.

Under each entry, you will find another key called InProcServer32 or LocalServer32, and within those keys will be a path on disk to the DLL or EXE (respectively) that provides the COM functionality.

COM hijacking is a technique [T1546.015arrow-up-right] where an adversary can change or leverage a COM entry to trick an application into loading/executing their malicious code, instead of the intended COM object.

Finding COM Hijacks

Set the below filters in procmon

  • The Operation is RegOpenKey.

  • The Path contains InprocServer32 or LocalServer32.

  • The Result is NAME NOT FOUND.

Example known good COM Hijack: DllHost.exe: HKCU\Software\Classes\CLSID\{AB8902B4-09CA-4bb6-B78D-A8F59079A8D5}\InprocServer32.

This key exists in HKLM but not HKCU:

Add the below registry values to perform the hijack

After logging out and back in this will trigger the hijack and give you a beacon!

Last updated